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

wire in changes to transition workspaces without window reload (for #32945)

上级 269ae60a
......@@ -1294,11 +1294,11 @@ export class WindowsManager implements IWindowsMainService {
});
}
public saveAndOpenWorkspace(win: CodeWindow, path: string): TPromise<void> {
public saveAndOpenWorkspace(win: CodeWindow, path: string): TPromise<IWorkspaceIdentifier> {
return this.workspacesManager.saveAndOpenWorkspace(win, path);
}
public createAndOpenWorkspace(win: CodeWindow, folders?: string[], path?: string): TPromise<void> {
public createAndOpenWorkspace(win: CodeWindow, folders?: string[], path?: string): TPromise<IWorkspaceIdentifier> {
return this.workspacesManager.createAndOpenWorkspace(win, folders, path);
}
......@@ -1637,7 +1637,7 @@ class WorkspacesManager {
) {
}
public saveAndOpenWorkspace(window: CodeWindow, path: string): TPromise<void> {
public saveAndOpenWorkspace(window: CodeWindow, path: string): TPromise<IWorkspaceIdentifier> {
if (!window || !window.win || window.readyState !== ReadyState.READY || !window.openedWorkspace || !path || !this.isValidTargetWorkspacePath(window, path)) {
return TPromise.as(null); // return early if the window is not ready or disposed or does not have a workspace
}
......@@ -1645,7 +1645,7 @@ class WorkspacesManager {
return this.doSaveAndOpenWorkspace(window, window.openedWorkspace, path);
}
public createAndOpenWorkspace(window: CodeWindow, folders?: string[], path?: string): TPromise<void> {
public createAndOpenWorkspace(window: CodeWindow, folders?: string[], path?: string): TPromise<IWorkspaceIdentifier> {
if (!window || !window.win || window.readyState !== ReadyState.READY || !this.isValidTargetWorkspacePath(window, path)) {
return TPromise.as(null); // return early if the window is not ready or disposed
}
......@@ -1688,7 +1688,7 @@ class WorkspacesManager {
return true; // OK
}
private doSaveAndOpenWorkspace(window: CodeWindow, workspace: IWorkspaceIdentifier, path?: string): TPromise<void> {
private doSaveAndOpenWorkspace(window: CodeWindow, workspace: IWorkspaceIdentifier, path?: string): TPromise<IWorkspaceIdentifier> {
let savePromise: TPromise<IWorkspaceIdentifier>;
if (path) {
savePromise = this.workspacesService.saveWorkspace(workspace, path);
......@@ -1699,26 +1699,18 @@ class WorkspacesManager {
return savePromise.then(workspace => {
window.focus();
// Only open workspace when the window has not vetoed this
return this.lifecycleService.unload(window, UnloadReason.RELOAD, workspace).done(veto => {
if (!veto) {
// Register window for backups and migrate current backups over
let backupPath: string;
if (window.config && !window.config.extensionDevelopmentPath) {
backupPath = this.backupService.registerWorkspaceBackupSync(workspace, window.config.backupPath);
}
// Register window for backups and migrate current backups over
let backupPath: string;
if (!window.config.extensionDevelopmentPath) {
backupPath = this.backupService.registerWorkspaceBackupSync(workspace, window.config.backupPath);
}
// Craft a new window configuration to use for the transition
const configuration: IWindowConfiguration = mixin({}, window.config);
configuration.folderPath = void 0;
configuration.workspace = workspace;
configuration.backupPath = backupPath;
// Update window configuration properly based on transition to workspace
window.config.folderPath = void 0;
window.config.workspace = workspace;
window.config.backupPath = backupPath;
// Reload
window.reload(configuration);
}
});
return workspace;
});
}
......
......@@ -43,8 +43,8 @@ export interface IWindowsService {
toggleDevTools(windowId: number): TPromise<void>;
closeWorkspace(windowId: number): TPromise<void>;
openWorkspace(windowId: number): TPromise<void>;
createAndOpenWorkspace(windowId: number, folders?: string[], path?: string): TPromise<void>;
saveAndOpenWorkspace(windowId: number, path: string): TPromise<void>;
createAndOpenWorkspace(windowId: number, folders?: string[], path?: string): TPromise<IWorkspaceIdentifier>;
saveAndOpenWorkspace(windowId: number, path: string): TPromise<IWorkspaceIdentifier>;
toggleFullScreen(windowId: number): TPromise<void>;
setRepresentedFilename(windowId: number, fileName: string): TPromise<void>;
addRecentlyOpened(files: string[]): TPromise<void>;
......@@ -111,8 +111,8 @@ export interface IWindowService {
closeWorkspace(): TPromise<void>;
openWorkspace(): TPromise<void>;
updateTouchBar(items: ICommandAction[][]): TPromise<void>;
createAndOpenWorkspace(folders?: string[], path?: string): TPromise<void>;
saveAndOpenWorkspace(path: string): TPromise<void>;
createAndOpenWorkspace(folders?: string[], path?: string): TPromise<IWorkspaceIdentifier>;
saveAndOpenWorkspace(path: string): TPromise<IWorkspaceIdentifier>;
toggleFullScreen(): TPromise<void>;
setRepresentedFilename(fileName: string): TPromise<void>;
getRecentlyOpened(): TPromise<IRecentlyOpened>;
......
......@@ -24,8 +24,8 @@ export interface IWindowsChannel extends IChannel {
call(command: 'toggleDevTools', arg: number): TPromise<void>;
call(command: 'closeWorkspace', arg: number): TPromise<void>;
call(command: 'openWorkspace', arg: number): TPromise<void>;
call(command: 'createAndOpenWorkspace', arg: [number, string[], string]): TPromise<void>;
call(command: 'saveAndOpenWorkspace', arg: [number, string]): TPromise<void>;
call(command: 'createAndOpenWorkspace', arg: [number, string[], string]): TPromise<IWorkspaceIdentifier>;
call(command: 'saveAndOpenWorkspace', arg: [number, string]): TPromise<IWorkspaceIdentifier>;
call(command: 'toggleFullScreen', arg: number): TPromise<void>;
call(command: 'setRepresentedFilename', arg: [number, string]): TPromise<void>;
call(command: 'addRecentlyOpened', arg: string[]): TPromise<void>;
......@@ -174,11 +174,11 @@ export class WindowsChannelClient implements IWindowsService {
return this.channel.call('openWorkspace', windowId);
}
createAndOpenWorkspace(windowId: number, folders?: string[], path?: string): TPromise<void> {
createAndOpenWorkspace(windowId: number, folders?: string[], path?: string): TPromise<IWorkspaceIdentifier> {
return this.channel.call('createAndOpenWorkspace', [windowId, folders, path]);
}
saveAndOpenWorkspace(windowId: number, path: string): TPromise<void> {
saveAndOpenWorkspace(windowId: number, path: string): TPromise<IWorkspaceIdentifier> {
return this.channel.call('saveAndOpenWorkspace', [windowId, path]);
}
......
......@@ -11,6 +11,7 @@ import { IWindowService, IWindowsService, INativeOpenDialogOptions } from 'vs/pl
import { remote } from 'electron';
import { IRecentlyOpened } from 'vs/platform/history/common/history';
import { ICommandAction } from 'vs/platform/actions/common/actions';
import { IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
export class WindowService implements IWindowService {
......@@ -69,11 +70,11 @@ export class WindowService implements IWindowService {
return this.windowsService.openWorkspace(this.windowId);
}
createAndOpenWorkspace(folders?: string[], path?: string): TPromise<void> {
createAndOpenWorkspace(folders?: string[], path?: string): TPromise<IWorkspaceIdentifier> {
return this.windowsService.createAndOpenWorkspace(this.windowId, folders, path);
}
saveAndOpenWorkspace(path: string): TPromise<void> {
saveAndOpenWorkspace(path: string): TPromise<IWorkspaceIdentifier> {
return this.windowsService.saveAndOpenWorkspace(this.windowId, path);
}
......
......@@ -61,8 +61,8 @@ export interface IWindowsMainService {
ready(initialUserEnv: IProcessEnvironment): void;
reload(win: ICodeWindow, cli?: ParsedArgs): void;
openWorkspace(win?: ICodeWindow): void;
createAndOpenWorkspace(win: ICodeWindow, folders?: string[], path?: string): void;
saveAndOpenWorkspace(win: ICodeWindow, path: string): void;
createAndOpenWorkspace(win: ICodeWindow, folders?: string[], path?: string): TPromise<IWorkspaceIdentifier>;
saveAndOpenWorkspace(win: ICodeWindow, path: string): TPromise<IWorkspaceIdentifier>;
closeWorkspace(win: ICodeWindow): void;
open(openConfig: IOpenConfiguration): ICodeWindow[];
openExtensionDevelopmentHostWindow(openConfig: IOpenConfiguration): void;
......
......@@ -135,21 +135,21 @@ export class WindowsService implements IWindowsService, IDisposable {
return TPromise.as(null);
}
createAndOpenWorkspace(windowId: number, folders?: string[], path?: string): TPromise<void> {
createAndOpenWorkspace(windowId: number, folders?: string[], path?: string): TPromise<IWorkspaceIdentifier> {
const codeWindow = this.windowsMainService.getWindowById(windowId);
if (codeWindow) {
this.windowsMainService.createAndOpenWorkspace(codeWindow, folders, path);
return this.windowsMainService.createAndOpenWorkspace(codeWindow, folders, path);
}
return TPromise.as(null);
}
saveAndOpenWorkspace(windowId: number, path: string): TPromise<void> {
saveAndOpenWorkspace(windowId: number, path: string): TPromise<IWorkspaceIdentifier> {
const codeWindow = this.windowsMainService.getWindowById(windowId);
if (codeWindow) {
this.windowsMainService.saveAndOpenWorkspace(codeWindow, path);
return this.windowsMainService.saveAndOpenWorkspace(codeWindow, path);
}
return TPromise.as(null);
......
......@@ -9,14 +9,14 @@ import { TPromise } from 'vs/base/common/winjs.base';
import { Action } from 'vs/base/common/actions';
import nls = require('vs/nls');
import { distinct } from 'vs/base/common/arrays';
import { IWindowService, IWindowsService } from 'vs/platform/windows/common/windows';
import { IWindowService } from 'vs/platform/windows/common/windows';
import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
import URI from 'vs/base/common/uri';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IWorkspacesService, WORKSPACE_FILTER } from 'vs/platform/workspaces/common/workspaces';
import { WORKSPACE_FILTER } from 'vs/platform/workspaces/common/workspaces';
import { IMessageService, Severity } from 'vs/platform/message/common/message';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { isLinux } from 'vs/base/common/platform';
......@@ -113,10 +113,12 @@ export class AddRootFolderAction extends BaseWorkspacesAction {
if (!folders || !folders.length) {
return TPromise.as(null);
}
return this.workspaceEditingService.addFolders(folders.map(folder => URI.file(folder))).then(() => {
return this.viewletService.openViewlet(this.viewletService.getDefaultViewletId(), true);
});
}
return this.instantiationService.createInstance(NewWorkspaceAction, NewWorkspaceAction.ID, NewWorkspaceAction.LABEL, this.contextService.getWorkspace().folders.map(folder => folder.uri)).run();
}
}
......@@ -133,8 +135,7 @@ class NewWorkspaceAction extends BaseWorkspacesAction {
@IWindowService windowService: IWindowService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IEnvironmentService environmentService: IEnvironmentService,
@IWorkspacesService protected workspacesService: IWorkspacesService,
@IWindowsService protected windowsService: IWindowsService,
@IWorkspaceEditingService private workspaceEditingService: IWorkspaceEditingService
) {
super(id, label, windowService, environmentService, contextService);
}
......@@ -151,7 +152,7 @@ class NewWorkspaceAction extends BaseWorkspacesAction {
private createWorkspace(folders: URI[]): TPromise<void> {
const workspaceFolders = distinct(folders.map(folder => folder.fsPath), folder => isLinux ? folder : folder.toLowerCase());
return this.windowService.createAndOpenWorkspace(workspaceFolders);
return this.workspaceEditingService.createAndOpenWorkspace(workspaceFolders);
}
}
......@@ -185,9 +186,8 @@ export class SaveWorkspaceAsAction extends BaseWorkspacesAction {
@IWindowService windowService: IWindowService,
@IEnvironmentService environmentService: IEnvironmentService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IWorkspacesService protected workspacesService: IWorkspacesService,
@IWindowsService private windowsService: IWindowsService,
@IMessageService private messageService: IMessageService
@IMessageService private messageService: IMessageService,
@IWorkspaceEditingService private workspaceEditingService: IWorkspaceEditingService
) {
super(id, label, windowService, environmentService, contextService);
}
......@@ -196,6 +196,7 @@ export class SaveWorkspaceAsAction extends BaseWorkspacesAction {
const workspaceState = this.contextService.getWorkbenchState();
if (workspaceState === WorkbenchState.EMPTY) {
this.messageService.show(Severity.Info, nls.localize('saveEmptyWorkspaceNotSupported', "Please open a workspace first to save."));
return TPromise.as(null);
}
......@@ -205,10 +206,10 @@ export class SaveWorkspaceAsAction extends BaseWorkspacesAction {
case WorkbenchState.FOLDER:
const workspaceFolders = this.contextService.getWorkspace().folders.map(root => root.uri.fsPath);
return this.windowService.createAndOpenWorkspace(workspaceFolders, configPath);
return this.workspaceEditingService.createAndOpenWorkspace(workspaceFolders, configPath);
case WorkbenchState.WORKSPACE:
return this.windowService.saveAndOpenWorkspace(configPath);
return this.workspaceEditingService.saveAndOpenWorkspace(configPath);
}
}
......
......@@ -390,7 +390,7 @@ export class ElectronWindow extends Themable {
workspaceFolders.push(...request.foldersToAdd.map(folderToAdd => URI.file(folderToAdd.filePath)));
// Create workspace and open (ensure no duplicates)
this.windowService.createAndOpenWorkspace(arrays.distinct(workspaceFolders.map(folder => folder.fsPath), folder => platform.isLinux ? folder : folder.toLowerCase()));
this.workspaceEditingService.createAndOpenWorkspace(arrays.distinct(workspaceFolders.map(folder => folder.fsPath), folder => platform.isLinux ? folder : folder.toLowerCase()));
}
}
......
......@@ -906,7 +906,8 @@ export class FileDragAndDrop extends SimpleFileResourceDragAndDrop {
const currentFolders = this.contextService.getWorkspace().folders.map(folder => folder.uri);
const newRoots = [...currentFolders, ...folders];
return this.windowService.createAndOpenWorkspace(distinct(newRoots.map(root => root.fsPath)));
// Create and open workspace
return this.workspaceEditingService.createAndOpenWorkspace(distinct(newRoots.map(root => root.fsPath)));
}
}
......
......@@ -24,6 +24,17 @@ export interface IWorkspaceEditingService {
* remove folders from the existing workspace
*/
removeFolders(folders: URI[]): TPromise<void>;
/**
* creates a new workspace with the provided folders and opens it. if path is provided
* the workspace will be saved into that location.
*/
createAndOpenWorkspace(folders?: string[], path?: string): TPromise<void>;
/**
* saves the workspace to the provided path and opens it. requires a workspace to be opened.
*/
saveAndOpenWorkspace(path: string): TPromise<void>;
}
export const IWorkspaceMigrationService = createDecorator<IWorkspaceMigrationService>('workspaceMigrationService');
......
......@@ -9,14 +9,15 @@ import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IWindowsService } from 'vs/platform/windows/common/windows';
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IJSONEditingService } from 'vs/workbench/services/configuration/common/jsonEditing';
import { IWorkspacesService, IStoredWorkspaceFolder } from 'vs/platform/workspaces/common/workspaces';
import { IWorkspacesService, IStoredWorkspaceFolder, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { dirname } from 'path';
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
import { massageFolderPathForWorkspace } from 'vs/platform/workspaces/node/workspaces';
import { isLinux } from 'vs/base/common/platform';
import { WorkspaceServiceImpl } from 'vs/workbench/services/configuration/node/configuration';
export class WorkspaceEditingService implements IWorkspaceEditingService {
......@@ -27,6 +28,7 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IWindowsService private windowsService: IWindowsService,
@IWindowService private windowService: IWindowService,
@IWorkspacesService private workspacesService: IWorkspacesService,
@IWorkspaceConfigurationService private workspaceConfigurationService: IWorkspaceConfigurationService
) {
......@@ -114,4 +116,16 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
return resource.toString().toLowerCase() === toCheck.toString().toLowerCase();
});
}
public createAndOpenWorkspace(folders?: string[], path?: string): TPromise<void> {
return this.windowService.createAndOpenWorkspace(folders).then(workspace => this.openWorkspace(workspace));
}
public saveAndOpenWorkspace(path: string): TPromise<void> {
return this.windowService.saveAndOpenWorkspace(path).then(workspace => this.openWorkspace(workspace));
}
private openWorkspace(workspace: IWorkspaceIdentifier): TPromise<void> {
return (this.contextService as WorkspaceServiceImpl).initialize(workspace); // TODO@Ben ugly cast
}
}
\ No newline at end of file
......@@ -903,11 +903,11 @@ export class TestWindowService implements IWindowService {
return TPromise.as(void 0);
}
createAndOpenWorkspace(folders?: string[], path?: string): TPromise<void> {
createAndOpenWorkspace(folders?: string[], path?: string): TPromise<IWorkspaceIdentifier> {
return TPromise.as(void 0);
}
saveAndOpenWorkspace(path: string): TPromise<void> {
saveAndOpenWorkspace(path: string): TPromise<IWorkspaceIdentifier> {
return TPromise.as(void 0);
}
......@@ -1051,11 +1051,11 @@ export class TestWindowsService implements IWindowsService {
return TPromise.as(void 0);
}
createAndOpenWorkspace(windowId: number, folders?: string[], path?: string): TPromise<void> {
createAndOpenWorkspace(windowId: number, folders?: string[], path?: string): TPromise<IWorkspaceIdentifier> {
return TPromise.as(void 0);
}
saveAndOpenWorkspace(windowId: number, path: string): TPromise<void> {
saveAndOpenWorkspace(windowId: number, path: string): TPromise<IWorkspaceIdentifier> {
return TPromise.as(void 0);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册