From 9f9b65f9ddbca0004d1bacd8beba41f74c18d91c Mon Sep 17 00:00:00 2001 From: "timeless%mac.com" Date: Tue, 8 Oct 2002 23:58:58 +0000 Subject: [PATCH] Bug 173258 controller.QueryInterface(Components.interfaces.nsICommandController) should be in goUpdateComposerMenuItems instead of goUpdateCommandState r=cmanske, r=brade, sr=kin --- .../ui/composer/content/ComposerCommands.js | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/editor/ui/composer/content/ComposerCommands.js b/editor/ui/composer/content/ComposerCommands.js index 53d6562c8883..d7f1cbeef69d 100644 --- a/editor/ui/composer/content/ComposerCommands.js +++ b/editor/ui/composer/content/ComposerCommands.js @@ -343,7 +343,7 @@ function noUIStateUpdateNeeded(commandID) return false; } -function goUpdateCommandState(command) +function goUpdateCommandState(cmdController, command) { // this code need to be trimmed down and possibly reworked // when we move to nsICommandGroup for command handling @@ -368,16 +368,6 @@ function goUpdateCommandState(command) try { - var controller = top.document.commandDispatcher.getControllerForCommand(command); - if (!controller) return; - - var cmdController; - try - { - cmdController = controller.QueryInterface(Components.interfaces.nsICommandController); - } catch(e) {} - if (!cmdController) return; - var params = newCommandParams(); if (!params) return; @@ -433,17 +423,37 @@ function goUpdateCommandState(command) catch (e) { dump("An error occurred updating the "+command+" command: \n"+e+"\n"); } } +var gMenuControllers = [{key:null}]; + function goUpdateComposerMenuItems(commandset) { // dump("Updating commands for " + commandset.id + "\n"); - - for (var i = 0; i < commandset.childNodes.length; i++) - { + + for (var i = 0; i < commandset.childNodes.length; i++) { var commandID = commandset.childNodes[i].id; - if (commandID) - { + if (commandID) { goUpdateCommand(commandID); // enable or disable - goUpdateCommandState(commandID); + var controller = top.document.commandDispatcher.getControllerForCommand(commandID); + if (controller) { + /* gMenuControllers contains a single entry buffer to allow for --j */ + for (var j = gMenuControllers.length; + --j && gMenuControllers[j].key != controller; + ); + + if (!j) { + /* obj stores the controller for the command and whether the QI succeeded */ + var obj = {key:controller, isCommandController:false}; + try { + /* QI modifies the object including the one wrapped in obj.key */ + controller.QueryInterface(Components.interfaces.nsICommandController); + obj.isCommandController = true; + } catch(e) {} + j = gMenuControllers.length; + gMenuControllers[j] = obj; + } + if (gMenuControllers[j].isCommandController) + goUpdateCommandState(controller, commandID); + } } } }