提交 fa40b32b 编写于 作者: B Benjamin Pasero

simplify workspace actions

上级 d693f035
......@@ -1265,14 +1265,6 @@ export class WindowsManager implements IWindowsMainService {
this.fileDialog.pickAndOpen({ pickFolders: true, forceNewWindow, window, title: nls.localize('openFolder', "Open Folder") }, 'openFolder', data);
}
public pickFolder(window?: CodeWindow, options?: { buttonLabel: string; title: string; }): TPromise<string[]> {
return new TPromise((c, e) => {
this.fileDialog.getFileOrFolderPaths({ pickFolders: true, window, buttonLabel: options && options.buttonLabel }, folders => {
c(folders || []);
});
});
}
public quit(): void {
// If the user selected to exit from an extension development host window, do not quit, but just
......
......@@ -26,7 +26,6 @@ export interface IWindowsService {
pickFileFolderAndOpen(windowId: number, forceNewWindow?: boolean, data?: ITelemetryData): TPromise<void>;
pickFileAndOpen(windowId: number, forceNewWindow?: boolean, path?: string, data?: ITelemetryData): TPromise<void>;
pickFolderAndOpen(windowId: number, forceNewWindow?: boolean, data?: ITelemetryData): TPromise<void>;
pickFolder(windowId: number, options?: { buttonLabel: string; title: string; }): TPromise<string[]>;
reloadWindow(windowId: number): TPromise<void>;
openDevTools(windowId: number): TPromise<void>;
toggleDevTools(windowId: number): TPromise<void>;
......@@ -81,7 +80,6 @@ export interface IWindowService {
pickFileFolderAndOpen(forceNewWindow?: boolean, data?: ITelemetryData): TPromise<void>;
pickFileAndOpen(forceNewWindow?: boolean, path?: string, data?: ITelemetryData): TPromise<void>;
pickFolderAndOpen(forceNewWindow?: boolean, data?: ITelemetryData): TPromise<void>;
pickFolder(options?: { buttonLabel: string; title: string; }): TPromise<string[]>;
reloadWindow(): TPromise<void>;
openDevTools(): TPromise<void>;
toggleDevTools(): TPromise<void>;
......
......@@ -19,7 +19,6 @@ export interface IWindowsChannel extends IChannel {
call(command: 'pickFileFolderAndOpen', arg: [number, boolean, ITelemetryData]): TPromise<void>;
call(command: 'pickFileAndOpen', arg: [number, boolean, string, ITelemetryData]): TPromise<void>;
call(command: 'pickFolderAndOpen', arg: [number, boolean, ITelemetryData]): TPromise<void>;
call(command: 'pickFolder', arg: [number, { buttonLabel: string; title: string; }]): TPromise<string[]>;
call(command: 'reloadWindow', arg: number): TPromise<void>;
call(command: 'toggleDevTools', arg: number): TPromise<void>;
call(command: 'closeWorkspace', arg: number): TPromise<void>;
......@@ -71,7 +70,6 @@ export class WindowsChannel implements IWindowsChannel {
case 'pickFileFolderAndOpen': return this.service.pickFileFolderAndOpen(arg[0], arg[1], arg[2]);
case 'pickFileAndOpen': return this.service.pickFileAndOpen(arg[0], arg[1], arg[2], arg[3]);
case 'pickFolderAndOpen': return this.service.pickFolderAndOpen(arg[0], arg[1], arg[2]);
case 'pickFolder': return this.service.pickFolder(arg[0], arg[1]);
case 'reloadWindow': return this.service.reloadWindow(arg);
case 'openDevTools': return this.service.openDevTools(arg);
case 'toggleDevTools': return this.service.toggleDevTools(arg);
......@@ -133,10 +131,6 @@ export class WindowsChannelClient implements IWindowsService {
return this.channel.call('pickFolderAndOpen', [windowId, forceNewWindow, data]);
}
pickFolder(windowId: number, options?: { buttonLabel: string; title: string; }): TPromise<string[]> {
return this.channel.call('pickFolder', [windowId, options]);
}
reloadWindow(windowId: number): TPromise<void> {
return this.channel.call('reloadWindow', windowId);
}
......
......@@ -36,10 +36,6 @@ export class WindowService implements IWindowService {
return this.windowsService.pickFolderAndOpen(this.windowId, forceNewWindow, data);
}
pickFolder(options?: { buttonLabel: string; title: string; }): TPromise<string[]> {
return this.windowsService.pickFolder(this.windowId, options);
}
reloadWindow(): TPromise<void> {
return this.windowsService.reloadWindow(this.windowId);
}
......
......@@ -57,7 +57,6 @@ export interface IWindowsMainService {
pickFileFolderAndOpen(forceNewWindow?: boolean, data?: ITelemetryData): void;
pickFileAndOpen(forceNewWindow?: boolean, path?: string, window?: ICodeWindow, data?: ITelemetryData): void;
pickFolderAndOpen(forceNewWindow?: boolean, window?: ICodeWindow, data?: ITelemetryData): void;
pickFolder(window?: ICodeWindow, options?: { buttonLabel: string; title: string; }): TPromise<string[]>;
focusLastActive(cli: ParsedArgs, context: OpenContext): ICodeWindow;
getLastActiveWindow(): ICodeWindow;
waitForWindowClose(windowId: number): TPromise<void>;
......
......@@ -69,12 +69,6 @@ export class WindowsService implements IWindowsService, IDisposable {
return TPromise.as(null);
}
pickFolder(windowId: number, options?: { buttonLabel: string; title: string; }): TPromise<string[]> {
const codeWindow = this.windowsMainService.getWindowById(windowId);
return this.windowsMainService.pickFolder(codeWindow, options);
}
reloadWindow(windowId: number): TPromise<void> {
const codeWindow = this.windowsMainService.getWindowById(windowId);
......
......@@ -18,6 +18,7 @@ import { IInstantiationService } from "vs/platform/instantiation/common/instanti
import { WORKSPACE_EXTENSION, IWorkspacesService } from "vs/platform/workspaces/common/workspaces";
import { IEnvironmentService } from "vs/platform/environment/common/environment";
import { isWindows, isLinux } from "vs/base/common/platform";
import { dirname } from "vs/base/common/paths";
export class OpenFolderAction extends Action {
......@@ -55,14 +56,15 @@ export class OpenFileFolderAction extends Action {
}
}
export abstract class BaseRootFolderAction extends Action {
export abstract class BaseWorkspacesAction extends Action {
constructor(
id: string,
label: string,
protected windowService: IWindowService,
protected instantiationService: IInstantiationService,
protected environmentService: IEnvironmentService
protected environmentService: IEnvironmentService,
protected contextService: IWorkspaceContextService
) {
super(id, label);
}
......@@ -107,9 +109,18 @@ export abstract class BaseRootFolderAction extends Action {
return label.replace(/&&/g, '&');
}
protected pickFolders(button: string, title: string): string[] {
return this.windowService.showOpenDialog({
buttonLabel: nls.localize('add', "Add"),
title: nls.localize('addFolderToWorkspaceTitle', "Add Folder to Workspace"),
properties: ['multiSelections', 'openDirectory', 'createDirectory'],
defaultPath: this.contextService.hasWorkspace() ? dirname(this.contextService.getWorkspace().roots[0].fsPath) : void 0 // pick the parent of the first root by default
});
}
}
export class AddRootFolderAction extends BaseRootFolderAction {
export class AddRootFolderAction extends BaseWorkspacesAction {
static ID = 'workbench.action.addRootFolder';
static LABEL = nls.localize('addFolderToWorkspace', "Add Folder to Workspace...");
......@@ -119,12 +130,12 @@ export class AddRootFolderAction extends BaseRootFolderAction {
label: string,
@IWindowService windowService: IWindowService,
@IInstantiationService instantiationService: IInstantiationService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IWorkspaceEditingService private workspaceEditingService: IWorkspaceEditingService,
@IViewletService private viewletService: IViewletService,
@IEnvironmentService environmentService: IEnvironmentService
) {
super(id, label, windowService, instantiationService, environmentService);
super(id, label, windowService, instantiationService, environmentService, contextService);
}
public run(): TPromise<any> {
......@@ -132,19 +143,18 @@ export class AddRootFolderAction extends BaseRootFolderAction {
return super.handleNotInMultiFolderWorkspaceCase(nls.localize('addSupported', "You can only add folders to workspaces. Do you want to create a new workspace?"));
}
return this.windowService.pickFolder({ buttonLabel: nls.localize('add', "Add"), title: nls.localize('addFolderToWorkspaceTitle', "Add Folder to Workspace") }).then(folders => {
if (!folders.length) {
return TPromise.as(null);
}
const folders = super.pickFolders(nls.localize('add', "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);
});
return this.workspaceEditingService.addRoots(folders.map(folder => URI.file(folder))).then(() => {
return this.viewletService.openViewlet(this.viewletService.getDefaultViewletId(), true);
});
}
}
export class NewWorkspaceAction extends Action {
export class NewWorkspaceAction extends BaseWorkspacesAction {
static ID = 'workbench.action.newWorkspace';
static LABEL = nls.localize('newWorkspace', "New Workspace...");
......@@ -152,20 +162,22 @@ export class NewWorkspaceAction extends Action {
constructor(
id: string,
label: string,
@IWindowService private windowService: IWindowService,
@IWindowService windowService: IWindowService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IWorkspaceEditingService private workspaceEditingService: IWorkspaceEditingService,
@IInstantiationService instantiationService: IInstantiationService,
@IEnvironmentService environmentService: IEnvironmentService
) {
super(id, label);
super(id, label, windowService, instantiationService, environmentService, contextService);
}
public run(): TPromise<any> {
return this.windowService.pickFolder({ buttonLabel: nls.localize('select', "Select"), title: nls.localize('selectWorkspace', "Select Folders for Workspace") }).then(folders => {
if (!folders.length) {
return TPromise.as(null);
}
const folders = super.pickFolders(nls.localize('select', "Select"), nls.localize('selectWorkspace', "Select Folders for Workspace"));
if (!folders || !folders.length) {
return TPromise.as(null);
}
return this.workspaceEditingService.createAndOpenWorkspace(folders.map(folder => URI.file(folder)));
});
return this.workspaceEditingService.createAndOpenWorkspace(folders.map(folder => URI.file(folder)));
}
}
......@@ -190,7 +202,7 @@ export class RemoveRootFolderAction extends Action {
const codeWorkspaceFilter = [{ name: nls.localize('codeWorkspace', "Code Workspace"), extensions: [WORKSPACE_EXTENSION] }];
export class SaveWorkspaceAction extends BaseRootFolderAction {
export class SaveWorkspaceAction extends BaseWorkspacesAction {
static ID = 'workbench.action.saveWorkspace';
static LABEL = nls.localize('saveWorkspaceAction', "Save Workspace...");
......@@ -200,12 +212,12 @@ export class SaveWorkspaceAction extends BaseRootFolderAction {
label: string,
@IWindowService windowService: IWindowService,
@IEnvironmentService environmentService: IEnvironmentService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IWorkspacesService private workspacesService: IWorkspacesService,
@IInstantiationService instantiationService: IInstantiationService,
@IWindowsService private windowsService: IWindowsService
) {
super(id, label, windowService, instantiationService, environmentService);
super(id, label, windowService, instantiationService, environmentService, contextService);
}
public run(): TPromise<any> {
......@@ -216,7 +228,8 @@ export class SaveWorkspaceAction extends BaseRootFolderAction {
const target = this.windowService.showSaveDialog({
buttonLabel: nls.localize('save', "Save"),
title: nls.localize('saveWorkspace', "Save Workspace"),
filters: codeWorkspaceFilter
filters: codeWorkspaceFilter,
defaultPath: dirname(this.contextService.getWorkspace().roots[0].fsPath) // pick the parent of the first root by default
});
if (target) {
......@@ -236,7 +249,8 @@ export class OpenWorkspaceAction extends Action {
id: string,
label: string,
@IWindowService private windowService: IWindowService,
@IWindowsService private windowsService: IWindowsService
@IWindowsService private windowsService: IWindowsService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
) {
super(id, label);
}
......@@ -246,7 +260,8 @@ export class OpenWorkspaceAction extends Action {
buttonLabel: nls.localize('open', "Open"),
title: nls.localize('openWorkspace', "Open Workspace"),
filters: codeWorkspaceFilter,
properties: ['openFile']
properties: ['openFile'],
defaultPath: this.contextService.hasWorkspace() ? dirname(this.contextService.getWorkspace().roots[0].fsPath) : void 0 // pick the parent of the first root by default
});
if (!files || !files.length) {
......
......@@ -127,7 +127,6 @@ export class WorkbenchShell {
private timerService: ITimerService;
private themeService: WorkbenchThemeService;
private lifecycleService: LifecycleService;
private mainProcessServices: ServiceCollection;
private container: HTMLElement;
......
......@@ -855,10 +855,6 @@ export class TestWindowService implements IWindowService {
return TPromise.as(void 0);
}
pickFolder(options?: { buttonLabel: string; title: string; }): TPromise<string[]> {
return TPromise.as([]);
}
reloadWindow(): TPromise<void> {
return TPromise.as(void 0);
}
......@@ -986,10 +982,6 @@ export class TestWindowsService implements IWindowsService {
return TPromise.as(void 0);
}
pickFolder(windowId: number, options?: { buttonLabel: string; title: string; }): TPromise<string[]> {
return TPromise.as([]);
}
reloadWindow(windowId: number): TPromise<void> {
return TPromise.as(void 0);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册