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

Commit a44edb9

Browse files
committed
Merge pull request #10327 from adobe/jeff/Fix-9654-rebased
Fix makeFileMostRecent API
2 parents 46b87ce + 8924dd6 commit a44edb9

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

src/view/MainViewManager.js

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,19 @@ define(function (require, exports, module) {
253253
function _makeMRUListEntry(file, paneId) {
254254
return {file: file, paneId: paneId};
255255
}
256+
257+
/**
258+
* Locates the first MRU entry of a file
259+
* @param {!File} File - the file
260+
* @return {{file:File, paneId:string}}
261+
* @private
262+
*/
263+
function _findFileInMRUList(file) {
264+
return _.findIndex(_mruList, function (record) {
265+
return (record.file.fullPath === file.fullPath);
266+
});
267+
}
268+
256269

257270
/**
258271
* Retrieves the currently active Pane Id
@@ -321,15 +334,21 @@ define(function (require, exports, module) {
321334
pane.makeViewMostRecent(file);
322335

323336
index = _.findIndex(_mruList, function (record) {
324-
return (record.file === file && record.paneId === paneId);
337+
return (record.file === file && record.paneId === pane.id);
325338
});
326339

327340
entry = _makeMRUListEntry(file, pane.id);
328341

329342
if (index !== -1) {
330343
_mruList.splice(index, 1);
331-
_mruList.unshift(entry);
332344
}
345+
346+
if (_findFileInMRUList(file) !== -1) {
347+
console.log(file.fullPath + " duplicated in mru list");
348+
}
349+
350+
// add it to the front of the list
351+
_mruList.unshift(entry);
333352
}
334353
}
335354

@@ -709,11 +728,13 @@ define(function (require, exports, module) {
709728
} else if (result === pane.ITEM_NOT_FOUND) {
710729
index = pane.addToViewList(file, index);
711730

712-
// Add to or update the position in MRU
713-
if (pane.getCurrentlyViewedFile() === file) {
714-
_mruList.unshift(entry);
715-
} else {
716-
_mruList.push(entry);
731+
if (_findFileInMRUList(file) === -1) {
732+
// Add to or update the position in MRU
733+
if (pane.getCurrentlyViewedFile() === file) {
734+
_mruList.unshift(entry);
735+
} else {
736+
_mruList.push(entry);
737+
}
717738
}
718739

719740
exports.trigger("workingSetAdd", file, index, pane.id);
@@ -732,6 +753,9 @@ define(function (require, exports, module) {
732753
uniqueFileList = pane.addListToViewList(fileList);
733754

734755
uniqueFileList.forEach(function (file) {
756+
if (_findFileInMRUList(file) !== -1) {
757+
console.log(file.fullPath + " duplicated in mru list");
758+
}
735759
_mruList.push(_makeMRUListEntry(file, pane.id));
736760
});
737761

@@ -1060,6 +1084,9 @@ define(function (require, exports, module) {
10601084
newPane.id);
10611085
}
10621086
});
1087+
$(newPane).on("viewDestroy.mainView", function (e, view) {
1088+
_removeFileFromMRU(newPane.id, view.getFile());
1089+
});
10631090
}
10641091

10651092
return newPane;
@@ -1253,6 +1280,10 @@ define(function (require, exports, module) {
12531280
});
12541281
}
12551282

1283+
result.done(function () {
1284+
_makeFileMostRecent(paneId, file);
1285+
});
1286+
12561287
return result;
12571288
}
12581289

@@ -1499,6 +1530,9 @@ define(function (require, exports, module) {
14991530
var fileList = pane.getViewList();
15001531

15011532
fileList.forEach(function (file) {
1533+
if (_findFileInMRUList(file) !== -1) {
1534+
console.log(file.fullPath + " duplicated in mru list");
1535+
}
15021536
_mruList.push(_makeMRUListEntry(file, pane.id));
15031537
});
15041538
exports.trigger("workingSetAddList", fileList, pane.id);

src/view/Pane.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@
5959
* - viewListChange - Whenever there is a file change to a file in the working set. These 2 events: `DocumentManger.pathRemove`
6060
* and `DocumentManger.fileNameChange` will cause a `viewListChange` event so the WorkingSetView can update.
6161
*
62-
* - currentViewChange - triggered whenever the current view changes.
62+
* - currentViewChange - Whenever the current view changes.
6363
* (e, newView:View, oldView:View)
6464
*
65+
* - viewDestroy - Whenever a view has been destroyed
66+
* (e, view:View)
67+
*
6568
* View Interface:
6669
*
6770
* The view is an anonymous object which has the following method signatures. see ImageViewer for an example or the sample
@@ -506,6 +509,7 @@ define(function (require, exports, module) {
506509

507510
// Destroy temporary views
508511
_.forEach(viewsToDestroy, function (view) {
512+
$(this).triggerHandler("viewDestroy", view);
509513
view.destroy();
510514
});
511515

@@ -739,6 +743,7 @@ define(function (require, exports, module) {
739743
this._hideCurrentView();
740744
}
741745
delete this._views[view.getFile().fullPath];
746+
$(this).triggerHandler("viewDestroy", view);
742747
view.destroy();
743748
};
744749

@@ -1084,6 +1089,7 @@ define(function (require, exports, module) {
10841089
var file = view.getFile(),
10851090
path = file && file.fullPath;
10861091
delete this._views[path];
1092+
$(this).triggerHandler("viewDestroy", view);
10871093
view.destroy();
10881094
}
10891095
};
@@ -1116,6 +1122,7 @@ define(function (require, exports, module) {
11161122

11171123
// Now destroy the views
11181124
views.forEach(function (_view) {
1125+
$(this).triggerHandler("viewDestroy", _view);
11191126
_view.destroy();
11201127
});
11211128
};

0 commit comments

Comments
 (0)