Add "bookmark find" dialog support.

This commit is contained in:
rjc%netscape.com 2000-04-13 23:28:14 +00:00
Родитель fd9cfa6689
Коммит 1b247a7bb8
11 изменённых файлов: 523 добавлений и 11 удалений

Просмотреть файл

@ -1,3 +1,5 @@
bm-find.js
bm-find.xul
bm-panel.js
bm-panel.xul
bm-props.js

Просмотреть файл

@ -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 \

Просмотреть файл

@ -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 <rjc@netscape.com>
*
* 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);
}

Просмотреть файл

@ -0,0 +1,192 @@
<?xml version="1.0"?> <!-- -*- Mode: SGML; indent-tabs-mode: nil; -*- -->
<!--
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 <rjc@netscape.com>
Contributor(s):
-->
<?xml-stylesheet href="chrome://bookmarks/skin/" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://bookmarks/locale/bm-find.dtd">
<window title="&window.title.label;" id="bookmark-find-window"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:web="http://home.netscape.com/WEB-rdf#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
width="630" height="400" x="20" y="20" persist="width height x y" align="vertical"
windowtype="bookmarks:find" class="dialog"
onload="doLoad()" onunload="doUnload()"
>
<html:script src="chrome://global/content/treePopups.js" />
<html:script src="chrome://bookmarks/content/bm-find.js" />
<menubar>
<menu value="&menu.file.label;">
<menupopup>
<menuitem value="&menuitem.close.label;" oncommand="window.close()" />
</menupopup>
</menu>
<menu value="&menu.edit.label;">
<menupopup>
<menuitem value="&menuitem.undo.label;" disabled="true" />
<menuseparator/>
<menuitem value="&menuitem.cut.label;" disabled="true" />
<menuitem value="&menuitem.copy.label;" disabled="true" />
<menuitem value="&menuitem.paste.label;" disabled="true" />
<menuitem value="&menuitem.delete.label;" disabled="true" />
<menuitem value="&menuitem.selectAll.label;" disabled="true" />
</menupopup>
</menu>
</menubar>
<box align="horizontal">
<spring align="horizontal" flex="100%" />
<box align="vertical">
<box align="horizontal">
<text value="&search1.label;" />
<menulist id="datasource">
<menupopup id="datasourcePopup">
<menuitem data="rdf:bookmarks" value="&bookmarks.label;" />
<menuitem data="rdf:history" value="&history.label;" />
</menupopup>
</menulist>
<text value="&search2.label;" />
</box>
<box align="horizontal">
<menulist id="match">
<menupopup id="matchPopup">
<menuitem data="http://home.netscape.com/NC-rdf#Name" value="&name.label;" />
<menuitem data="http://home.netscape.com/NC-rdf#URL" value="&url.label;" />
<menuitem data="http://home.netscape.com/NC-rdf#ShortcutURL" value="&shortcut.label;" />
<menuitem data="http://home.netscape.com/NC-Description" value="&description.label;" />
</menupopup>
</menulist>
<menulist id="method">
<menupopup id="methodPopup">
<menuitem data="contains" value="&contains.label;" />
<menuitem data="startswith" value="&startswith.label;" />
<menuitem data="endswith" value="&endswith.label;" />
<menuitem data="is" value="&is.label;" />
<menuitem data="isnot" value="&isnot.label;" />
<menuitem data="doesntcontain" value="&doesntcontain.label;" />
</menupopup>
</menulist>
<html:input id="findtext" type="text" width="20" onkeyup="if (event.which == 13) { doFind(); }" />
<titledbutton value="&search.button.label;" onclick="return doFind();" class="dialog toolbar-non-iconic" />
</box>
</box>
<spring align="horizontal" flex="100%" />
</box>
<spring align="vertical" style="height:10;" />
<tree id="findresultstree" ref="" flex="100%" style="height:0px"
datasources="rdf:bookmarks rdf:history rdf:localsearch"
onclick="return OpenURL(event, event.target.parentNode.parentNode);">
<treecolgroup id="theColumns">
<treecol id="NameColumn" persist="hidden width" width="2*"
rdf:resource="http://home.netscape.com/NC-rdf#Name"
sortActive="true" sortDirection="ascending" />
<treecol id="URLColumn" persist="hidden width" width="2*"
rdf:resource="http://home.netscape.com/NC-rdf#URL"/>
<treecol id="ShortcutURLColumn" persist="hidden width" width="1*"
rdf:resource="http://home.netscape.com/NC-rdf#ShortcutURL"/>
<treecol id="DescriptionColumn" persist="hidden width" width="1*"
rdf:resource="http://home.netscape.com/NC-rdf#Description"/>
<treecol id="PopupColumn" persist="width" fixed="true" width="14" />
</treecolgroup>
<template>
<rule rdf:type="http://home.netscape.com/NC-rdf#BookmarkSeparator">
<treechildren>
<treeitem uri="...">
<treerow>
<treecell>
<html:hr width="100%" align="center" size="1" />
</treecell>
</treerow>
</treeitem>
</treechildren>
</rule>
<rule>
<treechildren>
<treeitem uri="rdf:*">
<treerow>
<treecell align="left" crop="right" indent="true" value="rdf:http://home.netscape.com/NC-rdf#Name" src="rdf:http://home.netscape.com/NC-rdf#Icon" />
<treecell align="left" crop="right" value="rdf:http://home.netscape.com/NC-rdf#URL"/>
<treecell align="left" crop="right" value="rdf:http://home.netscape.com/NC-rdf#ShortcutURL"/>
<treecell align="left" crop="right" value="rdf:http://home.netscape.com/NC-rdf#Description"/>
</treerow>
</treeitem>
</treechildren>
</rule>
</template>
<treehead>
<treerow id="headRow">
<treecell observes="NameColumn" value="&name.label;" resource="http://home.netscape.com/NC-rdf#Name" onclick="return doSort('NameColumn', null);" sortActive="true" sortDirection="ascending" />
<treecell observes="URLColumn" value="&url.label;" resource="http://home.netscape.com/NC-rdf#URL" onclick="return doSort('URLColumn', null);" />
<treecell observes="ShortcutURLColumn" value="&shortcut.label;" resource="http://home.netscape.com/NC-rdf#ShortcutURL" onclick="return doSort('ShortcutURLColumn', null);" />
<treecell observes="DescriptionColumn" value="&description.label;" resource="http://home.netscape.com/NC-rdf#Description" onclick="return doSort('DescriptionColumn', null);" />
<treecell allowevents="true" id="popupCell">
<menu>
<titledbutton src="chrome://global/skin/opentwisty.gif"/>
<menupopup popupanchor="bottomright"
popupalign="topright"
oncreate="BuildTreePopup(document.getElementById('theColumns'), document.getElementById('headRow'), this,
document.getElementById('popupCell'))" />
</menu>
</treecell>
</treerow>
</treehead>
</tree>
<box align="horizontal">
<spring flex="1" />
<titledbutton id="SaveSearch" disabled="true" value="&save.button.label;" onclick="return saveFind();" class="dialog toolbar-non-iconic"/>
<spring flex="1" />
</box>
<!--
This extra "status" bar is necessary because the bottom right corner of
the window on MacOS is taken up by the growBox. If this window had a
horizontal scrollbar, we'd be alright, but since it doesn't the bottom
arrow on the vertical scrollbar was being hidden by this growBox. To
combat this, we can just stick in a 16px high bar to bump up the bottom
of the tree so that the scrollbar is visible. Yes, I know this is not
necessary for win32 or gtk, but we can use this area for information
(maybe full URL of selected item or the like) in the future.
-->
<box id="status-bar" style="min-height:16px; max-height:16px;">
<titledbutton class="status-bar" align="left" value=""/>
</box>
</window>

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -65,7 +65,7 @@
<menuitem value="&menuitem.delete.label;" oncommand="return doDelete(true)" />
<menuitem value="&menuitem.selectAll.label;" oncommand="return doSelectAll()" />
<menuseparator/>
<menuitem value="&menuitem.find.label;" oncommand="return OpenSearch('find');"/>
<menuitem value="&menuitem.find.label;" oncommand="return OpenBookmarksFind();"/>
<menuseparator/>
<menuitem value="&menuitem.properties.label;" oncommand="return BookmarkProperties();"/>
</menupopup>

Просмотреть файл

@ -1,3 +1,4 @@
en-US:bm-find.dtd
en-US:bm-props.dtd
en-US:bookmarks.dtd
en-US:bookmark.properties

Просмотреть файл

@ -1,3 +1,4 @@
bookmarks.dtd
bm-find.dtd
bm-props.dtd
bookmark.properties
bookmarks.dtd

Просмотреть файл

@ -0,0 +1,58 @@
<!--
- The contents of this file are subject to the Mozilla 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/MPL/
-
- 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 Communicator.
-
- The Initial Developer of the Original Code is Netscape
- Communications Corp. Portions created by Netscape Communications
- Corp. are Copyright (C) 1999 Netscape Communications Corp. All
- Rights Reserved.
-
- Original Author(s):
- Robert John Churchill <rjc@netscape.com>
-
- Contributor(s):
-->
<!ENTITY menu.file.label "File">
<!ENTITY menuitem.close.label "Close">
<!ENTITY menu.edit.label "Edit">
<!ENTITY menuitem.undo.label "Undo">
<!ENTITY menuitem.redo.label "Redo">
<!ENTITY menuitem.cut.label "Cut">
<!ENTITY menuitem.copy.label "Copy">
<!ENTITY menuitem.paste.label "Paste">
<!ENTITY menuitem.delete.label "Delete">
<!ENTITY menuitem.selectAll.label "Select All">
<!ENTITY window.title.label "Find">
<!ENTITY search1.label "Find items in ">
<!ENTITY search2.label " whose ">
<!ENTITY search.button.label "Find">
<!ENTITY save.button.label "Bookmark Find Query">
<!ENTITY bookmarks.label "Bookmarks">
<!ENTITY history.label "History">
<!ENTITY name.label "Name">
<!ENTITY url.label "URL">
<!ENTITY shortcut.label "Custom Keyword">
<!ENTITY description.label "Description">
<!ENTITY contains.label "contains">
<!ENTITY startswith.label "starts with">
<!ENTITY endswith.label "ends with">
<!ENTITY is.label "is">
<!ENTITY isnot.label "is not">
<!ENTITY doesntcontain.label "doesn't contain">

Просмотреть файл

@ -38,7 +38,7 @@
<!ENTITY menuitem.paste.label "Paste">
<!ENTITY menuitem.delete.label "Delete">
<!ENTITY menuitem.selectAll.label "Select All">
<!ENTITY menuitem.find.label "Search in Bookmarks...">
<!ENTITY menuitem.find.label "Find...">
<!ENTITY menuitem.properties.label "Properties...">
<!ENTITY menu.view.label "View">

Просмотреть файл

@ -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 \