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

Commit e532b74

Browse files
committed
Merge pull request #4437 from adobe/bchin/issue_4238
fix issue #4238- 'Save As on file in working set does not preserve working set order'
2 parents 220fae6 + 7274558 commit e532b74

File tree

4 files changed

+46
-32
lines changed

4 files changed

+46
-32
lines changed

src/document/DocumentCommandHandlers.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,12 @@ define(function (require, exports, module) {
329329

330330
/**
331331
* Opens the given file, makes it the current document, AND adds it to the working set.
332-
* @param {!{fullPath:string}} Params for FILE_OPEN command
332+
* @param {!{fullPath:string, index:number=}} Params for FILE_OPEN command
333333
*/
334334
function handleFileAddToWorkingSet(commandData) {
335335
return handleFileOpen(commandData).done(function (doc) {
336336
// addToWorkingSet is synchronous
337-
DocumentManager.addToWorkingSet(doc.file);
337+
DocumentManager.addToWorkingSet(doc.file, commandData.index);
338338
});
339339
}
340340

@@ -602,15 +602,13 @@ define(function (require, exports, module) {
602602
});
603603
} else { // Working set has file selection focus
604604
// replace original file in working set with new file
605+
var index = DocumentManager.findInWorkingSet(doc.file.fullPath);
605606
// remove old file from working set.
606-
DocumentManager.removeFromWorkingSet(doc.file);
607+
DocumentManager.removeFromWorkingSet(doc.file, true);
607608
//add new file to working set
608609
FileViewController
609-
.addToWorkingSetAndSelect(path,
610-
FileViewController.WORKING_SET_VIEW)
611-
.always(function () {
612-
_configureEditorAndResolve(file);
613-
});
610+
.addToWorkingSetAndSelect(path, FileViewController.WORKING_SET_VIEW, index)
611+
.always(_configureEditorAndResolve(file));
614612
}
615613
}
616614

src/document/DocumentManager.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ define(function (require, exports, module) {
227227
* Adds the given file to the end of the working set list, if it is not already in the list.
228228
* Does not change which document is currently open in the editor. Completes synchronously.
229229
* @param {!FileEntry} file
230+
* @param {number=} index - insert into the working set list at this 0-based index
230231
*/
231-
function addToWorkingSet(file) {
232+
function addToWorkingSet(file, index) {
232233
// If doc is already in working set, don't add it again
233234
if (findInWorkingSet(file.fullPath) !== -1) {
234235
return;
@@ -241,7 +242,13 @@ define(function (require, exports, module) {
241242
} else {
242243
file = new NativeFileSystem.FileEntry(file.fullPath);
243244
}
244-
_workingSet.push(file);
245+
if ((index === undefined) || (index === null) || (index === -1)) {
246+
// If no index is specified, just add the file to the end of the working set.
247+
_workingSet.push(file);
248+
} else {
249+
// If specified, insert into the working set list at this 0-based index
250+
_workingSet.splice(index, 0, file);
251+
}
245252

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

256263
// Dispatch event
257-
$(exports).triggerHandler("workingSetAdd", file);
264+
if ((index === undefined) || (index === null) || (index === -1)) {
265+
$(exports).triggerHandler("workingSetAdd", file);
266+
} else {
267+
$(exports).triggerHandler("workingSetSort");
268+
}
258269
}
259-
270+
260271
/**
261272
* Adds the given file list to the end of the working set list.
262273
* Does not change which document is currently open in the editor.
@@ -297,8 +308,9 @@ define(function (require, exports, module) {
297308
* Removes the given file from the working set list, if it was in the list. Does not change
298309
* the current editor even if it's for this file.
299310
* @param {!FileEntry} file
311+
* @param {boolean=} true to suppress redraw after removal
300312
*/
301-
function removeFromWorkingSet(file) {
313+
function removeFromWorkingSet(file, suppressRedraw) {
302314
// If doc isn't in working set, do nothing
303315
var index = findInWorkingSet(file.fullPath);
304316
if (index === -1) {
@@ -311,7 +323,7 @@ define(function (require, exports, module) {
311323
_workingSetAddedOrder.splice(findInWorkingSet(file.fullPath, _workingSetAddedOrder), 1);
312324

313325
// Dispatch event
314-
$(exports).triggerHandler("workingSetRemove", file);
326+
$(exports).triggerHandler("workingSetRemove", [file, suppressRedraw]);
315327
}
316328

317329
/**

src/project/FileViewController.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,12 @@ define(function (require, exports, module) {
178178
* @param {!fullPath}
179179
* @param {?String} selectIn - specify either WORING_SET_VIEW or PROJECT_MANAGER.
180180
* Default is WORING_SET_VIEW.
181+
* @param {number=} index - insert into the working set list at this 0-based index
181182
* @return {!$.Promise}
182183
*/
183-
function addToWorkingSetAndSelect(fullPath, selectIn) {
184+
function addToWorkingSetAndSelect(fullPath, selectIn, index) {
184185
var result = new $.Deferred(),
185-
promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: fullPath});
186+
promise = CommandManager.execute(Commands.FILE_ADD_TO_WORKING_SET, {fullPath: fullPath, index: index});
186187

187188
// This properly handles sending the right nofications in cases where the document
188189
// is already the current one. In that case we will want to notify with

src/project/WorkingSetView.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -511,23 +511,26 @@ define(function (require, exports, module) {
511511

512512
/**
513513
* @private
514-
* @param {FileEntry} file
514+
* @param {FileEntry} file
515+
* @param {boolean=} suppressRedraw If true, suppress redraw
515516
*/
516-
function _handleFileRemoved(file) {
517-
var $listItem = _findListItemFromFile(file);
518-
if ($listItem) {
519-
// Make the next file in the list show the close icon,
520-
// without having to move the mouse, if there is a next file.
521-
var $nextListItem = $listItem.next();
522-
if ($nextListItem && $nextListItem.length > 0) {
523-
var canClose = ($listItem.find(".can-close").length === 1);
524-
var isDirty = isOpenAndDirty($nextListItem.data(_FILE_KEY));
525-
_updateFileStatusIcon($nextListItem, isDirty, canClose);
517+
function _handleFileRemoved(file, suppressRedraw) {
518+
if (!suppressRedraw) {
519+
var $listItem = _findListItemFromFile(file);
520+
if ($listItem) {
521+
// Make the next file in the list show the close icon,
522+
// without having to move the mouse, if there is a next file.
523+
var $nextListItem = $listItem.next();
524+
if ($nextListItem && $nextListItem.length > 0) {
525+
var canClose = ($listItem.find(".can-close").length === 1);
526+
var isDirty = isOpenAndDirty($nextListItem.data(_FILE_KEY));
527+
_updateFileStatusIcon($nextListItem, isDirty, canClose);
528+
}
529+
$listItem.remove();
526530
}
527-
$listItem.remove();
531+
532+
_redraw();
528533
}
529-
530-
_redraw();
531534
}
532535

533536
function _handleRemoveList(removedFiles) {
@@ -592,8 +595,8 @@ define(function (require, exports, module) {
592595
_handleFileListAdded(addedFiles);
593596
});
594597

595-
$(DocumentManager).on("workingSetRemove", function (event, removedFile) {
596-
_handleFileRemoved(removedFile);
598+
$(DocumentManager).on("workingSetRemove", function (event, removedFile, suppressRedraw) {
599+
_handleFileRemoved(removedFile, suppressRedraw);
597600
});
598601

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

0 commit comments

Comments
 (0)