Fix for 76502 and related bugs. some parts sr=alecf, tested by several people (andred, fabian)

This commit is contained in:
ben%netscape.com 2007-05-05 04:34:43 +00:00
Родитель 2f915adcb5
Коммит ee16fb6c96
8 изменённых файлов: 315 добавлений и 38 удалений

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

@ -21,6 +21,62 @@
* Ben Goodger <ben@netscape.com> (Original Author)
*/
/**
* 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.
*
* 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) <default> (no fifth open parameter).
* Opens this dialog with the bookmark Name, URL and folder selection
* components visible, as well as a checkbox which allows the user
* to bypass the dialog for future bookmark additions. Only useful
* for a browser implementation which users BookmarksUtils methods for
* adding bookmarks
* 2) "addBookmark" (fifth open parameter = String("addBookmark"))
* Opens the dialog as in (1) above but with no checkbox. Useful
* in situations where user ability to choose not to see this dialog
* is not applicable, or for clients wishing to customize the launch
* behaviour.
* 3) "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.
* 4) "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.
*/
var gFld_Name = null;
var gFld_URL = null;
var gFolderTree = null;
@ -35,6 +91,8 @@ var gSelectItemObserver = null;
var gCreateInFolder = "NC:NewBookmarkFolder";
var gCanBypassDialogMode = true;
function Startup()
{
doSetOKCancel(onOK);
@ -44,31 +102,69 @@ function Startup()
var shouldSetOKButton = true;
if ("arguments" in window) {
// If we're being opened as a folder selection window
if (window.arguments[4] == "selectFolder") {
document.getElementById("bookmarknamegrid").setAttribute("hidden", "true");
toggleCreateIn();
switch (window.arguments[4]) {
case "selectFolder":
// If we're being opened as a folder selection window
document.getElementById("dontaskagain").setAttribute("hidden", "true");
document.getElementById("bookmarknamegrid").setAttribute("hidden", "true");
document.getElementById("createinseparator").setAttribute("hidden", "true");
document.getElementById("nameseparator").setAttribute("hidden", "true");
sizeToContent();
const kWindowNode = document.getElementById("newBookmarkWindow");
kWindowNode.setAttribute("title", kWindowNode.getAttribute("title-selectFolder"));
var windowNode = document.getElementById("newBookmarkWindow");
windowNode.setAttribute("title", windowNode.getAttribute("title-selectFolder"));
shouldSetOKButton = false;
}
else {
gFld_Name.value = window.arguments[0] || "";
gFld_URL.value = window.arguments[1] || "";
gBookmarkCharset = window.arguments [3] || null;
if (window.arguments[2])
var folderItem = document.getElementById(window.arguments[2]);
if (folderItem)
gFolderTree.selectItem(folderItem);
gCanBypassDialogMode = false;
break;
case "newBookmark":
setupFields();
if (window.arguments[2])
gCreateInFolder = window.arguments[2];
document.getElementById("folderbox").setAttribute("hidden", "true");
document.getElementById("dontaskagain").setAttribute("hidden", "true");
windowNode = document.getElementById("newBookmarkWindow");
windowNode.removeAttribute("persist");
windowNode.setAttribute("height", "0");
windowNode.setAttribute("width", "0");
windowNode.setAttribute("style", windowNode.getAttribute("style"));
sizeToContent();
gCanBypassDialogMode = false;
break;
case "addBookmark":
// Regular add bookmark window, but for some sinister purpose...
document.getElementById("dontaskagain").setAttribute("hidden", "true");
gCanBypassDialogMode = false;
// Fall through... --->
default:
// Regular Add Bookmark
setupFields();
if (window.arguments[2]) {
gCreateInFolder = window.arguments[2];
var folderItem = document.getElementById(gCreateInFolder);
if (folderItem)
gFolderTree.selectItem(folderItem);
}
}
}
if (shouldSetOKButton)
onLocationInput();
gFld_Name.focus();
gFld_Input
}
function setupFields()
{
// New bookmark in predetermined folder.
gFld_Name.value = window.arguments[0] || "";
gFld_URL.value = window.arguments[1] || "";
onLocationInput();
gFld_Name.select();
gFld_Name.focus();
gBookmarkCharset = window.arguments [3] || null;
}
function onLocationInput ()
{
var ok = document.getElementById("ok");
@ -77,9 +173,13 @@ function onLocationInput ()
function onOK()
{
// In Select Folder Mode, do nothing but tell our caller what
// folder was selected.
if (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;
@ -113,15 +213,17 @@ function onOK()
kBMS.AddBookmarkToFolder(url, rFolder, gFld_Name.value, gBookmarkCharset);
// Persist the 'show this dialog again' preference.
var checkbox = document.getElementById("dontaskagain");
const kPrefContractID = "@mozilla.org/preferences;1";
const kPrefIID = Components.interfaces.nsIPref;
const kPrefSvc = Components.classes[kPrefContractID].getService(kPrefIID);
try {
kPrefSvc.SetBoolPref("browser.bookmarks.add_without_dialog", checkbox.checked);
}
catch (e) {
if (gCanBypassDialogMode) {
// Persist the 'show this dialog again' preference.
var checkbox = document.getElementById("dontaskagain");
const kPrefContractID = "@mozilla.org/preferences;1";
const kPrefIID = Components.interfaces.nsIPref;
const kPrefSvc = Components.classes[kPrefContractID].getService(kPrefIID);
try {
kPrefSvc.SetBoolPref("browser.bookmarks.add_without_dialog", checkbox.checked);
}
catch (e) {
}
}
}
close();

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

@ -56,7 +56,7 @@
<keyset id="dialogKeys"/>
<separator class="thin"/>
<separator id="nameseparator" class="thin"/>
<grid id="bookmarknamegrid">
<columns>
@ -128,6 +128,7 @@
<separator/>
</vbox>
<!-- XXX - need to use an "Add Bookmark" string here -->
<box id="okCancelButtonsRight"/>
</window>

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

@ -38,13 +38,23 @@ function Startup()
const windowNode = document.getElementById("bookmark-window");
// If we've been opened with a parameter, root the tree on it.
if ("arguments" in window && window.arguments[0]) {
bookmarksTree.setAttribute("ref", window.arguments[0]);
const krNameArc = gBookmarksShell.RDF.GetResource(NC_NS + "Name");
const krRoot = gBookmarksShell.RDF.GetResource(window.arguments[0]);
var rName = gBookmarksShell.db.GetTarget(krRoot, krNameArc, true);
rName = rName.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
var uri = window.arguments[0];
bookmarksTree.setAttribute("ref", uri);
var title = "";
if (uri.substring(0,5) == "find:") {
title = gBookmarksShell.getLocaleString("search_results_title");
// Update the windowtype so that future searches are directed
// there and the window is not re-used for bookmarks.
windowNode.setAttribute("windowtype", "bookmarks:searchresults");
}
else {
const krNameArc = gBookmarksShell.RDF.GetResource(NC_NS + "Name");
const krRoot = gBookmarksShell.RDF.GetResource(window.arguments[0]);
var rName = gBookmarksShell.db.GetTarget(krRoot, krNameArc, true);
title = rName.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
}
const titleString = gBookmarksShell.getLocaleString("window_title");
windowNode.setAttribute("title", titleString.replace(/%folder_name%/gi, rName));
windowNode.setAttribute("title", titleString.replace(/%folder_name%/gi, title));
}
else {
var rootfoldername = gBookmarksShell.getLocaleString("bookmarks_root");
@ -58,6 +68,10 @@ function Startup()
// Update to the last sort.
RefreshSort();
var kids = document.getElementById("treechildren-bookmarks");
if (kids.firstChild)
bookmarksTree.selectItem(kids.firstChild);
bookmarksTree.focus();
}
@ -122,15 +136,26 @@ BookmarksWindowTree.prototype = {
catch (e) {
}
}
else
displayValue = LITERAL(this.db, currItem, NC_NS + "URL");
else {
try {
displayValue = LITERAL(this.db, currItem, NC_NS + "URL");
}
catch (e) {
displayValue = "";
}
}
if (displayValue.substring(0, 3) == "NC:")
displayValue = "";
}
kStatusBar.label = displayValue;
}
};
/*
Not used anymore but keeping code around in case it comes in handy for bookmarks button D&D
or personal toolbar D&D.
///////////////////////////////////////////////////////////////////////////////
// This will not work properly until drag & drop is asynchronous and allows
// events to be processed during a drag.
@ -267,3 +292,4 @@ var fileButton = {
}
};
*/

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

@ -34,7 +34,7 @@
src="chrome://communicator/locale/bookmarks/bookmark.properties"/>
</stringbundleset>
<popupset id="popupset">
<popupset id="bookmarksPopupset" appendto="_root">
<popup id="bmContext"
oncreate="gBookmarksShell.createContextMenu(event);"/>
</popupset>
@ -55,6 +55,7 @@
<command id="cmd_openfolderinnewwindow" oncommand="goDoCommand('cmd_openfolderinnewwindow');"/>
<command id="cmd_import" oncommand="goDoCommand('cmd_import');"/>
<command id="cmd_export" oncommand="goDoCommand('cmd_export');"/>
<command id="cmd_bm_fileBookmark" oncommand="goDoCommand('cmd_bm_fileBookmark');"/>
<command id="cmd_bm_cut" oncommand="goDoCommand('cmd_bm_cut');"/>
<command id="cmd_bm_copy" oncommand="goDoCommand('cmd_bm_copy');"/>

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

@ -0,0 +1,63 @@
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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):
* Ben Goodger <ben@netscape.com> (Original Author)
*/
function Startup()
{
doSetOKCancel(find);
var bundle = document.getElementById("bookmarksBundle");
document.getElementById("ok").label = bundle.getString("search_button_label");
document.getElementById("searchField").focus();
}
function find()
{
// Build up a find URI from the search fields and open a new window
// rooted on the URI.
var match = document.getElementById("matchList");
var method = document.getElementById("methodList");
var field = document.getElementById("searchField");
var searchURI = "find:datasource=rdf:bookmarks"
searchURI += "&match=" + match.selectedItem.value;
searchURI += "&method=" + method.selectedItem.value;
searchURI += "&text=" + escape(field.value);
var bmWindow = findMostRecentWindow("bookmarks:searchresults", "chrome://communicator/content/bookmarks/bookmarks.xul", searchURI);
// Update the root of the tree if we're using an existing search window.
if (!gCreatingNewWindow)
bmWindow.gBookmarksShell.setRoot(searchURI);
bmWindow.focus();
close();
}
var gCreatingNewWindow = false;
function findMostRecentWindow(aType, aURI, aParam)
{
var WM = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
WM = WM.QueryInterface(Components.interfaces.nsIWindowMediator);
var topWindow = WM.getMostRecentWindow(aType);
if (!topWindow) gCreatingNewWindow = true;
return topWindow || openDialog("chrome://communicator/content/bookmarks/bookmarks.xul",
"", "chrome,all,dialog=no", aParam);
}

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

@ -0,0 +1,74 @@
<?xml version="1.0"?>
<!-- -*- Mode: HTML; 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.
Contributor(s):
Ben Goodger <ben@netscape.com> (Original Author)
-->
<?xml-stylesheet href="chrome://communicator/skin/"?>
<?xul-overlay href="chrome://global/content/dialogOverlay.xul"?>
<!DOCTYPE window SYSTEM "chrome://communicator/locale/bookmarks/findBookmark.dtd">
<window id="findBookmarkWindow" style="width: 36em;"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="&findBookmark.title;"
orient="vertical" class="dialog"
onload="Startup();">
<keyset id="dialogKeys"/>
<stringbundle id="bookmarksBundle" src="chrome://communicator/locale/bookmarks/bookmark.properties"/>
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/bookmarksOverlay.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/bookmarks/findBookmark.js"/>
<text class="label" value="&search.for.label;"/>
<hbox autostretch="never" valign="middle">
<menulist id="matchList" class="menulist-toolbar">
<menupopup>
<menuitem value="http://home.netscape.com/NC-rdf#Name" label="&search.name.label;"/>
<menuitem value="http://home.netscape.com/NC-rdf#URL" label="&search.url.label;"/>
<menuitem value="http://home.netscape.com/NC-rdf#Description" label="&search.description.label;"/>
<menuitem value="http://home.netscape.com/NC-rdf#ShortcutURL" label="&search.shortcut.label;"/>
</menupopup>
</menulist>
<menulist id="methodList" class="menulist-toolbar">
<menupopup>
<menuitem value="contains" label="&search.contains.label;"/>
<menuitem value="startswith" label="&search.startswith.label;"/>
<menuitem value="endswith" label="&search.endswith.label;"/>
<menuitem value="is" label="&search.is.label;"/>
<menuitem value="isnot" label="&search.isnot.label;"/>
<menuitem value="doesntcontain" label="&search.doesntcontain.label;"/>
</menupopup>
</menulist>
<textbox id="searchField" onkeypress="if (event.keyCode == 13) find();" flex="1"/>
</hbox>
<separator/>
<box id="okCancelButtonsRight"/>
</window>

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

@ -39,7 +39,7 @@
<!ENTITY edit.properties.keybinding "i">
<!ENTITY command.rename.label "Rename...">
<!ENTITY command.delete.label "Delete">
<!ENTITY command.fileBookmark.label "File Bookmark">
<!ENTITY command.fileBookmark.label "File Bookmark(s)...">
<!ENTITY command.fileBookmark.accesskey "l">
<!ENTITY command.addBookmark.label "Add...">
<!ENTITY command.manageBookmarks.label "Manage">
@ -71,7 +71,3 @@
<!ENTITY tree.header.description.label "Description">
<!ENTITY bookmarksWindowTitle.label "Bookmarks">
<!ENTITY search.name.label "name">
<!ENTITY search.contains.label "contains">

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

@ -0,0 +1,14 @@
<!ENTITY search.name.label "name">
<!ENTITY search.url.label "location">
<!ENTITY search.shortcut.label "keyword">
<!ENTITY search.description.label "description">
<!ENTITY search.startswith.label "starts with">
<!ENTITY search.endswith.label "ends with">
<!ENTITY search.is.label "is">
<!ENTITY search.isnot.label "is not">
<!ENTITY search.contains.label "contains">
<!ENTITY search.doesntcontain.label "doesn't contain">
<!ENTITY search.for.label "Find Bookmarks whose">
<!ENTITY findBookmark.title "Find Bookmarks">