Skip to content

Commit d5eac26

Browse files
authored
Update meaning of order for composite bar (microsoft#98207)
* initial new order for composite bar * clean up
1 parent 84fe6dc commit d5eac26

5 files changed

Lines changed: 61 additions & 14 deletions

File tree

src/vs/workbench/browser/parts/activitybar/activitybarPart.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ export class ActivitybarPart extends Part implements IActivityBarService {
157157
hidePart: () => this.layoutService.setSideBarHidden(true),
158158
dndHandler: new CompositeDragAndDrop(this.viewDescriptorService, ViewContainerLocation.Sidebar,
159159
(id: string, focus?: boolean) => this.viewsService.openViewContainer(id, focus),
160-
(from: string, to: string, before?: Before2D) => this.compositeBar.move(from, to, before?.verticallyBefore)
160+
(from: string, to: string, before?: Before2D) => this.compositeBar.move(from, to, before?.verticallyBefore),
161+
() => this.compositeBar.getCompositeBarItems(),
161162
),
162163
compositeSize: 52,
163164
colors: (theme: IColorTheme) => this.getActivitybarItemColors(theme),
@@ -542,7 +543,7 @@ export class ActivitybarPart extends Part implements IActivityBarService {
542543
}
543544

544545
this.viewContainerDisposables.delete(viewContainer.id);
545-
this.hideComposite(viewContainer.id);
546+
this.removeComposite(viewContainer.id);
546547
}
547548

548549
private updateActivity(viewContainer: ViewContainer, viewContainerModel: IViewContainerModel): void {
@@ -619,6 +620,17 @@ export class ActivitybarPart extends Part implements IActivityBarService {
619620
}
620621
}
621622

623+
private removeComposite(compositeId: string): void {
624+
this.compositeBar.removeComposite(compositeId);
625+
626+
const compositeActions = this.compositeActions.get(compositeId);
627+
if (compositeActions) {
628+
compositeActions.activityAction.dispose();
629+
compositeActions.pinnedAction.dispose();
630+
this.compositeActions.delete(compositeId);
631+
}
632+
}
633+
622634
getPinnedViewContainerIds(): string[] {
623635
const pinnedCompositeIds = this.compositeBar.getPinnedComposites().map(v => v.id);
624636
return this.getViewContainers()

src/vs/workbench/browser/parts/compositeBar.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class CompositeDragAndDrop implements ICompositeDragAndDrop {
3939
private targetContainerLocation: ViewContainerLocation,
4040
private openComposite: (id: string, focus?: boolean) => Promise<IPaneComposite | null>,
4141
private moveComposite: (from: string, to: string, before?: Before2D) => void,
42+
private getItems: () => ICompositeBarItem[],
4243
) { }
4344

4445
drop(data: CompositeDragAndDropData, targetCompositeId: string | undefined, originalEvent: DragEvent, before?: Before2D): void {
@@ -61,12 +62,7 @@ export class CompositeDragAndDrop implements ICompositeDragAndDrop {
6162
return;
6263
}
6364

64-
this.viewDescriptorService.moveViewContainerToLocation(currentContainer, this.targetContainerLocation);
65-
66-
if (targetCompositeId) {
67-
this.moveComposite(currentContainer.id, targetCompositeId, before);
68-
}
69-
65+
this.viewDescriptorService.moveViewContainerToLocation(currentContainer, this.targetContainerLocation, this.getTargetIndex(targetCompositeId, before));
7066
this.openComposite(currentContainer.id);
7167
}
7268
}
@@ -100,6 +96,16 @@ export class CompositeDragAndDrop implements ICompositeDragAndDrop {
10096
return this.canDrop(data, targetCompositeId);
10197
}
10298

99+
private getTargetIndex(targetId: string | undefined, before2d: Before2D | undefined): number | undefined {
100+
if (!targetId) {
101+
return undefined;
102+
}
103+
104+
const items = this.getItems();
105+
const before = this.targetContainerLocation === ViewContainerLocation.Panel ? before2d?.horizontallyBefore : before2d?.verticallyBefore;
106+
return items.findIndex(o => o.id === targetId) + (before ? 0 : 1);
107+
}
108+
103109
private canDrop(data: CompositeDragAndDropData, targetCompositeId: string | undefined): boolean {
104110
const dragData = data.getData();
105111

@@ -668,9 +674,18 @@ class CompositeBarModel {
668674
}
669675
this._items = result;
670676
}
677+
678+
this.updateItemsOrder();
671679
return hasChanges;
672680
}
673681

682+
683+
private updateItemsOrder(): void {
684+
if (this._items) {
685+
this.items.forEach((item, index) => item.order = index);
686+
}
687+
}
688+
674689
get visibleItems(): ICompositeBarModelItem[] {
675690
return this.items.filter(item => item.visible);
676691
}
@@ -706,6 +721,8 @@ class CompositeBarModel {
706721
item.visible = true;
707722
changed = true;
708723
}
724+
725+
this.updateItemsOrder();
709726
return changed;
710727
} else {
711728
const item = this.createCompositeBarItem(id, name, order, true, true);
@@ -718,6 +735,8 @@ class CompositeBarModel {
718735
}
719736
this.items.splice(index, 0, item);
720737
}
738+
739+
this.updateItemsOrder();
721740
return true;
722741
}
723742
}
@@ -726,6 +745,7 @@ class CompositeBarModel {
726745
for (let index = 0; index < this.items.length; index++) {
727746
if (this.items[index].id === id) {
728747
this.items.splice(index, 1);
748+
this.updateItemsOrder();
729749
return true;
730750
}
731751
}
@@ -761,6 +781,8 @@ class CompositeBarModel {
761781
// Make sure a moved composite gets pinned
762782
sourceItem.pinned = true;
763783

784+
this.updateItemsOrder();
785+
764786
return true;
765787
}
766788

src/vs/workbench/browser/parts/panel/panelPart.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
144144

145145
this.dndHandler = new CompositeDragAndDrop(this.viewDescriptorService, ViewContainerLocation.Panel,
146146
(id: string, focus?: boolean) => (this.openPanel(id, focus) as Promise<IPaneComposite | undefined>).then(panel => panel || null),
147-
(from: string, to: string, before?: Before2D) => this.compositeBar.move(from, to, before?.horizontallyBefore)
147+
(from: string, to: string, before?: Before2D) => this.compositeBar.move(from, to, before?.horizontallyBefore),
148+
() => this.compositeBar.getCompositeBarItems()
148149
);
149150

150151
this.compositeBar = this._register(this.instantiationService.createInstance(CompositeBar, this.getCachedPanels(), {
@@ -211,7 +212,15 @@ export class PanelPart extends CompositePart<Panel> implements IPanelService {
211212
const isActive = activePanel?.getId() === panel.id || (!activePanel && this.getLastActivePanelId() === panel.id);
212213

213214
if (isActive || !this.shouldBeHidden(panel.id, cachedPanel)) {
214-
this.compositeBar.addComposite(panel);
215+
216+
// Override order
217+
const newPanel = {
218+
id: panel.id,
219+
name: panel.name,
220+
order: cachedPanel?.order === undefined ? panel.order : cachedPanel.order
221+
};
222+
223+
this.compositeBar.addComposite(newPanel);
215224

216225
// Pin it by default if it is new
217226
if (!cachedPanel) {

src/vs/workbench/common/views.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ export interface IViewContainerDescriptor {
5050

5151
readonly alwaysUseContainerInfo?: boolean;
5252

53-
readonly order?: number;
54-
5553
readonly focusCommand?: { id: string, keybindings?: IKeybindings };
5654

5755
readonly viewOrderDelegate?: ViewOrderDelegate;
@@ -61,6 +59,8 @@ export interface IViewContainerDescriptor {
6159
readonly extensionId?: ExtensionIdentifier;
6260

6361
readonly rejectAddedViews?: boolean;
62+
63+
order?: number;
6464
}
6565

6666
export interface IViewContainersRegistry {
@@ -510,7 +510,7 @@ export interface IViewDescriptorService {
510510
getViewContainerModel(viewContainer: ViewContainer): IViewContainerModel;
511511

512512
readonly onDidChangeContainerLocation: Event<{ viewContainer: ViewContainer, from: ViewContainerLocation, to: ViewContainerLocation }>;
513-
moveViewContainerToLocation(viewContainer: ViewContainer, location: ViewContainerLocation): void;
513+
moveViewContainerToLocation(viewContainer: ViewContainer, location: ViewContainerLocation, order?: number): void;
514514

515515
// Views
516516
getViewDescriptorById(id: string): IViewDescriptor | null;

src/vs/workbench/services/views/browser/viewDescriptorService.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
295295
return this.viewContainersRegistry.getDefaultViewContainer(location);
296296
}
297297

298-
moveViewContainerToLocation(viewContainer: ViewContainer, location: ViewContainerLocation): void {
298+
moveViewContainerToLocation(viewContainer: ViewContainer, location: ViewContainerLocation, order?: number): void {
299299
const from = this.getViewContainerLocation(viewContainer);
300300
const to = location;
301301
if (from !== to) {
@@ -304,6 +304,10 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
304304
const defaultLocation = this.isGeneratedContainerId(viewContainer.id) ? true : this.getViewContainerLocation(viewContainer) === this.getDefaultViewContainerLocation(viewContainer);
305305
this.getOrCreateDefaultViewContainerLocationContextKey(viewContainer).set(defaultLocation);
306306

307+
if (order !== undefined) {
308+
viewContainer.order = order;
309+
}
310+
307311
this._onDidChangeContainerLocation.fire({ viewContainer, from, to });
308312

309313
const views = this.getViewsByContainer(viewContainer);

0 commit comments

Comments
 (0)