Skip to content

Commit a1932df

Browse files
Eric Amodiosbatten
andcommitted
Changes moveViews command to "preserve" view state
When you move views via the command, they won't get expanded or made visible Co-authored-by: SteVen Batten <stbatt@microsoft.com>
1 parent 366f97b commit a1932df

3 files changed

Lines changed: 57 additions & 48 deletions

File tree

src/vs/workbench/api/common/apiCommands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { IWorkspacesService, hasWorkspaceFileExtension, IRecent } from 'vs/platf
1616
import { Schemas } from 'vs/base/common/network';
1717
import { ILogService } from 'vs/platform/log/common/log';
1818
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
19-
import { IViewDescriptorService, IViewsService } from 'vs/workbench/common/views';
19+
import { IViewDescriptorService, IViewsService, ViewVisibilityState } from 'vs/workbench/common/views';
2020

2121
// -----------------------------------------------------------------
2222
// The following commands are registered on both sides separately.
@@ -279,7 +279,7 @@ CommandsRegistry.registerCommand('_workbench.action.moveViews', async function (
279279
for (const viewId of options.viewIds) {
280280
const viewDescriptor = viewDescriptorService.getViewDescriptorById(viewId);
281281
if (viewDescriptor?.canMoveView) {
282-
viewDescriptorService.moveViewsToContainer([viewDescriptor], destination);
282+
viewDescriptorService.moveViewsToContainer([viewDescriptor], destination, ViewVisibilityState.Default);
283283
}
284284
}
285285

src/vs/workbench/common/views.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,11 @@ export function getVisbileViewContextKey(viewId: string): string { return `${vie
509509

510510
export const IViewDescriptorService = createDecorator<IViewDescriptorService>('viewDescriptorService');
511511

512+
export enum ViewVisibilityState {
513+
Default = 0,
514+
Expand = 1
515+
}
516+
512517
export interface IViewDescriptorService {
513518

514519
readonly _serviceBrand: undefined;
@@ -535,7 +540,7 @@ export interface IViewDescriptorService {
535540
getViewLocationById(id: string): ViewContainerLocation | null;
536541

537542
readonly onDidChangeContainer: Event<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }>;
538-
moveViewsToContainer(views: IViewDescriptor[], viewContainer: ViewContainer): void;
543+
moveViewsToContainer(views: IViewDescriptor[], viewContainer: ViewContainer, visibilityState?: ViewVisibilityState): void;
539544

540545
readonly onDidChangeLocation: Event<{ views: IViewDescriptor[], from: ViewContainerLocation, to: ViewContainerLocation }>;
541546
moveViewToLocation(view: IViewDescriptor, location: ViewContainerLocation): void;

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

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { ViewContainerLocation, IViewDescriptorService, ViewContainer, IViewsRegistry, IViewContainersRegistry, IViewDescriptor, Extensions as ViewExtensions } from 'vs/workbench/common/views';
6+
import { ViewContainerLocation, IViewDescriptorService, ViewContainer, IViewsRegistry, IViewContainersRegistry, IViewDescriptor, Extensions as ViewExtensions, ViewVisibilityState } from 'vs/workbench/common/views';
77
import { IContextKey, RawContextKey, IContextKeyService, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
88
import { IStorageService, StorageScope, IWorkspaceStorageChangeEvent } from 'vs/platform/storage/common/storage';
99
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
@@ -166,7 +166,7 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
166166
// This is needed when statically-registered views are moved to
167167
// other statically registered containers as they will both try to add on startup
168168
const viewsToAdd = containerData.views.filter(view => this.getViewContainerModel(viewContainer).allViewDescriptors.filter(vd => vd.id === view.id).length === 0);
169-
this.addViews(viewContainer, viewsToAdd);
169+
this.addViews(viewContainer, viewsToAdd, ViewVisibilityState.Default);
170170
}
171171
}
172172

@@ -197,7 +197,7 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
197197
const viewContainer = this.viewsRegistry.getViewContainer(viewId);
198198
const viewDescriptor = this.getViewDescriptorById(viewId);
199199
if (viewContainer && viewDescriptor) {
200-
this.addViews(viewContainer, [viewDescriptor]);
200+
this.addViews(viewContainer, [viewDescriptor], ViewVisibilityState.Default);
201201
}
202202
}
203203
}
@@ -330,7 +330,7 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
330330
this.moveViewsToContainer([view], container);
331331
}
332332

333-
moveViewsToContainer(views: IViewDescriptor[], viewContainer: ViewContainer): void {
333+
moveViewsToContainer(views: IViewDescriptor[], viewContainer: ViewContainer, visibilityState?: ViewVisibilityState): void {
334334
if (!views.length) {
335335
return;
336336
}
@@ -339,7 +339,7 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
339339
const to = viewContainer;
340340

341341
if (from && to && from !== to) {
342-
this.moveViews(views, from, to);
342+
this.moveViews(views, from, to, visibilityState);
343343
this.cleanUpViewContainer(from.id);
344344
}
345345
}
@@ -376,9 +376,9 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
376376
return this.isGeneratedContainerId(viewContainerId) && !this.cachedViewContainerInfo.has(viewContainerId);
377377
}
378378

379-
private moveViews(views: IViewDescriptor[], from: ViewContainer, to: ViewContainer, skipCacheUpdate?: boolean): void {
379+
private moveViews(views: IViewDescriptor[], from: ViewContainer, to: ViewContainer, visibilityState: ViewVisibilityState = ViewVisibilityState.Expand): void {
380380
this.removeViews(from, views);
381-
this.addViews(to, views, true);
381+
this.addViews(to, views, visibilityState);
382382

383383
const oldLocation = this.getViewContainerLocation(from);
384384
const newLocation = this.getViewContainerLocation(to);
@@ -389,46 +389,44 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
389389

390390
this._onDidChangeContainer.fire({ views, from, to });
391391

392-
if (!skipCacheUpdate) {
393-
this.saveViewPositionsToCache();
394-
395-
const containerToString = (container: ViewContainer): string => {
396-
if (container.id.startsWith(ViewDescriptorService.COMMON_CONTAINER_ID_PREFIX)) {
397-
return 'custom';
398-
}
399-
400-
if (!container.extensionId) {
401-
return container.id;
402-
}
403-
404-
return 'extension';
405-
};
392+
this.saveViewPositionsToCache();
406393

407-
// Log on cache update to avoid duplicate events in other windows
408-
const viewCount = views.length;
409-
const fromContainer = containerToString(from);
410-
const toContainer = containerToString(to);
411-
const fromLocation = oldLocation === ViewContainerLocation.Panel ? 'panel' : 'sidebar';
412-
const toLocation = newLocation === ViewContainerLocation.Panel ? 'panel' : 'sidebar';
413-
414-
interface ViewDescriptorServiceMoveViewsEvent {
415-
viewCount: number;
416-
fromContainer: string;
417-
toContainer: string;
418-
fromLocation: string;
419-
toLocation: string;
394+
const containerToString = (container: ViewContainer): string => {
395+
if (container.id.startsWith(ViewDescriptorService.COMMON_CONTAINER_ID_PREFIX)) {
396+
return 'custom';
420397
}
421398

422-
type ViewDescriptorServiceMoveViewsClassification = {
423-
viewCount: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
424-
fromContainer: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
425-
toContainer: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
426-
fromLocation: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
427-
toLocation: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
428-
};
399+
if (!container.extensionId) {
400+
return container.id;
401+
}
429402

430-
this.telemetryService.publicLog2<ViewDescriptorServiceMoveViewsEvent, ViewDescriptorServiceMoveViewsClassification>('viewDescriptorService.moveViews', { viewCount, fromContainer, toContainer, fromLocation, toLocation });
403+
return 'extension';
404+
};
405+
406+
// Log on cache update to avoid duplicate events in other windows
407+
const viewCount = views.length;
408+
const fromContainer = containerToString(from);
409+
const toContainer = containerToString(to);
410+
const fromLocation = oldLocation === ViewContainerLocation.Panel ? 'panel' : 'sidebar';
411+
const toLocation = newLocation === ViewContainerLocation.Panel ? 'panel' : 'sidebar';
412+
413+
interface ViewDescriptorServiceMoveViewsEvent {
414+
viewCount: number;
415+
fromContainer: string;
416+
toContainer: string;
417+
fromLocation: string;
418+
toLocation: string;
431419
}
420+
421+
type ViewDescriptorServiceMoveViewsClassification = {
422+
viewCount: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
423+
fromContainer: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
424+
toContainer: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
425+
fromLocation: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
426+
toLocation: { classification: 'SystemMetaData', purpose: 'FeatureInsight' };
427+
};
428+
429+
this.telemetryService.publicLog2<ViewDescriptorServiceMoveViewsEvent, ViewDescriptorServiceMoveViewsClassification>('viewDescriptorService.moveViews', { viewCount, fromContainer, toContainer, fromLocation, toLocation });
432430
}
433431

434432
private cleanUpViewContainer(viewContainerId: string): void {
@@ -699,7 +697,7 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
699697
// Add views that were registered prior to this view container
700698
const viewsToRegister = this.getViewsByContainer(viewContainer).filter(view => this.getDefaultContainerById(view.id) !== viewContainer);
701699
if (viewsToRegister.length) {
702-
this.addViews(viewContainer, viewsToRegister);
700+
this.addViews(viewContainer, viewsToRegister, ViewVisibilityState.Default);
703701
this.contextKeyService.bufferChangeEvents(() => {
704702
viewsToRegister.forEach(viewDescriptor => this.getOrCreateMovableViewContextKey(viewDescriptor).set(!!viewDescriptor.canMoveView));
705703
});
@@ -751,7 +749,7 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
751749
});
752750
}
753751

754-
private addViews(container: ViewContainer, views: IViewDescriptor[], expandViews?: boolean): void {
752+
private addViews(container: ViewContainer, views: IViewDescriptor[], visibilityState: ViewVisibilityState = ViewVisibilityState.Default): void {
755753
// Update in memory cache
756754
this.contextKeyService.bufferChangeEvents(() => {
757755
views.forEach(view => {
@@ -760,7 +758,13 @@ export class ViewDescriptorService extends Disposable implements IViewDescriptor
760758
});
761759
});
762760

763-
this.getViewContainerModel(container).add(views.map(view => { return { viewDescriptor: view, collapsed: expandViews ? false : undefined, visible: expandViews }; }));
761+
this.getViewContainerModel(container).add(views.map(view => {
762+
return {
763+
viewDescriptor: view,
764+
collapsed: visibilityState === ViewVisibilityState.Default ? undefined : false,
765+
visible: visibilityState === ViewVisibilityState.Default ? undefined : true
766+
};
767+
}));
764768
}
765769

766770
private removeViews(container: ViewContainer, views: IViewDescriptor[]): void {

0 commit comments

Comments
 (0)