On Apr 17, 2006, at 8:16 AM, bulia byak wrote:
This works for toolbar buttons because they are always on the same fixed desktop. But dialog buttons may apply, with their dialog, to different desktops. Do we have to recreate the action on each desktop switch (sensed by the dialog) and reassign that new action to the button? Mental, can you suggest a solution?
One general solution to decoupling this safely (and one that The GIMP uses), is to have things hooked to a "Context" object. This works as basically a mediator pattern.
When an action is created, it can be created to the Context instead of a Desktop directly. Then the Context follows the current Desktop (either as things are switched, or upon actual use by calling sp_active_desktop) and passes things along.
This context object could be built into the dialog class itself, or could be something separate. Also... it could be a separate class, or might just be a collection of aspects of code in the dialog itself. it doesn't matter quite as much how it's coded, just that this is the abstract design concept that would be involved.
Oh, one other thing to do would probably be to track the change of active desktop as it happens. Then the appropriate buttons in the dialog could be disabled and enabled as appropriate. In Aaron's case here that would involve a simple check on desktop switch to see if a non-empty selection is present. Then if so, the Context or dialog would disable or enable the proper Actions and the UI would do the helpful thing.