Skip to content

Commit 830e2aa

Browse files
author
Benjamin Pasero
authored
simple file dialog - add files to recently opened (microsoft#89994)
1 parent f647e12 commit 830e2aa

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/vs/workbench/services/dialogs/browser/abstractFileDialogService.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as nls from 'vs/nls';
7-
import { IWindowOpenable } from 'vs/platform/windows/common/windows';
7+
import { IWindowOpenable, isWorkspaceToOpen, isFileToOpen } from 'vs/platform/windows/common/windows';
88
import { IPickAndOpenOptions, ISaveDialogOptions, IOpenDialogOptions, FileFilter, IFileDialogService, IDialogService, ConfirmResult, getFileNamesMessage } from 'vs/platform/dialogs/common/dialogs';
99
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
1010
import { IHistoryService } from 'vs/workbench/services/history/common/history';
@@ -14,7 +14,7 @@ import { Schemas } from 'vs/base/common/network';
1414
import * as resources from 'vs/base/common/resources';
1515
import { IInstantiationService, } from 'vs/platform/instantiation/common/instantiation';
1616
import { SimpleFileDialog } from 'vs/workbench/services/dialogs/browser/simpleFileDialog';
17-
import { WORKSPACE_EXTENSION, isUntitledWorkspace } from 'vs/platform/workspaces/common/workspaces';
17+
import { WORKSPACE_EXTENSION, isUntitledWorkspace, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
1818
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
1919
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2020
import { IFileService } from 'vs/platform/files/common/files';
@@ -24,6 +24,7 @@ import Severity from 'vs/base/common/severity';
2424
import { coalesce } from 'vs/base/common/arrays';
2525
import { trim } from 'vs/base/common/strings';
2626
import { IModeService } from 'vs/editor/common/services/modeService';
27+
import { ILabelService } from 'vs/platform/label/common/label';
2728

2829
export abstract class AbstractFileDialogService implements IFileDialogService {
2930

@@ -39,7 +40,9 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
3940
@IFileService protected readonly fileService: IFileService,
4041
@IOpenerService protected readonly openerService: IOpenerService,
4142
@IDialogService private readonly dialogService: IDialogService,
42-
@IModeService private readonly modeService: IModeService
43+
@IModeService private readonly modeService: IModeService,
44+
@IWorkspacesService private readonly workspacesService: IWorkspacesService,
45+
@ILabelService private readonly labelService: ILabelService
4346
) { }
4447

4548
defaultFilePath(schemeFilter = this.getSchemeFilterForWindow()): URI | undefined {
@@ -132,6 +135,11 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
132135
const stat = await this.fileService.resolve(uri);
133136

134137
const toOpen: IWindowOpenable = stat.isDirectory ? { folderUri: uri } : { fileUri: uri };
138+
if (!isWorkspaceToOpen(toOpen) && isFileToOpen(toOpen)) {
139+
// add the picked file into the list of recently opened
140+
this.workspacesService.addRecentlyOpened([{ fileUri: toOpen.fileUri, label: this.labelService.getUriLabel(toOpen.fileUri) }]);
141+
}
142+
135143
if (stat.isDirectory || options.forceNewWindow || preferNewWindow) {
136144
return this.hostService.openWindow([toOpen], { forceNewWindow: options.forceNewWindow });
137145
} else {
@@ -146,6 +154,9 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
146154

147155
const uri = await this.pickResource({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems });
148156
if (uri) {
157+
// add the picked file into the list of recently opened
158+
this.workspacesService.addRecentlyOpened([{ fileUri: uri, label: this.labelService.getUriLabel(uri) }]);
159+
149160
if (options.forceNewWindow || preferNewWindow) {
150161
return this.hostService.openWindow([{ fileUri: uri }], { forceNewWindow: options.forceNewWindow });
151162
} else {

src/vs/workbench/services/dialogs/electron-browser/fileDialogService.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { IElectronService } from 'vs/platform/electron/node/electron';
2020
import { AbstractFileDialogService } from 'vs/workbench/services/dialogs/browser/abstractFileDialogService';
2121
import { Schemas } from 'vs/base/common/network';
2222
import { IModeService } from 'vs/editor/common/services/modeService';
23+
import { IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
24+
import { ILabelService } from 'vs/platform/label/common/label';
2325

2426
export class FileDialogService extends AbstractFileDialogService implements IFileDialogService {
2527

@@ -36,9 +38,11 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
3638
@IOpenerService openerService: IOpenerService,
3739
@IElectronService private readonly electronService: IElectronService,
3840
@IDialogService dialogService: IDialogService,
39-
@IModeService modeService: IModeService
41+
@IModeService modeService: IModeService,
42+
@IWorkspacesService workspacesService: IWorkspacesService,
43+
@ILabelService labelService: ILabelService
4044
) {
41-
super(hostService, contextService, historyService, environmentService, instantiationService, configurationService, fileService, openerService, dialogService, modeService);
45+
super(hostService, contextService, historyService, environmentService, instantiationService, configurationService, fileService, openerService, dialogService, modeService, workspacesService, labelService);
4246
}
4347

4448
private toNativeOpenDialogOptions(options: IPickAndOpenOptions): INativeOpenDialogOptions {

0 commit comments

Comments
 (0)