Add saved files to recently opened (#20470)

This commit is contained in:
Charles Gagnon
2022-08-29 09:04:59 -07:00
committed by GitHub
parent 96b7335cdd
commit a78a158acd
5 changed files with 20 additions and 40 deletions

View File

@@ -19,8 +19,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
import { ILifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
import { ILogService } from 'vs/platform/log/common/log';
import { IStateMainService } from 'vs/platform/state/electron-main/state';
import { ICodeWindow } from 'vs/platform/windows/electron-main/windows';
import { IRecent, IRecentFile, IRecentFolder, IRecentlyOpened, IRecentWorkspace, isRecentFile, isRecentFolder, isRecentWorkspace, isSingleFolderWorkspaceIdentifier, isWorkspaceIdentifier, IWorkspaceIdentifier, RecentlyOpenedStorageData, restoreRecentlyOpened, toStoreData, WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
import { IRecent, IRecentFile, IRecentFolder, IRecentlyOpened, IRecentWorkspace, isRecentFile, isRecentFolder, isRecentWorkspace, IWorkspaceIdentifier, RecentlyOpenedStorageData, restoreRecentlyOpened, toStoreData, WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
import { IWorkspacesManagementMainService } from 'vs/platform/workspaces/electron-main/workspacesManagementMainService';
export const IWorkspacesHistoryMainService = createDecorator<IWorkspacesHistoryMainService>('workspacesHistoryMainService');
@@ -32,7 +31,7 @@ export interface IWorkspacesHistoryMainService {
readonly onDidChangeRecentlyOpened: CommonEvent<void>;
addRecentlyOpened(recents: IRecent[]): void;
getRecentlyOpened(include?: ICodeWindow): IRecentlyOpened;
getRecentlyOpened(): IRecentlyOpened;
removeRecentlyOpened(paths: URI[]): void;
clearRecentlyOpened(): void;
@@ -241,29 +240,10 @@ export class WorkspacesHistoryMainService extends Disposable implements IWorkspa
this._onDidChangeRecentlyOpened.fire();
}
getRecentlyOpened(include?: ICodeWindow): IRecentlyOpened {
getRecentlyOpened(): IRecentlyOpened {
const workspaces: Array<IRecentFolder | IRecentWorkspace> = [];
const files: IRecentFile[] = [];
// Add current workspace to beginning if set
const currentWorkspace = include?.config?.workspace;
if (isWorkspaceIdentifier(currentWorkspace) && !this.workspacesManagementMainService.isUntitledWorkspace(currentWorkspace)) {
workspaces.push({ workspace: currentWorkspace });
} else if (isSingleFolderWorkspaceIdentifier(currentWorkspace)) {
workspaces.push({ folderUri: currentWorkspace.uri });
}
// Add currently files to open to the beginning if any
const currentFiles = include?.config?.filesToOpenOrCreate;
if (currentFiles) {
for (let currentFile of currentFiles) {
const fileUri = currentFile.fileUri;
if (fileUri && this.indexOfFile(files, fileUri) === -1) {
files.push({ fileUri });
}
}
}
this.addEntriesFromStorage(workspaces, files);
return { workspaces, files };

View File

@@ -53,7 +53,7 @@ export class WorkspacesMainService implements AddFirstParameterToFunctions<IWork
readonly onDidChangeRecentlyOpened = this.workspacesHistoryMainService.onDidChangeRecentlyOpened;
async getRecentlyOpened(windowId: number): Promise<IRecentlyOpened> {
return this.workspacesHistoryMainService.getRecentlyOpened(this.windowsMainService.getWindowById(windowId));
return this.workspacesHistoryMainService.getRecentlyOpened();
}
async addRecentlyOpened(windowId: number, recents: IRecent[]): Promise<void> {

View File

@@ -31,7 +31,6 @@ import { Emitter } from 'vs/base/common/event';
import { coalesce } from 'vs/base/common/arrays';
import { parse, stringify } from 'vs/base/common/marshalling';
import { ILabelService } from 'vs/platform/label/common/label';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { withNullAsUndefined } from 'vs/base/common/types';
//#region Editor / Resources DND
@@ -190,8 +189,7 @@ export class ResourcesDropHandler {
@IWorkspacesService private readonly workspacesService: IWorkspacesService,
@IEditorService private readonly editorService: IEditorService,
@IWorkspaceEditingService private readonly workspaceEditingService: IWorkspaceEditingService,
@IHostService private readonly hostService: IHostService,
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService
@IHostService private readonly hostService: IHostService
) {
}
@@ -216,12 +214,8 @@ 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
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

View File

@@ -193,12 +193,8 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
}
}
private 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) }]);
}
protected addFileToRecentlyOpened(uri: URI): void {
this.workspacesService.addRecentlyOpened([{ fileUri: uri, label: this.labelService.getUriLabel(uri) }]);
}
protected async pickFolderAndOpenSimplified(schema: string, options: IPickAndOpenOptions): Promise<void> {
@@ -228,7 +224,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> {

View File

@@ -131,7 +131,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 undefined; // {{SQL CARBON EDIT}} strict-null-check