Skip to content

Commit ff8afd0

Browse files
committed
label for recent
1 parent c7622aa commit ff8afd0

19 files changed

Lines changed: 402 additions & 321 deletions

File tree

src/vs/code/electron-main/windows.ts

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import { Event as CommonEvent, Emitter } from 'vs/base/common/event';
2424
import product from 'vs/platform/product/node/product';
2525
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
2626
import { IWindowsMainService, IOpenConfiguration, IWindowsCountChangedEvent, ICodeWindow, IWindowState as ISingleWindowState, WindowMode } from 'vs/platform/windows/electron-main/windows';
27-
import { IHistoryMainService } from 'vs/platform/history/common/history';
27+
import { IHistoryMainService, IRecent } from 'vs/platform/history/common/history';
2828
import { IProcessEnvironment, isMacintosh, isWindows } from 'vs/base/common/platform';
29-
import { IWorkspacesMainService, IWorkspaceIdentifier, WORKSPACE_FILTER, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier, hasWorkspaceFileExtension } from 'vs/platform/workspaces/common/workspaces';
29+
import { IWorkspacesMainService, IWorkspaceIdentifier, WORKSPACE_FILTER, isSingleFolderWorkspaceIdentifier, hasWorkspaceFileExtension } from 'vs/platform/workspaces/common/workspaces';
3030
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
3131
import { mnemonicButtonLabel } from 'vs/base/common/labels';
3232
import { Schemas } from 'vs/base/common/network';
@@ -37,6 +37,7 @@ import { exists } from 'vs/base/node/pfs';
3737
import { getComparisonKey, isEqual, normalizePath, basename as resourcesBasename, originalFSPath, hasTrailingPathSeparator, removeTrailingPathSeparator } from 'vs/base/common/resources';
3838
import { getRemoteAuthority } from 'vs/platform/remote/common/remoteHosts';
3939
import { restoreWindowsState, WindowsStateStorageData, getWindowsStateStoreData } from 'vs/code/electron-main/windowsStateStorage';
40+
import { getWorkspaceIdentifier } from 'vs/platform/workspaces/electron-main/workspacesMainService';
4041

4142
const enum WindowError {
4243
UNRESPONSIVE = 1,
@@ -114,6 +115,9 @@ interface IPathToOpen extends IPath {
114115

115116
// indicator to create the file path in the Code instance
116117
createFilePath?: boolean;
118+
119+
// optional label for the recent history
120+
label?: string;
117121
}
118122

119123
function isFolderPathToOpen(path: IPathToOpen): path is IFolderPathToOpen {
@@ -130,6 +134,9 @@ interface IFolderPathToOpen {
130134

131135
// the remote authority for the Code instance to open. Undefined if not remote.
132136
remoteAuthority?: string;
137+
138+
// optional label for the recent history
139+
label?: string;
133140
}
134141

135142
function isWorkspacePathToOpen(path: IPathToOpen): path is IWorkspacePathToOpen {
@@ -146,6 +153,9 @@ interface IWorkspacePathToOpen {
146153

147154
// the remote authority for the Code instance to open. Undefined if not remote.
148155
remoteAuthority?: string;
156+
157+
// optional label for the recent history
158+
label?: string;
149159
}
150160

151161
export class WindowsManager implements IWindowsMainService {
@@ -479,23 +489,18 @@ export class WindowsManager implements IWindowsMainService {
479489

480490
// Remember in recent document list (unless this opens for extension development)
481491
// Also do not add paths when files are opened for diffing, only if opened individually
482-
if (!usedWindows.some(w => w.isExtensionDevelopmentHost) && !openConfig.diffMode) {
483-
const recentlyOpenedWorkspaces: Array<IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier> = [];
484-
const recentlyOpenedFiles: URI[] = [];
485-
486-
pathsToOpen.forEach(win => {
487-
if (win.workspace) {
488-
recentlyOpenedWorkspaces.push(win.workspace);
489-
} else if (win.folderUri) {
490-
recentlyOpenedWorkspaces.push(win.folderUri);
491-
} else if (win.fileUri) {
492-
recentlyOpenedFiles.push(win.fileUri);
492+
if (!usedWindows.some(w => w.isExtensionDevelopmentHost) && !openConfig.diffMode && !this.environmentService.skipAddToRecentlyOpened) {
493+
const recents: IRecent[] = [];
494+
for (let pathToOpen of pathsToOpen) {
495+
if (pathToOpen.workspace) {
496+
recents.push({ label: pathToOpen.label, workspace: pathToOpen.workspace });
497+
} else if (pathToOpen.folderUri) {
498+
recents.push({ label: pathToOpen.label, folderUri: pathToOpen.folderUri });
499+
} else if (pathToOpen.fileUri) {
500+
recents.push({ label: pathToOpen.label, fileUri: pathToOpen.fileUri });
493501
}
494-
});
495-
496-
if (!this.environmentService.skipAddToRecentlyOpened) {
497-
this.historyMainService.addRecentlyOpened(recentlyOpenedWorkspaces, recentlyOpenedFiles);
498502
}
503+
this.historyMainService.addRecentlyOpened(recents);
499504
}
500505

501506
// If we got started with --wait from the CLI, we need to signal to the outside when the window
@@ -844,6 +849,7 @@ export class WindowsManager implements IWindowsMainService {
844849

845850
const path = this.parseUri(pathToOpen.uri, pathToOpen.typeHint, parseOptions);
846851
if (path) {
852+
path.label = pathToOpen.label;
847853
pathsToOpen.push(path);
848854
} else {
849855

@@ -1031,7 +1037,7 @@ export class WindowsManager implements IWindowsMainService {
10311037
}
10321038
if (hasWorkspaceFileExtension(uri.path) && !options.forceOpenWorkspaceAsFile) {
10331039
return {
1034-
workspace: this.workspacesMainService.getWorkspaceIdentifier(uri),
1040+
workspace: getWorkspaceIdentifier(uri),
10351041
remoteAuthority
10361042
};
10371043
}
@@ -1098,9 +1104,8 @@ export class WindowsManager implements IWindowsMainService {
10981104
}
10991105
}
11001106
} catch (error) {
1101-
this.historyMainService.removeFromRecentlyOpened([candidate]); // since file does not seem to exist anymore, remove from recent
1102-
11031107
const fileUri = URI.file(candidate);
1108+
this.historyMainService.removeFromRecentlyOpened([fileUri]); // since file does not seem to exist anymore, remove from recent
11041109
if (options && options.ignoreFileNotFound) {
11051110
return { fileUri, createFilePath: true, remoteAuthority }; // assume this is a file that does not yet exist
11061111
}
@@ -1513,7 +1518,7 @@ export class WindowsManager implements IWindowsMainService {
15131518
private doEnterWorkspace(win: ICodeWindow, result: IEnterWorkspaceResult): IEnterWorkspaceResult {
15141519

15151520
// Mark as recently opened
1516-
this.historyMainService.addRecentlyOpened([result.workspace], []);
1521+
this.historyMainService.addRecentlyOpened([{ workspace: result.workspace }]);
15171522

15181523
// Trigger Eevent to indicate load of workspace into window
15191524
this._onWindowReady.fire(win);
@@ -1968,7 +1973,7 @@ class WorkspacesManager {
19681973
if (!isValid) {
19691974
return null; // return early if the workspace is not valid
19701975
}
1971-
const workspaceIdentifier = this.workspacesMainService.getWorkspaceIdentifier(path);
1976+
const workspaceIdentifier = getWorkspaceIdentifier(path);
19721977
return this.doOpenWorkspace(window, workspaceIdentifier);
19731978
});
19741979

@@ -1984,7 +1989,7 @@ class WorkspacesManager {
19841989
}
19851990

19861991
// Prevent overwriting a workspace that is currently opened in another window
1987-
if (findWindowOnWorkspace(this.windowsMainService.getWindows(), this.workspacesMainService.getWorkspaceIdentifier(path))) {
1992+
if (findWindowOnWorkspace(this.windowsMainService.getWindows(), getWorkspaceIdentifier(path))) {
19881993
const options: Electron.MessageBoxOptions = {
19891994
title: product.nameLong,
19901995
type: 'info',

src/vs/platform/history/common/history.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,57 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { IPath } from 'vs/platform/windows/common/windows';
76
import { Event as CommonEvent } from 'vs/base/common/event';
87
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
98
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
109
import { URI } from 'vs/base/common/uri';
10+
import { IPath } from 'vs/platform/windows/common/windows';
1111

1212
export const IHistoryMainService = createDecorator<IHistoryMainService>('historyMainService');
1313

1414
export interface IRecentlyOpened {
15-
workspaces: Array<IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier>;
16-
files: URI[];
15+
workspaces: Array<IRecentWorkspace | IRecentFolder>;
16+
files: IRecentFile[];
17+
}
18+
19+
export type IRecent = IRecentWorkspace | IRecentFolder | IRecentFile;
20+
21+
export interface IRecentWorkspace {
22+
workspace: IWorkspaceIdentifier;
23+
label?: string;
24+
}
25+
26+
export interface IRecentFolder {
27+
folderUri: ISingleFolderWorkspaceIdentifier;
28+
label?: string;
29+
}
30+
31+
export interface IRecentFile {
32+
fileUri: URI;
33+
label?: string;
34+
}
35+
36+
export function isRecentWorkspace(curr: IRecent): curr is IRecentWorkspace {
37+
return !!curr['workspace'];
38+
}
39+
40+
export function isRecentFolder(curr: IRecent): curr is IRecentFolder {
41+
return !!curr['folderUri'];
42+
}
43+
44+
export function isRecentFile(curr: IRecent): curr is IRecentFile {
45+
return !!curr['fileUri'];
1746
}
1847

48+
1949
export interface IHistoryMainService {
2050
_serviceBrand: any;
2151

2252
onRecentlyOpenedChange: CommonEvent<void>;
2353

24-
addRecentlyOpened(workspaces: undefined | Array<IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier>, files: URI[]): void;
25-
getRecentlyOpened(currentWorkspace?: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier, currentFiles?: IPath[]): IRecentlyOpened;
26-
removeFromRecentlyOpened(paths: Array<IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier | URI | string>): void;
54+
addRecentlyOpened(recents: IRecent[]): void;
55+
getRecentlyOpened(currentWorkspace?: IWorkspaceIdentifier, currentFolder?: ISingleFolderWorkspaceIdentifier, currentFiles?: IPath[]): IRecentlyOpened;
56+
removeFromRecentlyOpened(paths: URI[]): void;
2757
clearRecentlyOpened(): void;
2858

2959
updateWindowsJumpList(): void;

0 commit comments

Comments
 (0)