home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-macos9-1.3.1.sea.bin / Mozilla1.3.1 / Chrome / comm.jar / content / communicator / bookmarks / bookmarks.js < prev    next >
Text File  |  2003-06-08  |  8KB  |  220 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 
  2.  *
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is mozilla.org code.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation.  Portions created by Netscape are
  17.  * Copyright (C) 1998 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *   Ben Goodger <ben@netscape.com> (Original Author, v3.0)
  22.  */
  23.  
  24. ////////////////////////////////////////////////////////////////////////////////
  25. // Initialize the command controllers, set focus, tree root, 
  26. // window title state, etc. 
  27. function Startup()
  28. {
  29.   const windowNode = document.getElementById("bookmark-window");
  30.   const bookmarksView = document.getElementById("bookmarks-view");
  31.   var titleString;
  32.  
  33.   // If we've been opened with a parameter, root the tree on it.
  34.   if ("arguments" in window && window.arguments[0]) {
  35.     var title;
  36.     var uri = window.arguments[0];
  37.     bookmarksView.tree.setAttribute("ref", uri);
  38.     if (uri.substring(0,5) == "find:") {
  39.       title = bookmarksView._bundle.GetStringFromName("search_results_title");
  40.       // Update the windowtype so that future searches are directed 
  41.       // there and the window is not re-used for bookmarks. 
  42.       windowNode.setAttribute("windowtype", "bookmarks:searchresults");
  43.     }
  44.     else {
  45.       const krNameArc = bookmarksView.rdf.GetResource(NC_NS + "Name");
  46.       const krRoot = bookmarksView.rdf.GetResource(window.arguments[0]);
  47.       var rName = bookmarksView.db.GetTarget(krRoot, krNameArc, true);
  48.       title = rName.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  49.     }
  50.     titleString = bookmarksView._bundle.GetStringFromName("window_title");
  51.     titleString = titleString.replace(/%folder_name%/gi, title);
  52.     windowNode.setAttribute("title", titleString);
  53.   }
  54.   else {
  55.     const kProfileContractID = "@mozilla.org/profile/manager;1";
  56.     const kProfileIID = Components.interfaces.nsIProfile;
  57.     const kProfile = Components.classes[kProfileContractID].getService(kProfileIID);
  58.     var length = {value:0};
  59.     var profileList = kProfile.getProfileList(length);
  60.     // unset the default BM title if the user has more than one profile
  61.     // or if he/she has changed the name of the default one.
  62.     // the profile "default" is not localizable.
  63.     if (length.value > 1 || kProfile.currentProfile.toLowerCase() != "default") {
  64.       titleString = bookmarksView._bundle.GetStringFromName("bookmarks_root");
  65.       titleString = titleString.replace(/%user_name%/, kProfile.currentProfile);
  66.       windowNode.setAttribute("title", titleString);
  67.     }
  68.   }
  69.  
  70.   bookmarksView.treeBoxObject.selection.select(0);
  71.   bookmarksView.tree.focus();
  72. }
  73.  
  74. function Shutdown ()
  75. {
  76.   // Store current window position and size in window attributes (for persistence).
  77.   var win = document.getElementById("bookmark-window");
  78.   win.setAttribute("x", screenX);
  79.   win.setAttribute("y", screenY);
  80.   win.setAttribute("height", outerHeight);
  81.   win.setAttribute("width", outerWidth);
  82.  
  83.   var bookmarksView = document.getElementById("bookmarks-view");
  84.   bookmarksView.flushBMDatasource();
  85. }
  86.  
  87. var gConstructedViewMenuSortItems = false;
  88. function fillViewMenu(aEvent)
  89. {
  90.   var adjacentElement = document.getElementById("fill-before-this-node");
  91.   var popupElement = aEvent.target;
  92.   
  93.   var bookmarksView = document.getElementById("bookmarks-view");
  94.   var columns = bookmarksView.columns;
  95.  
  96.   if (!gConstructedViewMenuSortItems) {
  97.     for (var i = 0; i < columns.length; ++i) {
  98.       var name = columns[i].name;
  99.       var accesskey = columns[i].accesskey;
  100.       
  101.       var menuitem = document.createElement("menuitem");
  102.       var nameTemplate = bookmarksView._bundle.GetStringFromName("SortMenuItem");
  103.       name = nameTemplate.replace(/%NAME%/g, columns[i].label);
  104.       menuitem.setAttribute("label", name);
  105.       menuitem.setAttribute("accesskey", columns[i].accesskey);
  106.       menuitem.setAttribute("resource", columns[i].resource);
  107.       menuitem.setAttribute("id", "sortMenuItem:" + columns[i].resource);
  108.       menuitem.setAttribute("checked", columns[i].sortActive);
  109.       menuitem.setAttribute("name", "sortSet");
  110.       menuitem.setAttribute("type", "radio");
  111.       
  112.       popupElement.insertBefore(menuitem, adjacentElement);
  113.     }
  114.     
  115.     gConstructedViewMenuSortItems = true;
  116.   }  
  117.  
  118.   const kPrefSvcContractID = "@mozilla.org/preferences;1";
  119.   const kPrefSvcIID = Components.interfaces.nsIPrefService;
  120.   var prefSvc = Components.classes[kPrefSvcContractID].getService(kPrefSvcIID);
  121.   var bookmarksSortPrefs = prefSvc.getBranch("browser.bookmarks.sort.");
  122.  
  123.   if (gConstructedViewMenuSortItems) {
  124.     var resource = bookmarksSortPrefs.getCharPref("resource");
  125.     var element = document.getElementById("sortMenuItem:" + resource);
  126.     if (element)
  127.       element.setAttribute("checked", "true");
  128.   }  
  129.  
  130.   var sortAscendingMenu = document.getElementById("ascending");
  131.   var sortDescendingMenu = document.getElementById("descending");
  132.   var noSortMenu = document.getElementById("natural");
  133.   
  134.   sortAscendingMenu.setAttribute("checked", "false");
  135.   sortDescendingMenu.setAttribute("checked", "false");
  136.   noSortMenu.setAttribute("checked", "false");
  137.   var direction = bookmarksSortPrefs.getCharPref("direction");
  138.   if (direction == "natural")
  139.     sortAscendingMenu.setAttribute("checked", "true");
  140.   else if (direction == "ascending") 
  141.     sortDescendingMenu.setAttribute("checked", "true");
  142.   else
  143.     noSortMenu.setAttribute("checked", "true");
  144. }
  145.  
  146. function onViewMenuSortItemSelected(aEvent)
  147. {
  148.   var resource = aEvent.target.getAttribute("resource");
  149.   
  150.   const kPrefSvcContractID = "@mozilla.org/preferences;1";
  151.   const kPrefSvcIID = Components.interfaces.nsIPrefService;
  152.   var prefSvc = Components.classes[kPrefSvcContractID].getService(kPrefSvcIID);
  153.   var bookmarksSortPrefs = prefSvc.getBranch("browser.bookmarks.sort.");
  154.  
  155.   switch (resource) {
  156.   case "":
  157.     break;
  158.   case "direction":
  159.     var dirn = bookmarksSortPrefs.getCharPref("direction");
  160.     if (aEvent.target.id == "ascending")
  161.       bookmarksSortPrefs.setCharPref("direction", "natural");
  162.     else if (aEvent.target.id == "descending")
  163.       bookmarksSortPrefs.setCharPref("direction", "ascending");
  164.     else
  165.       bookmarksSortPrefs.setCharPref("direction", "descending");
  166.     break;
  167.   default:
  168.     bookmarksSortPrefs.setCharPref("resource", resource);
  169.     var direction = bookmarksSortPrefs.getCharPref("direction");
  170.     if (direction == "descending")
  171.       bookmarksSortPrefs.setCharPref("direction", "natural");
  172.     break;
  173.   }
  174.  
  175.   aEvent.preventCapture();
  176. }  
  177.  
  178. var gConstructedColumnsMenuItems = false;
  179. function fillColumnsMenu(aEvent) 
  180. {
  181.   var bookmarksView = document.getElementById("bookmarks-view");
  182.   var columns = bookmarksView.columns;
  183.   var i;
  184.  
  185.   if (!gConstructedColumnsMenuItems) {
  186.     for (i = 0; i < columns.length; ++i) {
  187.       var menuitem = document.createElement("menuitem");
  188.       menuitem.setAttribute("label", columns[i].label);
  189.       menuitem.setAttribute("resource", columns[i].resource);
  190.       menuitem.setAttribute("id", "columnMenuItem:" + columns[i].resource);
  191.       menuitem.setAttribute("type", "checkbox");
  192.       menuitem.setAttribute("checked", columns[i].hidden != "true");
  193.       aEvent.target.appendChild(menuitem);
  194.     }
  195.  
  196.     gConstructedColumnsMenuItems = true;
  197.   }
  198.   else {
  199.     for (i = 0; i < columns.length; ++i) {
  200.       var element = document.getElementById("columnMenuItem:" + columns[i].resource);
  201.       if (element && columns[i].hidden != "true")
  202.         element.setAttribute("checked", "true");
  203.     }
  204.   }
  205.   
  206.   aEvent.preventBubble();
  207. }
  208.  
  209. function onViewMenuColumnItemSelected(aEvent)
  210. {
  211.   var resource = aEvent.target.getAttribute("resource");
  212.   if (resource != "") {
  213.     var bookmarksView = document.getElementById("bookmarks-view");
  214.     bookmarksView.toggleColumnVisibility(resource);
  215.   }  
  216.  
  217.   aEvent.preventBubble();
  218. }
  219.  
  220.