Skip to content

Commit dc2d2ef

Browse files
Eric Amodioeamodio
authored andcommitted
Moves command into vscode. namespace
Stops using moveViewsToContainer in 1 shot
1 parent 0d99d8a commit dc2d2ef

2 files changed

Lines changed: 43 additions & 37 deletions

File tree

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +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';
1920

2021
// -----------------------------------------------------------------
2122
// The following commands are registered on both sides separately.
@@ -264,3 +265,45 @@ CommandsRegistry.registerCommand('_extensionTests.getLogLevel', function (access
264265

265266
return logService.getLevel();
266267
});
268+
269+
270+
CommandsRegistry.registerCommand('_workbench.action.moveViews', async function (accessor: ServicesAccessor, options: { viewIds: string[], destinationId: string }) {
271+
const viewDescriptorService = accessor.get(IViewDescriptorService);
272+
273+
const destination = viewDescriptorService.getViewContainerById(options.destinationId);
274+
if (!destination) {
275+
return;
276+
}
277+
278+
// FYI, don't use `moveViewsToContainer` in 1 shot, because it expects all views to have the same current location
279+
for (const viewId of options.viewIds) {
280+
const viewDescriptor = viewDescriptorService.getViewDescriptorById(viewId);
281+
if (viewDescriptor?.canMoveView) {
282+
viewDescriptorService.moveViewsToContainer([viewDescriptor], destination);
283+
}
284+
}
285+
286+
const focusView = options.viewIds[options.viewIds.length - 1];
287+
if (focusView) {
288+
await accessor.get(IViewsService).openView(focusView, true);
289+
}
290+
});
291+
292+
export class MoveViewsAPICommand {
293+
public static readonly ID = 'vscode.moveViews';
294+
public static execute(executor: ICommandsExecutor, options: { viewIds: string[], destinationId: string }): Promise<any> {
295+
if (!Array.isArray(options?.viewIds) || typeof options?.destinationId !== 'string') {
296+
return Promise.reject('Invalid arguments');
297+
}
298+
299+
return executor.executeCommand('_workbench.action.moveViews', options);
300+
}
301+
}
302+
CommandsRegistry.registerCommand({
303+
id: MoveViewsAPICommand.ID,
304+
handler: adjustHandler(MoveViewsAPICommand.execute),
305+
description: {
306+
description: 'Move Views',
307+
args: []
308+
}
309+
});

src/vs/workbench/browser/actions/layoutActions.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -763,43 +763,6 @@ export class MoveFocusedViewAction extends Action {
763763

764764
registry.registerWorkbenchAction(SyncActionDescriptor.from(MoveFocusedViewAction), 'View: Move Focused View', viewCategory.value, FocusedViewContext.notEqualsTo(''));
765765

766-
export class MoveViewsAction extends Action2 {
767-
constructor() {
768-
super({
769-
id: 'workbench.action.moveViews',
770-
title: { value: nls.localize('moveViews', "Move Views"), original: 'Move Views' },
771-
category: viewCategory,
772-
f1: false
773-
});
774-
}
775-
776-
async run(accessor: ServicesAccessor, viewIds: string[], destinationId: string): Promise<void> {
777-
const viewDescriptorService = accessor.get(IViewDescriptorService);
778-
779-
const destination = viewDescriptorService.getViewContainerById(destinationId);
780-
if (!destination) {
781-
return;
782-
}
783-
784-
const viewDescriptors = viewIds.map(viewId => {
785-
const viewDescriptor = viewDescriptorService.getViewDescriptorById(viewId);
786-
return viewDescriptor?.canMoveView ? viewDescriptor : undefined;
787-
}).filter(<T>(i: T | undefined): i is T => Boolean(i));
788-
789-
if (viewDescriptors.length) {
790-
viewDescriptorService.moveViewsToContainer(viewDescriptors, destination);
791-
792-
const focusView = viewIds[viewIds.length - 1];
793-
if (focusView) {
794-
await accessor.get(IViewsService).openView(focusView, true);
795-
}
796-
}
797-
}
798-
}
799-
800-
registerAction2(MoveViewsAction);
801-
802-
803766
// --- Reset View Location with Command
804767
export class ResetFocusedViewLocationAction extends Action {
805768
static readonly ID = 'workbench.action.resetFocusedViewLocation';

0 commit comments

Comments
 (0)