メニューの enabled/disabled の仕方を追った。
- controller は window.controllers.appendController メソッド等から登録する
- controller とは以下のメソッドを備える
- supportsCommand (cmdName) // そのコントローラが管理する cmdName なら true を返すこと
- isCommandEnabled (cmdName) // そのコマンドが現在使える状態かを true / false で返すこと
- doCommand (cmdName) // そのコマンドを実行する
- onEvent (event) // 空メソッドであることが多い
- cmdName は command 要素の id 属性値である
- 多くは <menuitem command="cmdName"/> <command id="cmdName"/> で結びついている
- command 要素が disabled の場合、結びつく command , key , button 要素も disabled になる
<menupopup id="menu_GoPopup" onpopupshowing="InitGoMessagesMenu();">
<menuitem ..../>
</menupopup>
function InitGoMessagesMenu() {
document.commandDispatcher.updateCommands("create-menu-go");
}
document.commandDispatcher.updateCommands はたぶん、commandset events="create-menu-go" に commandupdate イベントを送る?
<commandset id="mailGoMenuItems"
commandupdator="true"
events="create-menu-go"
oncommandupdate="goUpdateMailMenuItems(this)">
<command ..../>
</commandset>
function goUpdateMailMenuItems(commandset) {
for (var i = 0; i < commandset.childNodes.length; i++) {
var commandID = commandset.childNodes[i].getAttribute("id");
if (commandID) {
goUpdateCommand(commandID);
}
}
}
function goUpdateCommand(aCommand) {
try {
var controller = top.document.commandDispatcher.getControllerForCommand(aCommand);
var enabled = false;
if (controller) {
enabled = controller.isCommandEnabled(aCommand);
}
goSetCommandEnabled(aCommand, enabled);
} catch (e) {
dump("An error occurred updating the " + aCommand + " command\n");
}
}
function goSetCommandEnabled(aID, aEnabled) {
var node = document.getElementById(aID);
if (node) {
if (aEnabled) {
node.removeAttribute("disabled");
} else {
node.setAttribute("disabled", "true");
}
}
}