зеркало из https://github.com/mozilla/gecko-dev.git
Bug 181033: add a "New Folder" button to the add bookmark dialog
This commit is contained in:
Родитель
c5035b17db
Коммит
1f1a132025
|
@ -74,7 +74,7 @@
|
|||
var gSelectedFolder;
|
||||
var gName;
|
||||
var gMenulist;
|
||||
var gBookmarkTree;
|
||||
var gBookmarksTree;
|
||||
var gGroup;
|
||||
|
||||
function Startup()
|
||||
|
@ -85,7 +85,7 @@ function Startup()
|
|||
gName = document.getElementById("name");
|
||||
gGroup = document.getElementById("addgroup");
|
||||
gMenulist = document.getElementById("select-menu");
|
||||
gBookmarkTree = document.getElementById("folder-tree");
|
||||
gBookmarksTree = document.getElementById("folder-tree");
|
||||
gName.value = window.arguments[0];
|
||||
gName.select();
|
||||
gName.focus();
|
||||
|
@ -136,9 +136,9 @@ function onOK()
|
|||
BookmarksUtils.insertAndCheckSelection("newbookmark", selection, target);
|
||||
|
||||
if (window.arguments[6] && rSource) {
|
||||
// Assert that we're a web panel.
|
||||
BMDS.Assert(rSource, RDF.GetResource(NC_NS+"WebPanel"),
|
||||
RDF.GetLiteral("true"), true);
|
||||
// Assert that we're a web panel.
|
||||
BMDS.Assert(rSource, RDF.GetResource(NC_NS+"WebPanel"),
|
||||
RDF.GetLiteral("true"), true);
|
||||
}
|
||||
|
||||
// in insertSelection, the ds flush is delayed. It will never be performed,
|
||||
|
@ -174,26 +174,54 @@ function getNormalizedURL(url)
|
|||
function selectMenulistFolder(aEvent)
|
||||
{
|
||||
gSelectedFolder = RDF.GetResource(aEvent.target.id);
|
||||
if (!gBookmarksTree.collapsed) {
|
||||
gBookmarksTree.treeBoxObject.selection.selectEventsSuppressed = true;
|
||||
gBookmarksTree.treeBoxObject.selection.clearSelection();
|
||||
gBookmarksTree.selectResource(gSelectedFolder);
|
||||
var index = gBookmarksTree.treeBuilder.getIndexOfResource(gSelectedFolder);
|
||||
gBookmarksTree.treeBoxObject.ensureRowIsVisible(index);
|
||||
gBookmarksTree.treeBoxObject.selection.selectEventsSuppressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
function selectTreeFolder()
|
||||
{
|
||||
gSelectedFolder = gBookmarkTree._selection.item[0];
|
||||
gSelectedFolder = gBookmarksTree._selection.item[0];
|
||||
gMenulist.label = BookmarksUtils.getProperty(gSelectedFolder, NC_NS+"Name");
|
||||
}
|
||||
|
||||
function expandTree()
|
||||
{
|
||||
setFolderTreeHeight();
|
||||
var isCollapsed = gBookmarkTree.collapsed;
|
||||
document.getElementById("expander").setAttribute("class", isCollapsed? "up":"down");
|
||||
gBookmarkTree.collapsed = !isCollapsed;
|
||||
var isCollapsed = !gBookmarksTree.collapsed;
|
||||
gBookmarksTree.collapsed = isCollapsed;
|
||||
sizeToContent();
|
||||
document.documentElement.getButton("extra2").collapsed = isCollapsed;
|
||||
if (isCollapsed)
|
||||
document.documentElement.buttons = "accept,cancel";
|
||||
else {
|
||||
document.documentElement.buttons = "accept,cancel,extra2";
|
||||
gBookmarksTree.focus();
|
||||
}
|
||||
}
|
||||
|
||||
function setFolderTreeHeight()
|
||||
{
|
||||
var isCollapsed = gBookmarkTree.collapsed;
|
||||
var isCollapsed = gBookmarksTree.collapsed;
|
||||
if (!isCollapsed)
|
||||
gBookmarkTree.setAttribute("height", gBookmarkTree.boxObject.height);
|
||||
gBookmarksTree.setAttribute("height", gBookmarksTree.boxObject.height);
|
||||
}
|
||||
|
||||
function newFolder()
|
||||
{
|
||||
gBookmarksTree.focus();
|
||||
// we should use goDoCommand, but the current way of inserting
|
||||
// resources do not insert in folders.
|
||||
//goDoCommand("cmd_bm_newfolder");
|
||||
gBookmarksTree.treeBoxObject.selection.selectEventsSuppressed = true;
|
||||
gBookmarksTree.treeBoxObject.selection.clearSelection();
|
||||
var target = BookmarksUtils.getTargetFromFolder(gSelectedFolder);
|
||||
var folder = BookmarksCommand.createNewFolder(target);
|
||||
gBookmarksTree.selectResource(folder);
|
||||
gBookmarksTree.treeBoxObject.selection.selectEventsSuppressed = false;
|
||||
}
|
||||
|
|
|
@ -31,12 +31,19 @@
|
|||
<dialog id="addBookmarkDialog"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
ondialogextra2="newFolder()"
|
||||
ondialogaccept="return onOK(event)"
|
||||
buttons="accept,cancel"
|
||||
buttonlabelextra2="&newFolder.label;" buttonaccesskeyextra2="&newFolder.accesskey;"
|
||||
#ifdef XP_UNIX
|
||||
buttonlabelaccept="&accept.label;"
|
||||
#endif
|
||||
title="&newBookmark.title;" title-selectFolder="&selectFolder.label;"
|
||||
onload="Startup();"
|
||||
onunload="setFolderTreeHeight();"
|
||||
persist="screenX screenY width">
|
||||
|
||||
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>
|
||||
<script type="application/x-javascript" src="chrome://browser/content/bookmarks/bookmarks.js"/>
|
||||
<script type="application/x-javascript" src="chrome://browser/content/bookmarks/addBookmark2.js"/>
|
||||
|
||||
|
|
|
@ -538,7 +538,9 @@ var BookmarksCommand = {
|
|||
// Bookmark Properties dialog is only ever opened with one selection
|
||||
// (command is disabled otherwise)
|
||||
var bookmark = aSelection.item[0].Value;
|
||||
return openDialog("chrome://browser/content/bookmarks/bookmarksProperties.xul", "", "centerscreen,chrome,dependent,resizable=no", bookmark);
|
||||
value = {};
|
||||
openDialog("chrome://browser/content/bookmarks/bookmarksProperties.xul", "", "centerscreen,chrome,modal,resizable=no", bookmark, value);
|
||||
return value.ok;
|
||||
},
|
||||
|
||||
// requires utilityOverlay.js if opening in new window for getTopWin()
|
||||
|
@ -651,6 +653,8 @@ var BookmarksCommand = {
|
|||
var name = BookmarksUtils.getLocaleString("ile_newfolder");
|
||||
var resource = BMSVC.createFolder(name);
|
||||
this.createNewResource(resource, aTarget, "newfolder");
|
||||
// temporary hack...
|
||||
return resource;
|
||||
},
|
||||
|
||||
createNewSeparator: function (aTarget)
|
||||
|
@ -664,20 +668,9 @@ var BookmarksCommand = {
|
|||
var selection = BookmarksUtils.getSelectionFromResource(aResource, aTarget.parent);
|
||||
var ok = BookmarksUtils.insertAndCheckSelection(aTxnType, selection, aTarget);
|
||||
if (ok) {
|
||||
var propWin = this.openBookmarkProperties(selection);
|
||||
|
||||
function canceledNewResource()
|
||||
{
|
||||
ok = this.openBookmarkProperties(selection);
|
||||
if (!ok)
|
||||
BookmarksCommand.deleteBookmark(selection);
|
||||
propWin.document.documentElement.removeEventListener("dialogcancel", canceledNewResource, false);
|
||||
propWin.removeEventListener("load", propertiesWindowLoad, false);
|
||||
}
|
||||
|
||||
function propertiesWindowLoad()
|
||||
{
|
||||
propWin.document.documentElement.addEventListener("dialogcancel", canceledNewResource, false);
|
||||
}
|
||||
propWin.addEventListener("load", propertiesWindowLoad, false);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -795,7 +788,7 @@ var BookmarksController = {
|
|||
|
||||
isCommandEnabled: function (aCommand, aSelection, aTarget)
|
||||
{
|
||||
var item0, type0;
|
||||
var item0, type0, junk;
|
||||
var length = aSelection.length;
|
||||
if (length != 0) {
|
||||
item0 = aSelection.item[0].Value;
|
||||
|
@ -913,7 +906,7 @@ var BookmarksController = {
|
|||
break;
|
||||
case "cmd_bm_rename":
|
||||
case "cmd_bm_properties":
|
||||
BookmarksCommand.openBookmarkProperties(aSelection);
|
||||
junk = BookmarksCommand.openBookmarkProperties(aSelection);
|
||||
break;
|
||||
case "cmd_cut":
|
||||
BookmarksCommand.cutBookmark(aSelection);
|
||||
|
@ -1070,21 +1063,6 @@ var BookmarksUtils = {
|
|||
return type;
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Returns the container of a given container
|
||||
getParentOfResource: function(aChild)
|
||||
{
|
||||
var arcsIn = BMDS.ArcLabelsIn(aChild);
|
||||
var containerArc;
|
||||
while (arcsIn.hasMoreElements()) {
|
||||
containerArc = arcsIn.getNext();
|
||||
if (RDFCU.IsOrdinalProperty(containerArc)) {
|
||||
return BMDS.GetSources(containerArc, aChild, true).getNext()
|
||||
.QueryInterface(kRDFRSCIID);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Caches frequently used informations about the selection
|
||||
|
@ -1150,7 +1128,7 @@ var BookmarksUtils = {
|
|||
if (aSelection.isContainer[i] && aSelection.item[i] == folder)
|
||||
return true;
|
||||
}
|
||||
folder = BookmarksUtils.getParentOfResource(folder);
|
||||
folder = BMSVC.getParent(folder);
|
||||
if (!folder)
|
||||
return false; // sanity check
|
||||
} while (folder.Value != "NC:BookmarksRoot")
|
||||
|
|
|
@ -61,6 +61,10 @@ function showDescription()
|
|||
|
||||
function Init()
|
||||
{
|
||||
|
||||
// assume the user will press cancel (only used when creating new resources)
|
||||
window.arguments[1].ok = false;
|
||||
|
||||
// This is the set of fields that are visible in the window.
|
||||
gFields = ["name", "url", "shortcut", "description", "webpanel"];
|
||||
|
||||
|
@ -320,6 +324,7 @@ function Commit()
|
|||
remote.Flush();
|
||||
}
|
||||
|
||||
window.arguments[1].ok = true;
|
||||
window.close();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
# Contributor(s):
|
||||
# Ben Goodger <ben@netscape.com> (Original Author)
|
||||
# Blake Ross <blaker@nemtscape.com>
|
||||
# Pierre Chanial <chanial@noos.fr>
|
||||
# Pierre Chanial <chanial@noos.fr> (v 2.0)
|
||||
|
||||
<!DOCTYPE window [
|
||||
<!ENTITY % bookmarksDTD SYSTEM "chrome://browser/locale/bookmarks/bookmarks.dtd" >
|
||||
|
@ -230,8 +230,14 @@
|
|||
elt.setAttribute("hidden", elt.getAttribute("hidden") != "true");
|
||||
]]>
|
||||
</body>
|
||||
</method>
|
||||
|
||||
</method>
|
||||
|
||||
<property name="tree">
|
||||
<getter><![CDATA[
|
||||
return document.getAnonymousElementByAttribute(this, "anonid", "bookmarks-tree");
|
||||
]]></getter>
|
||||
</property>
|
||||
|
||||
<property name="treeBoxObject">
|
||||
<getter><![CDATA[
|
||||
return this.tree.boxObject.QueryInterface(Components.interfaces.nsITreeBoxObject);
|
||||
|
@ -244,38 +250,6 @@
|
|||
]]></getter>
|
||||
</property>
|
||||
|
||||
<property name="tree">
|
||||
<getter><![CDATA[
|
||||
return document.getAnonymousElementByAttribute(this, "anonid", "bookmarks-tree");
|
||||
]]></getter>
|
||||
</property>
|
||||
|
||||
<property name="currentIndex">
|
||||
<getter><![CDATA[
|
||||
return this.treeBoxObject.selection.currentIndex;
|
||||
]]></getter>
|
||||
</property>
|
||||
|
||||
<property name="currentRes">
|
||||
<getter><![CDATA[
|
||||
return this.treeBuilder.getResourceAtIndex(this.currentIndex);
|
||||
]]></getter>
|
||||
</property>
|
||||
|
||||
<property name="parentRes">
|
||||
<getter><![CDATA[
|
||||
const currIndex = this.currentIndex;
|
||||
|
||||
if (currIndex == -1)
|
||||
return RDF.GetResource("NC:BookmarksRoot");
|
||||
|
||||
var parentIndex = this.treeBoxObject.view.getParentIndex(currIndex);
|
||||
if (parentIndex != -1)
|
||||
return this.treeBuilder.getResourceAtIndex(parentIndex)
|
||||
return RDF.GetResource("NC:BookmarksRoot"); // assume its parent is the root
|
||||
]]></getter>
|
||||
</property>
|
||||
|
||||
<property name="type">
|
||||
<getter><![CDATA[
|
||||
if (!this._type) {
|
||||
|
@ -312,8 +286,42 @@
|
|||
<method name="getRootResource">
|
||||
<body><![CDATA[
|
||||
var tree = document.getAnonymousElementByAttribute(this, "anonid", "bookmarks-tree");
|
||||
var rootURI = tree.ref;
|
||||
return RDF.GetResource(rootURI);
|
||||
return RDF.GetResource(tree.ref);
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<method name="selectResource">
|
||||
<parameter name="aResource"/>
|
||||
<body><![CDATA[
|
||||
var index = this.treeBuilder.getIndexOfResource(aResource);
|
||||
if (index != -1) {
|
||||
if (!this.treeBoxObject.selection.isSelected(index))
|
||||
this.treeBoxObject.selection.toggleSelect(index);
|
||||
return;
|
||||
}
|
||||
|
||||
var chain = BMSVC.getParentChain(aResource);
|
||||
//dump("Chain:"+chain.length+"\n");
|
||||
for (var i=0; i<chain.length; i++) {
|
||||
var rParent = chain.queryElementAt(i, kRDFRSCIID);
|
||||
index = this.treeBuilder.getIndexOfResource(rParent);
|
||||
//dump(i+":"+BookmarksUtils.getProperty(rParent, NC_NS+"Name")+", index:"+index+"\n");
|
||||
if (index == -1)
|
||||
# rParent is or is a parent of "ref", we go on searching for the
|
||||
# first parent in the tree.
|
||||
continue;
|
||||
|
||||
if (!this.treeBoxObject.view.isContainerOpen(index))
|
||||
# we found one, let's open it.
|
||||
this.treeBoxObject.view.toggleOpenState(index);
|
||||
}
|
||||
if (index == -1)
|
||||
# none of the parents were in the tree, bailing
|
||||
return;
|
||||
|
||||
index = this.treeBuilder.getIndexOfResource(aResource);
|
||||
if (index != -1)
|
||||
this.treeBoxObject.selection.toggleSelect(index);
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
|
@ -342,7 +350,7 @@
|
|||
for (var i = rangeMin.value; i <= rangeMax.value; ++i) {
|
||||
var selectedItem = this.getRowResource(i);
|
||||
var selectedParent = this.getParentResource(i);
|
||||
var isExpanded = this.treeBoxObject.view.isContainerOpen(i)
|
||||
var isExpanded = this.treeBoxObject.view.isContainerOpen(i);
|
||||
selection.item .push(selectedItem);
|
||||
selection.parent.push(selectedParent);
|
||||
selection.isExpanded.push(isExpanded);
|
||||
|
@ -604,7 +612,7 @@
|
|||
this.mOuter.treeBoxObject.selection.selectAll();
|
||||
break;
|
||||
case "cmd_bm_expandfolder":
|
||||
this.mOuter.treeBoxObject.view.toggleOpenState(this.mOuter.currentIndex);
|
||||
this.mOuter.treeBoxObject.view.toggleOpenState(this.mOuter.treeBoxObject.selection.currentIndex);
|
||||
break;
|
||||
default:
|
||||
this.mOuter.saveSelection();
|
||||
|
|
|
@ -1,23 +1,3 @@
|
|||
# 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.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Ben Goodger <ben@netscape.com> (Original Author)
|
||||
|
||||
<!ENTITY newBookmark.title "Add Bookmark">
|
||||
<!ENTITY newbookmark.label "&brandShortName; will add a bookmark to this page.">
|
||||
<!ENTITY name.label "Name:">
|
||||
|
@ -37,8 +17,10 @@
|
|||
<!ENTITY button.defaultfolder.label "Use Default">
|
||||
<!ENTITY button.defaultfolder.accesskey "d">
|
||||
<!ENTITY selectFolder.label "Choose Folder">
|
||||
<!ENTITY addGroup.label "Bookmark all tabs in a folder">
|
||||
<!ENTITY addGroup.accesskey "B">
|
||||
|
||||
|
||||
<!ENTITY addGroup.label "Bookmark all tabs in a folder">
|
||||
<!ENTITY addGroup.accesskey "B">
|
||||
<!ENTITY newFolder.label "New Folder">
|
||||
<!ENTITY newFolder.accesskey "N">
|
||||
<!ENTITY accept.label "Add">
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче