Merge Chris Lam's 'budget-sensitive-readonly' into maint.

This commit is contained in:
John Ralls 2022-03-14 09:39:00 -07:00
commit 4f956844f3
3 changed files with 52 additions and 0 deletions

View File

@ -1265,6 +1265,9 @@ budget_col_edited (Account *account, GtkTreeViewColumn *col,
guint period_num;
gnc_numeric numeric = gnc_numeric_error (GNC_ERROR_ARG);
if (qof_book_is_readonly (gnc_get_current_book ()))
return;
if (!xaccParseAmount (new_text, TRUE, &numeric, NULL) &&
!(new_text && *new_text == '\0'))
return;

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 (" ");
}

View File

@ -202,6 +202,17 @@ static GtkActionEntry gnc_plugin_page_budget_actions [] =
};
static const gchar *writeable_actions[] =
{
/* actions which must be disabled on a readonly book. */
"DeleteBudgetAction",
"OptionsBudgetAction",
"EstimateBudgetAction",
"AllPeriodsBudgetAction",
"BudgetNoteAction",
NULL
};
static guint gnc_plugin_page_budget_n_actions =
G_N_ELEMENTS(gnc_plugin_page_budget_actions);
@ -366,6 +377,10 @@ gnc_plugin_page_budget_init (GncPluginPageBudget *plugin_page)
plugin_page);
gnc_plugin_init_short_names (action_group, toolbar_labels);
if (qof_book_is_readonly (gnc_get_current_book()))
gnc_plugin_update_actions (action_group, writeable_actions,
"sensitive", FALSE);
/* Visible types */
priv->fd.visible_types = -1; /* Start with all types */
priv->fd.show_hidden = FALSE;