Merge Simon Arlott's branch 'view-menu-tab-position' into maint PR #1369

This commit is contained in:
Robert Fewell 2022-07-17 11:44:49 +01:00
commit 0a8dcdcd81
2 changed files with 108 additions and 0 deletions

View File

@ -168,6 +168,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);
@ -341,6 +342,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
@ -426,6 +428,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. */
@ -3578,12 +3606,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))
@ -3594,6 +3631,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 ("");
}
@ -3846,6 +3903,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);
@ -4603,6 +4666,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,

View File

@ -51,6 +51,12 @@
<menuitem name="ViewToolbar" action="ViewToolbarAction"/>
<menuitem name="ViewSummary" action="ViewSummaryAction"/>
<menuitem name="ViewStatusbar" action="ViewStatusbarAction"/>
<menu name="ViewTabPosition" action="ViewTabPositionAction">
<menuitem name="ViewTabPositionTop" action="ViewTabPositionTopAction"/>
<menuitem name="ViewTabPositionBottom" action="ViewTabPositionBottomAction"/>
<menuitem name="ViewTabPositionLeft" action="ViewTabPositionLeftAction"/>
<menuitem name="ViewTabPositionRight" action="ViewTabPositionRightAction"/>
</menu>
<separator name="ViewSep1"/>
<placeholder name="ViewContentPlaceholder"/>
<separator name="ViewSep2"/>