home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / browser.jar / content / browser / cookieviewer / treeUtils.js < prev   
Encoding:
JavaScript  |  2005-07-29  |  4.0 KB  |  133 lines

  1. // MERC - JCH: Need the cookie manager service to delete cookies.
  2. var cookiemanager = Components.classes["@mozilla.org/cookiemanager;1"].getService();
  3.     cookiemanager = cookiemanager.QueryInterface(Components.interfaces.nsICookieManager);
  4.  
  5. function DeleteAllFromTree
  6.     (tree, view, table, deletedTable, removeButton, removeAllButton) {
  7.  
  8.   // remove all items from table and place in deleted table
  9.   for (var i=0; i<table.length; i++) {
  10.     deletedTable[deletedTable.length] = table[i];
  11.   }
  12.   table.length = 0;
  13.  
  14.   // redisplay
  15.   var oldCount = view.rowCount;
  16.   view.rowCount = 0;
  17.   tree.treeBoxObject.rowCountChanged(0, -oldCount);
  18.  
  19.   // MERC - JCH: Delete all IE cookies, not just Netscape's.
  20.   // This is the easiest way to be sure that all are deleted.
  21.   if (cookiemanager)
  22.     cookiemanager.removeAll();
  23.  
  24.   // disable buttons
  25.   document.getElementById(removeButton).setAttribute("disabled", "true")
  26.   document.getElementById(removeAllButton).setAttribute("disabled","true");
  27. }
  28.  
  29. function DeleteSelectedItemFromTree
  30.     (tree, view, table, deletedTable, removeButton, removeAllButton) {
  31.   // Turn off tree selection notifications during the deletion
  32.   tree.treeBoxObject.view.selection.selectEventsSuppressed = true;
  33.  
  34.   // remove selected items from list (by setting them to null) and place in deleted list
  35.   var selections = GetTreeSelections(tree);
  36.   for (var s=selections.length-1; s>= 0; s--) {
  37.     var i = selections[s];
  38.     deletedTable[deletedTable.length] = table[i];
  39.     table[i] = null;
  40.   }
  41.  
  42.   // collapse list by removing all the null entries
  43.   for (var j=0; j<table.length; j++) {
  44.     if (table[j] == null) {
  45.       var k = j;
  46.       while ((k < table.length) && (table[k] == null)) {
  47.         k++;
  48.       }
  49.       table.splice(j, k-j);
  50.       view.rowCount -= k - j;
  51.       tree.treeBoxObject.rowCountChanged(j, j - k);
  52.     }
  53.   }
  54.  
  55.   // update selection and/or buttons
  56.   if (table.length) {
  57.  
  58.     // update selection
  59.     var nextSelection = (selections[0] < table.length) ? selections[0] : table.length-1;
  60.     tree.treeBoxObject.view.selection.select(nextSelection);
  61.     tree.treeBoxObject.ensureRowIsVisible(nextSelection);
  62.  
  63.   } else {
  64.  
  65.     // disable buttons
  66.     document.getElementById(removeButton).setAttribute("disabled", "true")
  67.     document.getElementById(removeAllButton).setAttribute("disabled","true");
  68.  
  69.   }
  70.   tree.treeBoxObject.view.selection.selectEventsSuppressed = false;
  71. }
  72.  
  73. function GetTreeSelections(tree) {
  74.   var selections = [];
  75.   var select = tree.treeBoxObject.selection;
  76.   if (select) {
  77.     var count = select.getRangeCount();
  78.     var min = new Object();
  79.     var max = new Object();
  80.     for (var i=0; i<count; i++) {
  81.       select.getRangeAt(i, min, max);
  82.       for (var k=min.value; k<=max.value; k++) {
  83.         if (k != -1) {
  84.           selections[selections.length] = k;
  85.         }
  86.       }
  87.     }
  88.   }
  89.   return selections;
  90. }
  91.  
  92. function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending, updateSelection) {
  93.  
  94.   // remember which item was selected so we can restore it after the sort
  95.   var selections = GetTreeSelections(tree);
  96.   var selectedNumber = selections.length ? table[selections[0]].id : -1;
  97.  
  98.   // determine if sort is to be ascending or descending
  99.   var ascending = (column == lastSortColumn) ? !lastSortAscending : true;
  100.  
  101.   // do the sort or re-sort
  102.   var compareFunc = function compare(first, second) {
  103.     return first[column].toLowerCase().localeCompare(second[column].toLowerCase());
  104.   }
  105.   table.sort(compareFunc);
  106.   if (!ascending)
  107.     table.reverse();
  108.  
  109.   // restore the selection
  110.   var selectedRow = -1;
  111.   if (selectedNumber>=0 && updateSelection) {
  112.     for (var s=0; s<table.length; s++) {
  113.       if (table[s].id == selectedNumber) {
  114.         // update selection
  115.         // note: we need to deselect before reselecting in order to trigger ...Selected()
  116.         tree.treeBoxObject.view.selection.select(-1);
  117.         tree.treeBoxObject.view.selection.select(s);
  118.         selectedRow = s;
  119.         break;
  120.       }
  121.     }
  122.   }
  123.  
  124.   // display the results
  125.   tree.treeBoxObject.invalidate();
  126.   if (selectedRow >= 0) {
  127.     tree.treeBoxObject.ensureRowIsVisible(selectedRow)
  128.   }
  129.  
  130.   return ascending;
  131. }
  132.  
  133.