mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-25 03:05:34 +00:00
Landing new add bookmark dialog (bug 214527).
Featuring an expandable tree and a dropdown menu containing the last used folders. The 'new folder' functionality has not been included, yet. Thanks to bz for the help on nsCOMArrays.
This commit is contained in:
parent
cce7112473
commit
7f600cc6ad
@ -73,29 +73,24 @@
|
||||
|
||||
var gSelectedFolder;
|
||||
var gName;
|
||||
var gMenulist;
|
||||
var gBookmarkTree;
|
||||
var gGroup;
|
||||
var gList;
|
||||
var gIndentation; // temporary hack to indent the folders
|
||||
var gNameArc;
|
||||
|
||||
function Startup()
|
||||
{
|
||||
sizeToContent(); //XXXpch buggy imo, we shouldn't need it
|
||||
initServices();
|
||||
initBMService();
|
||||
gNameArc = RDF.GetResource(NC_NS+"Name");
|
||||
gName = document.getElementById("name");
|
||||
gGroup = document.getElementById("addgroup");
|
||||
gList = document.getElementById("select-menu");
|
||||
gMenulist = document.getElementById("select-menu");
|
||||
gBookmarkTree = document.getElementById("folder-tree");
|
||||
gName.value = window.arguments[0];
|
||||
gName.select();
|
||||
gName.focus();
|
||||
onFieldInput();
|
||||
setTimeout(fillSelectFolderMenupopup, 0);
|
||||
gIndentation = Array(16);
|
||||
gIndentation[0] = "";
|
||||
for (var i=1; i<16; ++i)
|
||||
gIndentation[i]=gIndentation[i-1]+" ";
|
||||
|
||||
}
|
||||
|
||||
function onFieldInput()
|
||||
@ -106,9 +101,7 @@ function onFieldInput()
|
||||
|
||||
function onOK()
|
||||
{
|
||||
document.getElementById("addBookmarkDialog").setAttribute("selectedFolder",gSelectedFolder);
|
||||
var rFolder = RDF.GetResource(gSelectedFolder);
|
||||
RDFC.Init(BMDS, rFolder);
|
||||
RDFC.Init(BMDS, gSelectedFolder);
|
||||
|
||||
var url, rSource;
|
||||
if (gGroup && gGroup.checked) {
|
||||
@ -125,7 +118,7 @@ function onOK()
|
||||
}
|
||||
|
||||
var selection = BookmarksUtils.getSelectionFromResource(rSource);
|
||||
var target = BookmarksUtils.getTargetFromFolder(rFolder);
|
||||
var target = BookmarksUtils.getTargetFromFolder(gSelectedFolder);
|
||||
BookmarksUtils.insertAndCheckSelection("newbookmark", selection, target);
|
||||
|
||||
if (window.arguments[6] && rSource) {
|
||||
@ -164,51 +157,49 @@ function getNormalizedURL(url)
|
||||
return url;
|
||||
}
|
||||
|
||||
function fillFolder(aPopup, aFolder, aDepth)
|
||||
function selectMenulistFolder(aEvent)
|
||||
{
|
||||
RDFC.Init(BMDS, aFolder);
|
||||
var children = RDFC.GetElements();
|
||||
while (children.hasMoreElements()) {
|
||||
var curr = children.getNext();
|
||||
if (RDFCU.IsContainer(BMDS, curr)) {
|
||||
curr = curr.QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
var element = document.createElementNS(XUL_NS, "menuitem");
|
||||
var name = BMDS.GetTarget(curr, gNameArc, true).QueryInterface(kRDFLITIID).Value;
|
||||
element.setAttribute("label", gIndentation[aDepth]+name);
|
||||
element.setAttribute("id", curr.Value);
|
||||
aPopup.appendChild(element);
|
||||
if (curr.Value == gSelectedFolder)
|
||||
gList.selectedItem = element;
|
||||
fillFolder(aPopup, curr, ++aDepth);
|
||||
--aDepth;
|
||||
}
|
||||
}
|
||||
gSelectedFolder = RDF.GetResource(aEvent.target.id);
|
||||
}
|
||||
|
||||
function fillSelectFolderMenupopup ()
|
||||
function selectTreeFolder()
|
||||
{
|
||||
gSelectedFolder = gBookmarkTree._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;
|
||||
sizeToContent();
|
||||
}
|
||||
|
||||
function setFolderTreeHeight()
|
||||
{
|
||||
var isCollapsed = gBookmarkTree.collapsed;
|
||||
if (!isCollapsed)
|
||||
gBookmarkTree.setAttribute("height", gBookmarkTree.boxObject.height);
|
||||
}
|
||||
|
||||
function fillSelectFolderMenupopup()
|
||||
{
|
||||
|
||||
gSelectedFolder = document.getElementById("addBookmarkDialog").getAttribute("selectedFolder");
|
||||
var popup = document.getElementById("select-folder");
|
||||
// clearing the old menupopup
|
||||
while (popup.hasChildNodes())
|
||||
popup.removeChild(popup.firstChild);
|
||||
|
||||
// to be removed once I checkin the top folder
|
||||
var element = document.createElementNS(XUL_NS, "menuitem");
|
||||
element.setAttribute("label", "Bookmarks");
|
||||
element.setAttribute("id", "NC:BookmarksRoot");
|
||||
popup.appendChild(element);
|
||||
|
||||
var folder = RDF.GetResource("NC:BookmarksRoot");
|
||||
fillFolder(popup, folder, 1);
|
||||
if (gList.selectedIndex == -1) {
|
||||
gList.selectedIndex = 0;
|
||||
gSelectedFolder = "NC:BookmarksRoot";
|
||||
var arcs=BMSVC.GetTargets(RDF.GetResource("NC:LastModifiedFoldersRoot"), RDF.GetResource(NC_NS+"child"), true);
|
||||
while (arcs.hasMoreElements()) {
|
||||
var arc = arcs.getNext().QueryInterface(kRDFRSCIID);
|
||||
var element = document.createElementNS(XUL_NS, "menuitem");
|
||||
element.setAttribute("id", arc.Value);
|
||||
element.setAttribute("label", BookmarksUtils.getProperty(arc, NC_NS+"Name"));
|
||||
popup.appendChild(element);
|
||||
}
|
||||
}
|
||||
|
||||
function selectFolder(aEvent)
|
||||
{
|
||||
gSelectedFolder = aEvent.target.id;
|
||||
gMenulist.selectedIndex = 0;
|
||||
gSelectedFolder = RDF.GetResource(gMenulist.selectedItem.id);
|
||||
}
|
||||
|
@ -23,16 +23,18 @@
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin/"?>
|
||||
<?xml-stylesheet href="chrome://browser/content/bookmarks/bookmarks.css"?>
|
||||
<?xml-stylesheet href="chrome://global/skin/arrow.css" type="text/css"?>
|
||||
|
||||
<!DOCTYPE dialog SYSTEM "chrome://browser/locale/bookmarks/addBookmark.dtd">
|
||||
|
||||
<dialog id="addBookmarkDialog" style="width: 22em;"
|
||||
<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#"
|
||||
ondialogaccept="return onOK(event)"
|
||||
title="&newBookmark.title;" title-selectFolder="&selectFolder.label;"
|
||||
onload="Startup();"
|
||||
persist="screenX screenY selectedFolder"
|
||||
screenX="24" screenY="24">
|
||||
onunload="setFolderTreeHeight();"
|
||||
persist="screenX screenY width">
|
||||
|
||||
<script type="application/x-javascript" src="chrome://browser/content/bookmarks/bookmarks.js"/>
|
||||
<script type="application/x-javascript" src="chrome://browser/content/bookmarks/addBookmark2.js"/>
|
||||
@ -43,18 +45,30 @@
|
||||
<columns>
|
||||
<column/>
|
||||
<column flex="1"/>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row align="center">
|
||||
<label value="&name.label;" accesskey="&name.accesskey;" control="name"/>
|
||||
<textbox id="name" oninput="onFieldInput();"/>
|
||||
<button id="expander" class="down" oncommand="expandTree();" persist="class"/>
|
||||
</row>
|
||||
<row align="center">
|
||||
<label id="createinlabel" value="&createin.label;"/>
|
||||
<menulist id="select-menu"
|
||||
oncommand="selectFolder(event);">
|
||||
oncommand="selectMenulistFolder(event);">
|
||||
<menupopup id="select-folder"/>
|
||||
</menulist>
|
||||
|
||||
# <menulist id="select-menu" oncommand="selectMenulistFolder(event);"
|
||||
# datasources="rdf:bookmarks" ref="NC:LastModifiedFoldersRoot">
|
||||
# <template>
|
||||
# <menupopup>
|
||||
# <menuitem uri="rdf:*" label="rdf:http://home.netscape.com/NC-rdf#Name"/>
|
||||
# </menupopup>
|
||||
# </template>
|
||||
# </menulist>
|
||||
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
@ -64,6 +78,11 @@
|
||||
</hbox>
|
||||
|
||||
<separator class="thin"/>
|
||||
|
||||
<bookmarks-tree id="folder-tree" flex="1" type="folders" collapsed="true"
|
||||
seltype="single" persist="height" rows="6"
|
||||
onselect="selectTreeFolder();"/>
|
||||
|
||||
<script type="application/x-javascript"><![CDATA[
|
||||
if (!window.arguments[5])
|
||||
document.getElementById("addgroup").setAttribute("hidden", "true");
|
||||
|
@ -1664,7 +1664,7 @@ var BookmarkEditMenuTxnListener =
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef 0
|
||||
|
||||
var _dumpTIME;
|
||||
function dumpTIME(aString)
|
||||
|
@ -48,6 +48,7 @@
|
||||
*/
|
||||
|
||||
#include "nsBookmarksService.h"
|
||||
#include "nsArrayEnumerator.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIRDFContainer.h"
|
||||
@ -97,6 +98,9 @@ nsIRDFResource *kNC_BookmarkSeparator;
|
||||
nsIRDFResource *kNC_BookmarkAddDate;
|
||||
nsIRDFResource *kNC_BookmarksTopRoot;
|
||||
nsIRDFResource *kNC_BookmarksRoot;
|
||||
nsIRDFResource *kNC_LastModifiedFoldersRoot;
|
||||
nsIRDFResource *kNC_child;
|
||||
|
||||
nsIRDFResource *kNC_Description;
|
||||
nsIRDFResource *kNC_Folder;
|
||||
nsIRDFResource *kNC_IEFavorite;
|
||||
@ -133,6 +137,7 @@ nsIRDFResource *kNC_BookmarkCommand_Export;
|
||||
|
||||
#define BOOKMARK_TIMEOUT 15000 // fire every 15 seconds
|
||||
// #define DEBUG_BOOKMARK_PING_OUTPUT 1
|
||||
#define MAX_LAST_MODIFIED_FOLDERS 5
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -201,6 +206,10 @@ bm_AddRefGlobals()
|
||||
&kNC_IEFavoritesRoot);
|
||||
gRDF->GetResource(NS_LITERAL_CSTRING(kURINC_SystemBookmarksStaticRoot),
|
||||
&kNC_SystemBookmarksStaticRoot);
|
||||
gRDF->GetResource(NS_LITERAL_CSTRING("NC:LastModifiedFoldersRoot"),
|
||||
&kNC_LastModifiedFoldersRoot);
|
||||
gRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "child"),
|
||||
&kNC_child);
|
||||
gRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "BookmarksToolbarFolder"),
|
||||
&kNC_BookmarksToolbarFolder);
|
||||
gRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Bookmark"),
|
||||
@ -310,6 +319,8 @@ bm_ReleaseGlobals()
|
||||
NS_IF_RELEASE(kNC_BookmarkAddDate);
|
||||
NS_IF_RELEASE(kNC_BookmarksTopRoot);
|
||||
NS_IF_RELEASE(kNC_BookmarksRoot);
|
||||
NS_IF_RELEASE(kNC_LastModifiedFoldersRoot);
|
||||
NS_IF_RELEASE(kNC_child);
|
||||
NS_IF_RELEASE(kNC_Description);
|
||||
NS_IF_RELEASE(kNC_Folder);
|
||||
NS_IF_RELEASE(kNC_IEFavorite);
|
||||
@ -3317,6 +3328,76 @@ nsBookmarksService::SetBookmarksToolbarFolder(nsIRDFResource* aNewBTF)
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
CompareLastModifiedFolders(nsIRDFResource* aResource1, nsIRDFResource* aResource2, void* aOuter)
|
||||
{
|
||||
|
||||
nsCOMPtr<nsIRDFNode> node1, node2;
|
||||
nsIRDFDataSource* outer = NS_STATIC_CAST(nsIRDFDataSource*, aOuter);
|
||||
outer->GetTarget(aResource1, kWEB_LastModifiedDate, PR_TRUE, getter_AddRefs(node1));
|
||||
outer->GetTarget(aResource2, kWEB_LastModifiedDate, PR_TRUE, getter_AddRefs(node2));
|
||||
|
||||
nsCOMPtr<nsIRDFDate> date1 = do_QueryInterface(node1);
|
||||
if (!date1)
|
||||
return 1;
|
||||
nsCOMPtr<nsIRDFDate> date2 = do_QueryInterface(node2);
|
||||
if (!date2)
|
||||
return -1;
|
||||
|
||||
PRTime value1, value2;
|
||||
date1->GetValue(&value1);
|
||||
date2->GetValue(&value2);
|
||||
|
||||
PRInt64 delta;
|
||||
LL_SUB(delta, value1, value2);
|
||||
|
||||
return LL_GE_ZERO(delta)? -1 : 1;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBookmarksService::GetLastModifiedFolders(nsISimpleEnumerator **aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMArray<nsIRDFResource> folderArray;
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> elements;
|
||||
rv = mInner->GetAllResources(getter_AddRefs(elements));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// fill the array with all the bookmark folder resources
|
||||
PRBool hasMore = PR_FALSE;
|
||||
while (NS_SUCCEEDED(rv = elements->HasMoreElements(&hasMore)) &&
|
||||
hasMore) {
|
||||
nsCOMPtr<nsISupports> supports;
|
||||
rv = elements->GetNext(getter_AddRefs(supports));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> element = do_QueryInterface(supports, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> nodeType;
|
||||
rv = GetSynthesizedType(element, getter_AddRefs(nodeType));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (nodeType == kNC_Folder)
|
||||
folderArray.AppendObject(element);
|
||||
}
|
||||
|
||||
// sorting the array containing all the folders
|
||||
folderArray.Sort(CompareLastModifiedFolders, NS_STATIC_CAST(void*, mInner));
|
||||
|
||||
// only keep the first elements
|
||||
PRInt32 index;
|
||||
for (index = folderArray.Count()-1; index >= MAX_LAST_MODIFIED_FOLDERS; index--)
|
||||
folderArray.RemoveObjectAt(index);
|
||||
|
||||
return NS_NewArrayEnumerator(aResult, folderArray);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIRDFDataSource
|
||||
|
||||
@ -3410,6 +3491,32 @@ nsBookmarksService::GetTarget(nsIRDFResource* aSource,
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBookmarksService::GetTargets(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
PRBool aTruthValue,
|
||||
nsISimpleEnumerator** aTargets)
|
||||
{
|
||||
|
||||
NS_PRECONDITION(aSource != nsnull, "null ptr");
|
||||
if (! aSource)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aProperty != nsnull, "null ptr");
|
||||
if (! aProperty)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (!aTruthValue)
|
||||
return NS_NewEmptyEnumerator(aTargets);
|
||||
|
||||
if (aSource == kNC_LastModifiedFoldersRoot && aProperty == kNC_child) {
|
||||
return GetLastModifiedFolders(aTargets);
|
||||
}
|
||||
|
||||
return mInner->GetTargets(aSource, aProperty, aTruthValue, aTargets);
|
||||
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBookmarksService::ProcessCachedBookmarkIcon(nsIRDFResource* aSource,
|
||||
const PRUnichar *iconURL, nsIRDFNode** aTarget)
|
||||
|
@ -172,12 +172,13 @@ protected:
|
||||
|
||||
nsresult getLocaleString(const char *key, nsString &str);
|
||||
|
||||
nsresult
|
||||
GetURLFromResource(nsIRDFResource* aResource, nsAString& aURL);
|
||||
nsresult GetURLFromResource(nsIRDFResource* aResource, nsAString& aURL);
|
||||
|
||||
nsresult LoadBookmarks();
|
||||
nsresult InitDataSource();
|
||||
|
||||
nsresult GetLastModifiedFolders(nsISimpleEnumerator **aResult);
|
||||
|
||||
// nsIStreamObserver methods:
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
|
||||
@ -225,10 +226,7 @@ public:
|
||||
NS_IMETHOD GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsISimpleEnumerator** targets)
|
||||
{
|
||||
return mInner->GetTargets(source, property, tv, targets);
|
||||
}
|
||||
nsISimpleEnumerator** targets);
|
||||
|
||||
NS_IMETHOD Assert(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
|
Loading…
Reference in New Issue
Block a user