diff --git a/src/vs/platform/menubar/electron-main/menubar.ts b/src/vs/platform/menubar/electron-main/menubar.ts index 71f92ef6faf..88aa8edcd7e 100644 --- a/src/vs/platform/menubar/electron-main/menubar.ts +++ b/src/vs/platform/menubar/electron-main/menubar.ts @@ -491,7 +491,7 @@ export class Menubar { }).length > 0; if (!success) { - this.workspacesHistoryMainService.removeFromRecentlyOpened([revivedUri]); + this.workspacesHistoryMainService.removeRecentlyOpened([revivedUri]); } } }, false)); diff --git a/src/vs/platform/windows/electron-main/windowsMainService.ts b/src/vs/platform/windows/electron-main/windowsMainService.ts index 2d238b3bcc7..a5554fed40f 100644 --- a/src/vs/platform/windows/electron-main/windowsMainService.ts +++ b/src/vs/platform/windows/electron-main/windowsMainService.ts @@ -1190,7 +1190,7 @@ export class WindowsMainService extends Disposable implements IWindowsMainServic } } catch (error) { const fileUri = URI.file(candidate); - this.workspacesHistoryMainService.removeFromRecentlyOpened([fileUri]); // since file does not seem to exist anymore, remove from recent + this.workspacesHistoryMainService.removeRecentlyOpened([fileUri]); // since file does not seem to exist anymore, remove from recent // assume this is a file that does not yet exist if (options?.ignoreFileNotFound) { diff --git a/src/vs/platform/workspaces/common/workspaces.ts b/src/vs/platform/workspaces/common/workspaces.ts index 3864a42fd38..efef7f31107 100644 --- a/src/vs/platform/workspaces/common/workspaces.ts +++ b/src/vs/platform/workspaces/common/workspaces.ts @@ -40,7 +40,7 @@ export interface IWorkspacesService { // History readonly onRecentlyOpenedChange: CommonEvent; addRecentlyOpened(recents: IRecent[]): Promise; - removeFromRecentlyOpened(workspaces: URI[]): Promise; + removeRecentlyOpened(workspaces: URI[]): Promise; clearRecentlyOpened(): Promise; getRecentlyOpened(): Promise; } diff --git a/src/vs/platform/workspaces/electron-main/workspacesHistoryMainService.ts b/src/vs/platform/workspaces/electron-main/workspacesHistoryMainService.ts index 9c1239d1f13..f88997659d3 100644 --- a/src/vs/platform/workspaces/electron-main/workspacesHistoryMainService.ts +++ b/src/vs/platform/workspaces/electron-main/workspacesHistoryMainService.ts @@ -35,7 +35,7 @@ export interface IWorkspacesHistoryMainService { addRecentlyOpened(recents: IRecent[]): void; getRecentlyOpened(currentWorkspace?: IWorkspaceIdentifier, currentFolder?: ISingleFolderWorkspaceIdentifier, currentFiles?: IPath[]): IRecentlyOpened; - removeFromRecentlyOpened(paths: URI[]): void; + removeRecentlyOpened(paths: URI[]): void; clearRecentlyOpened(): void; updateWindowsJumpList(): void; @@ -148,7 +148,7 @@ export class WorkspacesHistoryMainService extends Disposable implements IWorkspa } } - removeFromRecentlyOpened(toRemove: URI[]): void { + removeRecentlyOpened(toRemove: URI[]): void { const keep = (recent: IRecent) => { const uri = location(recent); for (const r of toRemove) { @@ -344,7 +344,7 @@ export class WorkspacesHistoryMainService extends Disposable implements IWorkspa } } } - this.removeFromRecentlyOpened(toRemove); + this.removeRecentlyOpened(toRemove); // Add entries jumpList.push({ diff --git a/src/vs/platform/workspaces/electron-main/workspacesService.ts b/src/vs/platform/workspaces/electron-main/workspacesService.ts index f416b074be1..70f2bd9bb79 100644 --- a/src/vs/platform/workspaces/electron-main/workspacesService.ts +++ b/src/vs/platform/workspaces/electron-main/workspacesService.ts @@ -63,8 +63,8 @@ export class WorkspacesService implements AddFirstParameterToFunctions { - return this.workspacesHistoryMainService.removeFromRecentlyOpened(paths); + async removeRecentlyOpened(windowId: number, paths: URI[]): Promise { + return this.workspacesHistoryMainService.removeRecentlyOpened(paths); } async clearRecentlyOpened(windowId: number): Promise { diff --git a/src/vs/workbench/api/common/apiCommands.ts b/src/vs/workbench/api/common/apiCommands.ts index ee5b836f009..6e7bb05ba23 100644 --- a/src/vs/workbench/api/common/apiCommands.ts +++ b/src/vs/workbench/api/common/apiCommands.ts @@ -158,7 +158,7 @@ CommandsRegistry.registerCommand(OpenWithAPICommand.ID, adjustHandler(OpenWithAP CommandsRegistry.registerCommand('_workbench.removeFromRecentlyOpened', function (accessor: ServicesAccessor, uri: URI) { const workspacesService = accessor.get(IWorkspacesService); - return workspacesService.removeFromRecentlyOpened([uri]); + return workspacesService.removeRecentlyOpened([uri]); }); export class RemoveFromRecentlyOpenedAPICommand { diff --git a/src/vs/workbench/browser/actions/windowActions.ts b/src/vs/workbench/browser/actions/windowActions.ts index e59fdc54f75..707ba426404 100644 --- a/src/vs/workbench/browser/actions/windowActions.ts +++ b/src/vs/workbench/browser/actions/windowActions.ts @@ -129,7 +129,7 @@ abstract class BaseOpenRecentAction extends Action { onKeyMods: mods => keyMods = mods, quickNavigate: this.isQuickNavigate() ? { keybindings: this.keybindingService.lookupKeybindings(this.id) } : undefined, onDidTriggerItemButton: async context => { - await this.workspacesService.removeFromRecentlyOpened([context.item.resource]); + await this.workspacesService.removeRecentlyOpened([context.item.resource]); context.removeItem(); } }); diff --git a/src/vs/workbench/services/history/browser/history.ts b/src/vs/workbench/services/history/browser/history.ts index b05c5830535..a17f83a44e9 100644 --- a/src/vs/workbench/services/history/browser/history.ts +++ b/src/vs/workbench/services/history/browser/history.ts @@ -273,7 +273,7 @@ export class HistoryService extends Disposable implements IHistoryService { const input = arg1 as IResourceInput; - this.workspacesService.removeFromRecentlyOpened([input.resource]); + this.workspacesService.removeRecentlyOpened([input.resource]); } clear(): void { diff --git a/src/vs/workbench/services/workspaces/browser/workspacesService.ts b/src/vs/workbench/services/workspaces/browser/workspacesService.ts index 9ae880e83b4..9d41e4ea7a1 100644 --- a/src/vs/workbench/services/workspaces/browser/workspacesService.ts +++ b/src/vs/workbench/services/workspaces/browser/workspacesService.ts @@ -35,6 +35,8 @@ export class BrowserWorkspacesService extends Disposable implements IWorkspacesS ) { super(); + // Opening a workspace should push it as most + // recently used to the workspaces history this.addWorkspaceToRecentlyOpened(); this.registerListeners(); @@ -76,13 +78,13 @@ export class BrowserWorkspacesService extends Disposable implements IWorkspacesS recents.forEach(recent => { if (isRecentFile(recent)) { - this.doRemoveFromRecentlyOpened(recentlyOpened, [recent.fileUri]); + this.doRemoveRecentlyOpened(recentlyOpened, [recent.fileUri]); recentlyOpened.files.unshift(recent); } else if (isRecentFolder(recent)) { - this.doRemoveFromRecentlyOpened(recentlyOpened, [recent.folderUri]); + this.doRemoveRecentlyOpened(recentlyOpened, [recent.folderUri]); recentlyOpened.workspaces.unshift(recent); } else { - this.doRemoveFromRecentlyOpened(recentlyOpened, [recent.workspace.configPath]); + this.doRemoveRecentlyOpened(recentlyOpened, [recent.workspace.configPath]); recentlyOpened.workspaces.unshift(recent); } }); @@ -90,15 +92,15 @@ export class BrowserWorkspacesService extends Disposable implements IWorkspacesS return this.saveRecentlyOpened(recentlyOpened); } - async removeFromRecentlyOpened(paths: URI[]): Promise { + async removeRecentlyOpened(paths: URI[]): Promise { const recentlyOpened = await this.getRecentlyOpened(); - this.doRemoveFromRecentlyOpened(recentlyOpened, paths); + this.doRemoveRecentlyOpened(recentlyOpened, paths); return this.saveRecentlyOpened(recentlyOpened); } - private doRemoveFromRecentlyOpened(recentlyOpened: IRecentlyOpened, paths: URI[]): void { + private doRemoveRecentlyOpened(recentlyOpened: IRecentlyOpened, paths: URI[]): void { recentlyOpened.files = recentlyOpened.files.filter(file => { return !paths.some(path => path.toString() === file.fileUri.toString()); }); diff --git a/src/vs/workbench/services/workspaces/electron-browser/workspaceEditingService.ts b/src/vs/workbench/services/workspaces/electron-browser/workspaceEditingService.ts index eae32007ddc..976044b0f3a 100644 --- a/src/vs/workbench/services/workspaces/electron-browser/workspaceEditingService.ts +++ b/src/vs/workbench/services/workspaces/electron-browser/workspaceEditingService.ts @@ -131,11 +131,14 @@ export class NativeWorkspaceEditingService extends AbstractWorkspaceEditingServi try { await this.saveWorkspaceAs(workspaceIdentifier, newWorkspacePath); + // Make sure to add the new workspace to the history to find it again const newWorkspaceIdentifier = await this.workspacesService.getWorkspaceIdentifier(newWorkspacePath); + this.workspacesService.addRecentlyOpened([{ + label: this.labelService.getWorkspaceLabel(newWorkspaceIdentifier, { verbose: true }), + workspace: newWorkspaceIdentifier + }]); - const label = this.labelService.getWorkspaceLabel(newWorkspaceIdentifier, { verbose: true }); - this.workspacesService.addRecentlyOpened([{ label, workspace: newWorkspaceIdentifier }]); - + // Delete the untitled one this.workspacesService.deleteUntitledWorkspace(workspaceIdentifier); } catch (error) { // ignore