root/gaphor/tags/gaphor-0.12.3/doc/actions.txt

Revision 1310, 3.4 kB (checked in by arj..@yirdis.nl, 2 years ago)
  • Added item_at(x, y) method to diagram items.
  • updated class editor to use item_at()
Line 
1 Actions, menu items, toolbars and toolboxes
2 ===========================================
3
4 The GTK+ structure is like this::
5
6     UIManager
7         |
8    ActionGroup
9         |
10      Action
11
12 The do_activate signal is emitted when an action is activated.
13
14 Where it should lead:
15  * Actions should be coded closer to the object their working on
16     - main actions - not dependent on GUI components (load/save/new/quit)
17     - main actions dependent on GUI component (sub-windows, console)
18     - Item actions, act either on a diagram, the selected or focused item
19       or no item.
20     - diagram actions (zoom, grid) work on active diagram (tab)
21     - menus and actions for diagram items through adapters
22  
23  * Actions should behave more like adapters. E.g. when a popup menu is created
24    for an Association item, the menu actions should present themselves in the
25    context of that menu item (with toggles set right)
26     - Could be registered as adapters with a name.
27
28  * Each window has it's own action group (every item with a menu?)
29  * One toplevel UIManager per window or one per application/gui_manager?
30  * Normal actions can be modeled as functions. If an action is sensitive or
31    visible depends on the state in the action. Hence we require the update()
32    method.
33
34  * create services for for "dynamic" menus (e.g. recent files/stereotypes)
35
36
37 Solution for simple actions
38 ---------------------------
39
40 For an action to actually be useful a piece of menu xml is needed.
41
42 Hence an interface IActionProvider has to be defined::
43
44     class IActionProvider(interface.Interface):
45         menu_xml = interface.Attribute("The menu XML")
46         action_group = interface.Attribute("The accompanying ActionGroup")
47
48 Support for actions can be arranged by decorating actions with an @action
49 decorator and let the class create an ActionGroup using some
50 actionGroup factory function (no inheritance needed here).
51
52 Note that ActionGroup is a GTK class and should technically only be used in the
53 gaphor.ui package.
54
55 Autonom controllers can be defined, which provide a piece of functionality.
56 They can register handlers in order to update their state.
57
58 Maybe it's nice to configure those through the egg-info system. I suppose
59 gaphor.service will serve well (as they need to be initialized anyway)
60  ==> also inherit IActionProvider from IService?
61
62     [gaphor.services]
63     xx = gaphor.actions.whatever:SomeActionProviderClass
64
65
66 Solution for context sensitive menus
67 ------------------------------------
68
69 Context sensitive menus, such as popup menus, should be generated and switched
70 on and off on demand.
71
72 Technically they should be enabled through services/action-providers.
73
74 It becomes even tougher when popup menu's should act on parts of a diagram item
75 (such as association ends). This should be avoided. It may be a good idea to
76 provide such functionality through a special layer on the canvas, by means of
77 some easy clickable buttons around the "hot spot" (we already have something
78 like that for text around association ends).
79
80 Scheme:
81 1. User selects an item and presses the rigth mouse button: a popup menu
82    should be displayed.
83 2. find the actual item (this may be a composite item of the element drawn).
84    Use an IItemPicker adapter for that (if no such interface is available,
85    use the item itself).
86 2. Find a IActionProvider adapters for the selected (focused) item.
87 3. update the popup menu context (actions) for the selected item.
88
Note: See TracBrowser for help on using the browser.