Re: action menu demo (again)

(cc'ing gtk-devel-list as well, in case anyone else is interested)

Joshua N Pritikin wrote:

On Fri, Dec 07, 2001 at 02:53:04PM +0800, James Henstridge wrote:

With this patch applied, the code works perfectly.

I put the updated version up at:

i've looked at your gmenu demo a little bit.

What is the advantage of gmenu over the existing gtk+ API?  Do u have a
web page explaining the motivation behind your code?

At the moment, there is a large number of menu APIs that a programmer can use: GtkItemFactory, GnomeUIInfo, Bonobo's UI handler and manually creating menus. One problem with this is that switching a gtk app to gnome may entail rewriting all the menuing code. Having an app that can be built with or without gnome support (may be necessary for portability to platforms where the gnome libs haven't been ported), is a big pain due to the different APIs.

Having an API in gtk+ that could be extended for the needs of bonobo/gnome would simplify things a lot. It is too late to put something like this in gtk+ 2.0, but it is a possibility for 2.2. As 2.2 is going to be backward compatible with 2.0, such a menuing system needs to be implementable with the current menu/accelerator code. At the moment, my code is mainly a proof of concept for the new menuing code.

Out of the options, Bonobo's verb based approach is one of the nicer APIs, so I based my code on it's model.

Rather than attaching handlers to the activate signal of menu item widgets, you create a number of GMenuAction objects. These objects hold a label, stock icon, tooltip, and callback. It is possible to attach accelerators to these action objects as well, to handle keyboard shortcuts. As well as normal actions, there are also toggle and radio actions that act like check and radio menu items.

Each action object can have any number of menu items or toolbar buttons acting as `views'. When the menu item is activated, it activates the action it is associated with. The menu items/toolbars mirror the state of their associated action (eg. all menu items and toolbar buttons associated with a toggle action show the same state).

For menu items, dynamic accelerator changing works now, with the accelerators getting set on the action objects. In the first menu in the demo, you can see two "Bold" menu items. Notice that they both display the same keyboard shortcut on the right. If you try to dynamically change the accelerator, you will notice that the displayed keyboard shortcut changes on both menu items.

For constructing menus/toolbars from the group of available actions, I wrote some code that reads an XML file in the format used by the Bonobo UI handler, and creates the menus/toolbars (this is nowhere near as sophisticated as the bonobo code, as it doesn't handle menu merging).

No doubt the APIs in the demo need a lot of work, but it shows that it should be possible to build a very nice API for 2.2.


Email: james daa com au

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]