Bug 362292 - [places] implement places-based-bookmarks sidebar (NPOB). patch from Dan Mills <thunder@mozilla.com>, r=me.

This commit is contained in:
mozilla.mano%sent.com 2007-02-08 13:33:04 +00:00
parent 6040afd6ff
commit 5ffb8e8661
9 changed files with 224 additions and 96 deletions

View File

@ -155,9 +155,7 @@
label="&viewSidebarMenu.label;"
accesskey="&viewSidebarMenu.accesskey;">
<menupopup id="viewSidebarMenu">
#ifndef MOZ_PLACES_BOOKMARKS
<menuitem key="viewBookmarksSidebarKb" observes="viewBookmarksSidebar" accesskey="&bookmarksSidebarCmd.accesskey;"/>
#endif
<menuitem key="key_gotoHistory" observes="viewHistorySidebar" label="&historyButton.label;" accesskey="&historySidebarCmd.accesskey;"/>
</menupopup>
</menu>

View File

@ -0,0 +1,49 @@
# -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# 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.org code.
#
# The Initial Developer of the Original Code is Mozilla Corporation.
# Portions created by the Initial Developer are Copyright (C) 2007
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Dan Mills <thunder@mozilla.com> (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 MPL, 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 MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
function init() {
document.getElementById('search-box').focus();
}
function searchBookmarks(aSearchString) {
var tree = document.getElementById('bookmarks-view');
if (!aSearchString)
tree.place = tree.place;
else
tree.applyFilter(aSearchString, true);
}

View File

@ -0,0 +1,82 @@
<?xml version="1.0"?> <!-- -*- Mode: SGML; indent-tabs-mode: nil; -*- -->
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# 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.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 <ben@netscape.com> (Original Author, v2.0)
# Pierre Chanial <p_ch@verizon.net>
# Dan Mills <thunder@mozilla.com>
#
# 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 MPL, 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 MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://browser/content/places/places.css"?>
<?xml-stylesheet href="chrome://browser/skin/places/places.css"?>
<?xul-overlay href="chrome://global/content/editMenuOverlay.xul"?>
<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?>
<!DOCTYPE page SYSTEM "chrome://browser/locale/places/places.dtd">
<page id="bookmarksPanel"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="init();">
<script type="application/x-javascript"
src="chrome://browser/content/bookmarks/sidebarUtils.js"/>
<script type="application/x-javascript"
src="chrome://browser/content/bookmarks/bookmarksPanel.js"/>
<commandset id="placesCommands"/>
<commandset id="editMenuCommands"/>
<popup id="placesContext"/>
<hbox align="center">
<label value="&search.label;" accesskey="&search.accesskey;" control="search-box"/>
<textbox id="search-box" flex="1"
type="timed" timeout="500"
oncommand="searchBookmarks(this.value);"/>
</hbox>
<tree id="bookmarks-view" class="placesTree" type="places"
flex="1"
hidecolumnpicker="true"
place="place:&amp;folder=1&amp;group=3&amp;excludeQueries=1"
context="placesContext"
onkeypress="if (event.keyCode == 13) this.controller.openSelectedNodeWithEvent(event);"
onclick="SidebarUtils.handleClick(this, event);">
<treecols>
<treecol id="title" flex="1" primary="true" hideheader="true"/>
</treecols>
<treechildren id="bookmarks-view-children" view="bookmarks-view" flex="1"/>
</tree>
</page>

View File

@ -68,29 +68,6 @@ function HistorySidebarInit()
searchHistory(gSearchBox.value);
gSearchBox.focus();
}
function checkURLSecurity(aURL)
{
var uri = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService)
.newURI(aURL, null, null);
if (uri.schemeIs("javascript") || uri.schemeIs("data")) {
var strBundleService =
Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Ci.nsIStringBundleService);
var promptService =
Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService);
var historyBundle = strBundleService.createBundle("chrome://global/locale/history/history.properties");
var brandBundle = strBundleService.createBundle("chrome://branding/locale/brand.properties");
var brandStr = brandBundle.GetStringFromName("brandShortName");
var errorStr = historyBundle.GetStringFromName("load-js-data-url-error");
promptService.alert(window, brandStr, errorStr);
return false;
}
return true;
}
function GroupBy(groupingType)
{
@ -103,59 +80,6 @@ function collapseExpand()
{
var currentIndex = gHistoryTree.currentIndex;
gHistoryTree.view.toggleOpenState(currentIndex);
}
function openURLIn(aWhere)
{
// no need to check gHistoryTree.view.selection.count
// node will be null if there is a multiple selection
// or if the selected item is not a URI node
var node = gHistoryTree.selectedURINode;
if (!node)
return;
if (!checkURLSecurity(node.uri))
return;
openUILinkIn(node.uri, aWhere);
}
function openURL(aEvent)
{
openURLIn(whereToOpenLink(aEvent));
}
function handleHistoryClick(aEvent)
{
var tbo = gHistoryTree.treeBoxObject;
var row = { }, col = { }, obj = { };
tbo.getCellAt(aEvent.clientX, aEvent.clientY, row, col, obj);
var x = { }, y = { }, w = { }, h = { };
tbo.getCoordsForCellItem(row.value, col.value, "image",
x, y, w, h);
var mouseInGutter = aEvent.clientX < x.value;
if (row.value == -1 || obj.value == "twisty")
return;
var modifKey = aEvent.shiftKey || aEvent.ctrlKey || aEvent.altKey ||
aEvent.metaKey || (aEvent.button != 0);
if (!modifKey && tbo.view.isContainer(row.value)) {
tbo.view.toggleOpenState(row.value);
return;
}
if (!mouseInGutter &&
aEvent.originalTarget.localName == "treechildren" &&
(aEvent.button == 0 || aEvent.button == 1)) {
// Clear all other selection since we're loading a link now. We must
// do this *before* attempting to load the link since openURL uses
// selection as an indication of which link to load.
tbo.view.selection.select(row.value);
openURL(aEvent);
}
}
function historyAddBookmarks()

View File

@ -60,6 +60,8 @@
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="HistorySidebarInit();">
<script type="application/x-javascript"
src="chrome://browser/content/bookmarks/sidebarUtils.js"/>
<script type="application/x-javascript"
src="chrome://browser/content/places/history-panel.js"/>
#ifndef MOZ_PLACES_BOOKMARKS
@ -143,9 +145,9 @@
type="places"
place="place:&amp;beginTime=-2592000000000&amp;beginTimeRef=1&amp;endTime=7200000000&amp;endTimeRef=2&amp;type=1"
context="historyContextMenu"
onkeypress="if (event.keyCode == 13) openURL(event);"
onkeypress="if (event.keyCode == 13) this.controller.openSelectedNodeWithEvent(event);"
hidecolumnpicker="true"
onclick="handleHistoryClick(event);">
onclick="SidebarUtils.handleClick(this, event, true);">
<treecols>
<treecol id="title" flex="1" primary="true" hideheader="true"/>
</treecols>

View File

@ -0,0 +1,73 @@
# -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# 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.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):
# Dan Mills <thunder@mozilla.com> (Ported from history-panel.js)
#
# 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 MPL, 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 MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
var SidebarUtils = {
handleClick: function SU_handleClick(aTree, aEvent, aGutterSelect) {
var tbo = aTree.treeBoxObject;
var row = { }, col = { }, obj = { };
tbo.getCellAt(aEvent.clientX, aEvent.clientY, row, col, obj);
if (row.value == -1 || obj.value == "twisty")
return;
var mouseInGutter = false;
if (aGutterSelect) {
var x = { }, y = { }, w = { }, h = { };
tbo.getCoordsForCellItem(row.value, col.value, "image",
x, y, w, h);
mouseInGutter = aEvent.clientX < x.value;
}
var modifKey = aEvent.shiftKey || aEvent.ctrlKey || aEvent.altKey ||
aEvent.metaKey || (aEvent.button != 0);
if (!modifKey && tbo.view.isContainer(row.value)) {
tbo.view.toggleOpenState(row.value);
return;
}
if (!mouseInGutter &&
aEvent.originalTarget.localName == "treechildren" &&
(aEvent.button == 0 || aEvent.button == 1)) {
// Clear all other selection since we're loading a link now. We must
// do this *before* attempting to load the link since openURL uses
// selection as an indication of which link to load.
tbo.view.selection.select(row.value);
aTree.controller.openSelectedNodeWithEvent(aEvent);
}
}
};

View File

@ -104,22 +104,18 @@
query.searchTerms = filterString;
query.onlyBookmarked = onlyBookmarks;
// If we're searching over everything, or this is not an exclusively
// bookmarks search, we need to make sure that we remove "group by
// folder" from the options list, because otherwise we will end up
// with _no_ results if the user searches while a bookmarks folder
// is selected, since the options for the current view say group by
// folder and none of the results will match!
if (!onlyBookmarks) {
var groupings = options.getGroupingMode({});
function isFolderGrouping(grouping, index, ary) {
return grouping != Ci.nsINavHistoryQueryOptions.GROUP_BY_FOLDER;
}
var folderGroupings = groupings.filter(isFolderGrouping);
options.setGroupingMode(folderGroupings, folderGroupings.length);
// Remove "group by folder" from the options list, because
// nsNavHistory::RecursiveGroup doesn't support it.
function isFolderGrouping(grouping, index, ary) {
return grouping != Ci.nsINavHistoryQueryOptions.GROUP_BY_FOLDER;
}
if (onlyBookmarks)
var groupings = options.getGroupingMode({});
var folderGroupings = groupings.filter(isFolderGrouping);
options.setGroupingMode(folderGroupings, folderGroupings.length);
if (onlyBookmarks && folderRestrict)
query.setFolders(folderRestrict, folderRestrict.length);
this.load([query], options);
]]></body>
</method>

View File

@ -21,5 +21,11 @@ browser.jar:
# to prevent having to worry about between versions of the browser
* content/browser/history/history-panel.xul (content/history-panel.xul)
* content/browser/places/history-panel.js (content/history-panel.js)
#ifdef MOZ_PLACES_BOOKMARKS
# ditto for the bookmarks sidebar
* content/browser/bookmarks/bookmarksPanel.xul (content/bookmarksPanel.xul)
* content/browser/bookmarks/bookmarksPanel.js (content/bookmarksPanel.js)
#endif
* content/browser/bookmarks/sidebarUtils.js (content/sidebarUtils.js)
* content/browser/places/moveBookmarks.xul (content/moveBookmarks.xul)
* content/browser/places/moveBookmarks.js (content/moveBookmarks.js)

View File

@ -74,5 +74,3 @@ tabs.openButtonMultiple=Open tabs
tabs.openWarningPromptMeBranded=Warn me when opening multiple tabs might slow down %S
status_foldercount = %S object(s)
load-js-data-url-error=For security reasons, javascript or data urls cannot be loaded from the history window or sidebar.