From 6d79590a7e48311211a12f46bc7fde6274b670d9 Mon Sep 17 00:00:00 2001 From: "blakeross%telocity.com" Date: Thu, 15 Aug 2002 00:22:41 +0000 Subject: [PATCH] Forking bookmarks, adding QS. --- browser/components/Makefile.in | 2 +- browser/components/bookmarks/.cvsignore | 0 browser/components/bookmarks/Makefile.in | 30 + .../bookmarks/content/MANIFEST-content | 0 .../components/bookmarks/content/Makefile.in | 0 .../bookmarks/content/addBookmark.js | 341 ++++++ .../bookmarks/content/addBookmark.xul | 118 ++ .../components/bookmarks/content/bm-panel.xul | 0 .../components/bookmarks/content/bm-props.js | 0 .../components/bookmarks/content/bm-props.xul | 0 .../bookmarks/content/bookmarks-temp.js | 0 .../bookmarks/content/bookmarks.css | 14 + .../components/bookmarks/content/bookmarks.js | 0 .../bookmarks/content/bookmarks.xml | 0 .../bookmarks/content/bookmarks.xul | 237 ++++ .../bookmarks/content/bookmarksDD-temp.js | 0 .../bookmarks/content/bookmarksDD.js | 0 .../bookmarks/content/bookmarksOverlay.js | 1002 +++++++++++++++++ .../bookmarks/content/bookmarksOverlay.xul | 0 .../bookmarks/content/bookmarksPanel.js | 64 ++ .../bookmarks/content/bookmarksTree.js | 0 .../bookmarks/content/findBookmark.js | 97 ++ .../bookmarks/content/findBookmark.xul | 69 ++ .../components/bookmarks/content/manifest.jm | 0 .../components/bookmarks/content/oTest.css | 0 .../components/bookmarks/content/oTest.xul | 0 .../bookmarks/content/pref-bookmarks.xul | 0 browser/components/bookmarks/jar.mn | 47 + browser/components/bookmarks/locale/MANIFEST | 4 + .../bookmarks/locale/addBookmark.dtd | 46 + .../components/bookmarks/locale/bm-props.dtd | 0 .../bookmarks/locale/bookmark.properties | 0 .../components/bookmarks/locale/bookmarks.dtd | 89 ++ .../bookmarks/locale/bookmarksOverlay.dtd | 0 .../bookmarks/locale/findBookmark.dtd | 0 .../bookmarks/locale/pref-bookmarks.dtd | 0 36 files changed, 2159 insertions(+), 1 deletion(-) create mode 100644 browser/components/bookmarks/.cvsignore create mode 100644 browser/components/bookmarks/Makefile.in create mode 100644 browser/components/bookmarks/content/MANIFEST-content create mode 100644 browser/components/bookmarks/content/Makefile.in create mode 100644 browser/components/bookmarks/content/addBookmark.js create mode 100644 browser/components/bookmarks/content/addBookmark.xul create mode 100644 browser/components/bookmarks/content/bm-panel.xul create mode 100644 browser/components/bookmarks/content/bm-props.js create mode 100644 browser/components/bookmarks/content/bm-props.xul create mode 100644 browser/components/bookmarks/content/bookmarks-temp.js create mode 100644 browser/components/bookmarks/content/bookmarks.css create mode 100644 browser/components/bookmarks/content/bookmarks.js create mode 100644 browser/components/bookmarks/content/bookmarks.xml create mode 100644 browser/components/bookmarks/content/bookmarks.xul create mode 100644 browser/components/bookmarks/content/bookmarksDD-temp.js create mode 100644 browser/components/bookmarks/content/bookmarksDD.js create mode 100644 browser/components/bookmarks/content/bookmarksOverlay.js create mode 100644 browser/components/bookmarks/content/bookmarksOverlay.xul create mode 100644 browser/components/bookmarks/content/bookmarksPanel.js create mode 100644 browser/components/bookmarks/content/bookmarksTree.js create mode 100644 browser/components/bookmarks/content/findBookmark.js create mode 100644 browser/components/bookmarks/content/findBookmark.xul create mode 100644 browser/components/bookmarks/content/manifest.jm create mode 100644 browser/components/bookmarks/content/oTest.css create mode 100644 browser/components/bookmarks/content/oTest.xul create mode 100644 browser/components/bookmarks/content/pref-bookmarks.xul create mode 100644 browser/components/bookmarks/jar.mn create mode 100644 browser/components/bookmarks/locale/MANIFEST create mode 100644 browser/components/bookmarks/locale/addBookmark.dtd create mode 100644 browser/components/bookmarks/locale/bm-props.dtd create mode 100644 browser/components/bookmarks/locale/bookmark.properties create mode 100644 browser/components/bookmarks/locale/bookmarks.dtd create mode 100644 browser/components/bookmarks/locale/bookmarksOverlay.dtd create mode 100644 browser/components/bookmarks/locale/findBookmark.dtd create mode 100644 browser/components/bookmarks/locale/pref-bookmarks.dtd diff --git a/browser/components/Makefile.in b/browser/components/Makefile.in index b05026bd331..42192584505 100644 --- a/browser/components/Makefile.in +++ b/browser/components/Makefile.in @@ -42,6 +42,6 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -DIRS = prefwindow history +DIRS = prefwindow history bookmarks include $(topsrcdir)/config/rules.mk diff --git a/browser/components/bookmarks/.cvsignore b/browser/components/bookmarks/.cvsignore new file mode 100644 index 00000000000..e69de29bb2d diff --git a/browser/components/bookmarks/Makefile.in b/browser/components/bookmarks/Makefile.in new file mode 100644 index 00000000000..e07fb7c964b --- /dev/null +++ b/browser/components/bookmarks/Makefile.in @@ -0,0 +1,30 @@ +# +# The contents of this file are subject to the Netscape Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/NPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +include $(topsrcdir)/config/rules.mk + diff --git a/browser/components/bookmarks/content/MANIFEST-content b/browser/components/bookmarks/content/MANIFEST-content new file mode 100644 index 00000000000..e69de29bb2d diff --git a/browser/components/bookmarks/content/Makefile.in b/browser/components/bookmarks/content/Makefile.in new file mode 100644 index 00000000000..e69de29bb2d diff --git a/browser/components/bookmarks/content/addBookmark.js b/browser/components/bookmarks/content/addBookmark.js new file mode 100644 index 00000000000..6e9acfca56c --- /dev/null +++ b/browser/components/bookmarks/content/addBookmark.js @@ -0,0 +1,341 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Ben Goodger (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the NPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +/** + * Add Bookmark Dialog. + * ==================== + * + * This is a generic bookmark dialog that allows for bookmark addition + * and folder selection. It can be opened with various parameters that + * result in appearance/purpose differences and initial state. + * + * Use: Open with 'openDialog', with the flags + * 'centerscreen,chrome,dialog=no,resizable=yes' + * + * Parameters: + * Apart from the standard openDialog parameters, this dialog can + * be passed additional information, which gets mapped to the + * window.arguments array: + * + * window.arguments[0]: Bookmark Name. The value to be prefilled + * into the "Name: " field (if visible). + * window.arguments[1]: Bookmark URL: The location of the bookmark. + * The value to be filled in the "Location: " + * field (if visible). + * window.arguments[2]: Bookmark Folder. The RDF Resource URI of the + * folder that this bookmark should be created in. + * window.arguments[3]: Bookmark Charset. The charset that should be + * used when adding a bookmark to the specified + * URL. (Usually the charset of the current + * document when launching this window). + * window.arguments[4]: The mode of operation. See notes for details. + * window.arguments[5]: If the mode is "addGroup", this is an array + * of objects with name, URL and charset + * properties, one for each group member. + * + * Mode of Operation Notes: + * ------------------------ + * This dialog can be opened in four different ways by using a parameter + * passed through the call to openDialog. The 'mode' of operation + * of the window is expressed in window.arguments[4]. The valid modes are: + * + * 1) (no fifth open parameter). + * Opens this dialog with the bookmark Name, URL and folder selection + * components visible. + * 2) "newBookmark" (fifth open parameter = String("newBookmark")) + * Opens the dialog as in (1) above except the folder selection tree + * is hidden. This type of mode is useful when the creation folder + * is pre-determined. + * 3) "selectFolder" (fifth open parameter = String("selectFolder")) + * Opens the dialog as in (1) above except the Name/Location section + * is hidden, and the dialog takes on the utility of a Folder chooser. + * Used when the user must select a Folder for some purpose. + * 4) "addGroup" (fifth open parameter = String("addGroup")) + * Opens the dialog like , with a checkbox to select between + * filing a single bookmark or a group. For the single bookmark the + * values are taken from the name, URL and charset arguments. + * For the group, the values are taken from the sixth argument. + * This parameter can also be String("addGroup,group") where "group" + * specifies that the dialog starts in filing as a group. + */ + +var gFld_Name = null; +var gFld_URL = null; +var gFolderTree = null; +var gCB_AddGroup = null; + +var gBookmarkCharset = null; + +const kRDFSContractID = "@mozilla.org/rdf/rdf-service;1"; +const kRDFSIID = Components.interfaces.nsIRDFService; +const kRDF = Components.classes[kRDFSContractID].getService(kRDFSIID); + +var gSelectItemObserver = null; + +var gCreateInFolder = "NC:NewBookmarkFolder"; + +function Startup() +{ + gFld_Name = document.getElementById("name"); + gFld_URL = document.getElementById("url"); + gCB_AddGroup = document.getElementById("addgroup"); + var bookmarkView = document.getElementById("bookmarks-view"); + + var shouldSetOKButton = true; + var dialogElement = document.documentElement; + if ("arguments" in window) { + var ind; + var folderItem = null; + var arg; + if (window.arguments.length < 5) + arg = null; + else + arg = window.arguments[4]; + switch (arg) { + case "selectFolder": + // If we're being opened as a folder selection window + document.getElementById("bookmarknamegrid").setAttribute("hidden", "true"); + document.getElementById("createinseparator").setAttribute("hidden", "true"); + document.getElementById("nameseparator").setAttribute("hidden", "true"); + sizeToContent(); + dialogElement.setAttribute("title", dialogElement.getAttribute("title-selectFolder")); + shouldSetOKButton = false; + if (window.arguments[2]) + folderItem = bookmarkView.rdf.GetResource(window.arguments[2]); + if (folderItem) { + ind = bookmarkView.treeBuilder.getIndexOfResource(folderItem); + bookmarkView.treeBoxObject.selection.select(ind); + } + break; + case "newBookmark": + setupFields(); + if (window.arguments[2]) + gCreateInFolder = window.arguments[2]; + document.getElementById("folderbox").setAttribute("hidden", "true"); + sizeToFit(); + break; + case "addGroup": + document.getElementById("showaddgroup").setAttribute("hidden", "false"); + setupFields(); + sizeToFit(); + break; + case "addGroup,group": + document.getElementById("showaddgroup").setAttribute("hidden", "false"); + gCB_AddGroup.setAttribute("checked", "true"); + setupFields(); + toggleGroup(); + sizeToFit(); + break; + default: + // Regular Add Bookmark + setupFields(); + if (window.arguments[2]) { + gCreateInFolder = window.arguments[2]; + folderItem = bookmarkView.rdf.GetResource(gCreateInFolder); + if (folderItem) { + ind = bookmarkView.treeBuilder.getIndexOfResource(folderItem); + bookmarkView.treeBoxObject.selection.select(ind); + } + } + } + } + + if (shouldSetOKButton) + onFieldInput(); + if (document.getElementById("bookmarknamegrid").hasAttribute("hidden")) { + bookmarkView.tree.focus(); + if (bookmarkView.currentIndex == -1) + bookmarkView.treeBoxObject.selection.select(0); + } + else { + gFld_Name.select(); + gFld_Name.focus(); + } +} + +function sizeToFit() +{ + var dialogElement = document.documentElement; + dialogElement.removeAttribute("persist"); + dialogElement.removeAttribute("height"); + dialogElement.removeAttribute("width"); + dialogElement.setAttribute("style", dialogElement.getAttribute("style")); + sizeToContent(); +} + +function setupFields() +{ + // New bookmark in predetermined folder. + gFld_Name.value = window.arguments[0] || ""; + gFld_URL.value = window.arguments[1] || ""; + onFieldInput(); + gFld_Name.select(); + gFld_Name.focus(); + gBookmarkCharset = window.arguments[3] || null; +} + +function onFieldInput() +{ + const ok = document.documentElement.getButton("accept"); + ok.disabled = gFld_URL.value == "" && !addingGroup() || + gFld_Name.value == ""; +} + +function onOK() +{ + if (!document.getElementById("folderbox").hasAttribute("hidden")) { + var bookmarkView = document.getElementById("bookmarks-view"); + var currentIndex = bookmarkView.currentIndex; + if (currentIndex != -1) + gCreateInFolder = bookmarkView.treeBuilder.getResourceAtIndex(currentIndex).Value; + } + // In Select Folder Mode, do nothing but tell our caller what + // folder was selected. + if (window.arguments.length > 4 && window.arguments[4] == "selectFolder") + window.arguments[5].selectedFolder = gCreateInFolder; + else { + // Otherwise add a bookmark to the selected folder. + + const kBMDS = kRDF.GetDataSource("rdf:bookmarks"); + const kBMSContractID = "@mozilla.org/browser/bookmarks-service;1"; + const kBMSIID = Components.interfaces.nsIBookmarksService; + const kBMS = Components.classes[kBMSContractID].getService(kBMSIID); + var rFolder = kRDF.GetResource(gCreateInFolder, true); + const kRDFCContractID = "@mozilla.org/rdf/container;1"; + const kRDFIID = Components.interfaces.nsIRDFContainer; + const kRDFC = Components.classes[kRDFCContractID].getService(kRDFIID); + try { + kRDFC.Init(kBMDS, rFolder); + } + catch (e) { + // No "NC:NewBookmarkFolder" exists, just append to the root. + rFolder = kRDF.GetResource("NC:BookmarksRoot", true); + kRDFC.Init(kBMDS, rFolder); + } + + // if no URL was provided and we're not filing as a group, do nothing + if (!gFld_URL.value && !addingGroup()) + return; + + var url; + if (addingGroup()) { + const group = kBMS.createGroup(gFld_Name.value, rFolder); + const groups = window.arguments[5]; + for (var i = 0; i < groups.length; ++i) { + url = getNormalizedURL(groups[i].url); + kBMS.createBookmarkWithDetails(groups[i].name, url, + groups[i].charset, group, -1); + } + } else { + url = getNormalizedURL(gFld_URL.value); + var newBookmark = kBMS.createBookmarkWithDetails(gFld_Name.value, url, gBookmarkCharset, rFolder, -1); + if (window.arguments.length > 4 && window.arguments[4] == "newBookmark") { + window.arguments[5].newBookmark = newBookmark; + } + } + } +} + +function getNormalizedURL(url) +{ + // Check to see if the item is a local directory path, and if so, convert + // to a file URL so that aggregation with rdf:files works + try { + const kLF = Components.classes["@mozilla.org/file/local;1"] + .createInstance(Components.interfaces.nsILocalFile); + kLF.initWithPath(url); + if (kLF.exists()) { + var ioService = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.classes.nsIIOService); + + url = ioService.getURLSpecFromFile(kLF); + } + } + catch (e) { + } + + return url; +} + +var gBookmarksShell = null; +function createNewFolder () +{ + var bookmarksView = document.getElementById("bookmarks-view"); + bookmarksView.createNewFolder(); +} + +function useDefaultFolder () +{ + var bookmarkView = document.getElementById("bookmarks-view"); + var folder = BookmarksUtils.getNewBookmarkFolder(); + var ind = bookmarkView.treeBuilder.getIndexOfResource(folder); + if (ind != -1) { + bookmarkView.tree.focus(); + bookmarkView.treeBoxObject.selection.select(ind); + } else { + bookmarkView.treeBoxObject.selection.clearSelection(); + } + gCreateInFolder = folder.Value; +} + +var gOldNameValue = ""; +var gOldURLValue = ""; + +function toggleGroup() +{ + // swap between single bookmark and group name + var temp = gOldNameValue; + gOldNameValue = gFld_Name.value; + gFld_Name.value = temp; + + // swap between single bookmark and group url + temp = gOldURLValue; + gOldURLValue = gFld_URL.value; + gFld_URL.value = temp; + gFld_URL.disabled = gCB_AddGroup.getAttribute("checked") == "true"; + + gFld_Name.select(); + gFld_Name.focus(); + onFieldInput(); +} + +function addingGroup() +{ + const showAddGroup = document.getElementById("showaddgroup"); + return showAddGroup.getAttribute("hidden") != "true" && gCB_AddGroup.getAttribute("checked") == "true"; +} diff --git a/browser/components/bookmarks/content/addBookmark.xul b/browser/components/bookmarks/content/addBookmark.xul new file mode 100644 index 00000000000..b7895efd0a1 --- /dev/null +++ b/browser/components/bookmarks/content/addBookmark.xul @@ -0,0 +1,118 @@ + + + + + + + + + + +%brandDTD; + +%addBookmarkDTD; +]> + + + + + + + + + + +