Skip to content

Commit 091c626

Browse files
author
Benjamin Pasero
committed
1 parent 2f5f3bc commit 091c626

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/vs/workbench/services/textfile/common/textFileService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export abstract class TextFileService extends Disposable implements ITextFileSer
9999

100100
abstract resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent>;
101101

102-
abstract promptForPath(defaultPath: string): TPromise<string>;
102+
abstract promptForPath(resource: URI, defaultPath: string): TPromise<string>;
103103

104104
abstract confirmSave(resources?: URI[]): TPromise<ConfirmResult>;
105105

@@ -433,7 +433,7 @@ export abstract class TextFileService extends Disposable implements ITextFileSer
433433

434434
// Otherwise ask user
435435
else {
436-
const targetPath = await this.promptForPath(this.suggestFileName(untitled));
436+
const targetPath = await this.promptForPath(untitled, this.suggestFileName(untitled));
437437
if (!targetPath) {
438438
return TPromise.as({
439439
results: [...fileResources, ...untitledResources].map(r => {
@@ -534,7 +534,7 @@ export abstract class TextFileService extends Disposable implements ITextFileSer
534534
dialogPath = this.suggestFileName(resource);
535535
}
536536

537-
targetPromise = this.promptForPath(dialogPath).then(pathRaw => {
537+
targetPromise = this.promptForPath(resource, dialogPath).then(pathRaw => {
538538
if (pathRaw) {
539539
return URI.file(pathRaw);
540540
}

src/vs/workbench/services/textfile/electron-browser/textFileService.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
3030
import { IModelService } from 'vs/editor/common/services/modelService';
3131
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
3232
import { getConfirmMessage, IDialogService } from 'vs/platform/dialogs/common/dialogs';
33+
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
3334

3435
export class TextFileService extends AbstractTextFileService {
3536

@@ -49,7 +50,8 @@ export class TextFileService extends AbstractTextFileService {
4950
@IWindowsService windowsService: IWindowsService,
5051
@IHistoryService historyService: IHistoryService,
5152
@IContextKeyService contextKeyService: IContextKeyService,
52-
@IDialogService private dialogService: IDialogService
53+
@IDialogService private dialogService: IDialogService,
54+
@IEditorService private editorService: IEditorService
5355
) {
5456
super(lifecycleService, contextService, configurationService, fileService, untitledEditorService, instantiationService, notificationService, environmentService, backupFileService, windowsService, historyService, contextKeyService, modelService);
5557
}
@@ -102,8 +104,12 @@ export class TextFileService extends AbstractTextFileService {
102104
});
103105
}
104106

105-
promptForPath(defaultPath: string): TPromise<string> {
106-
return this.windowService.showSaveDialog(this.getSaveDialogOptions(defaultPath));
107+
promptForPath(resource: URI, defaultPath: string): TPromise<string> {
108+
109+
// Help user to find a name for the file by opening it first
110+
return this.editorService.openEditor({ resource, options: { revealIfOpened: true, preserveFocus: true, } }).then(() => {
111+
return this.windowService.showSaveDialog(this.getSaveDialogOptions(defaultPath));
112+
});
107113
}
108114

109115
private getSaveDialogOptions(defaultPath: string): Electron.SaveDialogOptions {

src/vs/workbench/test/workbenchTestServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ export class TestTextFileService extends TextFileService {
222222
});
223223
}
224224

225-
public promptForPath(defaultPath: string): TPromise<string> {
225+
public promptForPath(resource: URI, defaultPath: string): TPromise<string> {
226226
return TPromise.wrap(this.promptPath);
227227
}
228228

0 commit comments

Comments
 (0)