зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
8d74b970e3
Коммит
d6a800c0cd
|
@ -225,7 +225,7 @@ function onOK()
|
||||||
// In Select Folder Mode, do nothing but tell our caller what
|
// In Select Folder Mode, do nothing but tell our caller what
|
||||||
// folder was selected.
|
// folder was selected.
|
||||||
if (window.arguments.length > 4 && window.arguments[4] == "selectFolder")
|
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 {
|
else {
|
||||||
// Otherwise add a bookmark to the selected folder.
|
// Otherwise add a bookmark to the selected folder.
|
||||||
var rFolder = RDF.GetResource(gCreateInFolder);
|
var rFolder = RDF.GetResource(gCreateInFolder);
|
||||||
|
@ -258,10 +258,8 @@ function onOK()
|
||||||
window.arguments[5].newBookmark = rSource;
|
window.arguments[5].newBookmark = rSource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var selection, target;
|
var selection = BookmarksUtils.getSelectionFromResource(rSource);
|
||||||
selection = BookmarksUtils.getSelectionFromResource(rSource);
|
var target = BookmarksUtils.getTargetFromFolder(rFolder);
|
||||||
target = BookmarksUtils.getSelectionFromResource(rFolder);
|
|
||||||
target = BookmarksUtils.getTargetFromSelection(target);
|
|
||||||
BookmarksUtils.insertSelection("newbookmark", selection, target);
|
BookmarksUtils.insertSelection("newbookmark", selection, target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,10 +124,8 @@ function onOK()
|
||||||
if (!gBMtxmgr)
|
if (!gBMtxmgr)
|
||||||
gBMtxmgr= BookmarksUtils.getTransactionManager();
|
gBMtxmgr= BookmarksUtils.getTransactionManager();
|
||||||
|
|
||||||
var selection, target;
|
var selection = BookmarksUtils.getSelectionFromResource(rSource);
|
||||||
selection = BookmarksUtils.getSelectionFromResource(rSource);
|
var target = BookmarksUtils.getTargetFromFolder(rFolder);
|
||||||
target = BookmarksUtils.getSelectionFromResource(rFolder);
|
|
||||||
target = BookmarksUtils.getTargetFromSelection(target);
|
|
||||||
BookmarksUtils.insertSelection("newbookmark", selection, target);
|
BookmarksUtils.insertSelection("newbookmark", selection, target);
|
||||||
// in insertSelection, the ds flush is delayed. It will never be performed,
|
// in insertSelection, the ds flush is delayed. It will never be performed,
|
||||||
// since this dialog is destroyed before.
|
// since this dialog is destroyed before.
|
||||||
|
|
|
@ -500,12 +500,10 @@ var BookmarksCommand = {
|
||||||
var rv = { selectedFolder: null };
|
var rv = { selectedFolder: null };
|
||||||
openDialog("chrome://browser/content/bookmarks/addBookmark.xul", "",
|
openDialog("chrome://browser/content/bookmarks/addBookmark.xul", "",
|
||||||
"centerscreen,chrome,modal=yes,dialog=yes,resizable=yes", null, null, null, null, "selectFolder", rv);
|
"centerscreen,chrome,modal=yes,dialog=yes,resizable=yes", null, null, null, null, "selectFolder", rv);
|
||||||
if (!rv.selectedFolder)
|
if (!rv.target)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var target = RDF.GetResource(rv.selectedFolder);
|
var target = rv.target;
|
||||||
target = BookmarksUtils.getSelectionFromResource(target);
|
|
||||||
target = BookmarksUtils.getTargetFromSelection(target);
|
|
||||||
BookmarksUtils.moveSelection("move", aSelection, target);
|
BookmarksUtils.moveSelection("move", aSelection, target);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -754,13 +752,13 @@ var BookmarksController = {
|
||||||
|
|
||||||
isCommandEnabled: function (aCommand, aSelection, aTarget)
|
isCommandEnabled: function (aCommand, aSelection, aTarget)
|
||||||
{
|
{
|
||||||
var length = aSelection.length;
|
var item0, type0;
|
||||||
if (length == 0)
|
var length = aSelection.length;
|
||||||
return false;
|
if (length != 0) {
|
||||||
|
item0 = aSelection.item[0].Value;
|
||||||
|
type0 = aSelection.type[0];
|
||||||
|
}
|
||||||
var isValidTarget = BookmarksUtils.isValidTargetContainer(aTarget.parent)
|
var isValidTarget = BookmarksUtils.isValidTargetContainer(aTarget.parent)
|
||||||
var item0 = aSelection.item[0].Value;
|
|
||||||
var type0 = aSelection.type[0];
|
|
||||||
var isNotRef = !aSelection.isRef;
|
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
switch(aCommand) {
|
switch(aCommand) {
|
||||||
|
@ -790,21 +788,21 @@ var BookmarksController = {
|
||||||
var hasFlavours = clipboard.hasDataMatchingFlavors(flavourArray, kClipboardIID.kGlobalClipboard);
|
var hasFlavours = clipboard.hasDataMatchingFlavors(flavourArray, kClipboardIID.kGlobalClipboard);
|
||||||
return hasFlavours;
|
return hasFlavours;
|
||||||
case "cmd_bm_copy":
|
case "cmd_bm_copy":
|
||||||
return isNotRef;
|
return length > 0;
|
||||||
case "cmd_bm_cut":
|
case "cmd_bm_cut":
|
||||||
case "cmd_bm_delete":
|
case "cmd_bm_delete":
|
||||||
return isNotRef && aSelection.containsMutable;
|
return length > 0 && aSelection.containsMutable;
|
||||||
case "cmd_bm_selectAll":
|
case "cmd_bm_selectAll":
|
||||||
return true;
|
return true;
|
||||||
case "cmd_bm_open":
|
case "cmd_bm_open":
|
||||||
case "cmd_bm_expandfolder":
|
case "cmd_bm_expandfolder":
|
||||||
case "cmd_bm_managefolder":
|
case "cmd_bm_managefolder":
|
||||||
return isNotRef && length == 1;
|
return length == 1;
|
||||||
case "cmd_bm_openinnewwindow":
|
case "cmd_bm_openinnewwindow":
|
||||||
case "cmd_bm_openinnewtab":
|
case "cmd_bm_openinnewtab":
|
||||||
return true;
|
return true;
|
||||||
case "cmd_bm_openfolder":
|
case "cmd_bm_openfolder":
|
||||||
for (i=0; i<aSelection.length; ++i) {
|
for (i=0; i<length; ++i) {
|
||||||
if (aSelection.type[i] == "" ||
|
if (aSelection.type[i] == "" ||
|
||||||
aSelection.type[i] == "Bookmark" ||
|
aSelection.type[i] == "Bookmark" ||
|
||||||
aSelection.type[i] == "BookmarkSeparator")
|
aSelection.type[i] == "BookmarkSeparator")
|
||||||
|
@ -824,26 +822,26 @@ var BookmarksController = {
|
||||||
case "cmd_bm_newbookmark":
|
case "cmd_bm_newbookmark":
|
||||||
case "cmd_bm_newfolder":
|
case "cmd_bm_newfolder":
|
||||||
case "cmd_bm_newseparator":
|
case "cmd_bm_newseparator":
|
||||||
return isValidTarget && length == 1;
|
return isValidTarget;
|
||||||
case "cmd_bm_properties":
|
case "cmd_bm_properties":
|
||||||
case "cmd_bm_rename":
|
case "cmd_bm_rename":
|
||||||
return isNotRef && length == 1;
|
return length == 1;
|
||||||
case "cmd_bm_setnewbookmarkfolder":
|
case "cmd_bm_setnewbookmarkfolder":
|
||||||
if (!isNotRef || length != 1)
|
if (length != 1)
|
||||||
return false;
|
return false;
|
||||||
return item0 != "NC:NewBookmarkFolder" &&
|
return item0 != "NC:NewBookmarkFolder" &&
|
||||||
(type0 == "Folder" || type0 == "PersonalToolbarFolder");
|
(type0 == "Folder" || type0 == "PersonalToolbarFolder");
|
||||||
case "cmd_bm_setpersonaltoolbarfolder":
|
case "cmd_bm_setpersonaltoolbarfolder":
|
||||||
if (!isNotRef || length != 1)
|
if (length != 1)
|
||||||
return false
|
return false
|
||||||
return item0 != "NC:PersonalToolbarFolder" && type0 == "Folder";
|
return item0 != "NC:PersonalToolbarFolder" && type0 == "Folder";
|
||||||
case "cmd_bm_setnewsearchfolder":
|
case "cmd_bm_setnewsearchfolder":
|
||||||
if (!isNotRef || length != 1)
|
if (length != 1)
|
||||||
return false
|
return false
|
||||||
return item0 != "NC:NewSearchFolder" &&
|
return item0 != "NC:NewSearchFolder" &&
|
||||||
(type0 == "Folder" || type0 == "PersonalToolbarFolder");
|
(type0 == "Folder" || type0 == "PersonalToolbarFolder");
|
||||||
case "cmd_bm_movebookmark":
|
case "cmd_bm_movebookmark":
|
||||||
return isNotRef;
|
return length > 0;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1154,6 +1152,9 @@ var BookmarksUtils = {
|
||||||
// Caches frequently used informations about the selection
|
// Caches frequently used informations about the selection
|
||||||
checkSelection: function (aSelection)
|
checkSelection: function (aSelection)
|
||||||
{
|
{
|
||||||
|
if (aSelection.length == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
aSelection.type = new Array(aSelection.length);
|
aSelection.type = new Array(aSelection.length);
|
||||||
aSelection.protocol = new Array(aSelection.length);
|
aSelection.protocol = new Array(aSelection.length);
|
||||||
aSelection.isContainer = new Array(aSelection.length);
|
aSelection.isContainer = new Array(aSelection.length);
|
||||||
|
@ -1444,36 +1445,13 @@ var BookmarksUtils = {
|
||||||
return selection;
|
return selection;
|
||||||
},
|
},
|
||||||
|
|
||||||
getTargetFromSelection: function (aSelection, aOrientation)
|
getTargetFromFolder: function(aResource)
|
||||||
{
|
{
|
||||||
var parent, index;
|
var index = parseInt(this.getProperty(aResource, RDF_NS+"nextVal"));
|
||||||
var orientation = aOrientation !== undefined? aOrientation:
|
if (isNaN(index))
|
||||||
aSelection.isContainer[0]? BookmarksUtils.DROP_ON:BookmarksUtils.DROP_BEFORE;
|
return {parent: null, index: -1};
|
||||||
var item = aSelection.item[0];
|
else
|
||||||
if (orientation == BookmarksUtils.DROP_ON) {
|
return {parent: aResource, index: index};
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getSelectionFromResource: function (aItem, aParent)
|
getSelectionFromResource: function (aItem, aParent)
|
||||||
|
|
|
@ -187,7 +187,6 @@
|
||||||
selection.item = [RDF.GetResource(item)];
|
selection.item = [RDF.GetResource(item)];
|
||||||
selection.parent = [RDF.GetResource(parent)];
|
selection.parent = [RDF.GetResource(parent)];
|
||||||
selection.isExpanded = [isExpanded];
|
selection.isExpanded = [isExpanded];
|
||||||
selection.isRef = false;
|
|
||||||
selection.length = selection.item.length;
|
selection.length = selection.item.length;
|
||||||
BookmarksUtils.checkSelection(selection);
|
BookmarksUtils.checkSelection(selection);
|
||||||
return selection;
|
return selection;
|
||||||
|
@ -223,17 +222,16 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
parent = RDF.GetResource(parent);
|
parent = RDF.GetResource(parent);
|
||||||
if (item && aOrientation != BookmarksUtils.DROP_ON) {
|
if (aOrientation == BookmarksUtils.DROP_ON)
|
||||||
item = RDF.GetResource(item.id);
|
return BookmarksUtils.getTargetFromFolder(parent);
|
||||||
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 };
|
item = RDF.GetResource(item.id);
|
||||||
return target;
|
RDFC.Init(BMDS, parent);
|
||||||
|
index = RDFC.IndexOf(item);
|
||||||
|
if (aOrientation == BookmarksUtils.DROP_AFTER)
|
||||||
|
++index;
|
||||||
|
|
||||||
|
return { parent: parent, index: index };
|
||||||
]]></body>
|
]]></body>
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
|
|
|
@ -348,7 +348,6 @@ dump("error in refresh sort:"+e)
|
||||||
selection.item = [];
|
selection.item = [];
|
||||||
selection.parent = [];
|
selection.parent = [];
|
||||||
selection.isExpanded = [];
|
selection.isExpanded = [];
|
||||||
selection.isRef = false;
|
|
||||||
var rangeCount = this.treeBoxObject.selection.getRangeCount();
|
var rangeCount = this.treeBoxObject.selection.getRangeCount();
|
||||||
// workaround for bug 171547: if rowCount==0, rangeCount==1
|
// workaround for bug 171547: if rowCount==0, rangeCount==1
|
||||||
if (this.treeBuilder.rowCount > 0)
|
if (this.treeBuilder.rowCount > 0)
|
||||||
|
@ -365,21 +364,32 @@ dump("error in refresh sort:"+e)
|
||||||
selection.isExpanded.push(isExpanded);
|
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;
|
selection.length = selection.item.length;
|
||||||
BookmarksUtils.checkSelection(selection);
|
BookmarksUtils.checkSelection(selection);
|
||||||
return selection;
|
return selection;
|
||||||
]]></body>
|
]]></body>
|
||||||
</method>
|
</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="_itemToBeToggled"> []</field>
|
||||||
<field name="_parentToBeToggled">[]</field>
|
<field name="_parentToBeToggled">[]</field>
|
||||||
<method name="preUpdateTreeSelection">
|
<method name="preUpdateTreeSelection">
|
||||||
|
@ -589,8 +599,7 @@ dump("error in refresh sort:"+e)
|
||||||
!this.mOuter.treeBoxObject.view.isContainerEmpty(row))
|
!this.mOuter.treeBoxObject.view.isContainerEmpty(row))
|
||||||
target = { parent: rItem, index: 1 };
|
target = { parent: rItem, index: 1 };
|
||||||
else {
|
else {
|
||||||
target = BookmarksUtils.getSelectionFromResource(rItem, rParent);
|
target = this.mOuter.getTreeTarget(rItem, rParent, orientation);
|
||||||
target = BookmarksUtils.getTargetFromSelection(target, orientation);
|
|
||||||
}
|
}
|
||||||
var firstVisibleRow = this.mOuter.treeBoxObject.getFirstVisibleRow()
|
var firstVisibleRow = this.mOuter.treeBoxObject.getFirstVisibleRow()
|
||||||
this.mOuter.treeBoxObject.selection.selectEventsSuppressed = true;
|
this.mOuter.treeBoxObject.selection.selectEventsSuppressed = true;
|
||||||
|
@ -648,7 +657,7 @@ dump("6:"+(Date.now()-date)+"\n")
|
||||||
dump("ONSELECTION CHANGED\n")
|
dump("ONSELECTION CHANGED\n")
|
||||||
var selection = this.mOuter.getTreeSelection();
|
var selection = this.mOuter.getTreeSelection();
|
||||||
this.mOuter._selection = selection;
|
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();
|
this.mOuter.onCommandUpdate();
|
||||||
const kStatusBar = document.getAnonymousElementByAttribute(this.mOuter, "anonid", "statusbar-text");
|
const kStatusBar = document.getAnonymousElementByAttribute(this.mOuter, "anonid", "statusbar-text");
|
||||||
var displayValue;
|
var displayValue;
|
||||||
|
|
|
@ -38,34 +38,54 @@
|
||||||
|
|
||||||
var gBookmarkTree;
|
var gBookmarkTree;
|
||||||
var gOK;
|
var gOK;
|
||||||
|
var gUrls;
|
||||||
|
var gTimer;
|
||||||
|
|
||||||
function Startup()
|
function Startup()
|
||||||
{
|
{
|
||||||
initServices();
|
initServices();
|
||||||
initBMService();
|
initBMService();
|
||||||
|
gOK = document.documentElement.getButton("accept");
|
||||||
gBookmarkTree = document.getElementById("bookmarks-view");
|
gBookmarkTree = document.getElementById("bookmarks-view");
|
||||||
gBookmarkTree.treeBoxObject.selection.select(0);
|
gBookmarkTree.treeBoxObject.selection.select(0);
|
||||||
gBookmarkTree.tree.focus();
|
gBookmarkTree.tree.focus();
|
||||||
gOK = document.documentElement.getButton("accept");
|
|
||||||
}
|
|
||||||
|
|
||||||
function onDblClick()
|
|
||||||
{
|
|
||||||
if (!gOK.disabled)
|
|
||||||
document.documentElement.acceptDialog();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateOK()
|
function updateOK()
|
||||||
{
|
{
|
||||||
var selection = gBookmarkTree._selection;
|
var selection = gBookmarkTree._selection;
|
||||||
gOK.disabled = selection.length != 1 ||
|
var ds = gBookmarkTree.tree.database;
|
||||||
(selection.type[0] != "Bookmark" && selection.type[0] != "")
|
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)
|
function onOK(aEvent)
|
||||||
{
|
{
|
||||||
var selection = gBookmarkTree._selection;
|
window.arguments[0].url = gUrls.join("|");
|
||||||
var url = BookmarksUtils.getProperty(selection.item[0], NC_NS+"URL", gBookmarkTree.tree.database);
|
|
||||||
window.arguments[0].url = url;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,7 @@
|
||||||
|
|
||||||
<bookmarks-tree id="bookmarks-view" style="height:15em;" flex="1" type="single-column"
|
<bookmarks-tree id="bookmarks-view" style="height:15em;" flex="1" type="single-column"
|
||||||
onpopupshowing="return false;"
|
onpopupshowing="return false;"
|
||||||
ondblclick="onDblClick()"
|
onselect="clearTimeout(gTimer); gTimer=setTimeout(updateOK,100);"/>
|
||||||
onselect="updateOK();"/>
|
|
||||||
<separator/>
|
<separator/>
|
||||||
|
|
||||||
</dialog>
|
</dialog>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче