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:
chanial%noos.fr 2003-12-08 16:30:28 +00:00
Родитель cce7112473
Коммит 7f600cc6ad
5 изменённых файлов: 176 добавлений и 61 удалений

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

@ -73,29 +73,24 @@
var gSelectedFolder; var gSelectedFolder;
var gName; var gName;
var gMenulist;
var gBookmarkTree;
var gGroup; var gGroup;
var gList;
var gIndentation; // temporary hack to indent the folders
var gNameArc;
function Startup() function Startup()
{ {
sizeToContent(); //XXXpch buggy imo, we shouldn't need it
initServices(); initServices();
initBMService(); initBMService();
gNameArc = RDF.GetResource(NC_NS+"Name");
gName = document.getElementById("name"); gName = document.getElementById("name");
gGroup = document.getElementById("addgroup"); 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.value = window.arguments[0];
gName.select(); gName.select();
gName.focus(); gName.focus();
onFieldInput(); onFieldInput();
setTimeout(fillSelectFolderMenupopup, 0); setTimeout(fillSelectFolderMenupopup, 0);
gIndentation = Array(16);
gIndentation[0] = "";
for (var i=1; i<16; ++i)
gIndentation[i]=gIndentation[i-1]+" ";
} }
function onFieldInput() function onFieldInput()
@ -106,9 +101,7 @@ function onFieldInput()
function onOK() function onOK()
{ {
document.getElementById("addBookmarkDialog").setAttribute("selectedFolder",gSelectedFolder); RDFC.Init(BMDS, gSelectedFolder);
var rFolder = RDF.GetResource(gSelectedFolder);
RDFC.Init(BMDS, rFolder);
var url, rSource; var url, rSource;
if (gGroup && gGroup.checked) { if (gGroup && gGroup.checked) {
@ -125,7 +118,7 @@ function onOK()
} }
var selection = BookmarksUtils.getSelectionFromResource(rSource); var selection = BookmarksUtils.getSelectionFromResource(rSource);
var target = BookmarksUtils.getTargetFromFolder(rFolder); var target = BookmarksUtils.getTargetFromFolder(gSelectedFolder);
BookmarksUtils.insertAndCheckSelection("newbookmark", selection, target); BookmarksUtils.insertAndCheckSelection("newbookmark", selection, target);
if (window.arguments[6] && rSource) { if (window.arguments[6] && rSource) {
@ -164,51 +157,49 @@ function getNormalizedURL(url)
return url; return url;
} }
function fillFolder(aPopup, aFolder, aDepth) function selectMenulistFolder(aEvent)
{ {
RDFC.Init(BMDS, aFolder); gSelectedFolder = RDF.GetResource(aEvent.target.id);
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;
}
}
} }
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"); var popup = document.getElementById("select-folder");
// clearing the old menupopup // clearing the old menupopup
while (popup.hasChildNodes()) while (popup.hasChildNodes())
popup.removeChild(popup.firstChild); popup.removeChild(popup.firstChild);
// to be removed once I checkin the top folder var arcs=BMSVC.GetTargets(RDF.GetResource("NC:LastModifiedFoldersRoot"), RDF.GetResource(NC_NS+"child"), true);
var element = document.createElementNS(XUL_NS, "menuitem"); while (arcs.hasMoreElements()) {
element.setAttribute("label", "Bookmarks"); var arc = arcs.getNext().QueryInterface(kRDFRSCIID);
element.setAttribute("id", "NC:BookmarksRoot"); var element = document.createElementNS(XUL_NS, "menuitem");
popup.appendChild(element); element.setAttribute("id", arc.Value);
element.setAttribute("label", BookmarksUtils.getProperty(arc, NC_NS+"Name"));
var folder = RDF.GetResource("NC:BookmarksRoot"); popup.appendChild(element);
fillFolder(popup, folder, 1);
if (gList.selectedIndex == -1) {
gList.selectedIndex = 0;
gSelectedFolder = "NC:BookmarksRoot";
} }
} gMenulist.selectedIndex = 0;
gSelectedFolder = RDF.GetResource(gMenulist.selectedItem.id);
function selectFolder(aEvent)
{
gSelectedFolder = aEvent.target.id;
} }

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

@ -23,16 +23,18 @@
<?xml-stylesheet href="chrome://global/skin/"?> <?xml-stylesheet href="chrome://global/skin/"?>
<?xml-stylesheet href="chrome://browser/content/bookmarks/bookmarks.css"?> <?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"> <!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="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)" ondialogaccept="return onOK(event)"
title="&newBookmark.title;" title-selectFolder="&selectFolder.label;" title="&newBookmark.title;" title-selectFolder="&selectFolder.label;"
onload="Startup();" onload="Startup();"
persist="screenX screenY selectedFolder" onunload="setFolderTreeHeight();"
screenX="24" screenY="24"> 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/bookmarks.js"/>
<script type="application/x-javascript" src="chrome://browser/content/bookmarks/addBookmark2.js"/> <script type="application/x-javascript" src="chrome://browser/content/bookmarks/addBookmark2.js"/>
@ -43,18 +45,30 @@
<columns> <columns>
<column/> <column/>
<column flex="1"/> <column flex="1"/>
<column/>
</columns> </columns>
<rows> <rows>
<row align="center"> <row align="center">
<label value="&name.label;" accesskey="&name.accesskey;" control="name"/> <label value="&name.label;" accesskey="&name.accesskey;" control="name"/>
<textbox id="name" oninput="onFieldInput();"/> <textbox id="name" oninput="onFieldInput();"/>
<button id="expander" class="down" oncommand="expandTree();" persist="class"/>
</row> </row>
<row align="center"> <row align="center">
<label id="createinlabel" value="&createin.label;"/> <label id="createinlabel" value="&createin.label;"/>
<menulist id="select-menu" <menulist id="select-menu"
oncommand="selectFolder(event);"> oncommand="selectMenulistFolder(event);">
<menupopup id="select-folder"/> <menupopup id="select-folder"/>
</menulist> </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> </row>
</rows> </rows>
</grid> </grid>
@ -64,6 +78,11 @@
</hbox> </hbox>
<separator class="thin"/> <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[ <script type="application/x-javascript"><![CDATA[
if (!window.arguments[5]) if (!window.arguments[5])
document.getElementById("addgroup").setAttribute("hidden", "true"); document.getElementById("addgroup").setAttribute("hidden", "true");

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

@ -1664,7 +1664,7 @@ var BookmarkEditMenuTxnListener =
} }
} }
#ifdef DEBUG #ifdef 0
var _dumpTIME; var _dumpTIME;
function dumpTIME(aString) function dumpTIME(aString)

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

@ -48,6 +48,7 @@
*/ */
#include "nsBookmarksService.h" #include "nsBookmarksService.h"
#include "nsArrayEnumerator.h"
#include "nsIDOMWindow.h" #include "nsIDOMWindow.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsIRDFContainer.h" #include "nsIRDFContainer.h"
@ -97,6 +98,9 @@ nsIRDFResource *kNC_BookmarkSeparator;
nsIRDFResource *kNC_BookmarkAddDate; nsIRDFResource *kNC_BookmarkAddDate;
nsIRDFResource *kNC_BookmarksTopRoot; nsIRDFResource *kNC_BookmarksTopRoot;
nsIRDFResource *kNC_BookmarksRoot; nsIRDFResource *kNC_BookmarksRoot;
nsIRDFResource *kNC_LastModifiedFoldersRoot;
nsIRDFResource *kNC_child;
nsIRDFResource *kNC_Description; nsIRDFResource *kNC_Description;
nsIRDFResource *kNC_Folder; nsIRDFResource *kNC_Folder;
nsIRDFResource *kNC_IEFavorite; nsIRDFResource *kNC_IEFavorite;
@ -133,6 +137,7 @@ nsIRDFResource *kNC_BookmarkCommand_Export;
#define BOOKMARK_TIMEOUT 15000 // fire every 15 seconds #define BOOKMARK_TIMEOUT 15000 // fire every 15 seconds
// #define DEBUG_BOOKMARK_PING_OUTPUT 1 // #define DEBUG_BOOKMARK_PING_OUTPUT 1
#define MAX_LAST_MODIFIED_FOLDERS 5
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -201,6 +206,10 @@ bm_AddRefGlobals()
&kNC_IEFavoritesRoot); &kNC_IEFavoritesRoot);
gRDF->GetResource(NS_LITERAL_CSTRING(kURINC_SystemBookmarksStaticRoot), gRDF->GetResource(NS_LITERAL_CSTRING(kURINC_SystemBookmarksStaticRoot),
&kNC_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"), gRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "BookmarksToolbarFolder"),
&kNC_BookmarksToolbarFolder); &kNC_BookmarksToolbarFolder);
gRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Bookmark"), gRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Bookmark"),
@ -310,6 +319,8 @@ bm_ReleaseGlobals()
NS_IF_RELEASE(kNC_BookmarkAddDate); NS_IF_RELEASE(kNC_BookmarkAddDate);
NS_IF_RELEASE(kNC_BookmarksTopRoot); NS_IF_RELEASE(kNC_BookmarksTopRoot);
NS_IF_RELEASE(kNC_BookmarksRoot); NS_IF_RELEASE(kNC_BookmarksRoot);
NS_IF_RELEASE(kNC_LastModifiedFoldersRoot);
NS_IF_RELEASE(kNC_child);
NS_IF_RELEASE(kNC_Description); NS_IF_RELEASE(kNC_Description);
NS_IF_RELEASE(kNC_Folder); NS_IF_RELEASE(kNC_Folder);
NS_IF_RELEASE(kNC_IEFavorite); NS_IF_RELEASE(kNC_IEFavorite);
@ -3317,6 +3328,76 @@ nsBookmarksService::SetBookmarksToolbarFolder(nsIRDFResource* aNewBTF)
return rv; 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 // nsIRDFDataSource
@ -3410,6 +3491,32 @@ nsBookmarksService::GetTarget(nsIRDFResource* aSource,
return rv; 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 nsresult
nsBookmarksService::ProcessCachedBookmarkIcon(nsIRDFResource* aSource, nsBookmarksService::ProcessCachedBookmarkIcon(nsIRDFResource* aSource,
const PRUnichar *iconURL, nsIRDFNode** aTarget) const PRUnichar *iconURL, nsIRDFNode** aTarget)

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

@ -172,12 +172,13 @@ protected:
nsresult getLocaleString(const char *key, nsString &str); nsresult getLocaleString(const char *key, nsString &str);
nsresult nsresult GetURLFromResource(nsIRDFResource* aResource, nsAString& aURL);
GetURLFromResource(nsIRDFResource* aResource, nsAString& aURL);
nsresult LoadBookmarks(); nsresult LoadBookmarks();
nsresult InitDataSource(); nsresult InitDataSource();
nsresult GetLastModifiedFolders(nsISimpleEnumerator **aResult);
// nsIStreamObserver methods: // nsIStreamObserver methods:
NS_DECL_NSIREQUESTOBSERVER NS_DECL_NSIREQUESTOBSERVER
@ -225,10 +226,7 @@ public:
NS_IMETHOD GetTargets(nsIRDFResource* source, NS_IMETHOD GetTargets(nsIRDFResource* source,
nsIRDFResource* property, nsIRDFResource* property,
PRBool tv, PRBool tv,
nsISimpleEnumerator** targets) nsISimpleEnumerator** targets);
{
return mInner->GetTargets(source, property, tv, targets);
}
NS_IMETHOD Assert(nsIRDFResource* aSource, NS_IMETHOD Assert(nsIRDFResource* aSource,
nsIRDFResource* aProperty, nsIRDFResource* aProperty,