psppire-data-window: Only allow saving a file with at least one variable.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 25 Nov 2012 05:41:00 +0000 (21:41 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 25 Nov 2012 05:41:00 +0000 (21:41 -0800)
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.

src/ui/gui/psppire-data-window.c

index a2cfcbbffcb8ddf0b2982ad300478740b7e4e80d..3a032f0a285de1cc050d3d47b22aafd99e73cf34 100644 (file)
@@ -904,12 +904,25 @@ connect_action (PsppireDataWindow *dw, const char *action_name,
                                    GCallback handler)
 {
   GtkAction *action = get_action_assert (dw->builder, action_name);
+
   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.
 
@@ -1006,6 +1019,13 @@ psppire_data_window_finish_init (PsppireDataWindow *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));