diff --git a/content/xul/templates/public/nsIXULSortService.idl b/content/xul/templates/public/nsIXULSortService.idl index 99570332c9d7..29a74cd32c43 100755 --- a/content/xul/templates/public/nsIXULSortService.idl +++ b/content/xul/templates/public/nsIXULSortService.idl @@ -62,7 +62,7 @@ interface nsIXULSortService : nsISupports * aSortDirection as the direction. * * @param aNode A node in the XUL widget whose children are to be - * sorted. Sort will traverse upwards to find the + * sorted. sort will traverse upwards to find the * root node at which to begin the actualy sorting. For optimal * results, pass in the root of the widget. * @@ -74,14 +74,14 @@ interface nsIXULSortService : nsISupports * ascending to sort the contents in ascending order, or * descending to sort the contents in descending order. */ - void Sort(in nsIDOMNode aNode, - in string aSortResource, - in string aSortDirection); + void sort(in nsIDOMNode aNode, + in AString aSortResource, + in AString aSortDirection); /** * Used internally for insertion sorting. */ - [noscript] void InsertContainerNode(in nsIRDFCompositeDataSource db, + [noscript] void insertContainerNode(in nsIRDFCompositeDataSource db, in nsRDFSortState sortStatePtr, in nsIContent root, in nsIContent trueParent, diff --git a/content/xul/templates/src/nsXULSortService.cpp b/content/xul/templates/src/nsXULSortService.cpp index 37aa40a833c0..1eb4480375f8 100644 --- a/content/xul/templates/src/nsXULSortService.cpp +++ b/content/xul/templates/src/nsXULSortService.cpp @@ -170,13 +170,12 @@ private: nsresult FindDatabaseElement(nsIContent* aElement, nsIContent** aDatabaseElement); nsresult FindSortableContainer(nsIContent *tree, nsIContent **treeBody); -nsresult SetSortHints(nsIContent *tree, const nsString &sortResource, const nsString &sortDirection, const nsString &sortResource2, PRBool inbetweenSeparatorSort, PRBool found); -nsresult SetSortColumnHints(nsIContent *content, const nsString &sortResource, const nsString &sortDirection); -nsresult GetSortColumnInfo(nsIContent *tree, nsString &sortResource, nsString &sortDirection, nsString &sortResource2, PRBool &inbetweenSeparatorSort); +nsresult SetSortHints(nsIContent *tree, const nsAString &sortResource, const nsAString &sortDirection, const nsAString &sortResource2, PRBool inbetweenSeparatorSort, PRBool found); +nsresult SetSortColumnHints(nsIContent *content, const nsAString &sortResource, const nsAString &sortDirection); +nsresult GetSortColumnInfo(nsIContent *tree, nsAString &sortResource, nsAString &sortDirection, nsAString &sortResource2, PRBool &inbetweenSeparatorSort); nsresult SortContainer(nsIContent *container, sortPtr sortInfo, PRBool merelyInvertFlag); nsresult InvertSortInfo(contentSortInfo **data, PRInt32 numItems); -nsresult DoSort(nsIDOMNode* node, const nsString& sortResource, const nsString& sortDirection); static nsresult GetCachedTarget(sortPtr sortInfo, PRBool useCache, nsIRDFResource* aSource, nsIRDFResource *aProperty, PRBool aTruthValue, nsIRDFNode **aResult); static nsresult GetTarget(contentSortInfo *contentSortInfo, sortPtr sortInfo, PRBool first, PRBool onlyCollationHint, PRBool truthValue,nsIRDFNode **target, PRBool &isCollationKey); @@ -383,8 +382,8 @@ XULSortServiceImpl::FindSortableContainer(nsIContent *aRoot, nsIContent **aConta } nsresult -XULSortServiceImpl::SetSortHints(nsIContent *tree, const nsString &sortResource, - const nsString &sortDirection, const nsString &sortResource2, +XULSortServiceImpl::SetSortHints(nsIContent *tree, const nsAString &sortResource, + const nsAString &sortDirection, const nsAString &sortResource2, PRBool inbetweenSeparatorSort, PRBool found) { if (found) { @@ -416,7 +415,7 @@ XULSortServiceImpl::SetSortHints(nsIContent *tree, const nsString &sortResource, } nsresult -XULSortServiceImpl::SetSortColumnHints(nsIContent *content, const nsString &sortResource, const nsString &sortDirection) +XULSortServiceImpl::SetSortColumnHints(nsIContent *content, const nsAString &sortResource, const nsAString &sortDirection) { PRInt32 numChildren, childIndex, nameSpaceID; nsCOMPtr child; @@ -458,8 +457,8 @@ XULSortServiceImpl::SetSortColumnHints(nsIContent *content, const nsString &sort } nsresult -XULSortServiceImpl::GetSortColumnInfo(nsIContent *tree, nsString &sortResource, - nsString &sortDirection, nsString &sortResource2, +XULSortServiceImpl::GetSortColumnInfo(nsIContent *tree, nsAString &sortResource, + nsAString &sortDirection, nsAString &sortResource2, PRBool &inbetweenSeparatorSort) { nsresult rv = NS_ERROR_FAILURE; @@ -1584,13 +1583,7 @@ XULSortServiceImpl::InsertContainerNode(nsIRDFCompositeDataSource *db, nsRDFSort } NS_IMETHODIMP -XULSortServiceImpl::Sort(nsIDOMNode* node, const char *sortResource, const char *sortDirection) -{ - return DoSort(node, NS_ConvertASCIItoUCS2(sortResource), NS_ConvertASCIItoUCS2(sortDirection)); -} - -nsresult -XULSortServiceImpl::DoSort(nsIDOMNode* node, const nsString& sortResource, const nsString& sortDirection) +XULSortServiceImpl::Sort(nsIDOMNode* node, const nsAString& sortResource, const nsAString& sortDirection) { nsresult rv; _sortStruct sortInfo; @@ -1663,7 +1656,7 @@ XULSortServiceImpl::DoSort(nsIDOMNode* node, const nsString& sortResource, const GetSortColumnInfo(contentNode, unused, unused, sortResource2, sortInfo.inbetweenSeparatorSort); // build resource url for first sort resource - rv = gRDFService->GetUnicodeResource(sortResource.get(), getter_AddRefs(sortInfo.sortProperty)); + rv = gRDFService->GetUnicodeResource(PromiseFlatString(sortResource).get(), getter_AddRefs(sortInfo.sortProperty)); if (NS_FAILED(rv)) return rv; nsAutoString resourceUrl; diff --git a/extensions/irc/xul/content/handlers.js b/extensions/irc/xul/content/handlers.js index 1e0036f1f173..8194c0dee09f 100644 --- a/extensions/irc/xul/content/handlers.js +++ b/extensions/irc/xul/content/handlers.js @@ -628,11 +628,11 @@ function onSortCol(sortColName) return false; try { - xulSortService.Sort(node, sortResource, sortDirection); + xulSortService.sort(node, sortResource, sortDirection); } catch(ex) { - //dd("Exception calling xulSortService.Sort()"); + //dd("Exception calling xulSortService.sort()"); } return false; diff --git a/mailnews/base/prefs/resources/content/AccountManager.js b/mailnews/base/prefs/resources/content/AccountManager.js index 40c963655fd5..25c47f05c416 100644 --- a/mailnews/base/prefs/resources/content/AccountManager.js +++ b/mailnews/base/prefs/resources/content/AccountManager.js @@ -133,7 +133,7 @@ function onLoad() { function sortAccountList(accounttree) { var xulSortService = Components.classes["@mozilla.org/xul/xul-sort-service;1"].getService(Components.interfaces.nsIXULSortService); - xulSortService.Sort(accounttree, 'http://home.netscape.com/NC-rdf#FolderTreeName?sort=true', 'ascending'); + xulSortService.sort(accounttree, 'http://home.netscape.com/NC-rdf#FolderTreeName?sort=true', 'ascending'); } function selectServer(server, selectPage) diff --git a/xpfe/components/directory/directory.js b/xpfe/components/directory/directory.js index fd118101e779..71ecf48233ba 100644 --- a/xpfe/components/directory/directory.js +++ b/xpfe/components/directory/directory.js @@ -233,7 +233,7 @@ function doSort(aTarget) try { var sortService = Components.classes[XULSORTSERVICE_CONTRACTID].getService(nsIXULSortService); - sortService.Sort(aTarget, sortResource, sortDirection); + sortService.sort(aTarget, sortResource, sortDirection); } catch(ex) { } } diff --git a/xpfe/components/download-manager/resources/downloadmanager.js b/xpfe/components/download-manager/resources/downloadmanager.js index 28cc579fc72d..8c8090be04a5 100644 --- a/xpfe/components/download-manager/resources/downloadmanager.js +++ b/xpfe/components/download-manager/resources/downloadmanager.js @@ -81,6 +81,7 @@ function Startup() gNC_File = gRDFService.GetResource(NC_NS + "File"); gDownloadView = document.getElementById("downloadView"); + setSortVariables(gDownloadView); const dlmgrContractID = "@mozilla.org/download-manager;1"; const dlmgrIID = Components.interfaces.nsIDownloadManager; @@ -90,7 +91,7 @@ function Startup() gDownloadView.database.AddDataSource(ds); gDownloadView.builder.rebuild(); window.setTimeout(onRebuild, 0); - + var key; if (navigator.platform.indexOf("Win") != -1) key = "Win"; @@ -330,3 +331,40 @@ function Shutdown() catch (ex) { } } + +function setSortVariables(tree) +{ + var node; + for (node = document.getElementById("Name"); node; node = node.nextSibling) { + if (node.getAttribute("sortActive") == "true") + break; + } + if (!node) { + node = document.getElementById("Progress"); + node.setAttribute("sortActive", "true"); + node.setAttribute("sortDirection", "descending"); + } + + tree.setAttribute("sortActive", "true"); + tree.setAttribute("sortDirection", node.getAttribute("sortDirection")); + tree.setAttribute("sortResource", node.getAttribute("resource")); +} + +function doSort(node) +{ + if (node.localName != "treecol") + return; + + var sortResource = node.getAttribute("resource"); + + var sortDirection = node.getAttribute("sortDirection"); + sortDirection = sortDirection == "ascending" ? "descending" : "ascending"; + + try { + var sortService = Components.classes["@mozilla.org/xul/xul-sort-service;1"] + .getService(Components.interfaces.nsIXULSortService); + sortService.sort(node, sortResource, sortDirection); + } + catch(ex) { + } +} diff --git a/xpfe/components/download-manager/resources/downloadmanager.xul b/xpfe/components/download-manager/resources/downloadmanager.xul index e06fe8986a71..4a9deef784c8 100644 --- a/xpfe/components/download-manager/resources/downloadmanager.xul +++ b/xpfe/components/download-manager/resources/downloadmanager.xul @@ -132,54 +132,53 @@ datasources="rdf:null" ref="NC:DownloadsRoot" flags="dont-test-empty" ondblclick="return goDoCommand('cmd_properties');" enableColumnDrag="true" onselect="onSelect(event);"> - + + resource="http://home.netscape.com/NC-rdf#ProgressPercent" + persist="width hidden sortActive sortDirection"/>