Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 6e6b49b

Browse files
committed
Merge pull request #4514 from adobe/bchin/issue-4489
Fixed issue #4489- "Save/Close All with multiple untitled documents gives ambiguous Save dialogs"
2 parents c9ed878 + 62ebeea commit 6e6b49b

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/document/DocumentCommandHandlers.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,11 @@ define(function (require, exports, module) {
660660
origPath = doc.file.fullPath;
661661
// If the document is an untitled document, we should default to project root.
662662
if (doc.isUntitled()) {
663+
// (Issue #4489) if we're saving an untitled document, go ahead and switch to this document
664+
// in the editor, so that if we're, for example, saving several files (ie. Save All),
665+
// then the user can visually tell which document we're currently prompting them to save.
666+
DocumentManager.setCurrentDocument(doc);
667+
663668
// If the document is untitled, default to project root.
664669
saveAsDefaultPath = ProjectManager.getProjectRoot().fullPath;
665670
} else {

test/spec/DocumentCommandHandlers-test.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ define(function (require, exports, module) {
3434
DocumentCommandHandlers, // loaded from brackets.test
3535
DocumentManager, // loaded from brackets.test
3636
Dialogs, // loaded from brackets.test
37+
FileViewController, // loaded from brackets.test
3738
SpecRunnerUtils = require("spec/SpecRunnerUtils"),
3839
NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem,
3940
FileUtils = require("file/FileUtils"),
@@ -59,6 +60,7 @@ define(function (require, exports, module) {
5960
DocumentCommandHandlers = testWindow.brackets.test.DocumentCommandHandlers;
6061
DocumentManager = testWindow.brackets.test.DocumentManager;
6162
Dialogs = testWindow.brackets.test.Dialogs;
63+
FileViewController = testWindow.brackets.test.FileViewController;
6264
});
6365
});
6466

@@ -146,7 +148,7 @@ define(function (require, exports, module) {
146148
});
147149
});
148150

149-
it("should keep untitled document in the Working Set after saving with new name", function () {
151+
it("should swap out untitled document in the Working Set after saving with new name", function () {
150152
var newFilename = "testname.js",
151153
newFilePath = testPath + "/" + newFilename,
152154
promise;
@@ -173,12 +175,53 @@ define(function (require, exports, module) {
173175
expect(noLongerUntitledDocument.isUntitled()).toBe(false);
174176
expect(noLongerUntitledDocument.file.fullPath).toEqual(newFilePath);
175177
expect(DocumentManager.findInWorkingSet(newFilePath)).toBeGreaterThan(-1);
178+
expect(DocumentManager.getWorkingSet().length).toEqual(1); // no remnant of untitled doc left
176179

177180
// Verify file exists, & clean up
178181
expectAndDelete(newFilePath);
179182
});
180183
});
181184

185+
it("should swap out untitled document from working set even when not current", function () {
186+
var newFilePath = testPath + "/testname.js",
187+
promise;
188+
189+
runs(function () {
190+
promise = CommandManager.execute(Commands.FILE_NEW_UNTITLED);
191+
192+
waitsForDone(promise, "FILE_NEW_UNTITLED");
193+
});
194+
195+
runs(function () {
196+
// Select test.js in the project tree (so nothing is selected in the working set)
197+
promise = FileViewController.openAndSelectDocument(testPath + "/test.js", FileViewController.PROJECT_MANAGER);
198+
199+
waitsForDone(promise, "openAndSelectDocument");
200+
});
201+
202+
runs(function () {
203+
spyOn(testWindow.brackets.fs, 'showSaveDialog').andCallFake(function (dialogTitle, initialPath, proposedNewName, callback) {
204+
callback(undefined, newFilePath);
205+
});
206+
207+
var promise = CommandManager.execute(Commands.FILE_SAVE_ALL);
208+
waitsForDone(promise, "FILE_SAVE_ALL");
209+
});
210+
211+
runs(function () {
212+
var noLongerUntitledDocument = DocumentManager.getCurrentDocument();
213+
214+
expect(noLongerUntitledDocument.isDirty).toBe(false);
215+
expect(noLongerUntitledDocument.isUntitled()).toBe(false);
216+
expect(noLongerUntitledDocument.file.fullPath).toEqual(newFilePath);
217+
expect(DocumentManager.findInWorkingSet(newFilePath)).toBeGreaterThan(-1);
218+
expect(DocumentManager.getWorkingSet().length).toEqual(1); // no remnant of untitled doc left
219+
220+
// Verify file exists, & clean up
221+
expectAndDelete(newFilePath);
222+
});
223+
});
224+
182225
it("should ask to save untitled document upon closing", function () {
183226
var newFilename = "testname2.js",
184227
newFilePath = testPath + "/" + newFilename,

0 commit comments

Comments
 (0)