Change license from GPLv2+ to GPLv3+.
[pspp-builds.git] / src / ui / gui / data-editor.c
index cce4c521b29b0ed524c78e7ffbda341ff8d2d30b..ada84b1a66061580a7cf6f2587fdc1e8e5c66e61 100644 (file)
@@ -1,21 +1,18 @@
-/*
-    PSPPIRE --- A Graphical User Interface for PSPP
-    Copyright (C) 2006, 2007  Free Software Foundation
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2006, 2007  Free Software Foundation
 
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-    02110-1301, USA. */
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <config.h>
 #include <stdlib.h>
@@ -59,7 +56,7 @@ static gint update_data_ref_entry (const GtkSheet *sheet,
 
 static void register_data_editor_actions (struct data_editor *de);
 
-static void insert_variable (GtkCheckMenuItem *m, gpointer data);
+static void insert_variable (GtkAction *, gpointer data);
 
 
 /* Switch between the VAR SHEET and the DATA SHEET */
@@ -241,6 +238,24 @@ new_data_editor (void)
 
   register_data_editor_actions (de);
 
+  de->insert_variable =
+    gtk_action_new ("insert-variable",
+                   _("Insert Variable"),
+                   _("Create a new variable at the current position"),
+                   "pspp-insert-variable");
+
+  g_signal_connect (de->insert_variable, "activate",
+                   G_CALLBACK (insert_variable), de);
+
+
+  gtk_action_connect_proxy (de->insert_variable,
+                           get_widget_assert (de->xml, "button-insert-variable")
+                           );
+
+  gtk_action_connect_proxy (de->insert_variable,
+                           get_widget_assert (de->xml, "data_insert-variable")
+                           );
+
   de->invoke_weight_cases_dialog =
     gtk_action_new ("weight-cases-dialog",
                    _("Weights"),
@@ -389,10 +404,6 @@ new_data_editor (void)
                    de);
 
 
-  g_signal_connect (get_widget_assert (de->xml,"data_insert-variable"),
-                   "activate",
-                   G_CALLBACK (insert_variable),
-                   de);
 
   gtk_action_connect_proxy (de->invoke_weight_cases_dialog,
                            get_widget_assert (de->xml, "data_weight-cases")
@@ -828,10 +839,10 @@ on_clear_activate (GtkMenuItem *menuitem, gpointer data)
 /* Insert a new variable before the current row in the variable sheet,
    or before the current column in the data sheet, whichever is selected */
 static void
-insert_variable (GtkCheckMenuItem *m, gpointer data)
+insert_variable (GtkAction *action, gpointer data)
 {
   struct data_editor *de = data;
-  gint posn;
+  gint posn = -1;
 
   GtkWidget *notebook = get_widget_assert (de->xml, "notebook");
 
@@ -861,6 +872,8 @@ insert_variable (GtkCheckMenuItem *m, gpointer data)
       g_assert_not_reached ();
     }
 
+  if ( posn == -1 ) posn = 0;
+
   psppire_dict_insert_variable (vs->dict, posn, NULL);
 }
 
@@ -1271,7 +1284,8 @@ update_data_ref_entry (const GtkSheet *sheet, gint row, gint col, gpointer data)
 {
   GladeXML *data_editor_xml = data;
 
-  PsppireDataStore *data_store = PSPPIRE_DATA_STORE (gtk_sheet_get_model (sheet));
+  PsppireDataStore *data_store =
+    PSPPIRE_DATA_STORE (gtk_sheet_get_model (sheet));
 
   g_return_val_if_fail (data_editor_xml, FALSE);
 
@@ -1280,38 +1294,44 @@ update_data_ref_entry (const GtkSheet *sheet, gint row, gint col, gpointer data)
       const struct variable *var =
        psppire_dict_get_variable (data_store->dict, col);
 
-      {
-       /* The entry where the reference to the current cell is displayed */
-       GtkEntry *cell_ref_entry =
-         GTK_ENTRY (get_widget_assert (data_editor_xml,
-                                       "cell_ref_entry"));
+      /* The entry where the reference to the current cell is displayed */
+      GtkEntry *cell_ref_entry =
+       GTK_ENTRY (get_widget_assert (data_editor_xml,
+                                     "cell_ref_entry"));
+      GtkEntry *datum_entry =
+       GTK_ENTRY (get_widget_assert (data_editor_xml,
+                                     "datum_entry"));
 
-       gchar *text = g_strdup_printf ("%d: %s", row,
-                                      var ? var_get_name (var) : "");
+      if ( var )
+       {
+         gchar *text = g_strdup_printf ("%d: %s", row,
+                                        var_get_name (var));
 
-       gchar *s = pspp_locale_to_utf8 (text, -1, 0);
+         gchar *s = pspp_locale_to_utf8 (text, -1, 0);
 
-       g_free (text);
+         g_free (text);
 
-       gtk_entry_set_text (cell_ref_entry, s);
+         gtk_entry_set_text (cell_ref_entry, s);
 
-       g_free (s);
-      }
+         g_free (s);
+       }
+      else
+       gtk_entry_set_text (cell_ref_entry, "");
 
-      {
-       GtkEntry *datum_entry =
-         GTK_ENTRY (get_widget_assert (data_editor_xml,
-                                       "datum_entry"));
 
-       gchar *text =
-         psppire_data_store_get_string (data_store, row,
-                                        var_get_dict_index(var));
-       g_strchug (text);
+      if ( var )
+       {
+         gchar *text =
+           psppire_data_store_get_string (data_store, row,
+                                          var_get_dict_index(var));
+         g_strchug (text);
 
-       gtk_entry_set_text (datum_entry, text);
+         gtk_entry_set_text (datum_entry, text);
 
-       free (text);
-      }
+         free (text);
+       }
+      else
+       gtk_entry_set_text (datum_entry, "");
     }
 
   return FALSE;