|
|
|
|
@@ -13,7 +13,7 @@ import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/c
|
|
|
|
|
import { ADD_ROOT_FOLDER_COMMAND_ID, ADD_ROOT_FOLDER_LABEL, PICK_WORKSPACE_FOLDER_COMMAND_ID } from 'vs/workbench/browser/actions/workspaceCommands';
|
|
|
|
|
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
|
|
|
|
|
import { MenuRegistry, MenuId, SyncActionDescriptor } from 'vs/platform/actions/common/actions';
|
|
|
|
|
import { WorkbenchStateContext, SupportsWorkspacesContext, WorkspaceFolderCountContext } from 'vs/workbench/browser/contextkeys';
|
|
|
|
|
import { WorkbenchStateContext, WorkspaceFolderCountContext } from 'vs/workbench/browser/contextkeys';
|
|
|
|
|
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
|
|
|
|
import { Registry } from 'vs/platform/registry/common/platform';
|
|
|
|
|
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
|
|
|
|
|
@@ -22,6 +22,7 @@ import { IHostService } from 'vs/workbench/services/host/browser/host';
|
|
|
|
|
import { KeyChord, KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
|
|
|
|
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
|
|
|
|
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
|
|
|
|
import { IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
|
|
|
|
|
|
|
|
|
|
export class OpenFileAction extends Action {
|
|
|
|
|
|
|
|
|
|
@@ -195,14 +196,74 @@ export class GlobalRemoveRootFolderAction extends Action {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class SaveWorkspaceAsAction extends Action {
|
|
|
|
|
|
|
|
|
|
static readonly ID = 'workbench.action.saveWorkspaceAs';
|
|
|
|
|
static readonly LABEL = nls.localize('saveWorkspaceAsAction', "Save Workspace As...");
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
id: string,
|
|
|
|
|
label: string,
|
|
|
|
|
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
|
|
|
|
|
@IWorkspaceEditingService private readonly workspaceEditingService: IWorkspaceEditingService
|
|
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
super(id, label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async run(): Promise<any> {
|
|
|
|
|
const configPathUri = await this.workspaceEditingService.pickNewWorkspacePath();
|
|
|
|
|
if (configPathUri) {
|
|
|
|
|
switch (this.contextService.getWorkbenchState()) {
|
|
|
|
|
case WorkbenchState.EMPTY:
|
|
|
|
|
case WorkbenchState.FOLDER:
|
|
|
|
|
const folders = this.contextService.getWorkspace().folders.map(folder => ({ uri: folder.uri }));
|
|
|
|
|
return this.workspaceEditingService.createAndEnterWorkspace(folders, configPathUri);
|
|
|
|
|
case WorkbenchState.WORKSPACE:
|
|
|
|
|
return this.workspaceEditingService.saveAndEnterWorkspace(configPathUri);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class DuplicateWorkspaceInNewWindowAction extends Action {
|
|
|
|
|
|
|
|
|
|
static readonly ID = 'workbench.action.duplicateWorkspaceInNewWindow';
|
|
|
|
|
static readonly LABEL = nls.localize('duplicateWorkspaceInNewWindow', "Duplicate Workspace in New Window");
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
id: string,
|
|
|
|
|
label: string,
|
|
|
|
|
@IWorkspaceContextService private readonly workspaceContextService: IWorkspaceContextService,
|
|
|
|
|
@IWorkspaceEditingService private readonly workspaceEditingService: IWorkspaceEditingService,
|
|
|
|
|
@IHostService private readonly hostService: IHostService,
|
|
|
|
|
@IWorkspacesService private readonly workspacesService: IWorkspacesService,
|
|
|
|
|
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService
|
|
|
|
|
) {
|
|
|
|
|
super(id, label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async run(): Promise<any> {
|
|
|
|
|
const folders = this.workspaceContextService.getWorkspace().folders;
|
|
|
|
|
const remoteAuthority = this.environmentService.configuration.remoteAuthority;
|
|
|
|
|
|
|
|
|
|
const newWorkspace = await this.workspacesService.createUntitledWorkspace(folders, remoteAuthority);
|
|
|
|
|
await this.workspaceEditingService.copyWorkspaceSettings(newWorkspace);
|
|
|
|
|
|
|
|
|
|
return this.hostService.openWindow([{ workspaceUri: newWorkspace.configPath }], { forceNewWindow: true });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Actions Registration
|
|
|
|
|
|
|
|
|
|
const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
|
|
|
|
|
const workspacesCategory = nls.localize('workspaces', "Workspaces");
|
|
|
|
|
|
|
|
|
|
registry.registerWorkbenchAction(new SyncActionDescriptor(AddRootFolderAction, AddRootFolderAction.ID, AddRootFolderAction.LABEL), 'Workspaces: Add Folder to Workspace...', workspacesCategory, SupportsWorkspacesContext);
|
|
|
|
|
registry.registerWorkbenchAction(new SyncActionDescriptor(GlobalRemoveRootFolderAction, GlobalRemoveRootFolderAction.ID, GlobalRemoveRootFolderAction.LABEL), 'Workspaces: Remove Folder from Workspace...', workspacesCategory, SupportsWorkspacesContext);
|
|
|
|
|
registry.registerWorkbenchAction(new SyncActionDescriptor(CloseWorkspaceAction, CloseWorkspaceAction.ID, CloseWorkspaceAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_F) }), 'Workspaces: Close Workspace', workspacesCategory, SupportsWorkspacesContext);
|
|
|
|
|
registry.registerWorkbenchAction(new SyncActionDescriptor(AddRootFolderAction, AddRootFolderAction.ID, AddRootFolderAction.LABEL), 'Workspaces: Add Folder to Workspace...', workspacesCategory);
|
|
|
|
|
registry.registerWorkbenchAction(new SyncActionDescriptor(GlobalRemoveRootFolderAction, GlobalRemoveRootFolderAction.ID, GlobalRemoveRootFolderAction.LABEL), 'Workspaces: Remove Folder from Workspace...', workspacesCategory);
|
|
|
|
|
registry.registerWorkbenchAction(new SyncActionDescriptor(CloseWorkspaceAction, CloseWorkspaceAction.ID, CloseWorkspaceAction.LABEL, { primary: KeyChord(KeyMod.CtrlCmd | KeyCode.KEY_K, KeyCode.KEY_F) }), 'Workspaces: Close Workspace', workspacesCategory);
|
|
|
|
|
registry.registerWorkbenchAction(new SyncActionDescriptor(SaveWorkspaceAsAction, SaveWorkspaceAsAction.ID, SaveWorkspaceAsAction.LABEL), 'Workspaces: Save Workspace As...', workspacesCategory);
|
|
|
|
|
registry.registerWorkbenchAction(new SyncActionDescriptor(DuplicateWorkspaceInNewWindowAction, DuplicateWorkspaceInNewWindowAction.ID, DuplicateWorkspaceInNewWindowAction.LABEL), 'Workspaces: Duplicate Workspace in New Window', workspacesCategory);
|
|
|
|
|
|
|
|
|
|
// --- Menu Registration
|
|
|
|
|
|
|
|
|
|
@@ -216,8 +277,16 @@ MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
|
|
|
|
id: ADD_ROOT_FOLDER_COMMAND_ID,
|
|
|
|
|
title: nls.localize({ key: 'miAddFolderToWorkspace', comment: ['&& denotes a mnemonic'] }, "A&&dd Folder to Workspace...")
|
|
|
|
|
},
|
|
|
|
|
order: 1,
|
|
|
|
|
when: SupportsWorkspacesContext
|
|
|
|
|
order: 1
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
|
|
|
|
group: '3_workspace',
|
|
|
|
|
command: {
|
|
|
|
|
id: SaveWorkspaceAsAction.ID,
|
|
|
|
|
title: nls.localize('miSaveWorkspaceAs', "Save Workspace As...")
|
|
|
|
|
},
|
|
|
|
|
order: 2
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
|
|
|
|
|
@@ -246,5 +315,5 @@ MenuRegistry.appendMenuItem(MenuId.MenubarFileMenu, {
|
|
|
|
|
title: nls.localize({ key: 'miCloseWorkspace', comment: ['&& denotes a mnemonic'] }, "Close &&Workspace")
|
|
|
|
|
},
|
|
|
|
|
order: 3,
|
|
|
|
|
when: ContextKeyExpr.and(WorkbenchStateContext.isEqualTo('workspace'), SupportsWorkspacesContext)
|
|
|
|
|
when: ContextKeyExpr.and(WorkbenchStateContext.isEqualTo('workspace'))
|
|
|
|
|
});
|
|
|
|
|
|