Show keyboard accelerators in menus: Closes #6428

This commit is contained in:
Avi Levy 2013-06-25 14:16:39 -07:00 committed by Jim Nelson
parent 33aab4288e
commit 6785460869
2 changed files with 40 additions and 0 deletions

View file

@ -55,10 +55,17 @@ public class MainToolbar : Gtk.Box {
Gtk.IconSize.LARGE_TOOLBAR, mark_menu, mark_proxy_menu);
mark_menu_dropdown.attach(mark_menu_button);
// Ensure that shortcut keys are drawn in the mark menu
mark_menu.foreach(GtkUtil.show_menuitem_accel_labels);
// Setup the application menu.
GearyApplication.instance.load_ui_file("toolbar_menu.ui");
Gtk.Menu application_menu = GearyApplication.instance.ui_manager.get_widget("/ui/ToolbarMenu")
as Gtk.Menu;
// Ensure that shortcut keys are drawn in the gear menu
application_menu.foreach(GtkUtil.show_menuitem_accel_labels);
Gtk.Menu application_proxy_menu = GearyApplication.instance.ui_manager.get_widget("/ui/ToolbarMenuProxy")
as Gtk.Menu;
Gtk.ToggleToolButton app_menu_button = set_toolbutton_action(builder, GearyController.ACTION_GEAR_MENU)

View file

@ -211,5 +211,38 @@ public void add_accelerator(Gtk.UIManager ui_manager, Gtk.ActionGroup action_gro
});
}
public void show_menuitem_accel_labels(Gtk.Widget widget) {
Gtk.MenuItem? item = widget as Gtk.MenuItem;
if (item == null) {
return;
}
string? path = item.get_accel_path();
if (path == null) {
return;
}
Gtk.AccelKey? key = null;
Gtk.AccelMap.lookup_entry(path, out key);
if (key == null) {
return;
}
item.foreach(
(widget) => { add_accel_to_label(widget, key); }
);
}
private void add_accel_to_label(Gtk.Widget widget, Gtk.AccelKey key) {
Gtk.AccelLabel? label = widget as Gtk.AccelLabel;
if (label == null) {
return;
}
// We should check for (key.accel_flags & Gtk.AccelFlags.VISIBLE) before
// running the following code. However, there appears to be some
// funny business going on because key.accel_flags always turns up as 0,
// even though we explicitly set it to Gtk.AccelFlags.VISIBLE before.
label.set_accel(key.accel_key, key.accel_mods);
label.refetch();
}
}