Skip to content

Commit

Permalink
Merge pull request adobe#4437 from adobe/bchin/issue_4238
Browse files Browse the repository at this point in the history
fix issue adobe#4238- 'Save As on file in working set does not preserve working set order'
  • Loading branch information
gruehle committed Jul 12, 2013
2 parents 220fae6 + 7274558 commit e532b74
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 32 deletions.
14 changes: 6 additions & 8 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,12 @@ define(function (require, exports, module) {

/**
* Opens the given file, makes it the current document, AND adds it to the working set.
* @param {!{fullPath:string}} Params for FILE_OPEN command
* @param {!{fullPath:string, index:number=}} Params for FILE_OPEN command
*/
function handleFileAddToWorkingSet(commandData) {
return handleFileOpen(commandData).done(function (doc) {
// addToWorkingSet is synchronous
DocumentManager.addToWorkingSet(doc.file);
DocumentManager.addToWorkingSet(doc.file, commandData.index);
});
}

Expand Down Expand Up @@ -602,15 +602,13 @@ define(function (require, exports, module) {
});
} 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);
DocumentManager.removeFromWorkingSet(doc.file, true);
//add new file to working set
FileViewController
.addToWorkingSetAndSelect(path,
FileViewController.WORKING_SET_VIEW)
.always(function () {
_configureEditorAndResolve(file);
});
.addToWorkingSetAndSelect(path, FileViewController.WORKING_SET_VIEW, index)
.always(_configureEditorAndResolve(file));
}
}

Expand Down
24 changes: 18 additions & 6 deletions src/document/DocumentManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ define(function (require, exports, module) {
* Adds the given file to the end of the working set list, if it is not already in the list.
* Does not change which document is currently open in the editor. Completes synchronously.
* @param {!FileEntry} file
* @param {number=} index - insert into the working set list at this 0-based index
*/
function addToWorkingSet(file) {
function addToWorkingSet(file, index) {
// If doc is already in working set, don't add it again
if (findInWorkingSet(file.fullPath) !== -1) {
return;
Expand All @@ -241,7 +242,13 @@ define(function (require, exports, module) {
} else {
file = new NativeFileSystem.FileEntry(file.fullPath);
}
_workingSet.push(file);
if ((index === undefined) || (index === null) || (index === -1)) {
// If no index is specified, just add the file to the end of the working set.
_workingSet.push(file);
} else {
// If specified, insert into the working set list at this 0-based index
_workingSet.splice(index, 0, file);
}

// Add to MRU order: either first or last, depending on whether it's already the current doc or not
if (_currentDocument && _currentDocument.file.fullPath === file.fullPath) {
Expand All @@ -254,9 +261,13 @@ define(function (require, exports, module) {
_workingSetAddedOrder.unshift(file);

// Dispatch event
$(exports).triggerHandler("workingSetAdd", file);
if ((index === undefined) || (index === null) || (index === -1)) {
$(exports).triggerHandler("workingSetAdd", file);
} else {
$(exports).triggerHandler("workingSetSort");
}
}

/**
* Adds the given file list to the end of the working set list.
* Does not change which document is currently open in the editor.
Expand Down Expand Up @@ -297,8 +308,9 @@ define(function (require, exports, module) {
* Removes the given file from the working set list, if it was in the list. Does not change
* the current editor even if it's for this file.
* @param {!FileEntry} file
* @param {boolean=} true to suppress redraw after removal
*/
function removeFromWorkingSet(file) {
function removeFromWorkingSet(file, suppressRedraw) {
// If doc isn't in working set, do nothing
var index = findInWorkingSet(file.fullPath);
if (index === -1) {
Expand All @@ -311,7 +323,7 @@ define(function (require, exports, module) {
_workingSetAddedOrder.splice(findInWorkingSet(file.fullPath, _workingSetAddedOrder), 1);

// Dispatch event
$(exports).triggerHandler("workingSetRemove", file);
$(exports).triggerHandler("workingSetRemove", [file, suppressRedraw]);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/project/FileViewController.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,12 @@ define(function (require, exports, module) {
* @param {!fullPath}
* @param {?String} selectIn - specify either WORING_SET_VIEW or PROJECT_MANAGER.
* Default is WORING_SET_VIEW.
* @param {number=} index - insert into the working set list at this 0-based index
* @return {!$.Promise}
*/
function addToWorkingSetAndSelect(fullPath, selectIn) {
function addToWorkingSetAndSelect(fullPath, selectIn, index) {
var result = new $.Deferred(),
promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: fullPath});
promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: fullPath, index: index});

// This properly handles sending the right nofications in cases where the document
// is already the current one. In that case we will want to notify with
Expand Down
35 changes: 19 additions & 16 deletions src/project/WorkingSetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,23 +511,26 @@ define(function (require, exports, module) {

/**
* @private
* @param {FileEntry} file
* @param {FileEntry} file
* @param {boolean=} suppressRedraw If true, suppress redraw
*/
function _handleFileRemoved(file) {
var $listItem = _findListItemFromFile(file);
if ($listItem) {
// Make the next file in the list show the close icon,
// without having to move the mouse, if there is a next file.
var $nextListItem = $listItem.next();
if ($nextListItem && $nextListItem.length > 0) {
var canClose = ($listItem.find(".can-close").length === 1);
var isDirty = isOpenAndDirty($nextListItem.data(_FILE_KEY));
_updateFileStatusIcon($nextListItem, isDirty, canClose);
function _handleFileRemoved(file, suppressRedraw) {
if (!suppressRedraw) {
var $listItem = _findListItemFromFile(file);
if ($listItem) {
// Make the next file in the list show the close icon,
// without having to move the mouse, if there is a next file.
var $nextListItem = $listItem.next();
if ($nextListItem && $nextListItem.length > 0) {
var canClose = ($listItem.find(".can-close").length === 1);
var isDirty = isOpenAndDirty($nextListItem.data(_FILE_KEY));
_updateFileStatusIcon($nextListItem, isDirty, canClose);
}
$listItem.remove();
}
$listItem.remove();

_redraw();
}

_redraw();
}

function _handleRemoveList(removedFiles) {
Expand Down Expand Up @@ -592,8 +595,8 @@ define(function (require, exports, module) {
_handleFileListAdded(addedFiles);
});

$(DocumentManager).on("workingSetRemove", function (event, removedFile) {
_handleFileRemoved(removedFile);
$(DocumentManager).on("workingSetRemove", function (event, removedFile, suppressRedraw) {
_handleFileRemoved(removedFile, suppressRedraw);
});

$(DocumentManager).on("workingSetRemoveList", function (event, removedFiles) {
Expand Down

0 comments on commit e532b74

Please sign in to comment.