From e7cdad62dab60d65ffd2171122ef91a1c425debe Mon Sep 17 00:00:00 2001 From: Jason San Jose Date: Mon, 15 Jul 2013 16:55:39 -0700 Subject: [PATCH] fix bad callback when updating project after save as --- src/document/DocumentCommandHandlers.js | 33 ++++++++++++++--------- test/spec/DocumentCommandHandlers-test.js | 4 ++- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/document/DocumentCommandHandlers.js b/src/document/DocumentCommandHandlers.js index 592ff85ff96..09e1481b57e 100644 --- a/src/document/DocumentCommandHandlers.js +++ b/src/document/DocumentCommandHandlers.js @@ -332,10 +332,17 @@ define(function (require, exports, module) { * @param {!{fullPath:string, index:number=}} Params for FILE_OPEN command */ function handleFileAddToWorkingSet(commandData) { - return handleFileOpen(commandData).done(function (doc) { + var deferred = new $.Deferred(); + + handleFileOpen(commandData).done(function (doc) { // addToWorkingSet is synchronous DocumentManager.addToWorkingSet(doc.file, commandData.index); + deferred.resolve(); + }).fail(function (err) { + deferred.reject(err); }); + + return deferred.promise(); } /** @@ -593,23 +600,25 @@ define(function (require, exports, module) { } function updateProject(file) { + var fileViewControllerPromise; + if (FileViewController.getFileSelectionFocus() === FileViewController.PROJECT_MANAGER) { - FileViewController - .openAndSelectDocument(path, - FileViewController.PROJECT_MANAGER) - .always(function () { - _configureEditorAndResolve(file); - }); - } else { // Working set has file selection focus + fileViewControllerPromise = FileViewController + .openAndSelectDocument(path, FileViewController.PROJECT_MANAGER); + } else { // Working set has file selection focus // replace original file in working set with new file var index = DocumentManager.findInWorkingSet(doc.file.fullPath); // remove old file from working set. DocumentManager.removeFromWorkingSet(doc.file, true); - //add new file to working set - FileViewController - .addToWorkingSetAndSelect(path, FileViewController.WORKING_SET_VIEW, index) - .always(_configureEditorAndResolve(file)); + // add new file to working set + fileViewControllerPromise = FileViewController + .addToWorkingSetAndSelect(path, FileViewController.WORKING_SET_VIEW, index); } + + // always configure editor after file is opened + fileViewControllerPromise.always(function () { + _configureEditorAndResolve(file); + }); } if (!path) { diff --git a/test/spec/DocumentCommandHandlers-test.js b/test/spec/DocumentCommandHandlers-test.js index f9a94d206bf..a7d4a5cb518 100644 --- a/test/spec/DocumentCommandHandlers-test.js +++ b/test/spec/DocumentCommandHandlers-test.js @@ -101,7 +101,9 @@ define(function (require, exports, module) { runs(function () { spyOn(testWindow.brackets.fs, 'showSaveDialog').andCallFake(function (dialogTitle, initialPath, proposedNewName, callback) { - callback(undefined, newFilePath); + testWindow.setTimeout(function () { + callback(undefined, newFilePath) + }, 0); }); promise = CommandManager.execute(Commands.FILE_SAVE);