mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Change gnc_add_accelerator_keys_for_menu
To allow the menu short cuts to be changed by the use of an accelerator-map file, this function adds scanning the gtk accelerator map and if any changes are found updates the GMenuModel, GMenuItem
This commit is contained in:
parent
e8b0d4dd87
commit
6a3013046f
@ -382,7 +382,7 @@ gnc_embedded_window_new (const gchar *action_group_name,
|
||||
// need to add the accelerator keys
|
||||
accel_group = gtk_accel_group_new ();
|
||||
gtk_window_add_accel_group (GTK_WINDOW(enclosing_win), accel_group);
|
||||
gnc_add_accelerator_keys_for_menu (GTK_WIDGET(priv->menubar), accel_group);
|
||||
gnc_add_accelerator_keys_for_menu (GTK_WIDGET(priv->menubar), priv->menubar_model, accel_group);
|
||||
|
||||
g_free (ui_fullname);
|
||||
LEAVE("window %p", window);
|
||||
|
@ -360,6 +360,28 @@ gnc_disable_all_actions_in_group (GSimpleActionGroup *action_group)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
accel_map_foreach_func (gpointer user_data, const gchar* accel_path, guint accel_key,
|
||||
GdkModifierType accel_mods, gboolean changed)
|
||||
{
|
||||
GMenuModel *menu_model = user_data;
|
||||
gchar **accel_path_parts = NULL;
|
||||
guint accel_size = 0;
|
||||
gchar *accel_name_tmp = gtk_accelerator_name (accel_key, accel_mods);
|
||||
gchar *accel_name = g_strescape (accel_name_tmp, NULL);
|
||||
|
||||
accel_path_parts = g_strsplit (accel_path, "/", -1);
|
||||
accel_size = g_strv_length (accel_path_parts);
|
||||
|
||||
if (accel_size == 3)
|
||||
gnc_menubar_model_update_item (menu_model, accel_path_parts[2],
|
||||
NULL, accel_name, NULL);
|
||||
|
||||
g_strfreev (accel_path_parts);
|
||||
g_free (accel_name_tmp);
|
||||
g_free (accel_name);
|
||||
}
|
||||
|
||||
static void
|
||||
add_accel_for_menu_lookup (GtkWidget *widget, gpointer user_data)
|
||||
{
|
||||
@ -396,14 +418,20 @@ add_accel_for_menu_lookup (GtkWidget *widget, gpointer user_data)
|
||||
*
|
||||
* @param menu The menu widget.
|
||||
*
|
||||
* @param model The menu bar model.
|
||||
*
|
||||
* @param accel_group The accelerator group to use.
|
||||
*/
|
||||
void
|
||||
gnc_add_accelerator_keys_for_menu (GtkWidget *menu, GtkAccelGroup *accel_group)
|
||||
gnc_add_accelerator_keys_for_menu (GtkWidget *menu, GMenuModel *model, GtkAccelGroup *accel_group)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_WIDGET(menu));
|
||||
g_return_if_fail (model != NULL);
|
||||
g_return_if_fail (accel_group != NULL);
|
||||
|
||||
// this updates the menu accelerators based on accelerator-map
|
||||
gtk_accel_map_foreach (model, (GtkAccelMapForeach)accel_map_foreach_func);
|
||||
|
||||
gtk_container_foreach (GTK_CONTAINER(menu), add_accel_for_menu_lookup, accel_group);
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ GtkWidget *gnc_get_dialog_widget_from_id (GtkDialog *dialog, const gchar *id);
|
||||
|
||||
void gnc_disable_all_actions_in_group (GSimpleActionGroup *action_group);
|
||||
|
||||
void gnc_add_accelerator_keys_for_menu (GtkWidget *menu, GtkAccelGroup *accel_group);
|
||||
void gnc_add_accelerator_keys_for_menu (GtkWidget *menu, GMenuModel *model, GtkAccelGroup *accel_group);
|
||||
|
||||
GtkWidget *gnc_find_menu_item_by_action_name (GtkWidget *menu, const gchar *action_name);
|
||||
GtkWidget *gnc_find_menu_item_by_action_label (GtkWidget *menu, const gchar *action_label);
|
||||
|
@ -723,7 +723,7 @@ gnc_main_window_restore_window (GncMainWindow *window, GncMainWindowSaveData *da
|
||||
priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
|
||||
|
||||
// need to add the accelerator keys
|
||||
gnc_add_accelerator_keys_for_menu (GTK_WIDGET(priv->menubar), priv->accel_group);
|
||||
gnc_add_accelerator_keys_for_menu (GTK_WIDGET(priv->menubar), priv->menubar_model, priv->accel_group);
|
||||
|
||||
/* Common view menu items */
|
||||
action = gnc_main_window_find_action (window, "ViewToolbarAction");
|
||||
@ -3619,7 +3619,7 @@ gnc_main_window_menu_add_accelerator_keys (GncMainWindow *window)
|
||||
|
||||
priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
|
||||
|
||||
gnc_add_accelerator_keys_for_menu (priv->menubar, priv->accel_group);
|
||||
gnc_add_accelerator_keys_for_menu (priv->menubar, priv->menubar_model, priv->accel_group);
|
||||
}
|
||||
|
||||
|
||||
@ -3834,7 +3834,7 @@ gnc_main_window_update_menu_and_toolbar (GncMainWindow *window,
|
||||
gnc_plugin_add_menu_tooltip_callbacks (priv->menubar, priv->menubar_model, priv->statusbar);
|
||||
|
||||
// need to add the accelerator keys
|
||||
gnc_add_accelerator_keys_for_menu (priv->menubar, priv->accel_group);
|
||||
gnc_add_accelerator_keys_for_menu (priv->menubar, priv->menubar_model, priv->accel_group);
|
||||
#ifdef MAC_INTEGRATION
|
||||
gtkosx_application_sync_menubar (theApp);
|
||||
g_object_unref (theApp);
|
||||
@ -4059,7 +4059,7 @@ main_window_realize_cb (GtkWidget *widget, gpointer user_data)
|
||||
GncMainWindow *window = (GncMainWindow*)user_data;
|
||||
GncMainWindowPrivate *priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
|
||||
|
||||
gnc_add_accelerator_keys_for_menu (GTK_WIDGET(priv->menubar), priv->accel_group);
|
||||
gnc_add_accelerator_keys_for_menu (GTK_WIDGET(priv->menubar), priv->menubar_model, priv->accel_group);
|
||||
|
||||
/* need to signal menu has been changed, this will call the
|
||||
business function 'bind_extra_toolbuttons_visibility' */
|
||||
|
@ -1897,7 +1897,7 @@ recnWindowWithBalance (GtkWidget *parent, Account *account, gnc_numeric new_endi
|
||||
gtk_window_add_accel_group (GTK_WINDOW(recnData->window), accel_group);
|
||||
|
||||
// need to add the accelerator keys
|
||||
gnc_add_accelerator_keys_for_menu (menu_bar, accel_group);
|
||||
gnc_add_accelerator_keys_for_menu (menu_bar, menu_model, accel_group);
|
||||
|
||||
#ifdef MAC_INTEGRATION
|
||||
gtkosx_application_sync_menubar (theApp);
|
||||
|
Loading…
Reference in New Issue
Block a user