Use GtkApplicationWindow as basis for GncMainWindow

Geert's changes...
As a GtkApplicationWindow also implements the GActionMap interface
it can be used directly instead of the GSimpleActionGroup that was
set up to maintain our actions.

As a GtkApplicationWindow is not a GSimpleActionGroup (the other
object to implement GActionMap) this also needed a minor change in
the function signature of gnc_plugin_set_actions_enabled.
This commit is contained in:
Robert Fewell 2022-10-28 17:00:01 +01:00
parent d0d76c279a
commit 0aaf11ac25
14 changed files with 58 additions and 68 deletions

View File

@ -244,11 +244,6 @@ typedef struct GncMainWindowPrivate
* window that is contained in the status bar. This pointer
* provides easy access for updating the progressbar. */
GtkWidget *progressbar;
/** The group of all actions provided by the main window
* itself. This does not include any action provided by menu
* or content plugins. */
GSimpleActionGroup *simple_action_group; //FIXMEb added
/** A list of all pages that are installed in this window. */
GList *installed_pages;
/** A list of pages in order of use (most recent -> least recent) */
@ -273,7 +268,7 @@ typedef struct GncMainWindowPrivate
} GncMainWindowPrivate;
GNC_DEFINE_TYPE_WITH_CODE(GncMainWindow, gnc_main_window, GTK_TYPE_WINDOW,
GNC_DEFINE_TYPE_WITH_CODE(GncMainWindow, gnc_main_window, GTK_TYPE_APPLICATION_WINDOW,
G_ADD_PRIVATE (GncMainWindow)
G_IMPLEMENT_INTERFACE (GNC_TYPE_WINDOW,
gnc_window_main_window_init))
@ -1559,7 +1554,7 @@ gnc_main_window_generate_title (GncMainWindow *window)
/* Update the menus based upon whether this is an "immutable" page. */
immutable = page &&
g_object_get_data (G_OBJECT (page), PLUGIN_PAGE_IMMUTABLE);
gnc_plugin_set_actions_enabled (priv->simple_action_group,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(window),
immutable_page_actions,
!immutable);
/* Trigger sensitivity updtates of other actions such as Save/Revert */
@ -1862,7 +1857,7 @@ gnc_main_window_update_radio_button (GncMainWindow *window)
priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
action = g_action_map_lookup_action (G_ACTION_MAP(priv->simple_action_group),
action = g_action_map_lookup_action (G_ACTION_MAP(window),
"WindowAction");
/* Block the signal so as not to affect window ordering (top to
@ -3531,7 +3526,7 @@ gnc_main_window_find_action (GncMainWindow *window, const gchar *name)
priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
action = g_action_map_lookup_action (G_ACTION_MAP(priv->simple_action_group),
action = g_action_map_lookup_action (G_ACTION_MAP(window),
name);
return action;
@ -3550,7 +3545,7 @@ gnc_main_window_find_action_in_group (GncMainWindow *window,
auto action_group = gtk_widget_get_action_group (GTK_WIDGET(window), group_name);
if (action_group)
action = g_action_map_lookup_action (G_ACTION_MAP(action_group), name);
action = g_action_map_lookup_action (G_ACTION_MAP(window), name);
return action;
}
@ -3837,7 +3832,7 @@ 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);
action = g_action_map_lookup_action (G_ACTION_MAP(priv->simple_action_group),
action = g_action_map_lookup_action (G_ACTION_MAP(window),
"ViewTabPositionAction");
g_signal_handlers_block_by_func (G_OBJECT(action),
@ -4091,6 +4086,11 @@ gnc_main_window_setup_window (GncMainWindow *window)
return; //FIXMEb this may need changing
}
g_action_map_add_action_entries (G_ACTION_MAP(window),
gnc_menu_actions,
gnc_menu_n_actions,
window);
priv->menubar_model = (GMenuModel *)gtk_builder_get_object (builder, "mainwin-menu");
priv->menubar = gtk_menu_bar_new_from_model (priv->menubar_model);
gtk_container_add (GTK_CONTAINER(priv->menu_dock), priv->menubar); //FIXMEb this may need changing
@ -4101,17 +4101,10 @@ gnc_main_window_setup_window (GncMainWindow *window)
gtk_container_add (GTK_CONTAINER(priv->menu_dock), GTK_WIDGET(priv->toolbar)); //FIXMEb this may need changing
gtk_widget_show (GTK_WIDGET(priv->toolbar));
priv->simple_action_group = g_simple_action_group_new ();
g_action_map_add_action_entries (G_ACTION_MAP(priv->simple_action_group),
gnc_menu_actions,
gnc_menu_n_actions,
window);
gnc_plugin_set_actions_enabled (priv->simple_action_group,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(window),
initially_insensitive_actions,
FALSE);
gnc_plugin_set_actions_enabled (priv->simple_action_group,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(window),
always_insensitive_actions,
FALSE);
@ -4119,7 +4112,7 @@ gnc_main_window_setup_window (GncMainWindow *window)
always_hidden_actions, false);
gtk_widget_insert_action_group (GTK_WIDGET(window), "mainwin",
G_ACTION_GROUP(priv->simple_action_group));
G_ACTION_GROUP(window));
gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
GNC_PREF_TAB_POSITION_TOP,
@ -4143,17 +4136,15 @@ gnc_main_window_setup_window (GncMainWindow *window)
/* Disable the Transaction menu */
action = gnc_main_window_find_action (window, "TransactionAction");
g_simple_action_set_enabled (G_SIMPLE_ACTION(action), FALSE);
g_simple_action_set_enabled (G_SIMPLE_ACTION(action), false);
/* Disable the Schedule menu */
action = gnc_main_window_find_action (window, "ScheduledAction");
g_simple_action_set_enabled (G_SIMPLE_ACTION(action), FALSE);
g_simple_action_set_enabled (G_SIMPLE_ACTION(action), false);
/* Now update the "eXtensions" menu */
if (!gnc_prefs_is_extra_enabled())
{
GAction* action = g_action_map_lookup_action (G_ACTION_MAP(priv->simple_action_group),
"ExtensionsAction");
action = gnc_main_window_find_action (window, "ExtensionsAction");
g_simple_action_set_enabled (G_SIMPLE_ACTION(action), false);
}
@ -4275,7 +4266,7 @@ gnc_main_window_show_summarybar (GncMainWindow *window, GAction *action)
gboolean visible;
if (action == nullptr)
action = g_action_map_lookup_action (G_ACTION_MAP(priv->simple_action_group),
action = g_action_map_lookup_action (G_ACTION_MAP(window),
"ViewSummaryAction");
if (action == nullptr)
return TRUE;
@ -4348,7 +4339,7 @@ gnc_main_window_switch_page (GtkNotebook *notebook,
priv->usage_order = g_list_prepend (priv->usage_order, page);
}
gnc_plugin_set_actions_enabled (priv->simple_action_group,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(window),
multiple_page_actions,
g_list_length (priv->installed_pages) > 1);

View File

@ -64,15 +64,15 @@ typedef struct
/** The instance data structure for a main window object. */
typedef struct GncMainWindow
{
GtkWindow gtk_window; /**< The parent object for a main window. */
gboolean window_quitting; /**< Set to TRUE when quitting from this window. */
gboolean just_plugin_prefs; /**< Just remove preferences only from plugins */
GtkApplicationWindow gtk_application_window; /**< The parent object for a main window. */
gboolean window_quitting; /**< Set to TRUE when quitting from this window. */
gboolean just_plugin_prefs; /**< Just remove preferences only from plugins */
} GncMainWindow;
/** The class data structure for a main window object. */
typedef struct
{
GtkWindowClass gtk_window; /**< The parent class for a main window. */
GtkApplicationWindowClass gtk_application_window; /**< The parent class for a main window. */
/* callbacks */
void (*page_added) (GncMainWindow *window,

View File

@ -244,20 +244,20 @@ gnc_plugin_init_short_names (GtkWidget *toolbar,
/* Update the sensitivity of an action */
void
gnc_plugin_set_actions_enabled (GSimpleActionGroup *simple_action_group,
gnc_plugin_set_actions_enabled (GActionMap *action_map,
const gchar **action_names, gboolean enable)
{
g_return_if_fail (simple_action_group != NULL);
g_return_if_fail (action_map != NULL);
for (gint i = 0; action_names[i]; i++)
{
GAction *action = g_action_map_lookup_action (G_ACTION_MAP(simple_action_group),
GAction *action = g_action_map_lookup_action (G_ACTION_MAP(action_map),
action_names[i]);
if (action)
g_simple_action_set_enabled (G_SIMPLE_ACTION(action), enable);
else
PERR("No such action with name '%s' in action group %p)",
action_names[i], simple_action_group);
action_names[i], action_map);
}
}

View File

@ -250,8 +250,7 @@ void gnc_plugin_init_short_names (GtkWidget *toolbar,
/** This function sets the sensitivity of a GAction in a specific
* group.
*
* @param simple_action_group The group of all actions associated with a
* plugin or plugin page.
* @param action_map The action map associated with the window.
*
* @param action_names A NULL terminated list of actions names that
* should be modified.
@ -259,7 +258,7 @@ void gnc_plugin_init_short_names (GtkWidget *toolbar,
* @param enable A boolean specifying the new state for the specified
* property.
*/
void gnc_plugin_set_actions_enabled (GSimpleActionGroup *simple_action_group,
void gnc_plugin_set_actions_enabled (GActionMap *action_map,
const gchar **action_names,
gboolean enable); //FIXMEb added

View File

@ -225,7 +225,7 @@ gnc_plugin_basic_commands_add_to_window (GncPlugin *plugin,
GSimpleActionGroup *simple_action_group =
gnc_main_window_get_action_group (window, PLUGIN_ACTIONS_NAME);
gnc_plugin_set_actions_enabled (simple_action_group,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group),
gnc_plugin_initially_insensitive_actions,
FALSE);
@ -255,9 +255,9 @@ static void update_inactive_actions (GncPluginPage *plugin_page)
g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP(simple_action_group));
/* Set the action's sensitivity */
gnc_plugin_set_actions_enabled (simple_action_group, readwrite_only_active_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), readwrite_only_active_actions,
is_readwrite);
gnc_plugin_set_actions_enabled (simple_action_group, dirty_only_active_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), dirty_only_active_actions,
is_dirty);
}

View File

@ -114,7 +114,7 @@ page_changed (GncMainWindow *window, GncPluginPage *page, gpointer user_data)
gnc_main_window_get_action_group (window, PLUGIN_ACTIONS_NAME);
if (qof_book_is_readonly (gnc_get_current_book()))
gnc_plugin_set_actions_enabled (simple_action_group, plugin_writeable_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), plugin_writeable_actions,
FALSE);
}

View File

@ -819,10 +819,10 @@ gnc_plugin_business_update_menus (GncPluginPage *plugin_page)
is_bus_doc = (xaccTransGetTxnType (trans) == TXN_TYPE_INVOICE);
}
// Change visibility and also sensitivity according to whether we are in a txn register
gnc_plugin_set_actions_enabled (simple_action_group, register_txn_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), register_txn_actions,
is_txn_register && !is_bus_txn && !is_bus_doc);
gnc_plugin_set_actions_enabled (simple_action_group, register_bus_txn_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), register_bus_txn_actions,
is_txn_register && is_bus_txn && !is_bus_doc);
}
@ -972,7 +972,7 @@ update_inactive_actions (GncPluginPage *plugin_page)
g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP(simple_action_group));
/* Set the action's sensitivity */
gnc_plugin_set_actions_enabled (simple_action_group, readonly_inactive_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), readonly_inactive_actions,
is_readwrite);
}

View File

@ -803,15 +803,15 @@ update_inactive_actions (GncPluginPage *plugin_page)
g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP (simple_action_group));
/* Set the action's sensitivity */
gnc_plugin_set_actions_enabled (simple_action_group, readonly_inactive_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), readonly_inactive_actions,
allow_write);
gnc_plugin_set_actions_enabled (simple_action_group, actions_requiring_account_rw,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), actions_requiring_account_rw,
allow_write && has_account);
gnc_plugin_set_actions_enabled (simple_action_group, actions_requiring_account_always,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), actions_requiring_account_always,
has_account);
gnc_plugin_set_actions_enabled (simple_action_group, actions_requiring_subaccounts_rw,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), actions_requiring_subaccounts_rw,
allow_write && subaccounts);
gnc_plugin_set_actions_enabled (simple_action_group, actions_requiring_priced_account,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), actions_requiring_priced_account,
account && xaccAccountIsPriced (account));
g_signal_emit (plugin_page, plugin_page_signals[ACCOUNT_SELECTED], 0, account);

View File

@ -323,7 +323,7 @@ gnc_plugin_page_budget_init (GncPluginPageBudget *plugin_page)
plugin_page);
if (qof_book_is_readonly (gnc_get_current_book()))
gnc_plugin_set_actions_enabled (simple_action_group, writeable_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), writeable_actions,
FALSE);
/* Visible types */
@ -702,7 +702,7 @@ gppb_selection_changed_cb (GtkTreeSelection *selection,
}
simple_action_group = gnc_plugin_page_get_action_group (GNC_PLUGIN_PAGE(page));
gnc_plugin_set_actions_enabled (simple_action_group, actions_requiring_account,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), actions_requiring_account,
sensitive);
}
#endif

View File

@ -659,13 +659,13 @@ gnc_plugin_page_invoice_update_menus (GncPluginPage *page, gboolean is_posted, g
g_simple_action_set_enabled (G_SIMPLE_ACTION(action), TRUE);
simple_action_group = gnc_plugin_page_get_action_group (page);
gnc_plugin_set_actions_enabled (simple_action_group, posted_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), posted_actions,
is_posted);
gnc_plugin_set_actions_enabled (simple_action_group, unposted_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), unposted_actions,
!is_posted);
gnc_plugin_set_actions_enabled (simple_action_group, can_unpost_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), can_unpost_actions,
can_unpost);
gnc_plugin_set_actions_enabled (simple_action_group, invoice_book_readwrite_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), invoice_book_readwrite_actions,
!is_readonly);
/* update the action labels and tooltips */

View File

@ -438,7 +438,7 @@ update_inactive_actions(GncPluginPage *plugin_page)
g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP(simple_action_group));
/* Set the action's sensitivity */
gnc_plugin_set_actions_enabled (simple_action_group, readonly_inactive_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), readonly_inactive_actions,
is_sensitive);
}
@ -850,9 +850,9 @@ gnc_plugin_page_owner_tree_selection_changed_cb (GtkTreeSelection *selection,
}
simple_action_group = gnc_plugin_page_get_action_group (GNC_PLUGIN_PAGE(page));
gnc_plugin_set_actions_enabled (simple_action_group, actions_requiring_owner_always,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), actions_requiring_owner_always,
sensitive);
gnc_plugin_set_actions_enabled (simple_action_group, actions_requiring_owner_rw,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), actions_requiring_owner_rw,
sensitive && is_readwrite);
g_signal_emit (page, plugin_page_signals[OWNER_SELECTED], 0, owner);
}

View File

@ -922,11 +922,11 @@ gnc_plugin_page_register_ui_update (gpointer various,
gnc_split_reg_get_read_only (priv->gsr))
read_only_reg = TRUE;
gnc_plugin_set_actions_enabled (gnc_plugin_page_get_action_group (GNC_PLUGIN_PAGE(page)),
gnc_plugin_set_actions_enabled (G_ACTION_MAP(gnc_plugin_page_get_action_group (GNC_PLUGIN_PAGE(page))),
actions_requiring_account,
!read_only_reg && account != NULL);
gnc_plugin_set_actions_enabled (gnc_plugin_page_get_action_group (GNC_PLUGIN_PAGE(page)),
gnc_plugin_set_actions_enabled (G_ACTION_MAP(gnc_plugin_page_get_action_group (GNC_PLUGIN_PAGE(page))),
actions_requiring_priced_account,
account && xaccAccountIsPriced (account));
@ -1117,7 +1117,7 @@ gnc_plugin_page_register_ui_initial_state (GncPluginPageRegister* page)
simple_action_group = gnc_plugin_page_get_action_group (GNC_PLUGIN_PAGE(page));
g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP(simple_action_group));
gnc_plugin_set_actions_enabled (simple_action_group, actions_requiring_account,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), actions_requiring_account,
is_readwrite && account != NULL);
/* Set "style" radio button */

View File

@ -1326,7 +1326,7 @@ gnc_plugin_page_report_constr_init (GncPluginPageReport *plugin_page, gint repor
num_report_actions,
plugin_page);
gnc_plugin_set_actions_enabled (simple_action_group, initially_insensitive_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), initially_insensitive_actions,
FALSE);
}

View File

@ -280,7 +280,7 @@ static void update_inactive_actions(GncPluginPage *plugin_page)
g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP(simple_action_group));
/* Set the action's sensitivity */
gnc_plugin_set_actions_enabled (simple_action_group, readonly_inactive_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), readonly_inactive_actions,
is_readwrite);
}
@ -330,19 +330,19 @@ gnc_plugin_ab_account_selected (GncPluginPage *plugin_page, Account *account,
bankcode = gnc_ab_get_account_bankcode(account);
accountid = gnc_ab_get_account_accountid(account);
gnc_plugin_set_actions_enabled (simple_action_group, need_account_actions,
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), need_account_actions,
(account && bankcode && *bankcode
&& accountid && *accountid));
gnc_main_window_menu_item_vis_by_action (window, need_account_actions, TRUE);
#if (AQBANKING_VERSION_INT < 60400)
gnc_plugin_set_actions_enabled (simple_action_group, inactive_account_actions, FALSE);
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), inactive_account_actions, FALSE);
gnc_main_window_menu_item_vis_by_action (window, inactive_account_actions, FALSE);
#endif
}
else
{
gnc_plugin_set_actions_enabled (simple_action_group, need_account_actions, FALSE);
gnc_plugin_set_actions_enabled (G_ACTION_MAP(simple_action_group), need_account_actions, FALSE);
gnc_main_window_menu_item_vis_by_action (window, need_account_actions, FALSE);
}