Also update main menu Budget actions sensitivity

This commit is contained in:
Christopher Lam 2022-01-11 20:46:05 +08:00
parent f96585b863
commit 8ee0bee6d2

View File

@ -85,6 +85,16 @@ static GtkActionEntry gnc_plugin_actions [] =
};
static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
static const gchar *plugin_writeable_actions[] =
{
/* actions which must be disabled on a readonly book. */
"NewBudgetAction",
"CopyBudgetAction",
"DeleteBudgetAction",
NULL
};
typedef struct GncPluginBudgetPrivate
{
gpointer dummy;
@ -109,6 +119,28 @@ GncPlugin * gnc_plugin_budget_new (void)
return GNC_PLUGIN(plugin);
}
static void page_changed (GncMainWindow *window, GncPluginPage *page,
gpointer user_data)
{
GtkActionGroup *action_group =
gnc_main_window_get_action_group (window, PLUGIN_ACTIONS_NAME);
if (qof_book_is_readonly (gnc_get_current_book()))
gnc_plugin_update_actions (action_group, plugin_writeable_actions,
"sensitive", FALSE);
}
static void add_to_window (GncPlugin *plugin, GncMainWindow *mainwindow, GQuark type)
{
g_signal_connect (mainwindow, "page_changed", G_CALLBACK (page_changed), plugin);
}
static void remove_from_window (GncPlugin *plugin, GncMainWindow *window, GQuark type)
{
g_signal_handlers_disconnect_by_func (window, G_CALLBACK(page_changed), plugin);
PWARN ("removed");
}
G_DEFINE_TYPE_WITH_PRIVATE(GncPluginBudget, gnc_plugin_budget, GNC_TYPE_PLUGIN)
static void
@ -126,6 +158,8 @@ gnc_plugin_budget_class_init (GncPluginBudgetClass *klass)
plugin_class->actions = gnc_plugin_actions;
plugin_class->n_actions = gnc_plugin_n_actions;
plugin_class->ui_filename = PLUGIN_UI_FILENAME;
plugin_class->add_to_window = add_to_window;
plugin_class->remove_from_window = remove_from_window;
LEAVE (" ");
}