Patch #5676 (syntax string source).
[pspp] / src / ui / gui / data-editor.c
index 33d5a3e4c883840f6989c3a9e2fb981eb555e809..262ae543ac59e8f98766aac8558ac37fe3734ea0 100644 (file)
@@ -37,6 +37,7 @@
 
 #include "data-editor.h"
 #include "syntax-editor.h"
+#include <language/syntax-string-source.h>
 #include "window-manager.h"
 
 #include "psppire-data-store.h"
@@ -59,8 +60,10 @@ static gboolean click2row (GtkWidget *w, gint row, gpointer data);
 static void select_sheet (struct data_editor *de, guint page_num);
 
 
-/* Callback for when the dictionary changes its weights */
+/* Callback for when the dictionary changes properties*/
 static void on_weight_change (GObject *, gint, gpointer);
+static void on_filter_change (GObject *, gint, gpointer);
+static void on_split_change (PsppireDict *, gpointer);
 
 static void data_var_select (GtkNotebook *notebook,
                            GtkNotebookPage *page,
@@ -136,6 +139,14 @@ new_data_editor (void)
                    G_CALLBACK (on_weight_change),
                    de);
 
+  g_signal_connect (vs->dict, "filter-changed",
+                   G_CALLBACK (on_filter_change),
+                   de);
+
+  g_signal_connect (vs->dict, "split-changed",
+                   G_CALLBACK (on_split_change),
+                   de);
+
   connect_help (de->xml);
 
   de->invoke_weight_cases_dialog =
@@ -338,8 +349,6 @@ click2column (GtkWidget *w, gint col, gpointer data)
 }
 
 
-
-
 void
 new_data_window (GtkMenuItem *menuitem, gpointer parent)
 {
@@ -672,6 +681,72 @@ insert_variable (GtkCheckMenuItem *m, gpointer data)
   psppire_dict_insert_variable (vs->dict, posn, NULL);
 }
 
+/* Callback for when the dictionary changes its split variables */
+static void
+on_split_change (PsppireDict *dict, gpointer data)
+{
+  struct data_editor *de = data;
+
+  size_t n_split_vars = dict_get_split_cnt (dict->dict);
+
+  GtkWidget *split_status_area =
+    get_widget_assert (de->xml, "split-file-status-area");
+
+  if ( n_split_vars == 0 )
+    {
+      gtk_label_set_text (GTK_LABEL (split_status_area), _("No Split"));
+    }
+  else
+    {
+      gint i;
+      GString *text;
+      struct variable *const * split_vars = dict_get_split_vars (dict->dict);
+
+      text = g_string_new (_("Split by "));
+
+      for (i = 0 ; i < n_split_vars - 1; ++i )
+       {
+         g_string_append_printf (text, "%s, ", var_get_name (split_vars[i]));
+       }
+      g_string_append (text, var_get_name (split_vars[i]));
+
+      gtk_label_set_text (GTK_LABEL (split_status_area), text->str);
+
+      g_string_free (text, TRUE);
+    }
+}
+
+
+/* Callback for when the dictionary changes its filter variable */
+static void
+on_filter_change (GObject *o, gint filter_index, gpointer data)
+{
+  struct data_editor *de = data;
+  GtkWidget *filter_status_area =
+    get_widget_assert (de->xml, "filter-use-status-area");
+
+  if ( filter_index == -1 )
+    {
+      gtk_label_set_text (GTK_LABEL (filter_status_area), _("Filter off"));
+    }
+  else
+    {
+      GtkSheet *var_sheet =
+       GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
+
+      PsppireVarStore *vs = PSPPIRE_VAR_STORE
+       (gtk_sheet_get_model (var_sheet) );
+
+      struct variable *var = psppire_dict_get_variable (vs->dict,
+                                                       filter_index);
+
+      gchar *text = g_strdup_printf (_("Filter by %s"), var_get_name (var));
+
+      gtk_label_set_text (GTK_LABEL (filter_status_area), text);
+
+      g_free (text);
+    }
+}
 
 /* Callback for when the dictionary changes its weights */
 static void
@@ -704,7 +779,6 @@ on_weight_change (GObject *o, gint weight_index, gpointer data)
     }
 }
 
-
 static void
 weight_cases_dialog (GObject *o, gpointer data)
 {
@@ -734,20 +808,58 @@ weight_cases_dialog (GObject *o, gpointer data)
 
   g_object_unref (xml);
 
-  if (response == GTK_RESPONSE_OK)
+  switch (response)
+    {
+    case GTK_RESPONSE_OK:
     {
+      struct getl_interface *sss ;
       const GList *list = psppire_var_select_get_variables (select);
 
-      g_assert ( g_list_length (list) <= 1 );
+      g_assert ( g_list_length ((GList *)list) <= 1 );
 
       if ( list == NULL)
-       psppire_dict_set_weight_variable (select->dict, NULL);
+         {
+           sss = create_syntax_string_source ("WEIGHT OFF.");
+         }
       else
        {
          struct variable *var = list->data;
 
-         psppire_dict_set_weight_variable (select->dict, var);
+           sss = create_syntax_string_source ("WEIGHT BY %s.\n",
+                                              var_get_name (var));
+         }
+
+       execute_syntax (sss);
        }
+      break;
+    case PSPPIRE_RESPONSE_PASTE:
+      {
+       struct syntax_editor *se =  (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
+
+       const GList *list = psppire_var_select_get_variables (select);
+
+       g_assert ( g_list_length ((GList *)list) <= 1 );
+
+       if ( list == NULL)
+         {
+           gtk_text_buffer_insert_at_cursor (se->buffer, "WEIGHT OFF.", -1);
+         }
+       else
+         {
+           struct variable *var = list->data;
+
+           gchar *text = g_strdup_printf ("WEIGHT BY %s.",
+                                          var_get_name (var));
+
+           gtk_text_buffer_insert_at_cursor (se->buffer,
+                                             text, -1);
+
+           g_free (text);
+         }
+      }
+      break;
+    default:
+      break;
     }
 }