diff --git a/mailnews/base/prefs/resources/content/AccountManager.js b/mailnews/base/prefs/resources/content/AccountManager.js index e57914b045a..7d09e1b285d 100644 --- a/mailnews/base/prefs/resources/content/AccountManager.js +++ b/mailnews/base/prefs/resources/content/AccountManager.js @@ -65,6 +65,11 @@ var setDefaultButton; // called when the whole document loads // perform initialization here function onLoad() { + + var selectedAccount; + if (window.arguments && window.arguments[0]) + selectedServer = window.arguments[0].server; + accountArray = new Array; RDF = Components.classes["component://netscape/rdf/rdf-service"].getService(Components.interfaces.nsIRDFService); @@ -81,21 +86,43 @@ function onLoad() { deleteButton = document.getElementById("deleteButton"); setDefaultButton = document.getElementById("setDefaultButton"); - selectFirstAccount() + sortAccountList(accounttree); + selectServer(selectedServer) } -function selectFirstAccount() -{ - var tree = document.getElementById("accounttree"); - var firstItem = findFirstTreeItem(tree); +function sortAccountList(accounttree) +{ + var xulSortService = Components.classes["component://netscape/rdf/xul-sort-service"].getService(Components.interfaces.nsIXULSortService); + + xulSortService.Sort(accounttree, 'http://home.netscape.com/NC-rdf#FolderTreeName?sort=true', 'ascending'); +} - if (firstItem) accounttree.selectItem(firstItem); +function selectServer(server) +{ + var selectedItem; + + if (server) + selectedItem = document.getElementById(server.serverURI); + + if (!selectedItem) + selectedItem = getFirstAccount(); + + accounttree.selectItem(selectedItem); + var result = getServerIdAndPageIdFromTree(accounttree); if (result) { updateButtons(accounttree,result.serverId); } } +function getFirstAccount() +{ + var tree = document.getElementById("accounttree"); + var firstItem = findFirstTreeItem(tree); + + return firstItem; +} + function findFirstTreeItem(tree) { var children = tree.childNodes; diff --git a/mailnews/base/prefs/resources/content/AccountManager.xul b/mailnews/base/prefs/resources/content/AccountManager.xul index c7ff1bc369e..0594d675b66 100644 --- a/mailnews/base/prefs/resources/content/AccountManager.xul +++ b/mailnews/base/prefs/resources/content/AccountManager.xul @@ -36,10 +36,12 @@ - + diff --git a/mailnews/base/prefs/resources/content/accountUtils.js b/mailnews/base/prefs/resources/content/accountUtils.js index ca8b0c5c231..a35533b32dd 100644 --- a/mailnews/base/prefs/resources/content/accountUtils.js +++ b/mailnews/base/prefs/resources/content/accountUtils.js @@ -123,6 +123,13 @@ function msgOpenAccountWizard() function MsgAccountManager() { + var server; + try { + folderURI = GetSelectedFolderURI(); + server = GetServer(folderURI); + } catch (ex) { /* functions might not be defined */} + window.openDialog("chrome://messenger/content/AccountManager.xul", - "AccountManager", "chrome,modal,resizable"); + "AccountManager", "chrome,modal,resizable", + { server: server }); } diff --git a/mailnews/base/resources/content/msgMail3PaneWindow.js b/mailnews/base/resources/content/msgMail3PaneWindow.js index 8608469491c..6d934a8b622 100644 --- a/mailnews/base/resources/content/msgMail3PaneWindow.js +++ b/mailnews/base/resources/content/msgMail3PaneWindow.js @@ -588,6 +588,7 @@ function GetSelectedMessage() function GetServer(uri) { + if (!uri) return null; try { var folder = GetMsgFolderFromUri(uri); return folder.server; diff --git a/mailnews/base/src/nsMsgAccountManagerDS.cpp b/mailnews/base/src/nsMsgAccountManagerDS.cpp index fb22a051435..610428b7ac0 100644 --- a/mailnews/base/src/nsMsgAccountManagerDS.cpp +++ b/mailnews/base/src/nsMsgAccountManagerDS.cpp @@ -226,7 +226,6 @@ nsMsgAccountManagerDataSource::Init() void nsMsgAccountManagerDataSource::Cleanup() { - printf("*** AccountManager Datasource cleanup\n"); nsCOMPtr am = do_QueryReferent(mAccountManager); @@ -321,15 +320,37 @@ nsMsgAccountManagerDataSource::GetTarget(nsIRDFResource *source, // only answer for servers! if (NS_FAILED(rv) || !server) return NS_RDF_NO_VALUE; + + // order is: + // - default account + // - + // - Local Folders + // - news PRInt32 accountNum; nsCOMPtr am = do_QueryReferent(mAccountManager); - rv = am->FindServerIndex(server, &accountNum); - if (NS_FAILED(rv)) return rv; + + if (isDefaultServer(server)) + str = NS_LITERAL_STRING("0000"); + else { - accountNum += 1000; - str.AppendInt(accountNum); + rv = am->FindServerIndex(server, &accountNum); + if (NS_FAILED(rv)) return rv; + + // this is a hack for now - hardcode server order by type + nsXPIDLCString serverType; + server->GetType(getter_Copies(serverType)); + + if (nsCRT::strcasecmp(serverType, "none")==0) + accountNum += 2000; + else if (nsCRT::strcasecmp(serverType, "nntp")==0) + accountNum += 3000; + else + accountNum += 1000; // default is to appear at the top + + str.AppendInt(accountNum); + } } // GetTargets() stuff - need to return a valid answer so that