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

Commit

Permalink
Merge pull request #4465 from adobe/jasonsanjose/issue-4458
Browse files Browse the repository at this point in the history
fix bad callback when updating project after save as
  • Loading branch information
bchintx committed Jul 16, 2013
2 parents 505754c + e2e2a51 commit 1d16b05
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
33 changes: 21 additions & 12 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,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();
}

/**
Expand Down Expand Up @@ -589,23 +596,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) {
Expand Down
4 changes: 3 additions & 1 deletion test/spec/DocumentCommandHandlers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1d16b05

Please sign in to comment.