Bug 441666 - Filter dialog fails to list newsgroups. r/sr=bienvenu

This commit is contained in:
Joshua Cranmer 2008-08-29 15:08:31 -04:00
Родитель 2652ff39a4
Коммит 52c7d604f9
3 изменённых файлов: 70 добавлений и 20 удалений

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

@ -41,7 +41,7 @@ const MSG_FOLDER_FLAG_INBOX = 0x1000
var gFilterListMsgWindow = null;
var gCurrentFilterList;
var gCurrentServer;
var gCurrentFolder;
var gStatusFeedback = {
progressMeterVisible : false,
@ -110,28 +110,28 @@ function onLoad()
firstItem = getServerThatCanHaveFilters();
if (firstItem) {
selectServer(firstItem);
selectFolder(firstItem.rootFolder);
}
window.tryToClose = onFilterClose;
}
/**
* Called when a user selects a server in the list, so we can update the filters
* Called when a user selects a folder in the list, so we can update the filters
* that are displayed
*
* @param aServer the nsIMsgIncomingServer that was selected
* @param aFolder the nsIMsgFolder that was selected
*/
function onFilterServerClick(aServer)
function onFilterFolderClick(aFolder)
{
if (!aServer || aServer == gCurrentServer)
if (!aFolder || aFolder == gCurrentFolder)
return;
// Save the current filters to disk before switching because
// the dialog may be closed and we'll lose current filters.
gCurrentFilterList.saveToDefaultFile();
selectServer(aServer);
selectFolder(aFolder);
}
function CanRunFiltersAfterTheFact(aServer)
@ -145,14 +145,12 @@ function CanRunFiltersAfterTheFact(aServer)
return aServer.canSearchMessages;
}
// roots the tree at the specified server
function setServer(aServer)
// roots the tree at the specified folder
function setFolder(msgFolder)
{
if (aServer == gCurrentServer)
if (msgFolder == gCurrentFolder)
return;
var msgFolder = aServer.rootFolder;
//Calling getFilterList will detect any errors in rules.dat, backup the file, and alert the user
var filterList = msgFolder.getFilterList(gFilterListMsgWindow);
rebuildFilterList(filterList);
@ -171,6 +169,7 @@ function setServer(aServer)
// for POP3 and IMAP, select the first folder, which is the INBOX
document.getElementById("runFiltersFolder").selectedIndex = 0;
runMenu.selectFolder(getFirstFolder(msgFolder));
}
else {
document.getElementById("runFiltersFolder").setAttribute("hidden", "true");
@ -180,10 +179,9 @@ function setServer(aServer)
// Get the first folder for this server. INBOX for
// imap and pop accts and 1st news group for news.
runMenu.selectFolder(getFirstFolder(msgFolder));
updateButtons();
gCurrentServer = aServer;
gCurrentFolder = msgFolder;
}
function toggleFilter(aFilter, aIndex)
@ -204,13 +202,13 @@ function toggleFilter(aFilter, aIndex)
}
// sets up the menulist and the filter list
function selectServer(aServer)
function selectFolder(aFolder)
{
// update the server menu
var serverMenu = document.getElementById("serverMenuPopup");
serverMenu.selectFolder(aServer.rootFolder);
serverMenu.selectFolder(aFolder);
setServer(aServer);
setFolder(aFolder);
}
function currentFilter()

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

@ -71,8 +71,9 @@
accesskey="&filtersForPrefix.accesskey;" control="serverMenu"/>
<menulist id="serverMenu"
oncommand="onFilterServerClick(event.target._folder.server)">
<menupopup id="serverMenuPopup" type="folder" mode="filters" expandFolders="false"/>
oncommand="onFilterFolderClick(event.target._folder)">
<menupopup id="serverMenuPopup" type="folder" mode="filters"
expandFolders="nntp" headlabels="&choosethisnewsserver.label;" />
</menulist>
<spacer flex="1"/>
<vbox>

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

@ -395,11 +395,43 @@
if (this._parentFolder)
folders = folders.sort(nameCompare);
/* In some cases, the user wants to have a list of subfolders for only
* some account types (or maybe all of them). So we use this to
* determine what the user wanted.
*/
var shouldExpand;
var labels = null;
if (this.getAttribute("expandFolders") == "true" ||
!this.hasAttribute("expandFolders")) {
shouldExpand = function (e) { return true; };
} else if (this.getAttribute("expandFolders") == "false") {
shouldExpand = function (e) { return false; };
} else {
/* We want a subfolder list for only some servers. We also may need
* to create headers to select the servers. If so, then headlabels
* is a comma-delimited list of labels corresponding to the server
* types specified in expandFolders.
*/
var types = this.getAttribute("expandFolders").split(/ *, */);
// Set the labels. labels[type] = label
if (this.hasAttribute("headlabels")) {
var labelNames = this.getAttribute("headlabels").split(/ *, */);
labels = {};
// If the length isn't equal, don't give them any of the labels,
// since any combination will probably be wrong.
if (labelNames.length == types.length) {
for (var index in types)
labels[types[index]] = labelNames[index];
}
}
shouldExpand = function (e) { return types.indexOf(e) != -1; };
}
for each (var folder in folders) {
var node;
// If we're going to add subFolders, we need to make menus, not
// menuitems.
if (!folder.hasSubFolders || this.getAttribute("expandFolders") == "false") {
if (!folder.hasSubFolders || !shouldExpand(folder.server.type)) {
node = document.createElement("menuitem");
// Grumble, grumble, legacy code support
node.setAttribute("id", folder.URI);
@ -411,8 +443,20 @@
node = document.createElement("menu");
node.setAttribute("class", "folderMenuItem menu-iconic");
this.appendChild(node);
// Create the submenu
var popup = this.cloneNode(true);
popup._teardown();
// If there are labels, add the labels now
if (labels) {
var serverNode = document.createElement("menuitem");
serverNode.setAttribute("label", labels[folder.server.type]);
serverNode._folder = folder;
popup.appendChild(serverNode);
popup.appendChild(document.createElement("menuseparator"));
}
node.appendChild(popup);
popup.parentFolder = folder;
}
@ -625,6 +669,13 @@
this.parentNode.selectedIndex = i;
return;
}
// Is this a subfolder (that we expect to see)?
if (child.tagName == "menu" && child._folder.isAncestorOf(aFolder)) {
// If this is a subfolder of what's in question, we merely appear
// to select this node.
this.parentNode.setAttribute("label", aFolder.name);
return;
}
}
throw "unable to find folder to select!";
]]></body>