mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Add saved files to recently opened (#20470)
This commit is contained in:
@@ -19,8 +19,7 @@ import { createDecorator } from 'vs/platform/instantiation/common/instantiation'
|
|||||||
import { ILifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
|
import { ILifecycleMainService, LifecycleMainPhase } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
|
||||||
import { ILogService } from 'vs/platform/log/common/log';
|
import { ILogService } from 'vs/platform/log/common/log';
|
||||||
import { IStateMainService } from 'vs/platform/state/electron-main/state';
|
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, IWorkspaceIdentifier, RecentlyOpenedStorageData, restoreRecentlyOpened, toStoreData, WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
|
||||||
import { IRecent, IRecentFile, IRecentFolder, IRecentlyOpened, IRecentWorkspace, isRecentFile, isRecentFolder, isRecentWorkspace, isSingleFolderWorkspaceIdentifier, isWorkspaceIdentifier, IWorkspaceIdentifier, RecentlyOpenedStorageData, restoreRecentlyOpened, toStoreData, WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
|
|
||||||
import { IWorkspacesManagementMainService } from 'vs/platform/workspaces/electron-main/workspacesManagementMainService';
|
import { IWorkspacesManagementMainService } from 'vs/platform/workspaces/electron-main/workspacesManagementMainService';
|
||||||
|
|
||||||
export const IWorkspacesHistoryMainService = createDecorator<IWorkspacesHistoryMainService>('workspacesHistoryMainService');
|
export const IWorkspacesHistoryMainService = createDecorator<IWorkspacesHistoryMainService>('workspacesHistoryMainService');
|
||||||
@@ -32,7 +31,7 @@ export interface IWorkspacesHistoryMainService {
|
|||||||
readonly onDidChangeRecentlyOpened: CommonEvent<void>;
|
readonly onDidChangeRecentlyOpened: CommonEvent<void>;
|
||||||
|
|
||||||
addRecentlyOpened(recents: IRecent[]): void;
|
addRecentlyOpened(recents: IRecent[]): void;
|
||||||
getRecentlyOpened(include?: ICodeWindow): IRecentlyOpened;
|
getRecentlyOpened(): IRecentlyOpened;
|
||||||
removeRecentlyOpened(paths: URI[]): void;
|
removeRecentlyOpened(paths: URI[]): void;
|
||||||
clearRecentlyOpened(): void;
|
clearRecentlyOpened(): void;
|
||||||
|
|
||||||
@@ -241,29 +240,10 @@ export class WorkspacesHistoryMainService extends Disposable implements IWorkspa
|
|||||||
this._onDidChangeRecentlyOpened.fire();
|
this._onDidChangeRecentlyOpened.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
getRecentlyOpened(include?: ICodeWindow): IRecentlyOpened {
|
getRecentlyOpened(): IRecentlyOpened {
|
||||||
const workspaces: Array<IRecentFolder | IRecentWorkspace> = [];
|
const workspaces: Array<IRecentFolder | IRecentWorkspace> = [];
|
||||||
const files: IRecentFile[] = [];
|
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);
|
this.addEntriesFromStorage(workspaces, files);
|
||||||
|
|
||||||
return { workspaces, files };
|
return { workspaces, files };
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export class WorkspacesMainService implements AddFirstParameterToFunctions<IWork
|
|||||||
readonly onDidChangeRecentlyOpened = this.workspacesHistoryMainService.onDidChangeRecentlyOpened;
|
readonly onDidChangeRecentlyOpened = this.workspacesHistoryMainService.onDidChangeRecentlyOpened;
|
||||||
|
|
||||||
async getRecentlyOpened(windowId: number): Promise<IRecentlyOpened> {
|
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> {
|
async addRecentlyOpened(windowId: number, recents: IRecent[]): Promise<void> {
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import { Emitter } from 'vs/base/common/event';
|
|||||||
import { coalesce } from 'vs/base/common/arrays';
|
import { coalesce } from 'vs/base/common/arrays';
|
||||||
import { parse, stringify } from 'vs/base/common/marshalling';
|
import { parse, stringify } from 'vs/base/common/marshalling';
|
||||||
import { ILabelService } from 'vs/platform/label/common/label';
|
import { ILabelService } from 'vs/platform/label/common/label';
|
||||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
|
||||||
import { withNullAsUndefined } from 'vs/base/common/types';
|
import { withNullAsUndefined } from 'vs/base/common/types';
|
||||||
|
|
||||||
//#region Editor / Resources DND
|
//#region Editor / Resources DND
|
||||||
@@ -190,8 +189,7 @@ export class ResourcesDropHandler {
|
|||||||
@IWorkspacesService private readonly workspacesService: IWorkspacesService,
|
@IWorkspacesService private readonly workspacesService: IWorkspacesService,
|
||||||
@IEditorService private readonly editorService: IEditorService,
|
@IEditorService private readonly editorService: IEditorService,
|
||||||
@IWorkspaceEditingService private readonly workspaceEditingService: IWorkspaceEditingService,
|
@IWorkspaceEditingService private readonly workspaceEditingService: IWorkspaceEditingService,
|
||||||
@IHostService private readonly hostService: IHostService,
|
@IHostService private readonly hostService: IHostService
|
||||||
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService
|
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,12 +214,8 @@ export class ResourcesDropHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add external ones to recently open list unless dropped resource is a workspace
|
// 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) {
|
if (externalLocalFiles.length) {
|
||||||
this.workspacesService.addRecentlyOpened(externalLocalFiles
|
this.workspacesService.addRecentlyOpened(externalLocalFiles.map(resource => ({ fileUri: resource })));
|
||||||
.filter(resource => !this.contextService.isInsideWorkspace(resource))
|
|
||||||
.map(resource => ({ fileUri: resource }))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open in Editor
|
// Open in Editor
|
||||||
|
|||||||
@@ -193,12 +193,8 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private addFileToRecentlyOpened(uri: URI): void {
|
protected addFileToRecentlyOpened(uri: URI): void {
|
||||||
// add the picked file into the list of recently opened
|
this.workspacesService.addRecentlyOpened([{ fileUri: uri, label: this.labelService.getUriLabel(uri) }]);
|
||||||
// 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 async pickFolderAndOpenSimplified(schema: string, options: IPickAndOpenOptions): Promise<void> {
|
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');
|
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> {
|
protected async showSaveDialogSimplified(schema: string, options: ISaveDialogOptions): Promise<URI | undefined> {
|
||||||
|
|||||||
@@ -131,7 +131,11 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
|
|||||||
} else {
|
} else {
|
||||||
const result = await this.nativeHostService.showSaveDialog(this.toNativeSaveDialogOptions(options));
|
const result = await this.nativeHostService.showSaveDialog(this.toNativeSaveDialogOptions(options));
|
||||||
if (result && !result.canceled && result.filePath) {
|
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
|
return undefined; // {{SQL CARBON EDIT}} strict-null-check
|
||||||
|
|||||||
Reference in New Issue
Block a user