Open Bug 690631 Opened 13 years ago Updated 2 years ago

Command controllers should be more modular

Categories

(Thunderbird :: General, enhancement)

8 Branch
enhancement

Tracking

(Not tracked)

People

(Reporter: squib, Unassigned)

References

Details

Our command controllers should be refactored to be more modular so that extensions can override them more easily (or add all-new commands). The Add-on Manager does this[1]; here's a trimmed version of the code:

var gViewController = {
  commands: {
    cmd_back: {
      isEnabled: function() {
        return gHistory.canGoBack;
      },
      doCommand: function() {
        gHistory.back();
      }
    },
  },

  supportsCommand: function(aCommand) {
    return (aCommand in this.commands);
  },

  isCommandEnabled: function(aCommand) {
    if (!this.supportsCommand(aCommand))
      return false;
    var addon = this.currentViewObj.getSelectedAddon();
    return this.commands[aCommand].isEnabled(addon);
  },

  doCommand: function(aCommand, aAddon) {
    if (!this.supportsCommand(aCommand))
      return;
    var cmd = this.commands[aCommand];
    if (!aAddon)
      aAddon = this.currentViewObj.getSelectedAddon();
    if (!cmd.isEnabled(aAddon))
      return;
    cmd.doCommand(aAddon);
  },
};

[1]  http://mxr.mozilla.org/comm-central/source/mozilla/toolkit/mozapps/extensions/content/extensions.js#512
(In reply to Philip Chee from comment #1)
> Can't extensions just use  insertControllerAt()
> http://mxr.mozilla.org/comm-central/source/mozilla/content/xul/document/
> public/nsIControllers.idl#47

Hm, you're right. I suppose a better reason for this is that the code is considerably less messy, and we won't need to worry about bugs from switch statement fallthrough (like bug 670502).
Depends on: 633679
Depends on: 526998
No longer depends on: 633679
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.