зеркало из https://github.com/mozilla/pjs.git
Make removal of stored logins play nicer with the tree widget. Do a (batched) notification of the treeBoxObject that the row count is changing when deleting one or more stored logins. Also do a rowCountChanged notification when removing all stored logins.
This commit is contained in:
Родитель
991aa3a08f
Коммит
e4c449f3fd
|
@ -209,8 +209,8 @@ function SignonSelected() {
|
||||||
|
|
||||||
function DeleteSignon() {
|
function DeleteSignon() {
|
||||||
DeleteSelectedItemFromTree(signonsTree, signonsTreeView,
|
DeleteSelectedItemFromTree(signonsTree, signonsTreeView,
|
||||||
signons, deletedSignons,
|
signons, deletedSignons,
|
||||||
"removeSignon", "removeAllSignons");
|
"removeSignon", "removeAllSignons");
|
||||||
FinalizeSignonDeletions();
|
FinalizeSignonDeletions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,11 +367,14 @@ function DeleteAllFromTree
|
||||||
table.length = 0;
|
table.length = 0;
|
||||||
|
|
||||||
// clear out selections
|
// clear out selections
|
||||||
tree.treeBoxObject.view.selection.select(-1);
|
view.selection.select(-1);
|
||||||
|
|
||||||
// redisplay
|
// update the tree view and notify the tree
|
||||||
view.rowCount = 0;
|
view.rowCount = 0;
|
||||||
tree.treeBoxObject.invalidate();
|
|
||||||
|
var box = tree.treeBoxObject;
|
||||||
|
box.rowCountChanged(0, -deletedTable.length);
|
||||||
|
box.invalidate();
|
||||||
|
|
||||||
|
|
||||||
// disable buttons
|
// disable buttons
|
||||||
|
@ -382,52 +385,61 @@ function DeleteAllFromTree
|
||||||
function DeleteSelectedItemFromTree
|
function DeleteSelectedItemFromTree
|
||||||
(tree, view, table, deletedTable, removeButton, removeAllButton) {
|
(tree, view, table, deletedTable, removeButton, removeAllButton) {
|
||||||
|
|
||||||
// remove selected items from list (by setting them to null) and place in deleted list
|
var box = tree.treeBoxObject;
|
||||||
var selections = GetTreeSelections(tree);
|
|
||||||
for (var s=selections.length-1; s>= 0; s--) {
|
// Remove selected items from list (by setting them to null) and place in
|
||||||
var i = selections[s];
|
// deleted list. At the same time, notify the tree of the row count changes.
|
||||||
deletedTable[deletedTable.length] = table[i];
|
|
||||||
table[i] = null;
|
var selection = box.selection;
|
||||||
|
var oldSelectStart = table.length;
|
||||||
|
box.beginUpdateBatch();
|
||||||
|
|
||||||
|
var selCount = selection.getRangeCount();
|
||||||
|
var min = new Object();
|
||||||
|
var max = new Object();
|
||||||
|
|
||||||
|
for (var s = 0; s < selCount; ++s) {
|
||||||
|
selection.getRangeAt(s, min, max);
|
||||||
|
var minVal = min.value;
|
||||||
|
var maxVal = max.value;
|
||||||
|
|
||||||
|
oldSelectStart = minVal < oldSelectStart ? minVal : oldSelectStart;
|
||||||
|
|
||||||
|
var rowCount = maxVal - minVal + 1;
|
||||||
|
view.rowCount -= rowCount;
|
||||||
|
box.rowCountChanged(minVal, -rowCount);
|
||||||
|
|
||||||
|
for (var i = minVal; i <= maxVal; ++i) {
|
||||||
|
deletedTable[deletedTable.length] = table[i];
|
||||||
|
table[i] = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// collapse list by removing all the null entries
|
// collapse list by removing all the null entries
|
||||||
for (var j=0; j<table.length; j++) {
|
for (var j = 0; j < table.length; ++j) {
|
||||||
if (table[j] == null) {
|
if (!table[j]) {
|
||||||
var k = j;
|
var k = j;
|
||||||
while ((k < table.length) && (table[k] == null)) {
|
while (k < table.length && !table[k])
|
||||||
k++;
|
k++;
|
||||||
}
|
|
||||||
table.splice(j, k-j);
|
table.splice(j, k-j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// redisplay
|
box.endUpdateBatch();
|
||||||
var box = tree.treeBoxObject;
|
|
||||||
var firstRow = box.getFirstVisibleRow();
|
|
||||||
if (firstRow > (table.length-1) ) {
|
|
||||||
firstRow = table.length-1;
|
|
||||||
}
|
|
||||||
view.rowCount = table.length;
|
|
||||||
box.rowCountChanged(0, table.length);
|
|
||||||
box.scrollToRow(firstRow)
|
|
||||||
|
|
||||||
// update selection and/or buttons
|
// update selection and/or buttons
|
||||||
|
var removeButton = document.getElementById(removeButton);
|
||||||
|
var removeAllButton = document.getElementById(removeAllButton);
|
||||||
|
|
||||||
if (table.length) {
|
if (table.length) {
|
||||||
|
removeButton.removeAttribute("disabled");
|
||||||
|
removeAllButton.removeAttribute("disabled");
|
||||||
|
|
||||||
// update selection
|
selection.select(oldSelectStart < table.length ? oldSelectStart : table.length - 1);
|
||||||
// note: we need to deselect before reselecting in order to trigger ...Selected method
|
|
||||||
var nextSelection = (selections[0] < table.length) ? selections[0] : table.length-1;
|
|
||||||
tree.treeBoxObject.view.selection.select(-1);
|
|
||||||
tree.treeBoxObject.view.selection.select(nextSelection);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
removeButton.setAttribute("disabled", "true");
|
||||||
// disable buttons
|
removeAllButton.setAttribute("disabled", "true");
|
||||||
document.getElementById(removeButton).setAttribute("disabled", "true")
|
|
||||||
document.getElementById(removeAllButton).setAttribute("disabled","true");
|
|
||||||
|
|
||||||
// clear out selections
|
|
||||||
tree.treeBoxObject.view.selection.select(-1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче