XUL: Overlay state is not updated across multiple windows
I'm having problems with the appearance of my overlay which is dependent on the current state of the add-on.
I have a Menu Tools Popup Item e.g. 'Set Visible'. When selected, it shows something e.g. 'Sample Text' as a menu item in the Content Area Context Menu Popup. When unselected, 'Sample Text' is hidden. It works fine within a window, but the problem is when another window is already open.
Let's call the original window, Window A and the new window, Window B. When I select 'Set Visible' from Window A, the 'Sample Text' is shown in Window A, but when I switch to Window B, the 'Set Visible' in its Tools Menu stays unselecte开发者_Go百科d and that the 'Sample Text' remains hidden. I want to implement this feature across multiple windows such that when I make changes with a window, the other window instances will have its state updated as well. How should I address this?
As an additional information, when I select 'Set Visible' in Window A and open a new window, say Window C, the changes are accurately reflected in Window C i.e. the 'Set Visible' is selected from the Tools Menu and that 'Sample Text' becomes visible within Window C.
Each overlay operates on its own window only. If you want a change to affect all overlays then you need some central instance that will notify them. The most basic way to do this is to change a preference when "Set Visible" is clicked. All your overlays should register a listener for this preference so that when this preference is changed they can take the necessary actions.
The other way is to have a JavaScript code module in your extension (a module only loads once) and manage the state of "Set Visible" button there. Each overlay needs to load the module and register its listener function there. When the button is clicked later a module function should be called that will call all registered listener functions.
精彩评论