From d6a800c0cd75381adb3bb9dc4b86e172bbf0bc99 Mon Sep 17 00:00:00 2001 From: "chanial%noos.fr" Date: Fri, 13 Dec 2002 23:06:10 +0000 Subject: [PATCH] bookmark cleanup. make clear the distinction between target and selection in trees. now, insertion on a folder doesn't append but inserts before it. Allow multiple selection of bookmarks and folders for the home pages. --- .../bookmarks/content/addBookmark.js | 8 +- .../bookmarks/content/addBookmark2.js | 6 +- .../components/bookmarks/content/bookmarks.js | 76 +++++++------------ .../bookmarks/content/bookmarksToolbar.xml | 20 +++-- .../bookmarks/content/bookmarksTree.xml | 35 +++++---- .../bookmarks/content/selectBookmark.js | 46 +++++++---- .../bookmarks/content/selectBookmark.xul | 3 +- 7 files changed, 97 insertions(+), 97 deletions(-) diff --git a/browser/components/bookmarks/content/addBookmark.js b/browser/components/bookmarks/content/addBookmark.js index aba52d61f1b4..4d1565d1d58a 100644 --- a/browser/components/bookmarks/content/addBookmark.js +++ b/browser/components/bookmarks/content/addBookmark.js @@ -225,7 +225,7 @@ function onOK() // In Select Folder Mode, do nothing but tell our caller what // folder was selected. if (window.arguments.length > 4 && window.arguments[4] == "selectFolder") - window.arguments[5].selectedFolder = gCreateInFolder; + window.arguments[5].target = BookmarksUtils.getTargetFromFolder(bookmarkView.treeBuilder.getResourceAtIndex(currentIndex)); else { // Otherwise add a bookmark to the selected folder. var rFolder = RDF.GetResource(gCreateInFolder); @@ -258,10 +258,8 @@ function onOK() window.arguments[5].newBookmark = rSource; } } - var selection, target; - selection = BookmarksUtils.getSelectionFromResource(rSource); - target = BookmarksUtils.getSelectionFromResource(rFolder); - target = BookmarksUtils.getTargetFromSelection(target); + var selection = BookmarksUtils.getSelectionFromResource(rSource); + var target = BookmarksUtils.getTargetFromFolder(rFolder); BookmarksUtils.insertSelection("newbookmark", selection, target); } } diff --git a/browser/components/bookmarks/content/addBookmark2.js b/browser/components/bookmarks/content/addBookmark2.js index 79246a22eb68..9c1aaf3a1b80 100644 --- a/browser/components/bookmarks/content/addBookmark2.js +++ b/browser/components/bookmarks/content/addBookmark2.js @@ -124,10 +124,8 @@ function onOK() if (!gBMtxmgr) gBMtxmgr= BookmarksUtils.getTransactionManager(); - var selection, target; - selection = BookmarksUtils.getSelectionFromResource(rSource); - target = BookmarksUtils.getSelectionFromResource(rFolder); - target = BookmarksUtils.getTargetFromSelection(target); + var selection = BookmarksUtils.getSelectionFromResource(rSource); + var target = BookmarksUtils.getTargetFromFolder(rFolder); BookmarksUtils.insertSelection("newbookmark", selection, target); // in insertSelection, the ds flush is delayed. It will never be performed, // since this dialog is destroyed before. diff --git a/browser/components/bookmarks/content/bookmarks.js b/browser/components/bookmarks/content/bookmarks.js index 4b6b60cae062..f543001990b2 100644 --- a/browser/components/bookmarks/content/bookmarks.js +++ b/browser/components/bookmarks/content/bookmarks.js @@ -500,12 +500,10 @@ var BookmarksCommand = { var rv = { selectedFolder: null }; openDialog("chrome://browser/content/bookmarks/addBookmark.xul", "", "centerscreen,chrome,modal=yes,dialog=yes,resizable=yes", null, null, null, null, "selectFolder", rv); - if (!rv.selectedFolder) + if (!rv.target) return; - var target = RDF.GetResource(rv.selectedFolder); - target = BookmarksUtils.getSelectionFromResource(target); - target = BookmarksUtils.getTargetFromSelection(target); + var target = rv.target; BookmarksUtils.moveSelection("move", aSelection, target); }, @@ -754,13 +752,13 @@ var BookmarksController = { isCommandEnabled: function (aCommand, aSelection, aTarget) { - var length = aSelection.length; - if (length == 0) - return false; + var item0, type0; + var length = aSelection.length; + if (length != 0) { + item0 = aSelection.item[0].Value; + type0 = aSelection.type[0]; + } var isValidTarget = BookmarksUtils.isValidTargetContainer(aTarget.parent) - var item0 = aSelection.item[0].Value; - var type0 = aSelection.type[0]; - var isNotRef = !aSelection.isRef; var i; switch(aCommand) { @@ -790,21 +788,21 @@ var BookmarksController = { var hasFlavours = clipboard.hasDataMatchingFlavors(flavourArray, kClipboardIID.kGlobalClipboard); return hasFlavours; case "cmd_bm_copy": - return isNotRef; + return length > 0; case "cmd_bm_cut": case "cmd_bm_delete": - return isNotRef && aSelection.containsMutable; + return length > 0 && aSelection.containsMutable; case "cmd_bm_selectAll": return true; case "cmd_bm_open": case "cmd_bm_expandfolder": case "cmd_bm_managefolder": - return isNotRef && length == 1; + return length == 1; case "cmd_bm_openinnewwindow": case "cmd_bm_openinnewtab": return true; case "cmd_bm_openfolder": - for (i=0; i 0; default: return false; } @@ -1154,6 +1152,9 @@ var BookmarksUtils = { // Caches frequently used informations about the selection checkSelection: function (aSelection) { + if (aSelection.length == 0) + return; + aSelection.type = new Array(aSelection.length); aSelection.protocol = new Array(aSelection.length); aSelection.isContainer = new Array(aSelection.length); @@ -1444,36 +1445,13 @@ var BookmarksUtils = { return selection; }, - getTargetFromSelection: function (aSelection, aOrientation) + getTargetFromFolder: function(aResource) { - var parent, index; - var orientation = aOrientation !== undefined? aOrientation: - aSelection.isContainer[0]? BookmarksUtils.DROP_ON:BookmarksUtils.DROP_BEFORE; - var item = aSelection.item[0]; - if (orientation == BookmarksUtils.DROP_ON) { - parent = item; - if (aSelection.protocol == "file" || aSelection.protocol == "find") - parent = null; - } else - parent = aSelection.parent[0]; - - if (!parent) - // for file: or find: containers or children - index = -1; - else { - RDFC.Init(BMDS, parent); - if (orientation == BookmarksUtils.DROP_ON) - index = parseInt(this.getProperty(parent, RDF_NS+"nextVal")); - else { - if (orientation != this.DROP_ON) { - index = RDFC.IndexOf(item); - if (orientation == this.DROP_AFTER) - ++index; - } - } - } - var target = { parent: parent, index: index }; - return target; + var index = parseInt(this.getProperty(aResource, RDF_NS+"nextVal")); + if (isNaN(index)) + return {parent: null, index: -1}; + else + return {parent: aResource, index: index}; }, getSelectionFromResource: function (aItem, aParent) diff --git a/browser/components/bookmarks/content/bookmarksToolbar.xml b/browser/components/bookmarks/content/bookmarksToolbar.xml index 8ee9409d4f18..9f6e39308952 100644 --- a/browser/components/bookmarks/content/bookmarksToolbar.xml +++ b/browser/components/bookmarks/content/bookmarksToolbar.xml @@ -187,7 +187,6 @@ selection.item = [RDF.GetResource(item)]; selection.parent = [RDF.GetResource(parent)]; selection.isExpanded = [isExpanded]; - selection.isRef = false; selection.length = selection.item.length; BookmarksUtils.checkSelection(selection); return selection; @@ -223,17 +222,16 @@ } parent = RDF.GetResource(parent); - if (item && aOrientation != BookmarksUtils.DROP_ON) { - item = RDF.GetResource(item.id); - RDFC.Init(BMDS, parent); - index = RDFC.IndexOf(item); - if (aOrientation == BookmarksUtils.DROP_AFTER) - ++index; - } else - index = parseInt(BookmarksUtils.getProperty(parent, RDF_NS+"nextVal")); + if (aOrientation == BookmarksUtils.DROP_ON) + return BookmarksUtils.getTargetFromFolder(parent); - var target = { parent: parent, index: index }; - return target; + item = RDF.GetResource(item.id); + RDFC.Init(BMDS, parent); + index = RDFC.IndexOf(item); + if (aOrientation == BookmarksUtils.DROP_AFTER) + ++index; + + return { parent: parent, index: index }; ]]> diff --git a/browser/components/bookmarks/content/bookmarksTree.xml b/browser/components/bookmarks/content/bookmarksTree.xml index fd7759b85acd..d01b80544d3a 100644 --- a/browser/components/bookmarks/content/bookmarksTree.xml +++ b/browser/components/bookmarks/content/bookmarksTree.xml @@ -348,7 +348,6 @@ dump("error in refresh sort:"+e) selection.item = []; selection.parent = []; selection.isExpanded = []; - selection.isRef = false; var rangeCount = this.treeBoxObject.selection.getRangeCount(); // workaround for bug 171547: if rowCount==0, rangeCount==1 if (this.treeBuilder.rowCount > 0) @@ -365,21 +364,32 @@ dump("error in refresh sort:"+e) selection.isExpanded.push(isExpanded); } } - if (selection.item.length == 0) { - // if no item is selected, let's select the ref. - // but we have to keep track of it. - selection = { item : [this.getRootResource()], - parent : [null], - isExpanded: [true], - isRef : true - } - } selection.length = selection.item.length; BookmarksUtils.checkSelection(selection); return selection; ]]> + + + + + + + [] [] @@ -589,8 +599,7 @@ dump("error in refresh sort:"+e) !this.mOuter.treeBoxObject.view.isContainerEmpty(row)) target = { parent: rItem, index: 1 }; else { - target = BookmarksUtils.getSelectionFromResource(rItem, rParent); - target = BookmarksUtils.getTargetFromSelection(target, orientation); + target = this.mOuter.getTreeTarget(rItem, rParent, orientation); } var firstVisibleRow = this.mOuter.treeBoxObject.getFirstVisibleRow() this.mOuter.treeBoxObject.selection.selectEventsSuppressed = true; @@ -648,7 +657,7 @@ dump("6:"+(Date.now()-date)+"\n") dump("ONSELECTION CHANGED\n") var selection = this.mOuter.getTreeSelection(); this.mOuter._selection = selection; - this.mOuter._target = BookmarksUtils.getTargetFromSelection(selection); + this.mOuter._target = this.mOuter.getTreeTarget(selection.item[0], selection.parent[0], BookmarksUtils.DROP_BEFORE); this.mOuter.onCommandUpdate(); const kStatusBar = document.getAnonymousElementByAttribute(this.mOuter, "anonid", "statusbar-text"); var displayValue; diff --git a/browser/components/bookmarks/content/selectBookmark.js b/browser/components/bookmarks/content/selectBookmark.js index 9f53d073cbe7..9ef6df57c833 100644 --- a/browser/components/bookmarks/content/selectBookmark.js +++ b/browser/components/bookmarks/content/selectBookmark.js @@ -38,34 +38,54 @@ var gBookmarkTree; var gOK; +var gUrls; +var gTimer; function Startup() { initServices(); initBMService(); + gOK = document.documentElement.getButton("accept"); gBookmarkTree = document.getElementById("bookmarks-view"); gBookmarkTree.treeBoxObject.selection.select(0); gBookmarkTree.tree.focus(); - gOK = document.documentElement.getButton("accept"); -} - -function onDblClick() -{ - if (!gOK.disabled) - document.documentElement.acceptDialog(); - } function updateOK() { var selection = gBookmarkTree._selection; - gOK.disabled = selection.length != 1 || - (selection.type[0] != "Bookmark" && selection.type[0] != "") + var ds = gBookmarkTree.tree.database; + var url; + gUrls = []; + for (var i=0; i + onselect="clearTimeout(gTimer); gTimer=setTimeout(updateOK,100);"/>