mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 18:49:00 +01:00
Moves command into vscode. namespace
Stops using moveViewsToContainer in 1 shot
This commit is contained in:
@@ -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<any> {
|
||||
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: []
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user