【发布时间】:2014-08-03 14:34:05
【问题描述】:
我构建了一个小的Thunderbird addon,它添加了一个工具栏按钮。它按预期工作。
但是,在某些情况下,按钮应该看起来是禁用的。这类似于 Thunderbird 的“回复”和“全部回复”按钮。如果没有选择电子邮件,则这些按钮看起来已禁用。
我想对我的插件做同样的事情。我已经编写了刷新按钮的算法,但我不知道如何触发它。当电子邮件列表中的选择发生变化时如何触发它?
代码已经过测试并且可以运行:
var OpenConversation = {
refresh: function () {
document.getElementById("open-conversation").disabled = ! OpenConversation.isEnabled()
},
// Based on: https://github.com/mozilla/releases-comm-central/blob/9ba3a1faeb6db90254d7e67d9d0dd630fd1a90be/mail/base/content/mail3PaneWindowCommands.js#L330-L360
isEnabled: function () {
let numSelected = GetNumSelectedMessages();
if (numSelected == 1) {
if (! gFolderDisplay.getCommandStatus(nsMsgViewCommandType.cmdRequiringMsgBody))
return false;
// Check if we have a collapsed thread selected and are summarizing it.
// If so, selectedIndices.length won't match numSelected. Also check
// that we're not displaying a message, which handles the case
// where we failed to summarize the selection and fell back to
// displaying a message.
if (gFolderDisplay.selectedIndices.length != numSelected &&
command != "cmd_applyFiltersToSelection" &&
gDBView && gDBView.currentlyDisplayedMessage == nsMsgViewIndex_None)
return false;
return true;
}
return false;
}
};
/*
* Instead of this, events should be used. Whenever user selects/deselects mails in
* the list, `OpenConversation.refresh()` should be triggered.
*/
window.setInterval(OpenConversation.refresh, 50);
【问题讨论】:
-
下载插件 DOMInspector 和 ElementInspector 并按住 shift+右键单击禁用的按钮。您可能会找到一个属性
disabled=true,然后您执行相同的操作来禁用您的按钮。顺便说一句土耳其语吧?酷:) tarkan! -
谢谢,我已经可以做到了(上面代码中的第 3 行)。我不能做的是在电子邮件选择更改时运行该代码(请参阅底部的
setInterval用法)。我怎样才能做到这一点?有什么特别活动吗?
标签: javascript firefox-addon mozilla thunderbird-addon