@@ -18,11 +18,12 @@ import { IContextMenuService } from 'vs/platform/contextview/browser/contextView
1818import { Widget } from 'vs/base/browser/ui/widget' ;
1919import { isUndefinedOrNull } from 'vs/base/common/types' ;
2020import { IColorTheme } from 'vs/platform/theme/common/themeService' ;
21- import { Emitter } from 'vs/base/common/event' ;
21+ import { Emitter , Event } from 'vs/base/common/event' ;
2222import { ViewContainerLocation , IViewDescriptorService } from 'vs/workbench/common/views' ;
2323import { IPaneComposite } from 'vs/workbench/common/panecomposite' ;
2424import { IComposite } from 'vs/workbench/common/composite' ;
2525import { CompositeDragAndDropData , CompositeDragAndDropObserver , IDraggedCompositeData , ICompositeDragAndDrop , Before2D } from 'vs/workbench/browser/dnd' ;
26+ import { generateUuid } from 'vs/base/common/uuid' ;
2627
2728export interface ICompositeBarItem {
2829 id : string ;
@@ -102,7 +103,7 @@ export class CompositeDragAndDrop implements ICompositeDragAndDrop {
102103
103104 const items = this . getItems ( ) ;
104105 const before = this . targetContainerLocation === ViewContainerLocation . Panel ? before2d ?. horizontallyBefore : before2d ?. verticallyBefore ;
105- return items . findIndex ( o => o . id === targetId ) + ( before ? 0 : 1 ) ;
106+ return items . filter ( o => o . visible ) . findIndex ( o => o . id === targetId ) + ( before ? 0 : 1 ) ;
106107 }
107108
108109 private canDrop ( data : CompositeDragAndDropData , targetCompositeId : string | undefined ) : boolean {
@@ -284,9 +285,9 @@ export class CompositeBar extends Widget implements ICompositeBar {
284285 this . updateCompositeSwitcher ( ) ;
285286 }
286287
287- addComposite ( { id, name, order } : { id : string ; name : string , order ?: number } ) : void {
288+ addComposite ( { id, name, order, requestedIndex } : { id : string ; name : string , order ?: number , requestedIndex ?: number } ) : void {
288289 // Add to the model
289- if ( this . model . add ( id , name , order ) ) {
290+ if ( this . model . add ( id , name , order , requestedIndex ) ) {
290291 this . computeSizes ( [ this . model . findItem ( id ) ] ) ;
291292 this . updateCompositeSwitcher ( ) ;
292293 }
@@ -674,17 +675,9 @@ class CompositeBarModel {
674675 this . _items = result ;
675676 }
676677
677- this . updateItemsOrder ( ) ;
678678 return hasChanges ;
679679 }
680680
681-
682- private updateItemsOrder ( ) : void {
683- if ( this . _items ) {
684- this . items . forEach ( ( item , index ) => { if ( item . order !== undefined ) { item . order = index ; } } ) ;
685- }
686- }
687-
688681 get visibleItems ( ) : ICompositeBarModelItem [ ] {
689682 return this . items . filter ( item => item . visible ) ;
690683 }
@@ -707,7 +700,7 @@ class CompositeBarModel {
707700 } ;
708701 }
709702
710- add ( id : string , name : string , order : number | undefined ) : boolean {
703+ add ( id : string , name : string , order : number | undefined , requestedIndex : number | undefined ) : boolean {
711704 const item = this . findItem ( id ) ;
712705 if ( item ) {
713706 let changed = false ;
@@ -721,11 +714,20 @@ class CompositeBarModel {
721714 changed = true ;
722715 }
723716
724- this . updateItemsOrder ( ) ;
725717 return changed ;
726718 } else {
727719 const item = this . createCompositeBarItem ( id , name , order , true , true ) ;
728- if ( isUndefinedOrNull ( order ) ) {
720+ if ( ! isUndefinedOrNull ( requestedIndex ) ) {
721+ let index = 0 ;
722+ let rIndex = requestedIndex ;
723+ while ( rIndex > 0 && index < this . items . length ) {
724+ if ( this . items [ index ++ ] . visible ) {
725+ rIndex -- ;
726+ }
727+ }
728+
729+ this . items . splice ( index , 0 , item ) ;
730+ } else if ( isUndefinedOrNull ( order ) ) {
729731 this . items . push ( item ) ;
730732 } else {
731733 let index = 0 ;
@@ -735,7 +737,6 @@ class CompositeBarModel {
735737 this . items . splice ( index , 0 , item ) ;
736738 }
737739
738- this . updateItemsOrder ( ) ;
739740 return true ;
740741 }
741742 }
@@ -744,7 +745,6 @@ class CompositeBarModel {
744745 for ( let index = 0 ; index < this . items . length ; index ++ ) {
745746 if ( this . items [ index ] . id === id ) {
746747 this . items . splice ( index , 1 ) ;
747- this . updateItemsOrder ( ) ;
748748 return true ;
749749 }
750750 }
@@ -780,8 +780,6 @@ class CompositeBarModel {
780780 // Make sure a moved composite gets pinned
781781 sourceItem . pinned = true ;
782782
783- this . updateItemsOrder ( ) ;
784-
785783 return true ;
786784 }
787785
0 commit comments