Re-added Data->Insert_Variable menu item
authorJohn Darrington <john@darrington.wattle.id.au>
Thu, 28 Dec 2006 04:21:07 +0000 (04:21 +0000)
committerJohn Darrington <john@darrington.wattle.id.au>
Thu, 28 Dec 2006 04:21:07 +0000 (04:21 +0000)
src/data/dictionary.c
src/ui/gui/data-editor.c
src/ui/gui/data-editor.glade
src/ui/gui/data-sheet.c
src/ui/gui/psppire-data-store.c
src/ui/gui/psppire-dict.c
src/ui/gui/psppire-var-store.c

index 1d15fe8be6b2882df9aad512c877ad9151002b50..a7478596c0b0be2c9ef9d752aee9a70a979f7567 100644 (file)
@@ -400,8 +400,12 @@ static void
 set_var_dict_index (struct variable *v, int dict_index)
 {
   struct vardict_info vdi = *var_get_vardict (v);
+  struct dictionary *d = vdi.dict;
   vdi.dict_index = dict_index;
   var_set_vardict (v, &vdi);
+
+  if ( d->callbacks && d->callbacks->var_changed )
+    d->callbacks->var_changed (d, dict_index, d->cb_data);
 }
 
 /* Sets the case_index in V's vardict to DICT_INDEX. */
@@ -537,20 +541,20 @@ dict_reorder_var (struct dictionary *d, struct variable *v, size_t new_index)
    listed in ORDER in that order at the beginning of D.  The
    other variables in D, if any, retain their relative
    positions. */
-void 
+void
 dict_reorder_vars (struct dictionary *d,
-                   struct variable *const *order, size_t count) 
+                   struct variable *const *order, size_t count)
 {
   struct variable **new_var;
   size_t i;
-  
+
   assert (d != NULL);
   assert (count == 0 || order != NULL);
   assert (count <= d->var_cnt);
 
   new_var = xnmalloc (d->var_cnt, sizeof *new_var);
   memcpy (new_var, order, count * sizeof *new_var);
-  for (i = 0; i < count; i++) 
+  for (i = 0; i < count; i++)
     {
       size_t index = var_get_dict_index (order[i]);
       assert (d->var[index] == order[i]);
index 76612b5e9461fe7296a3c201ab791ef48cf353f3..10f57885342b95d4daf9055a1c5b69c27c1d6114 100644 (file)
@@ -41,6 +41,9 @@
 #include "psppire-var-store.h"
 
 
+static void insert_variable (GtkCheckMenuItem *m, gpointer data);
+
+
 /* Switch between the VAR SHEET and the DATA SHEET */
 enum {PAGE_DATA_SHEET = 0, PAGE_VAR_SHEET};
 
@@ -145,6 +148,11 @@ new_data_editor (void)
                    de);
 
 
+  g_signal_connect (get_widget_assert (de->xml,"data_insert-variable"),
+                   "activate",
+                   G_CALLBACK (insert_variable),
+                   de);
+
 
   g_signal_connect (get_widget_assert (de->xml,"help_about"),
                    "activate",
@@ -297,7 +305,7 @@ new_data_window (GtkMenuItem *menuitem, gpointer parent)
 static void
 select_sheet (struct data_editor *de, guint page_num)
 {
-  GtkWidget *insert_variable = get_widget_assert (de->xml, "insert-variable");
+  GtkWidget *insert_variable = get_widget_assert (de->xml, "data_insert-variable");
   GtkWidget *insert_cases = get_widget_assert (de->xml, "insert-cases");
 
   GtkWidget *view_data = get_widget_assert (de->xml, "view_data");
@@ -314,8 +322,9 @@ select_sheet (struct data_editor *de, guint page_num)
     case PAGE_DATA_SHEET:
       gtk_widget_show (view_variables);
       gtk_widget_hide (view_data);
-      gtk_widget_set_sensitive (insert_variable, FALSE);
+#if 0
       gtk_widget_set_sensitive (insert_cases, TRUE);
+#endif
       break;
     default:
       g_assert_not_reached ();
@@ -579,3 +588,49 @@ on_clear_activate (GtkMenuItem *menuitem, gpointer data)
        g_assert_not_reached ();
     }
 }
+
+
+/* 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)
+{
+  struct data_editor *de = data;
+  gint posn;
+
+  GtkWidget *notebook = get_widget_assert (de->xml, "notebook");
+
+  GtkSheet *var_sheet =
+    GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
+
+
+
+  PsppireVarStore *vs = PSPPIRE_VAR_STORE
+    (gtk_sheet_get_model (var_sheet) );
+
+
+  switch ( gtk_notebook_get_current_page ( GTK_NOTEBOOK (notebook)) )
+    {
+    case PAGE_VAR_SHEET:
+      posn = var_sheet->active_cell.row;
+      break;
+    case PAGE_DATA_SHEET:
+      {
+       GtkSheet *data_sheet =
+         GTK_SHEET (get_widget_assert (de->xml, "data_sheet"));
+
+       if ( data_sheet->state == GTK_SHEET_COLUMN_SELECTED )
+         posn = data_sheet->range.col0;
+       else
+         posn = data_sheet->active_cell.col;
+      }
+      break;
+    default:
+      g_assert_not_reached ();
+    }
+
+  psppire_dict_insert_variable (vs->dict, posn, NULL);
+
+}
+
+
index 419a9c604ee0f450f8c7072422d28aaa964f97a3..f34d24a919c0982c44433ecd96a49645c1237b28 100644 (file)
                      <property name="use_underline">True</property>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image44">
+                       <widget class="GtkImage" id="image47">
                          <property name="visible">True</property>
                          <property name="stock">gtk-find</property>
                          <property name="icon_size">1</property>
          </child>
 
          <child>
-           <widget class="GtkMenuItem" id="menuitem4">
+           <widget class="GtkMenuItem" id="data">
              <property name="visible">True</property>
-             <property name="sensitive">False</property>
              <property name="label" translatable="yes">_Data</property>
              <property name="use_underline">True</property>
 
              <child>
-               <widget class="GtkMenu" id="menuitem4_menu">
+               <widget class="GtkMenu" id="data_menu">
 
                  <child>
-                   <widget class="GtkMenuItem" id="insert-variable">
+                   <widget class="GtkMenuItem" id="data_insert-variable">
                      <property name="visible">True</property>
                      <property name="sensitive">False</property>
                      <property name="label" translatable="yes">Insert Variable</property>
                  <child>
                    <widget class="GtkMenuItem" id="insert-cases">
                      <property name="visible">True</property>
+                     <property name="sensitive">False</property>
                      <property name="label" translatable="yes">Insert Cases</property>
                      <property name="use_underline">True</property>
                      <signal name="activate" handler="on_insert_cases" last_modification_time="Sat, 01 Jul 2006 08:40:06 GMT"/>
                  <child>
                    <widget class="GtkImageMenuItem" id="go_to_case">
                      <property name="visible">True</property>
+                     <property name="sensitive">False</property>
                      <property name="label" translatable="yes">Go To Case</property>
                      <property name="use_underline">True</property>
                      <signal name="activate" handler="on_go_to_case_activate" last_modification_time="Mon, 19 Jun 2006 10:29:37 GMT"/>
 
                      <child internal-child="image">
-                       <widget class="GtkImage" id="image45">
+                       <widget class="GtkImage" id="image48">
                          <property name="visible">True</property>
                          <property name="stock">gtk-jump-to</property>
                          <property name="icon_size">1</property>
                  <child>
                    <widget class="GtkSeparatorMenuItem" id="separator4">
                      <property name="visible">True</property>
+                     <property name="sensitive">False</property>
                    </widget>
                  </child>
 
                  <child>
                    <widget class="GtkMenuItem" id="sort_cases">
                      <property name="visible">True</property>
+                     <property name="sensitive">False</property>
                      <property name="label" translatable="yes">Sort Cases</property>
                      <property name="use_underline">True</property>
                      <signal name="activate" handler="on_sort_cases_activate" last_modification_time="Tue, 20 Jun 2006 10:27:11 GMT"/>
                  <child>
                    <widget class="GtkSeparatorMenuItem" id="separator5">
                      <property name="visible">True</property>
+                     <property name="sensitive">False</property>
                    </widget>
                  </child>
 
index 0998de055a15e3b848f863e85e8a50d4cc4aa1c8..0fdba1164c27c6934ed7e764bb3d5d41e6f10748 100644 (file)
@@ -156,6 +156,8 @@ font_change_callback (GObject *obj, gpointer data)
   ds->width_of_m = calc_m_width (sheet, ds->font_desc);
 }
 
+
+
 GtkWidget*
 psppire_data_sheet_create (gchar *widget_name, gchar *string1, gchar *string2,
                           gint int1, gint int2)
@@ -180,7 +182,6 @@ psppire_data_sheet_create (gchar *widget_name, gchar *string1, gchar *string2,
 
   gtk_sheet_set_active_cell (GTK_SHEET (sheet), -1, -1);
 
-
   gtk_sheet_set_model (GTK_SHEET (sheet), G_SHEET_MODEL (the_data_store));
 
   gtk_widget_show (sheet);
index d75348584211afe2e72b3dbe5da8f8975c6d7fc9..531b5b92214eb6d64c9d5dbb75d5be9e1632ad65 100644 (file)
@@ -286,6 +286,25 @@ delete_variables_callback (GObject *obj, gint var_num, gint n_vars, gpointer dat
                                   var_num, -1);
 }
 
+
+static void
+variable_changed_callback (GObject *obj, gint var_num, gpointer data)
+{
+  PsppireDataStore *store;
+
+  g_return_if_fail (data);
+
+  store  = PSPPIRE_DATA_STORE (data);
+
+  g_sheet_column_columns_changed (G_SHEET_COLUMN (store),
+                                 var_num, 1);
+
+
+  g_sheet_model_range_changed (G_SHEET_MODEL (store),
+                              -1, var_num,
+                              -1, var_num);
+}
+
 static void
 insert_variable_callback (GObject *obj, gint var_num, gpointer data)
 {
@@ -398,6 +417,11 @@ psppire_data_store_set_dictionary (PsppireDataStore *data_store, PsppireDict *di
                   G_CALLBACK (delete_variables_callback),
                   data_store);
 
+  g_signal_connect (dict, "variable-changed",
+                  G_CALLBACK (variable_changed_callback),
+                  data_store);
+
+
   g_signal_connect (dict, "dict-size-changed",
                    G_CALLBACK (dict_size_change_callback),
                    data_store);
index 15a3deff0c995f730d53290cac2b671287fe3a76..9637e3cf9cb2b420fca9de381556b62f3849fe9e 100644 (file)
@@ -243,10 +243,10 @@ void
 psppire_dict_insert_variable (PsppireDict *d, gint idx, const gchar *name)
 {
   struct variable *var ;
+  g_return_if_fail (idx >= 0);
   g_return_if_fail (d);
   g_return_if_fail (G_IS_PSPPIRE_DICT (d));
 
-
   if ( ! name )
     name = auto_generate_var_name (d);
 
index b84b0c6e2c9e8586164d8d0099b62d6ac7abdca7..9ce4f38f63245e5ae8a98de5e2614b3140e5798a 100644 (file)
@@ -263,6 +263,7 @@ static void
 var_change_callback (GtkWidget *w, gint n, gpointer data)
 {
   GSheetModel *model = G_SHEET_MODEL (data);
+
   g_sheet_model_range_changed (model,
                                 n, 0, n, n_COLS);
 }