Search code examples
firefox-addonfirefox-addon-sdkcontextmenu

How to deactivate an item of the context-menu (Mozilla addon-kit)


I would like to deactivate all top-level context-menu-items of my addon under certain circumstances (for example when the addon has been disabled by the user).
Somehow I can't figure out how this is done except for completely destroying the item; but I'd prefer using a method that allows easy switching between deactivation and activation.
There must be some way around the missing of an remove- or deactivate-method. For items that are not on top-level but belong to a submenu this is easyly done with the methods addItem() and removeItem() of the parentMenu.


EDIT:
Items on top-level do have the property parentMenu- which is null though. So the problem seems to be that the context-menu.js only offers removeItem/addItem methods for the submenus but not for the parentNode of top-level items.


I still find the context-menu-api kind of confusing. There is no onClick method for the item. It seems to me that I need a content script for every item, instead(?)
Also, I havent found a way to place items on top-level where I want (instead of being forced to the bottom).


Solution

  • Upcoming changes in the SDK's context-menu module due to ship at the end of the month should allow you to use addItem()/removeItem(). This re-written implementation of the context-menu module will ship in SDK 1.13. Currently there is no way to 'deactivate' an item programmatically until this new version is available.