зеркало из https://github.com/mozilla/pjs.git
Bug 397218 - Persist the selection when sorting a places tree. r=dietrich. a=mconnor.
This commit is contained in:
Родитель
cfcb865b69
Коммит
04762f216f
|
@ -160,8 +160,6 @@ PlacesTreeView.prototype = {
|
|||
* Call to completely rebuild the list of visible items. Note if there is no
|
||||
* tree or root this will just clear out the list, so you can also call this
|
||||
* when a tree is detached to clear the list.
|
||||
*
|
||||
* This does NOT update the screen.
|
||||
*/
|
||||
_buildVisibleList: function PTV__buildVisibleList() {
|
||||
if (this._result) {
|
||||
|
@ -171,11 +169,6 @@ PlacesTreeView.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
var oldCount = this.rowCount;
|
||||
this._visibleElements.splice(0);
|
||||
if (this._tree)
|
||||
this._tree.rowCountChanged(0, -oldCount);
|
||||
|
||||
var rootNode = this._result.root;
|
||||
if (rootNode && this._tree) {
|
||||
this._computeShowSessions();
|
||||
|
@ -189,7 +182,7 @@ PlacesTreeView.prototype = {
|
|||
}
|
||||
else if (!rootNode.containerOpen) {
|
||||
// this triggers containerOpened which then builds the visible
|
||||
// selection
|
||||
// section
|
||||
rootNode.containerOpen = true;
|
||||
return;
|
||||
}
|
||||
|
@ -325,8 +318,8 @@ PlacesTreeView.prototype = {
|
|||
if (aContainer.viewIndex != -1)
|
||||
replaceCount-=1;
|
||||
|
||||
// Mark the removees as invisible
|
||||
for (var i = 0; i < replaceCount; i ++)
|
||||
// Mark the removes as invisible
|
||||
for (var i = 0; i < replaceCount; i++)
|
||||
this._visibleElements[startReplacement + i].viewIndex = -1;
|
||||
|
||||
// Building the new list will set the new elements' visible indices.
|
||||
|
@ -334,6 +327,22 @@ PlacesTreeView.prototype = {
|
|||
var toOpenElements = [];
|
||||
this._buildVisibleSection(aContainer, newElements, toOpenElements, startReplacement);
|
||||
|
||||
// Persist selection state
|
||||
var nodesToSelect = [];
|
||||
var selection = this.selection;
|
||||
var rc = selection.getRangeCount();
|
||||
for (var rangeIndex = 0; rangeIndex < rc; rangeIndex++) {
|
||||
var min = { }, max = { };
|
||||
selection.getRangeAt(rangeIndex, min, max);
|
||||
if (min.value > startReplacement + replaceCount)
|
||||
continue;
|
||||
|
||||
for (var nodeIndex = min.value; nodeIndex <= max.value; nodeIndex++) {
|
||||
if (newElements.indexOf(this._visibleElements[nodeIndex]) != -1)
|
||||
nodesToSelect.push(this._visibleElements[nodeIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
// actually update the visible list
|
||||
this._visibleElements =
|
||||
this._visibleElements.slice(0, startReplacement).concat(newElements)
|
||||
|
@ -350,6 +359,9 @@ PlacesTreeView.prototype = {
|
|||
}
|
||||
|
||||
// now update the number of elements
|
||||
if (nodesToSelect.length > 0)
|
||||
selection.selectEventsSuppressed = true;
|
||||
|
||||
this._tree.beginUpdateBatch();
|
||||
if (replaceCount)
|
||||
this._tree.rowCountChanged(startReplacement, -replaceCount);
|
||||
|
@ -362,6 +374,15 @@ PlacesTreeView.prototype = {
|
|||
var item = asContainer(toOpenElements[i]);
|
||||
item.containerOpen = !item.containerOpen;
|
||||
}
|
||||
|
||||
// restore selection
|
||||
if (nodesToSelect.length > 0) {
|
||||
for each (var node in nodesToSelect) {
|
||||
var index = node.viewIndex;
|
||||
selection.rangedSelect(index, index, true);
|
||||
}
|
||||
selection.selectEventsSuppressed = false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -387,7 +408,7 @@ PlacesTreeView.prototype = {
|
|||
aShowThisOne.value = aTop.time < aNext.time;
|
||||
return true;
|
||||
},
|
||||
|
||||
|
||||
_convertPRTimeToString: function PTV__convertPRTimeToString(aTime) {
|
||||
var timeInMilliseconds = aTime / 1000; // PRTime is in microseconds
|
||||
var timeObj = new Date(timeInMilliseconds);
|
||||
|
@ -415,7 +436,7 @@ PlacesTreeView.prototype = {
|
|||
timeObj.getDate(), timeObj.getHours(),
|
||||
timeObj.getMinutes(), timeObj.getSeconds()));
|
||||
},
|
||||
|
||||
|
||||
COLUMN_TYPE_UNKNOWN: 0,
|
||||
COLUMN_TYPE_TITLE: 1,
|
||||
COLUMN_TYPE_URI: 2,
|
||||
|
@ -726,12 +747,6 @@ PlacesTreeView.prototype = {
|
|||
|
||||
// update flat list to new contents
|
||||
this._buildVisibleList();
|
||||
|
||||
// redraw the tree, inserting new items
|
||||
this._tree.beginUpdateBatch();
|
||||
this._tree.rowCountChanged(0, -oldRowCount);
|
||||
this._tree.rowCountChanged(0, this._visibleElements.length);
|
||||
this._tree.endUpdateBatch();
|
||||
},
|
||||
|
||||
sortingChanged: function PTV__sortingChanged(aSortingMode) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче