Whole document tree
7.2. A quick example of using GnomeAppHelperThis section presents a simple example of creating a menu bar for an application window. The menu bar would serve for a hypotetical text editing application. The purpose of this example is to give you a general idea of how GnomeAppHelper works. GnomeAppHelper uses a hierarchy of arrays to define menus and tool bars. Here we will define a simple menu bar with three submenus, called File, Edit, and Help. We will use the stock icon mechanism to provide standard icons for the menu items, and we will provide hot keys for the most common functions. In the example above, you can see the most general form of defining arrays of GnomeUIInfo structures to construct a menu hierarchy. Each structure in the array contains information about the type of item to be created, its label, hint, and pixmap, its associated callback, and keyboard accelerators. You can see that text labels are marked with the N_() macro. This macro is used by the internationalization programs to detech which strings to mark for translation. The last item in GnomeUIInfo arrays marks termination of the array. Finally, the main_menu array ties all the submenus together to form the main menu bar. The following sections explain GnomeUIInfo structures in detail. You do not need to remember all the details to use GnomeAppHelper; it also provides convenient macros to make creating simple items easier, as we shall see. The gnome_app_create_menus() function is the simplest way to create a menu bar's widgets out of a GnomeUIInfo array. There are other functions to create menus and toolbars, as we will see below. |