提交 347422bd 编写于 作者: B Benjamin Pasero

💄

上级 b8c9bff4
......@@ -98,6 +98,7 @@ export abstract class BaseWorkspacesAction extends Action {
}
const res = this.windowService.showMessageBox(opts);
return !buttons[res].canceled;
}
......@@ -117,10 +118,10 @@ export abstract class BaseWorkspacesAction extends Action {
}
}
export class NewWorkspaceFromExistingAction extends BaseWorkspacesAction {
export class AddRootFolderAction extends BaseWorkspacesAction {
static ID = 'workbench.action.newWorkspaceFromExisting';
static LABEL = nls.localize('newWorkspaceFormExisting', "New Workspace From Existing...");
static ID = 'workbench.action.addRootFolder';
static LABEL = nls.localize('addFolderToWorkspace', "Add Folder to Workspace...");
constructor(
id: string,
......@@ -128,34 +129,56 @@ export class NewWorkspaceFromExistingAction extends BaseWorkspacesAction {
@IWindowService windowService: IWindowService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IEnvironmentService environmentService: IEnvironmentService,
@IWorkspacesService protected workspacesService: IWorkspacesService,
@IWindowsService protected windowsService: IWindowsService,
@IInstantiationService private instantiationService: IInstantiationService,
@IWorkspaceEditingService private workspaceEditingService: IWorkspaceEditingService,
@IViewletService private viewletService: IViewletService
) {
super(id, label, windowService, environmentService, contextService);
}
public run(): TPromise<any> {
if (this.contextService.hasWorkspace()) {
let folders = this.pickFolders(mnemonicLabel(nls.localize({ key: 'select', comment: ['&& denotes a mnemonic'] }, "&&Select")), nls.localize('selectWorkspace', "Select Folders for Workspace"));
if (folders && folders.length) {
if (this.handleNotInMultiFolderWorkspaceCase(nls.localize('addSupported', "To open multiple folders, window reload is required."))) {
return this.createWorkspace([this.contextService.getWorkspace().roots[0], ...folders.map(folder => URI.file(folder))]);
}
}
if (!this.contextService.hasWorkspace()) {
return this.instantiationService.createInstance(NewWorkspaceAction, NewWorkspaceAction.ID, NewWorkspaceAction.LABEL).run();
}
return TPromise.as(null);
if (this.contextService.hasFolderWorkspace()) {
return this.instantiationService.createInstance(NewWorkspaceFromExistingAction, NewWorkspaceFromExistingAction.ID, NewWorkspaceFromExistingAction.LABEL).run();
}
const folders = super.pickFolders(mnemonicLabel(nls.localize({ key: 'add', comment: ['&& denotes a mnemonic'] }, "&&Add")), nls.localize('addFolderToWorkspaceTitle', "Add Folder to Workspace"));
if (!folders || !folders.length) {
return TPromise.as(null);
}
return this.workspaceEditingService.addRoots(folders.map(folder => URI.file(folder))).then(() => {
return this.viewletService.openViewlet(this.viewletService.getDefaultViewletId(), true);
});
}
}
private createWorkspace(folders: URI[]): TPromise<void> {
return this.workspacesService.createWorkspace(distinct(folders.map(folder => folder.toString(true /* encoding */))))
.then(({ configPath }) => this.windowsService.openWindow([configPath]));
class NewWorkspaceAction extends Action {
static ID = 'workbench.action.newWorkspace';
static LABEL = nls.localize('newWorkspace', "New Workspace...");
constructor(
id: string,
label: string,
@IWindowService private windowService: IWindowService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
) {
super(id, label);
}
public run(): TPromise<any> {
return this.windowService.newWorkspace();
}
}
export class AddRootFolderAction extends BaseWorkspacesAction {
class NewWorkspaceFromExistingAction extends BaseWorkspacesAction {
static ID = 'workbench.action.addRootFolder';
static LABEL = nls.localize('addFolderToWorkspace', "Add Folder to Workspace...");
static ID = 'workbench.action.newWorkspaceFromExisting';
static LABEL = nls.localize('newWorkspaceFormExisting', "New Workspace From Existing...");
constructor(
id: string,
......@@ -163,30 +186,28 @@ export class AddRootFolderAction extends BaseWorkspacesAction {
@IWindowService windowService: IWindowService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IEnvironmentService environmentService: IEnvironmentService,
@IInstantiationService private instantiationService: IInstantiationService,
@IWorkspaceEditingService private workspaceEditingService: IWorkspaceEditingService,
@IViewletService private viewletService: IViewletService
@IWorkspacesService protected workspacesService: IWorkspacesService,
@IWindowsService protected windowsService: IWindowsService,
) {
super(id, label, windowService, environmentService, contextService);
}
public run(): TPromise<any> {
if (!this.contextService.hasWorkspace()) {
return this.instantiationService.createInstance(NewWorkspaceAction, NewWorkspaceAction.ID, NewWorkspaceAction.LABEL).run();
}
if (this.contextService.hasFolderWorkspace()) {
return this.instantiationService.createInstance(NewWorkspaceFromExistingAction, NewWorkspaceFromExistingAction.ID, NewWorkspaceFromExistingAction.LABEL).run();
let folders = this.pickFolders(mnemonicLabel(nls.localize({ key: 'select', comment: ['&& denotes a mnemonic'] }, "&&Select")), nls.localize('selectWorkspace', "Select Folders for Workspace"));
if (folders && folders.length) {
if (this.handleNotInMultiFolderWorkspaceCase(nls.localize('addSupported', "To open multiple folders, window reload is required."))) {
return this.createWorkspace([this.contextService.getWorkspace().roots[0], ...folders.map(folder => URI.file(folder))]);
}
}
}
const folders = super.pickFolders(mnemonicLabel(nls.localize({ key: 'add', comment: ['&& denotes a mnemonic'] }, "&&Add")), nls.localize('addFolderToWorkspaceTitle', "Add Folder to Workspace"));
if (!folders || !folders.length) {
return TPromise.as(null);
}
return TPromise.as(null);
}
return this.workspaceEditingService.addRoots(folders.map(folder => URI.file(folder))).then(() => {
return this.viewletService.openViewlet(this.viewletService.getDefaultViewletId(), true);
});
private createWorkspace(folders: URI[]): TPromise<void> {
return this.workspacesService.createWorkspace(distinct(folders.map(folder => folder.toString(true /* encoding */))))
.then(({ configPath }) => this.windowsService.openWindow([configPath]));
}
}
......@@ -258,6 +279,7 @@ export class SaveWorkspaceAsAction extends BaseWorkspacesAction {
.then(({ configPath }) => this.windowsService.openWindow([configPath]));
});
}
return TPromise.as(null);
}
......@@ -292,7 +314,6 @@ export class OpenWorkspaceAction extends Action {
id: string,
label: string,
@IWindowService private windowService: IWindowService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
) {
super(id, label);
}
......@@ -302,25 +323,6 @@ export class OpenWorkspaceAction extends Action {
}
}
class NewWorkspaceAction extends Action {
static ID = 'workbench.action.newWorkspace';
static LABEL = nls.localize('newWorkspace', "New Workspace...");
constructor(
id: string,
label: string,
@IWindowService private windowService: IWindowService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
) {
super(id, label);
}
public run(): TPromise<any> {
return this.windowService.newWorkspace();
}
}
export class OpenWorkspaceConfigFileAction extends Action {
public static ID = 'workbench.action.openWorkspaceConfigFile';
......@@ -333,6 +335,7 @@ export class OpenWorkspaceConfigFileAction extends Action {
@IWorkbenchEditorService private editorService: IWorkbenchEditorService
) {
super(id, label);
this.enabled = this.workspaceContextService.hasMultiFolderWorkspace();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册