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"/>
diff --git a/xpfe/components/download-manager/src/nsDownloadManager.cpp b/xpfe/components/download-manager/src/nsDownloadManager.cpp
index 8789f497575e..2bd9c3900b9c 100644
--- a/xpfe/components/download-manager/src/nsDownloadManager.cpp
+++ b/xpfe/components/download-manager/src/nsDownloadManager.cpp
@@ -425,18 +425,8 @@ nsDownloadManager::AddDownload(nsIURI* aSource,
nsCOMPtr downloadRes;
gRDFService->GetResource(path.get(), getter_AddRefs(downloadRes));
- // if the resource is in the container already (the user has already
- // downloaded this file), remove it
- PRInt32 itemIndex;
nsCOMPtr node;
- downloads->IndexOf(downloadRes, &itemIndex);
- if (itemIndex > 0) {
- rv = downloads->RemoveElementAt(itemIndex, PR_TRUE, getter_AddRefs(node));
- if (NS_FAILED(rv)) return rv;
- }
- rv = downloads->AppendElement(downloadRes);
- if (NS_FAILED(rv)) return rv;
-
+
// Assert source url information
nsCAutoString spec;
aSource->GetSpec(spec);
@@ -448,11 +438,7 @@ nsDownloadManager::AddDownload(nsIURI* aSource,
rv = mDataSource->Change(downloadRes, gNC_URL, node, urlResource);
else
rv = mDataSource->Assert(downloadRes, gNC_URL, urlResource, PR_TRUE);
- if (NS_FAILED(rv)) {
- downloads->IndexOf(downloadRes, &itemIndex);
- downloads->RemoveElementAt(itemIndex, PR_TRUE, getter_AddRefs(node));
- return rv;
- }
+ if (NS_FAILED(rv)) return rv;
// Set and assert the "pretty" (display) name of the download
nsAutoString displayName; displayName.Assign(aDisplayName);
@@ -468,11 +454,7 @@ nsDownloadManager::AddDownload(nsIURI* aSource,
rv = mDataSource->Change(downloadRes, gNC_Name, node, nameLiteral);
else
rv = mDataSource->Assert(downloadRes, gNC_Name, nameLiteral, PR_TRUE);
- if (NS_FAILED(rv)) {
- downloads->IndexOf(downloadRes, &itemIndex);
- downloads->RemoveElementAt(itemIndex, PR_TRUE, getter_AddRefs(node));
- return rv;
- }
+ if (NS_FAILED(rv)) return rv;
internalDownload->SetMIMEInfo(aMIMEInfo);
internalDownload->SetStartTime(aStartTime);
@@ -481,11 +463,7 @@ nsDownloadManager::AddDownload(nsIURI* aSource,
nsCOMPtr fileResource;
gRDFService->GetResource(path.get(), getter_AddRefs(fileResource));
rv = mDataSource->Assert(downloadRes, gNC_File, fileResource, PR_TRUE);
- if (NS_FAILED(rv)) {
- downloads->IndexOf(downloadRes, &itemIndex);
- downloads->RemoveElementAt(itemIndex, PR_TRUE, getter_AddRefs(node));
- return rv;
- }
+ if (NS_FAILED(rv)) return rv;
// Assert download state information (NOTSTARTED, since it's just now being added)
nsCOMPtr intLiteral;
@@ -495,20 +473,19 @@ nsDownloadManager::AddDownload(nsIURI* aSource,
rv = mDataSource->Change(downloadRes, gNC_DownloadState, node, intLiteral);
else
rv = mDataSource->Assert(downloadRes, gNC_DownloadState, intLiteral, PR_TRUE);
- if (NS_FAILED(rv)) {
- downloads->IndexOf(downloadRes, &itemIndex);
- downloads->RemoveElementAt(itemIndex, PR_TRUE, getter_AddRefs(node));
- return rv;
- }
+ if (NS_FAILED(rv)) return rv;
+ PRInt32 itemIndex;
+ downloads->IndexOf(downloadRes, &itemIndex);
+ if (itemIndex == -1) {
+ rv = downloads->AppendElement(downloadRes);
+ if (NS_FAILED(rv)) return rv;
+ }
+
// Now flush all this to disk
nsCOMPtr remote(do_QueryInterface(mDataSource));
rv = remote->Flush();
- if (NS_FAILED(rv)) {
- downloads->IndexOf(downloadRes, &itemIndex);
- downloads->RemoveElementAt(itemIndex, PR_TRUE, getter_AddRefs(node));
- return rv;
- }
+ if (NS_FAILED(rv)) return rv;
// if a persist object was specified, set the download item as the progress listener
// this will create a cycle that will be broken in nsDownload::OnStateChange
diff --git a/xpfe/components/search/resources/search-editor.js b/xpfe/components/search/resources/search-editor.js
index eede01d97262..77e2ce432c73 100644
--- a/xpfe/components/search/resources/search-editor.js
+++ b/xpfe/components/search/resources/search-editor.js
@@ -240,11 +240,11 @@ function doSort(sortColName, naturalOrderResource)
if (!xulSortService) return(false);
try
{
- xulSortService.Sort(node, sortResource, sortDirection);
+ xulSortService.sort(node, sortResource, sortDirection);
}
catch(ex)
{
- debug("Exception calling xulSortService.Sort()");
+ debug("Exception calling xulSortService.sort()");
}
return(true);
}
diff --git a/xpfe/components/search/resources/shared.js b/xpfe/components/search/resources/shared.js
index e14f7dd1ccf6..095959a6aaba 100644
--- a/xpfe/components/search/resources/shared.js
+++ b/xpfe/components/search/resources/shared.js
@@ -337,11 +337,11 @@ function doSort(sortColName, naturalOrderResource)
if (!xulSortService) return(false);
try
{
- xulSortService.Sort(node, sortResource, sortDirection);
+ xulSortService.sort(node, sortResource, sortDirection);
}
catch(ex)
{
- debug("Exception calling xulSortService.Sort()");
+ debug("Exception calling xulSortService.sort()");
}
return(true);
}
@@ -360,7 +360,7 @@ function setInitialSort(node, sortDirection)
if (!isupports) return(false);
var xulSortService = isupports.QueryInterface(Components.interfaces.nsIXULSortService);
if (!xulSortService) return(false);
- xulSortService.Sort(node, sortResource, sortDirection);
+ xulSortService.sort(node, sortResource, sortDirection);
}
catch(ex)
{