From 93cc2f8a6ffe7524680ec99b90a7c2f0cde65a94 Mon Sep 17 00:00:00 2001 From: "neil%parkwaycc.co.uk" Date: Thu, 30 Oct 2003 09:33:40 +0000 Subject: [PATCH] Bug 215656 Cookie and Popup managers don't update scrollbar correctly r=mvl/dwitte sr=bryner --- .../resources/content/nsWalletTreeUtils.js | 56 ++++--------------- .../resources/content/popupManager.js | 22 ++------ .../permissions/content/permissionsManager.js | 22 ++------ .../permissions/content/treeUtils.js | 56 ++++--------------- 4 files changed, 32 insertions(+), 124 deletions(-) diff --git a/extensions/wallet/cookieviewer/resources/content/nsWalletTreeUtils.js b/extensions/wallet/cookieviewer/resources/content/nsWalletTreeUtils.js index f0bd0ebce7e9..35b7d9756b65 100644 --- a/extensions/wallet/cookieviewer/resources/content/nsWalletTreeUtils.js +++ b/extensions/wallet/cookieviewer/resources/content/nsWalletTreeUtils.js @@ -29,12 +29,10 @@ function DeleteAllFromTree } table.length = 0; - // clear out selections - tree.treeBoxObject.view.selection.select(-1); - // redisplay + var oldCount = view.rowCount; view.rowCount = 0; - tree.treeBoxObject.invalidate(); + tree.treeBoxObject.rowCountChanged(0, -oldCount); // disable buttons @@ -61,27 +59,18 @@ function DeleteSelectedItemFromTree k++; } table.splice(j, k-j); + view.rowCount -= k - j; + tree.treeBoxObject.rowCountChanged(j, j - k); } } - // redisplay - 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 if (table.length) { // update selection - // 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); + tree.treeBoxObject.ensureRowIsVisible(nextSelection); } else { @@ -89,8 +78,6 @@ function DeleteSelectedItemFromTree document.getElementById(removeButton).setAttribute("disabled", "true") document.getElementById(removeAllButton).setAttribute("disabled","true"); - // clear out selections - tree.treeBoxObject.view.selection.select(-1); } } @@ -122,18 +109,13 @@ function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending, // determine if sort is to be ascending or descending var ascending = (column == lastSortColumn) ? !lastSortAscending : true; - // do the sort - var compareFunc; - if (ascending) { - compareFunc = function compare(first, second) { - return CompareLowerCase(first[column], second[column]); - } - } else { - compareFunc = function compare(first, second) { - return CompareLowerCase(second[column], first[column]); - } + // do the sort or re-sort + var compareFunc = function compare(first, second) { + return first[column].toLowerCase().localeCompare(second[column].toLowerCase()); } table.sort(compareFunc); + if (!ascending) + table.reverse(); // restore the selection var selectedRow = -1; @@ -159,21 +141,3 @@ function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending, return ascending; } -/** - * Case insensitive string comparator. - */ -function CompareLowerCase(first, second) { - - var firstLower = first.toLowerCase(); - var secondLower = second.toLowerCase(); - - if (firstLower < secondLower) { - return -1; - } - - if (firstLower > secondLower) { - return 1; - } - - return 0; -} diff --git a/xpfe/communicator/resources/content/popupManager.js b/xpfe/communicator/resources/content/popupManager.js index 0877b7a6dab6..ef0802c28f96 100644 --- a/xpfe/communicator/resources/content/popupManager.js +++ b/xpfe/communicator/resources/content/popupManager.js @@ -229,28 +229,19 @@ function deletePermissions() { k++; } permissions.splice(j, k-j); + permissionsTreeView.rowCount -= k - j; + permissionsTree.treeBoxObject.rowCountChanged(j, j - k); } } - var box = permissionsTree.treeBoxObject; - var firstRow = box.getFirstVisibleRow(); - if (firstRow > (permissions.length - 1) ) { - firstRow = permissions.length - 1; - } - permissionsTreeView.rowCount = permissions.length; - box.rowCountChanged(0, permissions.length); - box.scrollToRow(firstRow); - if (permissions.length) { var nextSelection = (selections[0] < permissions.length) ? selections[0] : permissions.length - 1; - box.view.selection.select(-1); - box.view.selection.select(nextSelection); + permissionsTreeView.selection.select(nextSelection); + permissionsTree.treeBoxObject.ensureRowIsVisible(nextSelection); } else { document.getElementById("removePermission").setAttribute("disabled", "true") document.getElementById("removeAllPermissions").setAttribute("disabled","true"); - - permissionsTree.treeBoxObject.view.selection.select(-1); } } @@ -272,10 +263,9 @@ function updatePendingRemovals(host) { } function clearTree() { - permissionsTree.treeBoxObject.view.selection.select(-1); - + var oldCount = permissionsTreeView.rowCount; permissionsTreeView.rowCount = 0; - permissionsTree.treeBoxObject.invalidate(); + permissionsTree.treeBoxObject.rowCountChanged(0, -oldCount); document.getElementById("removePermission").setAttribute("disabled", "true") document.getElementById("removeAllPermissions").setAttribute("disabled","true"); diff --git a/xpfe/components/permissions/content/permissionsManager.js b/xpfe/components/permissions/content/permissionsManager.js index 0877b7a6dab6..ef0802c28f96 100644 --- a/xpfe/components/permissions/content/permissionsManager.js +++ b/xpfe/components/permissions/content/permissionsManager.js @@ -229,28 +229,19 @@ function deletePermissions() { k++; } permissions.splice(j, k-j); + permissionsTreeView.rowCount -= k - j; + permissionsTree.treeBoxObject.rowCountChanged(j, j - k); } } - var box = permissionsTree.treeBoxObject; - var firstRow = box.getFirstVisibleRow(); - if (firstRow > (permissions.length - 1) ) { - firstRow = permissions.length - 1; - } - permissionsTreeView.rowCount = permissions.length; - box.rowCountChanged(0, permissions.length); - box.scrollToRow(firstRow); - if (permissions.length) { var nextSelection = (selections[0] < permissions.length) ? selections[0] : permissions.length - 1; - box.view.selection.select(-1); - box.view.selection.select(nextSelection); + permissionsTreeView.selection.select(nextSelection); + permissionsTree.treeBoxObject.ensureRowIsVisible(nextSelection); } else { document.getElementById("removePermission").setAttribute("disabled", "true") document.getElementById("removeAllPermissions").setAttribute("disabled","true"); - - permissionsTree.treeBoxObject.view.selection.select(-1); } } @@ -272,10 +263,9 @@ function updatePendingRemovals(host) { } function clearTree() { - permissionsTree.treeBoxObject.view.selection.select(-1); - + var oldCount = permissionsTreeView.rowCount; permissionsTreeView.rowCount = 0; - permissionsTree.treeBoxObject.invalidate(); + permissionsTree.treeBoxObject.rowCountChanged(0, -oldCount); document.getElementById("removePermission").setAttribute("disabled", "true") document.getElementById("removeAllPermissions").setAttribute("disabled","true"); diff --git a/xpfe/components/permissions/content/treeUtils.js b/xpfe/components/permissions/content/treeUtils.js index f0bd0ebce7e9..35b7d9756b65 100644 --- a/xpfe/components/permissions/content/treeUtils.js +++ b/xpfe/components/permissions/content/treeUtils.js @@ -29,12 +29,10 @@ function DeleteAllFromTree } table.length = 0; - // clear out selections - tree.treeBoxObject.view.selection.select(-1); - // redisplay + var oldCount = view.rowCount; view.rowCount = 0; - tree.treeBoxObject.invalidate(); + tree.treeBoxObject.rowCountChanged(0, -oldCount); // disable buttons @@ -61,27 +59,18 @@ function DeleteSelectedItemFromTree k++; } table.splice(j, k-j); + view.rowCount -= k - j; + tree.treeBoxObject.rowCountChanged(j, j - k); } } - // redisplay - 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 if (table.length) { // update selection - // 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); + tree.treeBoxObject.ensureRowIsVisible(nextSelection); } else { @@ -89,8 +78,6 @@ function DeleteSelectedItemFromTree document.getElementById(removeButton).setAttribute("disabled", "true") document.getElementById(removeAllButton).setAttribute("disabled","true"); - // clear out selections - tree.treeBoxObject.view.selection.select(-1); } } @@ -122,18 +109,13 @@ function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending, // determine if sort is to be ascending or descending var ascending = (column == lastSortColumn) ? !lastSortAscending : true; - // do the sort - var compareFunc; - if (ascending) { - compareFunc = function compare(first, second) { - return CompareLowerCase(first[column], second[column]); - } - } else { - compareFunc = function compare(first, second) { - return CompareLowerCase(second[column], first[column]); - } + // do the sort or re-sort + var compareFunc = function compare(first, second) { + return first[column].toLowerCase().localeCompare(second[column].toLowerCase()); } table.sort(compareFunc); + if (!ascending) + table.reverse(); // restore the selection var selectedRow = -1; @@ -159,21 +141,3 @@ function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending, return ascending; } -/** - * Case insensitive string comparator. - */ -function CompareLowerCase(first, second) { - - var firstLower = first.toLowerCase(); - var secondLower = second.toLowerCase(); - - if (firstLower < secondLower) { - return -1; - } - - if (firstLower > secondLower) { - return 1; - } - - return 0; -}