A data file with no variables can't be saved to a file. Until now, this
wasn't detected until the user had already chosen a file name, and the
message used to report it was confusing: "SAVE is allowed only after the
active file has been defined." With this commit, the menu item and toolbar
item for save operations is, instead, disabled if the file has no
variables.
Bug #30700.
Reported by eric thivant, via Harry Thijssen, with help from Michel
Boaventura.
GCallback handler)
{
GtkAction *action = get_action_assert (dw->builder, action_name);
GCallback handler)
{
GtkAction *action = get_action_assert (dw->builder, action_name);
g_signal_connect_swapped (action, "activate", handler, dw);
return action;
}
g_signal_connect_swapped (action, "activate", handler, dw);
return action;
}
+/* Only a data file with at least one variable can be saved. */
+static void
+enable_save (PsppireDataWindow *dw)
+{
+ PsppireDict *dict = dw->var_store->dictionary;
+ gboolean enable = psppire_dict_get_var_cnt (dict) > 0;
+
+ gtk_action_set_sensitive (get_action_assert (dw->builder, "file_save"),
+ enable);
+ gtk_action_set_sensitive (get_action_assert (dw->builder, "file_save_as"),
+ enable);
+}
+
/* Initializes as much of a PsppireDataWindow as we can and must before the
dataset has been set.
/* Initializes as much of a PsppireDataWindow as we can and must before the
dataset has been set.
G_CALLBACK (on_split_change),
de);
G_CALLBACK (on_split_change),
de);
+ g_signal_connect_swapped (dict, "backend-changed",
+ G_CALLBACK (enable_save), de);
+ g_signal_connect_swapped (dict, "variable-inserted",
+ G_CALLBACK (enable_save), de);
+ g_signal_connect_swapped (dict, "variable-deleted",
+ G_CALLBACK (enable_save), de);
+ enable_save (de);
connect_action (de, "edit_copy", G_CALLBACK (on_edit_copy));
connect_action (de, "edit_copy", G_CALLBACK (on_edit_copy));