Skip to content

Commit 33189b3

Browse files
author
Benjamin Pasero
committed
workspaces service 💄
1 parent 4a59a41 commit 33189b3

10 files changed

Lines changed: 25 additions & 20 deletions

File tree

src/vs/platform/menubar/electron-main/menubar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ export class Menubar {
491491
}).length > 0;
492492

493493
if (!success) {
494-
this.workspacesHistoryMainService.removeFromRecentlyOpened([revivedUri]);
494+
this.workspacesHistoryMainService.removeRecentlyOpened([revivedUri]);
495495
}
496496
}
497497
}, false));

src/vs/platform/windows/electron-main/windowsMainService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic
11901190
}
11911191
} catch (error) {
11921192
const fileUri = URI.file(candidate);
1193-
this.workspacesHistoryMainService.removeFromRecentlyOpened([fileUri]); // since file does not seem to exist anymore, remove from recent
1193+
this.workspacesHistoryMainService.removeRecentlyOpened([fileUri]); // since file does not seem to exist anymore, remove from recent
11941194

11951195
// assume this is a file that does not yet exist
11961196
if (options?.ignoreFileNotFound) {

src/vs/platform/workspaces/common/workspaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface IWorkspacesService {
4040
// History
4141
readonly onRecentlyOpenedChange: CommonEvent<void>;
4242
addRecentlyOpened(recents: IRecent[]): Promise<void>;
43-
removeFromRecentlyOpened(workspaces: URI[]): Promise<void>;
43+
removeRecentlyOpened(workspaces: URI[]): Promise<void>;
4444
clearRecentlyOpened(): Promise<void>;
4545
getRecentlyOpened(): Promise<IRecentlyOpened>;
4646
}

src/vs/platform/workspaces/electron-main/workspacesHistoryMainService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface IWorkspacesHistoryMainService {
3535

3636
addRecentlyOpened(recents: IRecent[]): void;
3737
getRecentlyOpened(currentWorkspace?: IWorkspaceIdentifier, currentFolder?: ISingleFolderWorkspaceIdentifier, currentFiles?: IPath[]): IRecentlyOpened;
38-
removeFromRecentlyOpened(paths: URI[]): void;
38+
removeRecentlyOpened(paths: URI[]): void;
3939
clearRecentlyOpened(): void;
4040

4141
updateWindowsJumpList(): void;
@@ -148,7 +148,7 @@ export class WorkspacesHistoryMainService extends Disposable implements IWorkspa
148148
}
149149
}
150150

151-
removeFromRecentlyOpened(toRemove: URI[]): void {
151+
removeRecentlyOpened(toRemove: URI[]): void {
152152
const keep = (recent: IRecent) => {
153153
const uri = location(recent);
154154
for (const r of toRemove) {
@@ -344,7 +344,7 @@ export class WorkspacesHistoryMainService extends Disposable implements IWorkspa
344344
}
345345
}
346346
}
347-
this.removeFromRecentlyOpened(toRemove);
347+
this.removeRecentlyOpened(toRemove);
348348

349349
// Add entries
350350
jumpList.push({

src/vs/platform/workspaces/electron-main/workspacesService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ export class WorkspacesService implements AddFirstParameterToFunctions<IWorkspac
6363
return this.workspacesHistoryMainService.addRecentlyOpened(recents);
6464
}
6565

66-
async removeFromRecentlyOpened(windowId: number, paths: URI[]): Promise<void> {
67-
return this.workspacesHistoryMainService.removeFromRecentlyOpened(paths);
66+
async removeRecentlyOpened(windowId: number, paths: URI[]): Promise<void> {
67+
return this.workspacesHistoryMainService.removeRecentlyOpened(paths);
6868
}
6969

7070
async clearRecentlyOpened(windowId: number): Promise<void> {

src/vs/workbench/api/common/apiCommands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ CommandsRegistry.registerCommand(OpenWithAPICommand.ID, adjustHandler(OpenWithAP
158158

159159
CommandsRegistry.registerCommand('_workbench.removeFromRecentlyOpened', function (accessor: ServicesAccessor, uri: URI) {
160160
const workspacesService = accessor.get(IWorkspacesService);
161-
return workspacesService.removeFromRecentlyOpened([uri]);
161+
return workspacesService.removeRecentlyOpened([uri]);
162162
});
163163

164164
export class RemoveFromRecentlyOpenedAPICommand {

src/vs/workbench/browser/actions/windowActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ abstract class BaseOpenRecentAction extends Action {
129129
onKeyMods: mods => keyMods = mods,
130130
quickNavigate: this.isQuickNavigate() ? { keybindings: this.keybindingService.lookupKeybindings(this.id) } : undefined,
131131
onDidTriggerItemButton: async context => {
132-
await this.workspacesService.removeFromRecentlyOpened([context.item.resource]);
132+
await this.workspacesService.removeRecentlyOpened([context.item.resource]);
133133
context.removeItem();
134134
}
135135
});

src/vs/workbench/services/history/browser/history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ export class HistoryService extends Disposable implements IHistoryService {
273273

274274
const input = arg1 as IResourceInput;
275275

276-
this.workspacesService.removeFromRecentlyOpened([input.resource]);
276+
this.workspacesService.removeRecentlyOpened([input.resource]);
277277
}
278278

279279
clear(): void {

src/vs/workbench/services/workspaces/browser/workspacesService.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export class BrowserWorkspacesService extends Disposable implements IWorkspacesS
3535
) {
3636
super();
3737

38+
// Opening a workspace should push it as most
39+
// recently used to the workspaces history
3840
this.addWorkspaceToRecentlyOpened();
3941

4042
this.registerListeners();
@@ -76,29 +78,29 @@ export class BrowserWorkspacesService extends Disposable implements IWorkspacesS
7678

7779
recents.forEach(recent => {
7880
if (isRecentFile(recent)) {
79-
this.doRemoveFromRecentlyOpened(recentlyOpened, [recent.fileUri]);
81+
this.doRemoveRecentlyOpened(recentlyOpened, [recent.fileUri]);
8082
recentlyOpened.files.unshift(recent);
8183
} else if (isRecentFolder(recent)) {
82-
this.doRemoveFromRecentlyOpened(recentlyOpened, [recent.folderUri]);
84+
this.doRemoveRecentlyOpened(recentlyOpened, [recent.folderUri]);
8385
recentlyOpened.workspaces.unshift(recent);
8486
} else {
85-
this.doRemoveFromRecentlyOpened(recentlyOpened, [recent.workspace.configPath]);
87+
this.doRemoveRecentlyOpened(recentlyOpened, [recent.workspace.configPath]);
8688
recentlyOpened.workspaces.unshift(recent);
8789
}
8890
});
8991

9092
return this.saveRecentlyOpened(recentlyOpened);
9193
}
9294

93-
async removeFromRecentlyOpened(paths: URI[]): Promise<void> {
95+
async removeRecentlyOpened(paths: URI[]): Promise<void> {
9496
const recentlyOpened = await this.getRecentlyOpened();
9597

96-
this.doRemoveFromRecentlyOpened(recentlyOpened, paths);
98+
this.doRemoveRecentlyOpened(recentlyOpened, paths);
9799

98100
return this.saveRecentlyOpened(recentlyOpened);
99101
}
100102

101-
private doRemoveFromRecentlyOpened(recentlyOpened: IRecentlyOpened, paths: URI[]): void {
103+
private doRemoveRecentlyOpened(recentlyOpened: IRecentlyOpened, paths: URI[]): void {
102104
recentlyOpened.files = recentlyOpened.files.filter(file => {
103105
return !paths.some(path => path.toString() === file.fileUri.toString());
104106
});

src/vs/workbench/services/workspaces/electron-browser/workspaceEditingService.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,14 @@ export class NativeWorkspaceEditingService extends AbstractWorkspaceEditingServi
131131
try {
132132
await this.saveWorkspaceAs(workspaceIdentifier, newWorkspacePath);
133133

134+
// Make sure to add the new workspace to the history to find it again
134135
const newWorkspaceIdentifier = await this.workspacesService.getWorkspaceIdentifier(newWorkspacePath);
136+
this.workspacesService.addRecentlyOpened([{
137+
label: this.labelService.getWorkspaceLabel(newWorkspaceIdentifier, { verbose: true }),
138+
workspace: newWorkspaceIdentifier
139+
}]);
135140

136-
const label = this.labelService.getWorkspaceLabel(newWorkspaceIdentifier, { verbose: true });
137-
this.workspacesService.addRecentlyOpened([{ label, workspace: newWorkspaceIdentifier }]);
138-
141+
// Delete the untitled one
139142
this.workspacesService.deleteUntitledWorkspace(workspaceIdentifier);
140143
} catch (error) {
141144
// ignore

0 commit comments

Comments
 (0)