From 2b447d47874b9698edb1bef63669dc0d1415a7f9 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Tue, 14 Jun 2022 23:35:24 +0100 Subject: [PATCH] Add action group to View menu for the tab position --- gnucash/gnome-utils/gnc-main-window.c | 102 ++++++++++++++++++++++++++ gnucash/ui/gnc-main-window-ui.xml | 6 ++ 2 files changed, 108 insertions(+) diff --git a/gnucash/gnome-utils/gnc-main-window.c b/gnucash/gnome-utils/gnc-main-window.c index 249de04909..41f8b6e0c0 100644 --- a/gnucash/gnome-utils/gnc-main-window.c +++ b/gnucash/gnome-utils/gnc-main-window.c @@ -166,6 +166,7 @@ static void gnc_main_window_cmd_view_refresh (GtkAction *action, GncMainWindow * static void gnc_main_window_cmd_view_toolbar (GtkAction *action, GncMainWindow *window); static void gnc_main_window_cmd_view_summary (GtkAction *action, GncMainWindow *window); static void gnc_main_window_cmd_view_statusbar (GtkAction *action, GncMainWindow *window); +static void gnc_main_window_cmd_view_tab_position (GtkAction *action, GtkRadioAction *current, GncMainWindow *window); static void gnc_main_window_cmd_actions_reset_warnings (GtkAction *action, GncMainWindow *window); static void gnc_main_window_cmd_actions_rename_page (GtkAction *action, GncMainWindow *window); static void gnc_main_window_cmd_window_new (GtkAction *action, GncMainWindow *window); @@ -339,6 +340,7 @@ static GtkActionEntry gnc_menu_actions [] = /* View menu */ + { "ViewTabPositionAction", NULL, N_("Tab P_osition"), NULL, NULL, NULL }, { "ViewSortByAction", NULL, N_("_Sort By..."), NULL, N_("Select sorting criteria for this page view"), NULL @@ -424,6 +426,32 @@ static GtkToggleActionEntry toggle_actions [] = /** The number of toggle actions provided by the main window. */ static guint n_toggle_actions = G_N_ELEMENTS (toggle_actions); +/** An array of all of the radio actions provided by the main window + * for tab positions. */ +static GtkRadioActionEntry tab_pos_radio_entries [] = +{ + { + "ViewTabPositionTopAction", NULL, N_("To_p"), NULL, + N_("Display the notebook tabs at the top of the window."), GTK_POS_TOP + }, + { + "ViewTabPositionBottomAction", NULL, N_("B_ottom"), NULL, + N_("Display the notebook tabs at the bottom of the window."), GTK_POS_BOTTOM + }, + { + "ViewTabPositionLeftAction", NULL, N_("_Left"), NULL, + N_("Display the notebook tabs at the left of the window."), GTK_POS_LEFT + }, + { + "ViewTabPositionRightAction", NULL, N_("_Right"), NULL, + N_("Display the notebook tabs at the right of the window."), GTK_POS_RIGHT + }, +}; + +/** The number of radio actions provided by the main window for tab + * positions. */ +static guint n_tab_pos_radio_entries = G_N_ELEMENTS (tab_pos_radio_entries); + #ifndef MAC_INTEGRATION /** An array of all of the radio action provided by the main window * code. */ @@ -3576,12 +3604,21 @@ gnc_main_window_update_tab_position (gpointer prefs, gchar *pref, gpointer user_ GncMainWindow *window; GtkPositionType position = GTK_POS_TOP; GncMainWindowPrivate *priv; + GtkAction *first_action; + GtkAction *position_action; + gsize i; g_return_if_fail (GNC_IS_MAIN_WINDOW(user_data)); window = GNC_MAIN_WINDOW(user_data); ENTER ("window %p", window); + + /* Ignore notification of the preference that is being set to false when + * the choice of tab position changes. */ + if (pref && !gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, pref)) + return; + if (gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TAB_POSITION_BOTTOM)) position = GTK_POS_BOTTOM; else if (gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TAB_POSITION_LEFT)) @@ -3592,6 +3629,26 @@ gnc_main_window_update_tab_position (gpointer prefs, gchar *pref, gpointer user_ priv = GNC_MAIN_WINDOW_GET_PRIVATE (window); gtk_notebook_set_tab_pos (GTK_NOTEBOOK (priv->notebook), position); + /* Groups of radio actions use the first action for the callback and all + * change events so block/unblock signals on the first radio action. */ + first_action = gtk_action_group_get_action (priv->action_group, + tab_pos_radio_entries[0].name); + + for (i = n_tab_pos_radio_entries - 1; i > 0; i--) + if (tab_pos_radio_entries[i].value == position) + break; + + position_action = gtk_action_group_get_action (priv->action_group, + tab_pos_radio_entries[i].name); + + g_signal_handlers_block_by_func (G_OBJECT (first_action), + G_CALLBACK (gnc_main_window_cmd_view_tab_position), + window); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (position_action), TRUE); + g_signal_handlers_unblock_by_func (G_OBJECT (first_action), + G_CALLBACK (gnc_main_window_cmd_view_tab_position), + window); + LEAVE (""); } @@ -3844,6 +3901,12 @@ gnc_main_window_setup_window (GncMainWindow *window) g_assert(merge_id || error); if (merge_id) { + gtk_action_group_add_radio_actions (priv->action_group, + tab_pos_radio_entries, + n_tab_pos_radio_entries, + 0, + G_CALLBACK(gnc_main_window_cmd_view_tab_position), + window); gtk_window_add_accel_group (GTK_WINDOW (window), gtk_ui_manager_get_accel_group(window->ui_merge)); gtk_ui_manager_ensure_update (window->ui_merge); @@ -4601,6 +4664,45 @@ gnc_main_window_cmd_window_move_page (GtkAction *action, GncMainWindow *window) LEAVE("page moved"); } +static void +gnc_main_window_cmd_view_tab_position (GtkAction *action, + GtkRadioAction *current, + GncMainWindow *window) +{ + GtkPositionType value = gtk_radio_action_get_current_value(current); + + if (value != GTK_POS_TOP && gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TAB_POSITION_TOP)) + gnc_prefs_set_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TAB_POSITION_TOP, FALSE); + + if (value != GTK_POS_BOTTOM && gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TAB_POSITION_BOTTOM)) + gnc_prefs_set_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TAB_POSITION_BOTTOM, FALSE); + + if (value != GTK_POS_LEFT && gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TAB_POSITION_LEFT)) + gnc_prefs_set_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TAB_POSITION_LEFT, FALSE); + + if (value != GTK_POS_RIGHT && gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TAB_POSITION_RIGHT)) + gnc_prefs_set_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TAB_POSITION_RIGHT, FALSE); + + switch (value) + { + case GTK_POS_TOP: + gnc_prefs_set_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TAB_POSITION_TOP, TRUE); + break; + + case GTK_POS_BOTTOM: + gnc_prefs_set_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TAB_POSITION_BOTTOM, TRUE); + break; + + case GTK_POS_LEFT: + gnc_prefs_set_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TAB_POSITION_LEFT, TRUE); + break; + + case GTK_POS_RIGHT: + gnc_prefs_set_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_TAB_POSITION_RIGHT, TRUE); + break; + } +} + #ifndef MAC_INTEGRATION static void gnc_main_window_cmd_window_raise (GtkAction *action, diff --git a/gnucash/ui/gnc-main-window-ui.xml b/gnucash/ui/gnc-main-window-ui.xml index 77580a7c19..64068dafc0 100644 --- a/gnucash/ui/gnc-main-window-ui.xml +++ b/gnucash/ui/gnc-main-window-ui.xml @@ -51,6 +51,12 @@ + + + + + +