From 1b247a7bb8dcd30de469168ac7853e56a7f683b7 Mon Sep 17 00:00:00 2001 From: "rjc%netscape.com" Date: Thu, 13 Apr 2000 23:28:14 +0000 Subject: [PATCH] Add "bookmark find" dialog support. --- .../bookmarks/resources/MANIFEST-content | 2 + .../bookmarks/resources/Makefile.in | 3 + .../components/bookmarks/resources/bm-find.js | 257 ++++++++++++++++++ .../bookmarks/resources/bm-find.xul | 192 +++++++++++++ .../bookmarks/resources/bookmarks.js | 11 +- .../bookmarks/resources/bookmarks.xul | 2 +- .../bookmarks/resources/locale/MANIFEST | 1 + .../bookmarks/resources/locale/en-US/MANIFEST | 3 +- .../resources/locale/en-US/bm-find.dtd | 58 ++++ .../resources/locale/en-US/bookmarks.dtd | 2 +- .../bookmarks/resources/makefile.win | 3 + 11 files changed, 523 insertions(+), 11 deletions(-) create mode 100755 xpfe/components/bookmarks/resources/bm-find.js create mode 100755 xpfe/components/bookmarks/resources/bm-find.xul create mode 100755 xpfe/components/bookmarks/resources/locale/en-US/bm-find.dtd diff --git a/xpfe/components/bookmarks/resources/MANIFEST-content b/xpfe/components/bookmarks/resources/MANIFEST-content index 495dc926224d..c73bd2ace848 100644 --- a/xpfe/components/bookmarks/resources/MANIFEST-content +++ b/xpfe/components/bookmarks/resources/MANIFEST-content @@ -1,3 +1,5 @@ +bm-find.js +bm-find.xul bm-panel.js bm-panel.xul bm-props.js diff --git a/xpfe/components/bookmarks/resources/Makefile.in b/xpfe/components/bookmarks/resources/Makefile.in index 9f7ecac4eb50..2178f530a852 100644 --- a/xpfe/components/bookmarks/resources/Makefile.in +++ b/xpfe/components/bookmarks/resources/Makefile.in @@ -29,6 +29,8 @@ include $(DEPTH)/config/autoconf.mk CHROME_DIR = bookmarks CHROME_CONTENT = \ + bm-find.js \ + bm-find.xul \ bm-panel.js \ bm-panel.xul \ bm-props.js \ @@ -52,6 +54,7 @@ CHROME_SKIN = \ $(NULL) CHROME_L10N = \ + locale/en-US/bm-find.dtd \ locale/en-US/bm-props.dtd \ locale/en-US/bookmarks.dtd \ locale/en-US/bookmark.properties \ diff --git a/xpfe/components/bookmarks/resources/bm-find.js b/xpfe/components/bookmarks/resources/bm-find.js new file mode 100755 index 000000000000..0c9e43d3ac7c --- /dev/null +++ b/xpfe/components/bookmarks/resources/bm-find.js @@ -0,0 +1,257 @@ +/* -*- Mode: Java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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. + * + * Original Author(s): + * Robert John Churchill + * + * Contributor(s): + */ + + +function debug(msg) +{ + // uncomment for noise + // dump(msg+"\n"); +} + + + +function doLoad() +{ + // disable "Save Search" button (initially) + var searchButton = document.getElementById("SaveSearch"); + if (searchButton) + { + searchButton.setAttribute("disabled", "true"); + } +} + + + +function doUnload() +{ + // Get the current window position/size. + var x = window.screenX; + var y = window.screenY; + var h = window.outerHeight; + var w = window.outerWidth; + + // Store these into the window attributes (for persistence). + var win = document.getElementById( "bookmark-window" ); + win.setAttribute( "x", x ); + win.setAttribute( "y", y ); + win.setAttribute( "height", h ); + win.setAttribute( "width", w ); +} + + + + +var gDatasourceName = ""; +var gMatchName = ""; +var gMethodName = ""; +var gTextName = ""; + +function doFind() +{ + gDatasourceName = ""; + gMatchName = ""; + gMethodName = ""; + gTextName = ""; + + // get RDF datasource to query + var datasourceNode = document.getElementById("datasource"); + if (!datasourceNode) return(false); + var datasource = datasourceNode.selectedItem.getAttribute("data"); + gDatasourceName = datasourceNode.selectedItem.getAttribute("value"); + debug("Datasource: " + gDatasourceName + "\n"); + + // get match + var matchNode = document.getElementById("match"); + if (!matchNode) return(false); + var match = matchNode.selectedItem.getAttribute("data"); + gMatchName = matchNode.selectedItem.getAttribute("value"); + debug("Match: " + match + "\n"); + + // get method + var methodNode = document.getElementById("method"); + if (!methodNode) return(false); + var method = methodNode.selectedItem.getAttribute("data"); + gMethodName = methodNode.selectedItem.getAttribute("value"); + debug("Method: " + method + "\n"); + + // get user text to find + var textNode = document.getElementById("findtext"); + if (!textNode) return(false); + gTextName = textNode.value; + if (!gTextName || gTextName=="") return(false); + debug("Find text: " + gTextName + "\n"); + + // construct find URL + var url = "find:datasource=" + datasource; + url += "&match=" + match; + url += "&method=" + method; + url += "&text=" + gTextName; + debug("Find URL: " + url + "\n"); + + // load find URL into results pane + var resultsTree = document.getElementById("findresultstree"); + if (!resultsTree) return(false); + resultsTree.setAttribute("ref", ""); + resultsTree.setAttribute("ref", url); + + // enable "Save Search" button + var searchButton = document.getElementById("SaveSearch"); + if (searchButton) + { + searchButton.removeAttribute("disabled", "true"); + } + + debug("doFind done.\n"); + return(true); +} + + + +function saveFind() +{ + var resultsTree = document.getElementById("findresultstree"); + if (!resultsTree) return(false); + var searchURL = resultsTree.getAttribute("ref"); + if ((!searchURL) || (searchURL == "")) return(false); + + debug("Bookmark search URL: " + searchURL + "\n"); + var searchTitle = "Find: " + gMatchName + " " + gMethodName + " '" + gTextName + "' in " + gDatasourceName; + debug("Title: " + searchTitle + "\n\n"); + + var bmks = Components.classes["component://netscape/browser/bookmarks-service"].getService(); + if (bmks) bmks = bmks.QueryInterface(Components.interfaces.nsIBookmarksService); + if (bmks) bmks.AddBookmark(searchURL, searchTitle); + + return(true); +} + + + +function getAbsoluteID(root, node) +{ + var url = node.getAttribute("ref"); + if ((url == null) || (url == "")) + { + url = node.getAttribute("id"); + } + try + { + var rootNode = document.getElementById(root); + var ds = null; + if (rootNode) + { + ds = rootNode.database; + } + + // add support for anonymous resources such as Internet Search results, + // IE favorites under Win32, and NetPositive URLs under BeOS + var rdf = Components.classes["component://netscape/rdf/rdf-service"].getService(); + if (rdf) rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService); + if (rdf && ds) + { + var src = rdf.GetResource(url, true); + var prop = rdf.GetResource("http://home.netscape.com/NC-rdf#URL", true); + var target = ds.GetTarget(src, prop, true); + if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral); + if (target) target = target.Value; + if (target) url = target; + } + } + catch(ex) + { + } + return(url); +} + + + +function OpenURL(event, node, root) +{ + if ((event.button != 1) || (event.clickCount != 2) || (node.nodeName != "treeitem")) + return(false); + + if (node.getAttribute("container") == "true") + return(false); + + var url = getAbsoluteID(root, node); + + // Ignore "NC:" urls. + if (url.substring(0, 3) == "NC:") + return(false); + + // get right sized window + window.openDialog( "chrome://navigator/content/navigator.xul", "_blank", "chrome,all,dialog=no", url ); + return(true); +} + + + +/* Note: doSort() does NOT support natural order sorting, unless naturalOrderResource is valid, + in which case we sort ascending on naturalOrderResource + */ +function doSort(sortColName, naturalOrderResource) +{ + var node = document.getElementById(sortColName); + // determine column resource to sort on + var sortResource = node.getAttribute('resource'); + if (!sortResource) return(false); + + var sortDirection="ascending"; + var isSortActive = node.getAttribute('sortActive'); + if (isSortActive == "true") + { + sortDirection = "ascending"; + + var currentDirection = node.getAttribute('sortDirection'); + if (currentDirection == "ascending") + { + if (sortResource != naturalOrderResource) + { + sortDirection = "descending"; + } + } + else if (currentDirection == "descending") + { + if (naturalOrderResource != null && naturalOrderResource != "") + { + sortResource = naturalOrderResource; + } + } + } + + var isupports = Components.classes["component://netscape/rdf/xul-sort-service"].getService(); + if (!isupports) return(false); + var xulSortService = isupports.QueryInterface(Components.interfaces.nsIXULSortService); + if (!xulSortService) return(false); + try + { + xulSortService.Sort(node, sortResource, sortDirection); + } + catch(ex) + { + debug("Exception calling xulSortService.Sort()"); + } + return(true); +} diff --git a/xpfe/components/bookmarks/resources/bm-find.xul b/xpfe/components/bookmarks/resources/bm-find.xul new file mode 100755 index 000000000000..938604f425e2 --- /dev/null +++ b/xpfe/components/bookmarks/resources/bm-find.xul @@ -0,0 +1,192 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xpfe/components/bookmarks/resources/bookmarks.js b/xpfe/components/bookmarks/resources/bookmarks.js index 2e59da8ac3d0..0fbab64ec6ff 100644 --- a/xpfe/components/bookmarks/resources/bookmarks.js +++ b/xpfe/components/bookmarks/resources/bookmarks.js @@ -406,7 +406,6 @@ function doUnload() function BookmarkProperties() { var treeNode = document.getElementById('bookmarksTree'); - // var select_list = treeNode.getElementsByAttribute("selected", "true"); var select_list = treeNode.selectedItems; if (select_list.length >= 1) @@ -416,22 +415,18 @@ function BookmarkProperties() if (type != "http://home.netscape.com/NC-rdf#BookmarkSeparator") { window.openDialog("chrome://bookmarks/content/bm-props.xul", - "_blank", "chrome,menubar", + "_blank", "centerscreen,chrome,menubar", select_list[0].getAttribute("id")); } } - else - { - debug("nothing selected!\n"); - } return(true); } -function OpenSearch(tabName) +function OpenBookmarksFind() { - window.openDialog("chrome://search/content/search.xul", "SearchWindow", "dialog=no,close,chrome,resizable", tabName, ""); + window.openDialog("chrome://bookmarks/content/bm-find.xul", "FindBookmarksWindow", "centerscreen,dialog=no,close,chrome,resizable"); return(true); } diff --git a/xpfe/components/bookmarks/resources/bookmarks.xul b/xpfe/components/bookmarks/resources/bookmarks.xul index d7800766c21c..534c69abd652 100644 --- a/xpfe/components/bookmarks/resources/bookmarks.xul +++ b/xpfe/components/bookmarks/resources/bookmarks.xul @@ -65,7 +65,7 @@ - + diff --git a/xpfe/components/bookmarks/resources/locale/MANIFEST b/xpfe/components/bookmarks/resources/locale/MANIFEST index 815f70269a34..4bfab79287f8 100644 --- a/xpfe/components/bookmarks/resources/locale/MANIFEST +++ b/xpfe/components/bookmarks/resources/locale/MANIFEST @@ -1,3 +1,4 @@ +en-US:bm-find.dtd en-US:bm-props.dtd en-US:bookmarks.dtd en-US:bookmark.properties diff --git a/xpfe/components/bookmarks/resources/locale/en-US/MANIFEST b/xpfe/components/bookmarks/resources/locale/en-US/MANIFEST index 9bcade833f97..19c0cda84c49 100644 --- a/xpfe/components/bookmarks/resources/locale/en-US/MANIFEST +++ b/xpfe/components/bookmarks/resources/locale/en-US/MANIFEST @@ -1,3 +1,4 @@ -bookmarks.dtd +bm-find.dtd bm-props.dtd bookmark.properties +bookmarks.dtd diff --git a/xpfe/components/bookmarks/resources/locale/en-US/bm-find.dtd b/xpfe/components/bookmarks/resources/locale/en-US/bm-find.dtd new file mode 100755 index 000000000000..b5ff07a7f01b --- /dev/null +++ b/xpfe/components/bookmarks/resources/locale/en-US/bm-find.dtd @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/xpfe/components/bookmarks/resources/locale/en-US/bookmarks.dtd b/xpfe/components/bookmarks/resources/locale/en-US/bookmarks.dtd index aaa9fbcd9eaf..152af795c36a 100644 --- a/xpfe/components/bookmarks/resources/locale/en-US/bookmarks.dtd +++ b/xpfe/components/bookmarks/resources/locale/en-US/bookmarks.dtd @@ -38,7 +38,7 @@ - + diff --git a/xpfe/components/bookmarks/resources/makefile.win b/xpfe/components/bookmarks/resources/makefile.win index c7a8b138d1c8..fe34e8974215 100644 --- a/xpfe/components/bookmarks/resources/makefile.win +++ b/xpfe/components/bookmarks/resources/makefile.win @@ -29,6 +29,8 @@ CHROME_SKIN_DIR = skin/default CHROME_SOURCE_DIR = $(srcdir) CHROME_CONTENT = \ + .\bm-find.js \ + .\bm-find.xul \ .\bm-panel.js \ .\bm-panel.xul \ .\bm-props.js \ @@ -52,6 +54,7 @@ CHROME_SKIN = \ $(NULL) CHROME_L10N = \ + .\locale\en-US\bm-find.dtd \ .\locale\en-US\bm-props.dtd \ .\locale\en-US\bookmarks.dtd \ .\locale\en-US\bookmark.properties \