diff --git a/src/vs/workbench/api/common/apiCommands.ts b/src/vs/workbench/api/common/apiCommands.ts index 5e55c18f426..91837a29dcd 100644 --- a/src/vs/workbench/api/common/apiCommands.ts +++ b/src/vs/workbench/api/common/apiCommands.ts @@ -16,6 +16,7 @@ import { IWorkspacesService, hasWorkspaceFileExtension, IRecent } from 'vs/platf import { Schemas } from 'vs/base/common/network'; import { ILogService } from 'vs/platform/log/common/log'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import { IViewDescriptorService, IViewsService } from 'vs/workbench/common/views'; // ----------------------------------------------------------------- // The following commands are registered on both sides separately. @@ -264,3 +265,45 @@ CommandsRegistry.registerCommand('_extensionTests.getLogLevel', function (access return logService.getLevel(); }); + + +CommandsRegistry.registerCommand('_workbench.action.moveViews', async function (accessor: ServicesAccessor, options: { viewIds: string[], destinationId: string }) { + const viewDescriptorService = accessor.get(IViewDescriptorService); + + const destination = viewDescriptorService.getViewContainerById(options.destinationId); + if (!destination) { + return; + } + + // FYI, don't use `moveViewsToContainer` in 1 shot, because it expects all views to have the same current location + for (const viewId of options.viewIds) { + const viewDescriptor = viewDescriptorService.getViewDescriptorById(viewId); + if (viewDescriptor?.canMoveView) { + viewDescriptorService.moveViewsToContainer([viewDescriptor], destination); + } + } + + const focusView = options.viewIds[options.viewIds.length - 1]; + if (focusView) { + await accessor.get(IViewsService).openView(focusView, true); + } +}); + +export class MoveViewsAPICommand { + public static readonly ID = 'vscode.moveViews'; + public static execute(executor: ICommandsExecutor, options: { viewIds: string[], destinationId: string }): Promise { + if (!Array.isArray(options?.viewIds) || typeof options?.destinationId !== 'string') { + return Promise.reject('Invalid arguments'); + } + + return executor.executeCommand('_workbench.action.moveViews', options); + } +} +CommandsRegistry.registerCommand({ + id: MoveViewsAPICommand.ID, + handler: adjustHandler(MoveViewsAPICommand.execute), + description: { + description: 'Move Views', + args: [] + } +}); diff --git a/src/vs/workbench/browser/actions/layoutActions.ts b/src/vs/workbench/browser/actions/layoutActions.ts index 69c163596f3..1e92e6c2f74 100644 --- a/src/vs/workbench/browser/actions/layoutActions.ts +++ b/src/vs/workbench/browser/actions/layoutActions.ts @@ -763,43 +763,6 @@ export class MoveFocusedViewAction extends Action { registry.registerWorkbenchAction(SyncActionDescriptor.from(MoveFocusedViewAction), 'View: Move Focused View', viewCategory.value, FocusedViewContext.notEqualsTo('')); -export class MoveViewsAction extends Action2 { - constructor() { - super({ - id: 'workbench.action.moveViews', - title: { value: nls.localize('moveViews', "Move Views"), original: 'Move Views' }, - category: viewCategory, - f1: false - }); - } - - async run(accessor: ServicesAccessor, viewIds: string[], destinationId: string): Promise { - const viewDescriptorService = accessor.get(IViewDescriptorService); - - const destination = viewDescriptorService.getViewContainerById(destinationId); - if (!destination) { - return; - } - - const viewDescriptors = viewIds.map(viewId => { - const viewDescriptor = viewDescriptorService.getViewDescriptorById(viewId); - return viewDescriptor?.canMoveView ? viewDescriptor : undefined; - }).filter((i: T | undefined): i is T => Boolean(i)); - - if (viewDescriptors.length) { - viewDescriptorService.moveViewsToContainer(viewDescriptors, destination); - - const focusView = viewIds[viewIds.length - 1]; - if (focusView) { - await accessor.get(IViewsService).openView(focusView, true); - } - } - } -} - -registerAction2(MoveViewsAction); - - // --- Reset View Location with Command export class ResetFocusedViewLocationAction extends Action { static readonly ID = 'workbench.action.resetFocusedViewLocation';