提交 7b8dbf65 编写于 作者: B Benjamin Pasero

add a method to fully resolve a workspace on the main side

上级 84fd73be
......@@ -273,7 +273,7 @@ export class WindowsManager implements IWindowsMainService {
// Don't Save: delete workspace
case ConfirmResult.DONT_SAVE:
this.workspacesService.deleteUntitledWorkspace(workspace);
this.workspacesService.deleteUntitledWorkspaceSync(workspace);
e.veto(false);
break;
......@@ -915,7 +915,7 @@ export class WindowsManager implements IWindowsMainService {
// Workspace
const workspace = this.workspacesService.resolveWorkspaceSync(candidate);
if (workspace) {
return { workspace };
return { workspace: { id: workspace.id, configPath: candidate } };
}
// File
......
......@@ -47,10 +47,10 @@ export interface IWorkspacesMainService extends IWorkspacesService {
onWorkspaceSaved: Event<IWorkspaceSavedEvent>;
onWorkspaceDeleted: Event<IWorkspaceIdentifier>;
resolveWorkspaceSync(path: string): IWorkspaceIdentifier;
resolveWorkspaceSync(path: string): IStoredWorkspace;
isUntitledWorkspace(workspace: IWorkspaceIdentifier): boolean;
deleteUntitledWorkspace(workspace: IWorkspaceIdentifier): void;
deleteUntitledWorkspaceSync(workspace: IWorkspaceIdentifier): void;
}
export interface IWorkspacesService {
......
......@@ -46,7 +46,7 @@ export class WorkspacesMainService implements IWorkspacesMainService {
return this._onWorkspaceDeleted.event;
}
public resolveWorkspaceSync(path: string): IWorkspaceIdentifier {
public resolveWorkspaceSync(path: string): IStoredWorkspace {
const isWorkspace = this.isInsideWorkspacesHome(path) || extname(path) === `.${WORKSPACE_EXTENSION}`;
if (!isWorkspace) {
return null; // does not look like a valid workspace config file
......@@ -60,10 +60,7 @@ export class WorkspacesMainService implements IWorkspacesMainService {
return null; // looks like an invalid workspace file
}
return {
id: workspace.id,
configPath: path
};
return workspace;
} catch (error) {
this.logService.log(`${path} cannot be parsed as JSON file (${error}).`);
......@@ -115,18 +112,19 @@ export class WorkspacesMainService implements IWorkspacesMainService {
// Copy to new target
return nfcall(copy, workspace.configPath, target).then(() => {
const savedWorkspace = this.resolveWorkspaceSync(target);
const savedWorkspaceIdentifier = { id: savedWorkspace.id, configPath: target };
// Event
this._onWorkspaceSaved.fire({ workspace: savedWorkspace, oldConfigPath: workspace.configPath });
this._onWorkspaceSaved.fire({ workspace: savedWorkspaceIdentifier, oldConfigPath: workspace.configPath });
// Delete untitled workspace
this.deleteUntitledWorkspace(workspace);
this.deleteUntitledWorkspaceSync(workspace);
return savedWorkspace;
return savedWorkspaceIdentifier;
});
}
public deleteUntitledWorkspace(workspace: IWorkspaceIdentifier): void {
public deleteUntitledWorkspaceSync(workspace: IWorkspaceIdentifier): void {
if (!this.isUntitledWorkspace(workspace)) {
return; // only supported for untitled workspaces
}
......
......@@ -30,10 +30,10 @@ suite('WorkspacesMainService', () => {
class TestWorkspacesMainService extends WorkspacesMainService {
public deleteWorkspaceCall: IWorkspaceIdentifier;
public deleteUntitledWorkspace(workspace: IWorkspaceIdentifier): void {
public deleteUntitledWorkspaceSync(workspace: IWorkspaceIdentifier): void {
this.deleteWorkspaceCall = workspace;
super.deleteUntitledWorkspace(workspace);
super.deleteUntitledWorkspaceSync(workspace);
}
}
......@@ -83,7 +83,6 @@ suite('WorkspacesMainService', () => {
test('resolveWorkspace', done => {
return service.createWorkspace([process.cwd(), os.tmpdir()]).then(workspace => {
assert.ok(service.resolveWorkspaceSync(workspace.configPath));
// make it a valid workspace path
......@@ -92,7 +91,7 @@ suite('WorkspacesMainService', () => {
workspace.configPath = newPath;
const resolved = service.resolveWorkspaceSync(workspace.configPath);
assert.deepEqual(resolved, { id: workspace.id, configPath: workspace.configPath });
assert.deepEqual(resolved, { id: workspace.id, folders: [process.cwd(), os.tmpdir()] });
done();
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册