← Back to team overview

kicad-developers team mailing list archive

[RFC] Switch from SyncToolbars to wxUpdateUIEvent


Following on from the discussion in this merge request (
https://code.launchpad.net/~imcinerney/kicad/+git/kicad/+merge/371156), I
thought a little about if the current framework could be adapted to use the
wxUpdateUIEvent handlers to do the synchronization, and I think it can be.
Here is my thinking of how it can be done, and I would appreciate comments
about this idea.

>From my understanding there are three classes that will create menu/toolbar
items that need to be synced: ACTION_MENU, ACTION_TOOLBAR, and
CONDITIONAL_MENU. The first change would be to make the Add functions for
all of these classes take a SelectionConditions argument that will be used
to define the enable/checkmark status of the item (currently only
CONDITIONAL_MENU takes these).

First question, do we need to synchronize any items that aren't
action-based? If we will only synchronize action-based items, then only
those Add functions would need to be extended.

The TOOL_MANAGER would then handle the majority of the work. The Add
functions would call into the TOOL_MANAGER requesting an event handler be
created, passing the selection conditions as well.

To create the event handler, the TOOL_MANAGER would do the following:
1) Consult a list that associates actions with their selection conditions
(being on the list would indicate the action already has a handler in the
window containing the tool manager).
2) If the action is on the list, compare the provided selection condition
with what is already in the list, and if they are different from each
other, assert (this will require selection conditions used in multiple
places in the same tool manager for the same action to point to the same
object). This way the code is kept synchronized as well.
3) If it is not on the list, then call Bind and bind an event handler for
the event. The selection condition would be passed into the Bind as the
user data so that it can be used in the handler. This handler would be
bound to the parent of the tool manager.

There would be two handlers, one for checkmark entries and one for
enable/disable entries, and the correct one would be bound based on the
type of menu item. These would modify the aEvent object to actually
check/enable/disable the UI element (like what the original handlers did).

I believe this will remove the need for the SyncToolbars functions (and the
need for the tool manager to explicitly call this, which had caused some
issues in the past if I remember correctly). It will also mean that the
conditional menu's Evaluate function would no longer need to do the
checking/enabling itself, since that is handled in the event handler.



Follow ups