@@ -16,6 +16,7 @@ import { IWorkspacesService, hasWorkspaceFileExtension, IRecent } from 'vs/platf
1616import { Schemas } from 'vs/base/common/network' ;
1717import { ILogService } from 'vs/platform/log/common/log' ;
1818import { 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+ } ) ;
0 commit comments