Actions, Menus and Toolbars - Introduction: libgedit-amtk 5 Reference Manual

## Actions, Menus and Toolbars - Introduction Actions, Menus and Toolbars - Introduction — Overview of the Actions, Menus and Toolbars Kit |

“Amtk” initially was the acronym for “Actions, Menus and Toolbars Kit”. It provides a basic GtkUIManager replacement based on GAction that is suitable for both a traditional UI or a modern UI with a GtkHeaderBar.

GtkUIManager has been deprecated in GTK 3 (and removed in GTK 4), without a good replacement for applications that want to keep a traditional UI (with a GtkMenuBar, a GtkToolbar and a GtkStatusbar). libgedit-amtk is also suitable for a new UI with a GtkHeaderBar and a “sandwich menu”.

With libgedit-amtk, menus, toolbars or other objects like GtkShortcutsWindow are created programmatically (not with a *.ui file), but with convenient APIs. The support for an XML format will maybe be added in the future.

Note that the heavy-lifting is still done by GTK of course (and GIO for GAction). This library is just a small layer on top, providing an alternative way of doing things.

## General advantages

- Primarily, encoding the information about an action only once, to create various objects such as a menu item, a toolbar item, a GtkShortcutsShortcut, etc. The information needed about an action: a label (i.e. a short description), possibly an icon, a tooltip (i.e. a longer description) and keyboard shortcuts. This is implemented by AmtkActionInfo, with AmtkFactory functions to create various objects.

  This also has the nice benefit that all the information about an action is centralized in only one place, to keep related information close together. This permits to more easily catch inconsistencies.

- libgedit-amtk has been designed to be able to share AmtkActionInfo's in a library (with translations); this is a bit similar to GtkStockItem, to reduce the amount of work that an application (and translators) need to do. As a result the library can provide a higher-level API.

## Advantages for a traditional UI

- When writing an XML file to create a GMenu with the format understood by GtkBuilder (see the class description of GtkApplicationWindow), the information in the XML file can be used only to create a GMenu, not a toolbar. It is not a good programming practice to duplicate the information. With libgedit-amtk the information is encoded just once, in AmtkActionInfo's, and menu and toolbar items are created with AmtkFactory which uses the information provided by the AmtkActionInfo's.

- Something that is not possible to do with the support of GMenu in GTK, that libgedit-amtk solves when using GtkMenuItem's: when a GtkMenuItem is selected (e.g. when the mouse hovers it), showing a longer description in the GtkStatusbar. This is implemented by AmtkApplicationWindow. It makes the UI better self-discoverable, to improve the usability.

- Related to the previous point: having a GtkRecentChooser menu that shows in a GtkStatusbar the full file path when a menu item is selected. This is implemented by amtk_application_window_connect_recent_chooser_menu_to_statusbar().

## Sanity checks

libgedit-amtk has several functions to do various sanity checks. They normally don't impact too much the performances, so it is recommended to always run them, although they could be disabled on production. The functions:

- amtk_action_map_add_action_entries_check_dups()

- amtk_action_info_store_check_all_used()

- Another sanity check, but which cannot be disabled: the AmtkActionInfoCentralStore checks that each AmtkActionInfo has a unique action name. Which means that AmtkActionInfo's provided by a library must be namespaced.