mirror of
https://github.com/Microsoft/vscode
synced 2024-09-18 01:58:27 +00:00
Add saved files to "Open Recent" (fix #153275)
This commit is contained in:
parent
23a31cb18d
commit
b1446a6693
|
@ -20,9 +20,8 @@ import { ILifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle
|
|||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
|
||||
import { IApplicationStorageMainService } from 'vs/platform/storage/electron-main/storageMainService';
|
||||
import { ICodeWindow } from 'vs/platform/window/electron-main/window';
|
||||
import { IRecent, IRecentFile, IRecentFolder, IRecentlyOpened, IRecentWorkspace, isRecentFile, isRecentFolder, isRecentWorkspace, restoreRecentlyOpened, toStoreData } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { isSingleFolderWorkspaceIdentifier, isWorkspaceIdentifier, IWorkspaceIdentifier, WORKSPACE_EXTENSION } from 'vs/platform/workspace/common/workspace';
|
||||
import { IWorkspaceIdentifier, WORKSPACE_EXTENSION } from 'vs/platform/workspace/common/workspace';
|
||||
import { IWorkspacesManagementMainService } from 'vs/platform/workspaces/electron-main/workspacesManagementMainService';
|
||||
|
||||
export const IWorkspacesHistoryMainService = createDecorator<IWorkspacesHistoryMainService>('workspacesHistoryMainService');
|
||||
|
@ -34,7 +33,7 @@ export interface IWorkspacesHistoryMainService {
|
|||
readonly onDidChangeRecentlyOpened: CommonEvent<void>;
|
||||
|
||||
addRecentlyOpened(recents: IRecent[]): Promise<void>;
|
||||
getRecentlyOpened(include?: ICodeWindow): Promise<IRecentlyOpened>;
|
||||
getRecentlyOpened(): Promise<IRecentlyOpened>;
|
||||
removeRecentlyOpened(paths: URI[]): Promise<void>;
|
||||
clearRecentlyOpened(): Promise<void>;
|
||||
}
|
||||
|
@ -162,31 +161,10 @@ export class WorkspacesHistoryMainService extends Disposable implements IWorkspa
|
|||
this._onDidChangeRecentlyOpened.fire();
|
||||
}
|
||||
|
||||
async getRecentlyOpened(include?: ICodeWindow): Promise<IRecentlyOpened> {
|
||||
async getRecentlyOpened(): Promise<IRecentlyOpened> {
|
||||
const workspaces: Array<IRecentFolder | IRecentWorkspace> = [];
|
||||
const files: IRecentFile[] = [];
|
||||
|
||||
// Add current workspace to beginning if set
|
||||
if (include) {
|
||||
const currentWorkspace = include.config?.workspace;
|
||||
if (isWorkspaceIdentifier(currentWorkspace) && !this.workspacesManagementMainService.isUntitledWorkspace(currentWorkspace)) {
|
||||
workspaces.push({ workspace: currentWorkspace, remoteAuthority: include.remoteAuthority });
|
||||
} else if (isSingleFolderWorkspaceIdentifier(currentWorkspace)) {
|
||||
workspaces.push({ folderUri: currentWorkspace.uri, remoteAuthority: include.remoteAuthority });
|
||||
}
|
||||
}
|
||||
|
||||
// Add currently files to open to the beginning if any
|
||||
const currentFiles = include?.config?.filesToOpenOrCreate;
|
||||
if (currentFiles) {
|
||||
for (const currentFile of currentFiles) {
|
||||
const fileUri = currentFile.fileUri;
|
||||
if (fileUri && this.indexOfFile(files, fileUri) === -1) {
|
||||
files.push({ fileUri });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await this.addEntriesFromStorage(workspaces, files);
|
||||
|
||||
return { workspaces, files };
|
||||
|
|
|
@ -55,7 +55,7 @@ export class WorkspacesMainService implements AddFirstParameterToFunctions<IWork
|
|||
readonly onDidChangeRecentlyOpened = this.workspacesHistoryMainService.onDidChangeRecentlyOpened;
|
||||
|
||||
getRecentlyOpened(windowId: number): Promise<IRecentlyOpened> {
|
||||
return this.workspacesHistoryMainService.getRecentlyOpened(this.windowsMainService.getWindowById(windowId));
|
||||
return this.workspacesHistoryMainService.getRecentlyOpened();
|
||||
}
|
||||
|
||||
addRecentlyOpened(windowId: number, recents: IRecent[]): Promise<void> {
|
||||
|
|
|
@ -121,13 +121,9 @@ export class ResourcesDropHandler {
|
|||
}
|
||||
|
||||
// Add external ones to recently open list unless dropped resource is a workspace
|
||||
// and only for resources that are outside of the currently opened workspace
|
||||
const externalLocalFiles = coalesce(editors.filter(editor => editor.isExternal && editor.resource?.scheme === Schemas.file).map(editor => editor.resource));
|
||||
if (externalLocalFiles.length) {
|
||||
this.workspacesService.addRecentlyOpened(externalLocalFiles
|
||||
.filter(resource => !this.contextService.isInsideWorkspace(resource))
|
||||
.map(resource => ({ fileUri: resource }))
|
||||
);
|
||||
this.workspacesService.addRecentlyOpened(externalLocalFiles.map(resource => ({ fileUri: resource })));
|
||||
}
|
||||
|
||||
// Open in Editor
|
||||
|
|
|
@ -205,13 +205,7 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
|
|||
}
|
||||
|
||||
protected addFileToRecentlyOpened(uri: URI): void {
|
||||
|
||||
// add the picked file into the list of recently opened
|
||||
// only if it is outside the currently opened workspace
|
||||
|
||||
if (!this.contextService.isInsideWorkspace(uri)) {
|
||||
this.workspacesService.addRecentlyOpened([{ fileUri: uri, label: this.labelService.getUriLabel(uri) }]);
|
||||
}
|
||||
this.workspacesService.addRecentlyOpened([{ fileUri: uri, label: this.labelService.getUriLabel(uri) }]);
|
||||
}
|
||||
|
||||
protected async pickFolderAndOpenSimplified(schema: string, options: IPickAndOpenOptions): Promise<void> {
|
||||
|
@ -241,7 +235,13 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
|
|||
}
|
||||
|
||||
options.title = nls.localize('saveFileAs.title', 'Save As');
|
||||
return this.saveRemoteResource(options);
|
||||
const uri = await this.saveRemoteResource(options);
|
||||
|
||||
if (uri) {
|
||||
this.addFileToRecentlyOpened(uri);
|
||||
}
|
||||
|
||||
return uri;
|
||||
}
|
||||
|
||||
protected async showSaveDialogSimplified(schema: string, options: ISaveDialogOptions): Promise<URI | undefined> {
|
||||
|
|
|
@ -133,7 +133,11 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
|
|||
} else {
|
||||
const result = await this.nativeHostService.showSaveDialog(this.toNativeSaveDialogOptions(options));
|
||||
if (result && !result.canceled && result.filePath) {
|
||||
return URI.file(result.filePath);
|
||||
const uri = URI.file(result.filePath);
|
||||
|
||||
this.addFileToRecentlyOpened(uri);
|
||||
|
||||
return uri;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue