Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add _workbench.enterWorkspace #54129

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 36 additions & 13 deletions src/vs/code/electron-main/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,10 @@ export class WindowsManager implements IWindowsMainService {
return this.workspacesManager.saveAndEnterWorkspace(win, path).then(result => this.doEnterWorkspace(win, result));
}

enterWorkspace(win: ICodeWindow, path: string): TPromise<IEnterWorkspaceResult> {
return this.workspacesManager.enterWorkspace(win, path).then(result => this.doEnterWorkspace(win, result));
}

createAndEnterWorkspace(win: ICodeWindow, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
return this.workspacesManager.createAndEnterWorkspace(win, folders, path).then(result => this.doEnterWorkspace(win, result));
}
Expand Down Expand Up @@ -1775,6 +1779,23 @@ class WorkspacesManager {
return this.doSaveAndOpenWorkspace(window, window.openedWorkspace, path);
}

enterWorkspace(window: ICodeWindow, path: string): TPromise<IEnterWorkspaceResult> {
if (!window || !window.win || window.readyState !== ReadyState.READY) {
return TPromise.as(null); // return early if the window is not ready or disposed
}

return this.isValidTargetWorkspacePath(window, path).then(isValid => {
if (!isValid) {
return TPromise.as<IEnterWorkspaceResult>(null); // return early if the workspace is not valid
}

return this.workspacesMainService.resolveWorkspace(path).then(workspace => {
return this.doOpenWorkspace(window, workspace);
});
});

}

createAndEnterWorkspace(window: ICodeWindow, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
if (!window || !window.win || window.readyState !== ReadyState.READY) {
return TPromise.as(null); // return early if the window is not ready or disposed
Expand Down Expand Up @@ -1826,22 +1847,24 @@ class WorkspacesManager {
savePromise = TPromise.as(workspace);
}

return savePromise.then(workspace => {
window.focus();
return savePromise.then(workspace => this.doOpenWorkspace(window, workspace));
}

// Register window for backups and migrate current backups over
let backupPath: string;
if (!window.config.extensionDevelopmentPath) {
backupPath = this.backupMainService.registerWorkspaceBackupSync(workspace, window.config.backupPath);
}
private doOpenWorkspace(window: ICodeWindow, workspace: IWorkspaceIdentifier): IEnterWorkspaceResult {
window.focus();

// Update window configuration properly based on transition to workspace
window.config.folderPath = void 0;
window.config.workspace = workspace;
window.config.backupPath = backupPath;
// Register window for backups and migrate current backups over
let backupPath: string;
if (!window.config.extensionDevelopmentPath) {
backupPath = this.backupMainService.registerWorkspaceBackupSync(workspace, window.config.backupPath);
}

return { workspace, backupPath };
});
// Update window configuration properly based on transition to workspace
window.config.folderPath = void 0;
window.config.workspace = workspace;
window.config.backupPath = backupPath;

return { workspace, backupPath };
}

pickWorkspaceAndOpen(options: INativeOpenDialogOptions): void {
Expand Down
2 changes: 2 additions & 0 deletions src/vs/platform/windows/common/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export interface IWindowsService {
openDevTools(windowId: number, options?: IDevToolsOptions): TPromise<void>;
toggleDevTools(windowId: number): TPromise<void>;
closeWorkspace(windowId: number): TPromise<void>;
enterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult>;
createAndEnterWorkspace(windowId: number, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult>;
saveAndEnterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult>;
toggleFullScreen(windowId: number): TPromise<void>;
Expand Down Expand Up @@ -200,6 +201,7 @@ export interface IWindowService {
toggleDevTools(): TPromise<void>;
closeWorkspace(): TPromise<void>;
updateTouchBar(items: ISerializableCommandAction[][]): TPromise<void>;
enterWorkspace(path: string): TPromise<IEnterWorkspaceResult>;
createAndEnterWorkspace(folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult>;
saveAndEnterWorkspace(path: string): TPromise<IEnterWorkspaceResult>;
toggleFullScreen(): TPromise<void>;
Expand Down
6 changes: 6 additions & 0 deletions src/vs/platform/windows/common/windowsIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface IWindowsChannel extends IChannel {
call(command: 'reloadWindow', arg: [number, ParsedArgs]): TPromise<void>;
call(command: 'toggleDevTools', arg: number): TPromise<void>;
call(command: 'closeWorkspace', arg: number): TPromise<void>;
call(command: 'enterWorkspace', arg: [number, string]): TPromise<IEnterWorkspaceResult>;
call(command: 'createAndEnterWorkspace', arg: [number, IWorkspaceFolderCreationData[], string]): TPromise<IEnterWorkspaceResult>;
call(command: 'saveAndEnterWorkspace', arg: [number, string]): TPromise<IEnterWorkspaceResult>;
call(command: 'toggleFullScreen', arg: number): TPromise<void>;
Expand Down Expand Up @@ -120,6 +121,7 @@ export class WindowsChannel implements IWindowsChannel {
case 'openDevTools': return this.service.openDevTools(arg[0], arg[1]);
case 'toggleDevTools': return this.service.toggleDevTools(arg);
case 'closeWorkspace': return this.service.closeWorkspace(arg);
case 'enterWorkspace': return this.service.enterWorkspace(arg[0], arg[1]);
case 'createAndEnterWorkspace': {
const rawFolders: IWorkspaceFolderCreationData[] = arg[1];
let folders: IWorkspaceFolderCreationData[];
Expand Down Expand Up @@ -234,6 +236,10 @@ export class WindowsChannelClient implements IWindowsService {
return this.channel.call('closeWorkspace', windowId);
}

enterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult> {
return this.channel.call('enterWorkspace', [windowId, path]);
}

createAndEnterWorkspace(windowId: number, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
return this.channel.call('createAndEnterWorkspace', [windowId, folders, path]);
}
Expand Down
4 changes: 4 additions & 0 deletions src/vs/platform/windows/electron-browser/windowService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export class WindowService implements IWindowService {
return this.windowsService.closeWorkspace(this.windowId);
}

enterWorkspace(path: string): TPromise<IEnterWorkspaceResult> {
return this.windowsService.enterWorkspace(this.windowId, path);
}

createAndEnterWorkspace(folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
return this.windowsService.createAndEnterWorkspace(this.windowId, folders, path);
}
Expand Down
1 change: 1 addition & 0 deletions src/vs/platform/windows/electron-main/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface IWindowsMainService {
// methods
ready(initialUserEnv: IProcessEnvironment): void;
reload(win: ICodeWindow, cli?: ParsedArgs): void;
enterWorkspace(win: ICodeWindow, path: string): TPromise<IEnterWorkspaceResult>;
createAndEnterWorkspace(win: ICodeWindow, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult>;
saveAndEnterWorkspace(win: ICodeWindow, path: string): TPromise<IEnterWorkspaceResult>;
closeWorkspace(win: ICodeWindow): void;
Expand Down
11 changes: 11 additions & 0 deletions src/vs/platform/windows/electron-main/windowsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ export class WindowsService implements IWindowsService, IURLHandler, IDisposable
return TPromise.as(null);
}

enterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult> {
this.logService.trace('windowsService#enterWorkspace', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);

if (codeWindow) {
return this.windowsMainService.enterWorkspace(codeWindow, path);
}

return TPromise.as(null);
}

createAndEnterWorkspace(windowId: number, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
this.logService.trace('windowsService#createAndEnterWorkspace', windowId);
const codeWindow = this.windowsMainService.getWindowById(windowId);
Expand Down
2 changes: 2 additions & 0 deletions src/vs/platform/workspaces/common/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export interface IWorkspacesMainService extends IWorkspacesService {

createWorkspaceSync(folders?: IWorkspaceFolderCreationData[]): IWorkspaceIdentifier;

resolveWorkspace(path: string): TPromise<IResolvedWorkspace>;

resolveWorkspaceSync(path: string): IResolvedWorkspace;

isUntitledWorkspace(workspace: IWorkspaceIdentifier): boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ export class WorkspacesMainService implements IWorkspacesMainService {
return this._onUntitledWorkspaceDeleted.event;
}

resolveWorkspace(path: string): TPromise<IResolvedWorkspace> {
if (!this.isWorkspacePath(path)) {
return TPromise.as(null); // does not look like a valid workspace config file
}

return readFile(path, 'utf8').then(contents => this.doResolveWorkspace(path, contents));
}

resolveWorkspaceSync(path: string): IResolvedWorkspace {
if (!this.isWorkspacePath(path)) {
return null; // does not look like a valid workspace config file
Expand Down
9 changes: 8 additions & 1 deletion src/vs/workbench/api/electron-browser/mainThreadWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import URI, { UriComponents } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { localize } from 'vs/nls';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IFileMatch, IFolderQuery, IPatternInfo, IQueryOptions, ISearchConfiguration, ISearchQuery, ISearchService, QueryType } from 'vs/platform/search/common/search';
import { IStatusbarService } from 'vs/platform/statusbar/common/statusbar';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
Expand All @@ -19,6 +19,7 @@ import { QueryBuilder } from 'vs/workbench/parts/search/common/queryBuilder';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
import { ExtHostContext, ExtHostWorkspaceShape, IExtHostContext, MainContext, MainThreadWorkspaceShape } from '../node/extHost.protocol';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';

@extHostNamedCustomer(MainContext.MainThreadWorkspace)
export class MainThreadWorkspace implements MainThreadWorkspaceShape {
Expand Down Expand Up @@ -210,3 +211,9 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {
});
}
}

CommandsRegistry.registerCommand('_workbench.enterWorkspace', function (accessor: ServicesAccessor, workspace: URI) {
const workspaceEditingService = accessor.get(IWorkspaceEditingService);

return workspaceEditingService.enterWorkspace(workspace.fsPath);
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface IWorkspaceEditingService {
*/
updateFolders(index: number, deleteCount?: number, foldersToAdd?: IWorkspaceFolderCreationData[], donotNotifyError?: boolean): TPromise<void>;

/**
* enters the workspace with the provided path.
*/
enterWorkspace(path: string): 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ export class WorkspaceEditingService implements IWorkspaceEditingService {
return false;
}

enterWorkspace(path: string): TPromise<void> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we should move entering workspace API to IWorkspaceContextService? Because I think having these APIs in IWorkspaceEditingService does not fit good to me.

If agreed, I will tackle it in the next debt week

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sandy081 yeah, but there are more methods like createAndEnterWorkspace and saveAndEnterWorkspace which then should also move. I am all up for not having that in the editing service if possible.

return this.doEnterWorkspace(() => this.windowService.enterWorkspace(path));
}

createAndEnterWorkspace(folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<void> {
return this.doEnterWorkspace(() => this.windowService.createAndEnterWorkspace(folders, path));
}
Expand Down
8 changes: 8 additions & 0 deletions src/vs/workbench/test/workbenchTestServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,10 @@ export class TestWindowService implements IWindowService {
return TPromise.as(void 0);
}

enterWorkspace(path: string): TPromise<IEnterWorkspaceResult> {
return TPromise.as(void 0);
}

createAndEnterWorkspace(folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
return TPromise.as(void 0);
}
Expand Down Expand Up @@ -1162,6 +1166,10 @@ export class TestWindowsService implements IWindowsService {
return TPromise.as(void 0);
}

enterWorkspace(windowId: number, path: string): TPromise<IEnterWorkspaceResult> {
return TPromise.as(void 0);
}

createAndEnterWorkspace(windowId: number, folders?: IWorkspaceFolderCreationData[], path?: string): TPromise<IEnterWorkspaceResult> {
return TPromise.as(void 0);
}
Expand Down