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.
This commit is contained in:
chanial%noos.fr 2002-12-13 23:06:10 +00:00
Родитель 8d74b970e3
Коммит d6a800c0cd
7 изменённых файлов: 97 добавлений и 97 удалений

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

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

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

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

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

@ -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 item0, type0;
var length = aSelection.length;
if (length == 0)
return false;
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<aSelection.length; ++i) {
for (i=0; i<length; ++i) {
if (aSelection.type[i] == "" ||
aSelection.type[i] == "Bookmark" ||
aSelection.type[i] == "BookmarkSeparator")
@ -824,26 +822,26 @@ var BookmarksController = {
case "cmd_bm_newbookmark":
case "cmd_bm_newfolder":
case "cmd_bm_newseparator":
return isValidTarget && length == 1;
return isValidTarget;
case "cmd_bm_properties":
case "cmd_bm_rename":
return isNotRef && length == 1;
return length == 1;
case "cmd_bm_setnewbookmarkfolder":
if (!isNotRef || length != 1)
if (length != 1)
return false;
return item0 != "NC:NewBookmarkFolder" &&
(type0 == "Folder" || type0 == "PersonalToolbarFolder");
case "cmd_bm_setpersonaltoolbarfolder":
if (!isNotRef || length != 1)
if (length != 1)
return false
return item0 != "NC:PersonalToolbarFolder" && type0 == "Folder";
case "cmd_bm_setnewsearchfolder":
if (!isNotRef || length != 1)
if (length != 1)
return false
return item0 != "NC:NewSearchFolder" &&
(type0 == "Folder" || type0 == "PersonalToolbarFolder");
case "cmd_bm_movebookmark":
return isNotRef;
return length > 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)

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

@ -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) {
if (aOrientation == BookmarksUtils.DROP_ON)
return BookmarksUtils.getTargetFromFolder(parent);
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"));
var target = { parent: parent, index: index };
return target;
return { parent: parent, index: index };
]]></body>
</method>

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

@ -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;
]]></body>
</method>
<method name="getTreeTarget">
<parameter name="aItem"/>
<parameter name="aParent"/>
<parameter name="aOrientation"/>
<body><![CDATA[
if (aItem === undefined)
return BookmarksUtils.getTargetFromFolder(this.getRootResource());
if (aOrientation == BookmarksUtils.DROP_ON) {
return BookmarksUtils.getTargetFromFolder(aItem);
}
RDFC.Init(this.db, aParent);
var index = RDFC.IndexOf(aItem);
if (aOrientation == BookmarksUtils.DROP_AFTER)
++index;
return { parent: aParent, index: index };
]]></body>
</method>
<field name="_itemToBeToggled"> []</field>
<field name="_parentToBeToggled">[]</field>
<method name="preUpdateTreeSelection">
@ -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;

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

@ -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<selection.length; ++i) {
var type = selection.type[i];
var protocol = selection.protocol[i];
if ((type == "Bookmark" || type == "") &&
protocol != "find" && protocol != "javascript") {
url = BookmarksUtils.getProperty(selection.item[i], NC_NS+"URL", ds)
if (url)
gUrls.push(url);
} else if (type == "Folder" || type == "PersonalToolbarFolder" ||
type == "FolderGroup") {
RDFC.Init(ds, selection.item[i]);
var children = RDFC.GetElements();
while (children.hasMoreElements()) {
var child = children.getNext().QueryInterface(kRDFRSCIID);
type = BookmarksUtils.getProperty(child, RDF_NS+"type", ds);
protocol = child.Value.split(":")[0];
if (type == NC_NS+"Bookmark" && protocol != "find" &&
protocol != "javascript") {
url = BookmarksUtils.getProperty(child, NC_NS+"URL", ds);
if (url)
gUrls.push(url);
}
}
}
}
gOK.disabled = gUrls.length == 0;
}
function onOK(aEvent)
{
var selection = gBookmarkTree._selection;
var url = BookmarksUtils.getProperty(selection.item[0], NC_NS+"URL", gBookmarkTree.tree.database);
window.arguments[0].url = url;
window.arguments[0].url = gUrls.join("|");
}

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

@ -39,8 +39,7 @@
<bookmarks-tree id="bookmarks-view" style="height:15em;" flex="1" type="single-column"
onpopupshowing="return false;"
ondblclick="onDblClick()"
onselect="updateOK();"/>
onselect="clearTimeout(gTimer); gTimer=setTimeout(updateOK,100);"/>
<separator/>
</dialog>