From 835c77b8a5919d1908164f238f736a1758f4826e Mon Sep 17 00:00:00 2001 From: SteVen Batten Date: Wed, 26 Feb 2020 11:16:51 -0800 Subject: [PATCH] improve view moving command flow fixes #91422 --- .../browser/actions/layoutActions.ts | 76 ++++++++++--------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/src/vs/workbench/browser/actions/layoutActions.ts b/src/vs/workbench/browser/actions/layoutActions.ts index 50906972e6c..f03e93dd95f 100644 --- a/src/vs/workbench/browser/actions/layoutActions.ts +++ b/src/vs/workbench/browser/actions/layoutActions.ts @@ -25,9 +25,10 @@ import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/commo import { SideBarVisibleContext } from 'vs/workbench/common/viewlet'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IViewDescriptorService, IViewContainersRegistry, Extensions as ViewContainerExtensions, IViewsService, FocusedViewContext, ViewContainerLocation } from 'vs/workbench/common/views'; -import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput'; +import { IQuickInputService, IQuickPickItem, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; +import { IActivityBarService } from 'vs/workbench/services/activityBar/browser/activityBarService'; const registry = Registry.as(WorkbenchExtensions.WorkbenchActions); const viewCategory = nls.localize('view', "View"); @@ -534,6 +535,7 @@ export class MoveFocusedViewAction extends Action { @IQuickInputService private quickInputService: IQuickInputService, @IContextKeyService private contextKeyService: IContextKeyService, @INotificationService private notificationService: INotificationService, + @IActivityBarService private activityBarService: IActivityBarService, @IViewletService private viewletService: IViewletService ) { super(id, label); @@ -542,58 +544,64 @@ export class MoveFocusedViewAction extends Action { run(): Promise { const viewContainerRegistry = Registry.as(ViewContainerExtensions.ViewContainersRegistry); - const focusedView = FocusedViewContext.getValue(this.contextKeyService); + const focusedViewId = FocusedViewContext.getValue(this.contextKeyService); - if (focusedView === undefined || focusedView.trim() === '') { + if (focusedViewId === undefined || focusedViewId.trim() === '') { this.notificationService.error(nls.localize('moveFocusedView.error.noFocusedView', "There is no view currently focused.")); return Promise.resolve(); } - const viewDescriptor = this.viewDescriptorService.getViewDescriptor(focusedView); + const viewDescriptor = this.viewDescriptorService.getViewDescriptor(focusedViewId); if (!viewDescriptor || !viewDescriptor.canMoveView) { - this.notificationService.error(nls.localize('moveFocusedView.error.nonMovableView', "The currently focused view is not movable {0}.", focusedView)); + this.notificationService.error(nls.localize('moveFocusedView.error.nonMovableView', "The currently focused view is not movable {0}.", focusedViewId)); return Promise.resolve(); } const quickPick = this.quickInputService.createQuickPick(); - quickPick.placeholder = nls.localize('moveFocusedView.selectDestination', "Select a destination area for the view..."); - quickPick.autoFocusOnList = true; + quickPick.placeholder = nls.localize('moveFocusedView.selectDestination', "Select a Destination for the View"); - quickPick.items = [ - { - id: 'sidebar', - label: nls.localize('sidebar', "Sidebar") - }, - { - id: 'panel', + const pinnedViewlets = this.activityBarService.getPinnedViewletIds(); + const items: Array = this.viewletService.getViewlets() + .filter(viewlet => { + if (viewlet.id === this.viewDescriptorService.getViewContainer(focusedViewId)!.id) { + return false; + } + + return !viewContainerRegistry.get(viewlet.id)!.rejectAddedViews && pinnedViewlets.indexOf(viewlet.id) !== -1; + }) + .map(viewlet => { + return { + id: viewlet.id, + label: viewlet.name, + }; + }); + + if (this.viewDescriptorService.getViewLocation(focusedViewId) !== ViewContainerLocation.Panel) { + items.unshift({ + type: 'separator', + label: nls.localize('sidebar', "Side Bar") + }); + items.push({ + type: 'separator', label: nls.localize('panel', "Panel") - } - ]; + }); + items.push({ + id: '_.panel.newcontainer', + label: nls.localize('moveFocusedView.newContainerInPanel', "New Container in Panel"), + }); + } + + quickPick.items = items; quickPick.onDidAccept(() => { const destination = quickPick.selectedItems[0]; - if (destination.id === 'panel') { - quickPick.hide(); + if (destination.id === '_.panel.newcontainer') { this.viewDescriptorService.moveViewToLocation(viewDescriptor!, ViewContainerLocation.Panel); - this.viewsService.openView(focusedView, true); - - return; - } else if (destination.id === 'sidebar') { - quickPick.placeholder = nls.localize('moveFocusedView.selectDestinationContainer', "Select a destination view group..."); - quickPick.items = this.viewletService.getViewlets().map(viewlet => { - return { - id: viewlet.id, - label: viewlet.name - }; - }); - - return; + this.viewsService.openView(focusedViewId, true); } else if (destination.id) { - quickPick.hide(); this.viewDescriptorService.moveViewsToContainer([viewDescriptor], viewContainerRegistry.get(destination.id)!); - this.viewsService.openView(focusedView, true); - return; + this.viewsService.openView(focusedViewId, true); } quickPick.hide();