Bug 1877390 - Reduce code duplication in about3pane.js and threadPane.js. r=aleca
In threadPane.js exists similar code as in about3pane.js, to convert the sort type of the current sort column into a columnId. This patch moves these functions as an additional getter into DBViewWrapper.jsm. To avoid circular dependencies, this patch moves OUTGOING_FOLDER_FLAGS from DBViewWrapper.jsm to FolderUtils.jsm. Differential Revision: https://phabricator.services.mozilla.com/D200242 --HG-- extra : rebase_source : 1e47ef7b626915999d743915cd842d55fc3bb7d9
This commit is contained in:
Родитель
ff677d05c9
Коммит
efd02ab3e8
|
@ -4775,7 +4775,7 @@ var threadPane = {
|
|||
if (!gDBView) {
|
||||
return;
|
||||
}
|
||||
this.updateSortIndicator(sortController.getCurrentSortColumnId());
|
||||
this.updateSortIndicator(gViewWrapper.primarySortColumnId);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -5079,7 +5079,7 @@ var threadPane = {
|
|||
* @param {object} data - The detail of the custom event.
|
||||
*/
|
||||
onSortChanged(data) {
|
||||
const curSortColumnId = sortController.getCurrentSortColumnId();
|
||||
const curSortColumnId = gViewWrapper.primarySortColumnId;
|
||||
const newSortColumnId = data.column;
|
||||
|
||||
// A click happened on the column that is already used to sort the list.
|
||||
|
@ -6208,91 +6208,6 @@ var sortController = {
|
|||
threadPane.ensureThreadStateForQuickSearchView();
|
||||
threadTree.style.scrollBehavior = null;
|
||||
},
|
||||
getCurrentSortColumnId() {
|
||||
const sortKey = gViewWrapper.primarySortType;
|
||||
let columnID;
|
||||
|
||||
switch (sortKey) {
|
||||
// In the case of None, we default to the date column. This appears to be
|
||||
// the case in such instances as Global search, so don't complain about
|
||||
// it.
|
||||
case Ci.nsMsgViewSortType.byNone:
|
||||
case Ci.nsMsgViewSortType.byDate:
|
||||
columnID = "dateCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byReceived:
|
||||
columnID = "receivedCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byAuthor:
|
||||
columnID = "senderCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byRecipient:
|
||||
columnID = "recipientCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.bySubject:
|
||||
columnID = "subjectCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byLocation:
|
||||
columnID = "locationCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byAccount:
|
||||
columnID = "accountCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byUnread:
|
||||
columnID = "unreadButtonColHeader";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byStatus:
|
||||
columnID = "statusCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byTags:
|
||||
columnID = "tagsCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.bySize:
|
||||
columnID = "sizeCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byPriority:
|
||||
columnID = "priorityCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byFlagged:
|
||||
columnID = "flaggedCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byThread:
|
||||
columnID = "threadCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byId:
|
||||
columnID = "idCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byJunkStatus:
|
||||
columnID = "junkStatusCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byAttachments:
|
||||
columnID = "attachmentCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byCustom:
|
||||
{
|
||||
const curCustomColumn = gDBView.curCustomColumn;
|
||||
if (threadPane.columns.some(c => c.id == curCustomColumn)) {
|
||||
columnID = curCustomColumn;
|
||||
} else {
|
||||
dump(
|
||||
"getCurrentSortColumnId: custom sort key but no handler for column '" +
|
||||
columnID +
|
||||
"'\n"
|
||||
);
|
||||
columnID = "dateCol";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byCorrespondent:
|
||||
columnID = "correspondentCol";
|
||||
break;
|
||||
default:
|
||||
dump("unsupported sort key: " + sortKey + "\n");
|
||||
columnID = "dateCol";
|
||||
break;
|
||||
}
|
||||
return columnID;
|
||||
},
|
||||
};
|
||||
|
||||
commandController.registerCallback(
|
||||
|
|
|
@ -368,7 +368,10 @@ FolderDisplayWidget.prototype = {
|
|||
* will not get this notification if the view was re-created, for example.
|
||||
*/
|
||||
onSortChanged() {
|
||||
UpdateSortIndicators(this.view.primarySortType, this.view.primarySortOrder);
|
||||
UpdateSortIndicators(
|
||||
this.view.primarySortColumnId,
|
||||
this.view.primarySortOrder
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,8 +15,8 @@ XPCOMUtils.defineLazyPreferenceGetter(
|
|||
);
|
||||
|
||||
ChromeUtils.defineESModuleGetters(lazy, {
|
||||
DBViewWrapper: "resource:///modules/DBViewWrapper.sys.mjs",
|
||||
FeedUtils: "resource:///modules/FeedUtils.sys.mjs",
|
||||
FolderUtils: "resource:///modules/FolderUtils.sys.mjs",
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -290,10 +290,7 @@ const DEFAULT_COLUMNS = [
|
|||
* @returns {boolean} True if the folder is Outgoing.
|
||||
*/
|
||||
const isOutgoing = folder => {
|
||||
return folder.isSpecialFolder(
|
||||
lazy.DBViewWrapper.prototype.OUTGOING_FOLDER_FLAGS,
|
||||
true
|
||||
);
|
||||
return folder.isSpecialFolder(lazy.FolderUtils.OUTGOING_FOLDER_FLAGS, true);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -340,7 +340,7 @@ function MsgReverseSortThreadPane() {
|
|||
|
||||
// XXX this should probably migrate into FolderDisplayWidget, or whatever
|
||||
// FolderDisplayWidget ends up using if it refactors column management out.
|
||||
function UpdateSortIndicators(sortType, sortOrder) {
|
||||
function UpdateSortIndicators(colID, sortOrder) {
|
||||
// Remove the sort indicator from all the columns
|
||||
const treeColumns = document.getElementById("threadCols").children;
|
||||
for (let i = 0; i < treeColumns.length; i++) {
|
||||
|
@ -349,7 +349,6 @@ function UpdateSortIndicators(sortType, sortOrder) {
|
|||
|
||||
let sortedColumn;
|
||||
// set the sort indicator on the column we are sorted by
|
||||
const colID = ConvertSortTypeToColumnID(sortType);
|
||||
if (colID) {
|
||||
sortedColumn = document.getElementById(colID);
|
||||
}
|
||||
|
@ -414,91 +413,4 @@ function UpdateSelectCol() {
|
|||
}
|
||||
}
|
||||
|
||||
function ConvertSortTypeToColumnID(sortKey) {
|
||||
var columnID;
|
||||
|
||||
// Hack to turn this into an integer, if it was a string.
|
||||
// It would be a string if it came from XULStore.json.
|
||||
sortKey = sortKey - 0;
|
||||
|
||||
switch (sortKey) {
|
||||
// In the case of None, we default to the date column
|
||||
// This appears to be the case in such instances as
|
||||
// Global search, so don't complain about it.
|
||||
case Ci.nsMsgViewSortType.byNone:
|
||||
case Ci.nsMsgViewSortType.byDate:
|
||||
columnID = "dateCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byReceived:
|
||||
columnID = "receivedCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byAuthor:
|
||||
columnID = "senderCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byRecipient:
|
||||
columnID = "recipientCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.bySubject:
|
||||
columnID = "subjectCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byLocation:
|
||||
columnID = "locationCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byAccount:
|
||||
columnID = "accountCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byUnread:
|
||||
columnID = "unreadButtonColHeader";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byStatus:
|
||||
columnID = "statusCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byTags:
|
||||
columnID = "tagsCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.bySize:
|
||||
columnID = "sizeCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byPriority:
|
||||
columnID = "priorityCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byFlagged:
|
||||
columnID = "flaggedCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byId:
|
||||
columnID = "idCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byJunkStatus:
|
||||
columnID = "junkStatusCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byAttachments:
|
||||
columnID = "attachmentCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byCustom:
|
||||
// TODO: either change try() catch to if (property exists) or restore the getColumnHandler() check
|
||||
try {
|
||||
// getColumnHandler throws an error when the ID is not handled
|
||||
columnID = window.gDBView.curCustomColumn;
|
||||
} catch (err) {
|
||||
// error - means no handler
|
||||
dump(
|
||||
"ConvertSortTypeToColumnID: custom sort key but no handler for column '" +
|
||||
columnID +
|
||||
"'\n"
|
||||
);
|
||||
columnID = "dateCol";
|
||||
}
|
||||
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byCorrespondent:
|
||||
columnID = "correspondentCol";
|
||||
break;
|
||||
default:
|
||||
dump("unsupported sort key: " + sortKey + "\n");
|
||||
columnID = "dateCol";
|
||||
break;
|
||||
}
|
||||
return columnID;
|
||||
}
|
||||
|
||||
addEventListener("load", ThreadPaneOnLoad, true);
|
||||
|
|
|
@ -9,6 +9,8 @@ import {
|
|||
MailViewManager,
|
||||
} from "resource:///modules/MailViewManager.sys.mjs";
|
||||
import { SearchSpec } from "resource:///modules/SearchSpec.sys.mjs";
|
||||
import { ThreadPaneColumns } from "chrome://messenger/content/thread-pane-columns.mjs";
|
||||
import { FolderUtils } from "resource:///modules/FolderUtils.sys.mjs";
|
||||
|
||||
import { VirtualFolderHelper } from "resource:///modules/VirtualFolderWrapper.sys.mjs";
|
||||
|
||||
|
@ -1537,11 +1539,6 @@ DBViewWrapper.prototype = {
|
|||
);
|
||||
},
|
||||
|
||||
OUTGOING_FOLDER_FLAGS:
|
||||
Ci.nsMsgFolderFlags.SentMail |
|
||||
Ci.nsMsgFolderFlags.Drafts |
|
||||
Ci.nsMsgFolderFlags.Queue |
|
||||
Ci.nsMsgFolderFlags.Templates,
|
||||
/**
|
||||
* @returns true if the folder is an outgoing folder by virtue of being a
|
||||
* sent mail folder, drafts folder, queue folder, or template folder,
|
||||
|
@ -1550,7 +1547,10 @@ DBViewWrapper.prototype = {
|
|||
get isOutgoingFolder() {
|
||||
return (
|
||||
this.displayedFolder &&
|
||||
this.displayedFolder.isSpecialFolder(this.OUTGOING_FOLDER_FLAGS, true)
|
||||
this.displayedFolder.isSpecialFolder(
|
||||
FolderUtils.OUTGOING_FOLDER_FLAGS,
|
||||
true
|
||||
)
|
||||
);
|
||||
},
|
||||
/**
|
||||
|
@ -1598,6 +1598,96 @@ DBViewWrapper.prototype = {
|
|||
}
|
||||
},
|
||||
|
||||
get primarySortColumnId() {
|
||||
const sortKey = this.primarySortType;
|
||||
let columnID;
|
||||
|
||||
switch (sortKey) {
|
||||
// In the case of None, we default to the date column. This appears to be
|
||||
// the case in such instances as Global search, so don't complain about
|
||||
// it.
|
||||
case Ci.nsMsgViewSortType.byNone:
|
||||
case Ci.nsMsgViewSortType.byDate:
|
||||
columnID = "dateCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byReceived:
|
||||
columnID = "receivedCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byAuthor:
|
||||
columnID = "senderCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byRecipient:
|
||||
columnID = "recipientCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.bySubject:
|
||||
columnID = "subjectCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byLocation:
|
||||
columnID = "locationCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byAccount:
|
||||
columnID = "accountCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byUnread:
|
||||
columnID = "unreadButtonColHeader";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byStatus:
|
||||
columnID = "statusCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byTags:
|
||||
columnID = "tagsCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.bySize:
|
||||
columnID = "sizeCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byPriority:
|
||||
columnID = "priorityCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byFlagged:
|
||||
columnID = "flaggedCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byThread:
|
||||
columnID = "threadCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byId:
|
||||
columnID = "idCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byJunkStatus:
|
||||
columnID = "junkStatusCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byAttachments:
|
||||
columnID = "attachmentCol";
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byCustom:
|
||||
{
|
||||
const curCustomColumn = this.dbView.curCustomColumn;
|
||||
if (
|
||||
ThreadPaneColumns.getCustomColumns().some(
|
||||
c => c.id == curCustomColumn
|
||||
)
|
||||
) {
|
||||
columnID = curCustomColumn;
|
||||
} else {
|
||||
dump(
|
||||
"getCurrentSortColumnId: custom sort key but no handler for column '" +
|
||||
columnID +
|
||||
"'\n"
|
||||
);
|
||||
columnID = "dateCol";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Ci.nsMsgViewSortType.byCorrespondent:
|
||||
columnID = "correspondentCol";
|
||||
break;
|
||||
default:
|
||||
dump("unsupported sort key: " + sortKey + "\n");
|
||||
columnID = "dateCol";
|
||||
break;
|
||||
}
|
||||
return columnID;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns the primary sort type (as one of the numeric constants from
|
||||
* nsMsgViewSortType).
|
||||
|
|
|
@ -6,6 +6,12 @@
|
|||
* This file contains helper methods for dealing with nsIMsgFolders.
|
||||
*/
|
||||
|
||||
const OUTGOING_FOLDER_FLAGS =
|
||||
Ci.nsMsgFolderFlags.SentMail |
|
||||
Ci.nsMsgFolderFlags.Drafts |
|
||||
Ci.nsMsgFolderFlags.Queue |
|
||||
Ci.nsMsgFolderFlags.Templates;
|
||||
|
||||
export var FolderUtils = {
|
||||
allAccountsSorted,
|
||||
compareAccounts,
|
||||
|
@ -17,6 +23,7 @@ export var FolderUtils = {
|
|||
canRenameDeleteJunkMail,
|
||||
isSmartTagsFolder,
|
||||
isSmartVirtualFolder,
|
||||
OUTGOING_FOLDER_FLAGS,
|
||||
};
|
||||
|
||||
import { MailServices } from "resource:///modules/MailServices.sys.mjs";
|
||||
|
|
Загрузка…
Ссылка в новой задаче