Refactor common code in dialog implementations
[pspp-builds.git] / src / ui / gui / recode-dialog.c
index 34145b0eddd2eaccb20ba87f36be9736ca2a0d62..642dae02d4a01283276c86356618b79cf7689603 100644 (file)
 #include "recode-dialog.h"
 
 #include <gtk/gtk.h>
-#include <gtksheet/gtksheet.h>
 
 #include <language/syntax-string-source.h>
-#include <ui/gui/data-editor.h>
+#include <ui/gui/psppire-data-window.h>
 #include <ui/gui/dialog-common.h>
 #include <ui/gui/dict-display.h>
 #include <ui/gui/helper.h>
 #include <ui/gui/psppire-dialog.h>
 #include <ui/gui/psppire-var-store.h>
-#include <ui/gui/syntax-editor.h>
-#include <libpspp/syntax-gen.h>
+#include <ui/gui/helper.h>
+#include <ui/syntax-gen.h>
 
 #include "psppire-acr.h"
 
@@ -471,14 +470,14 @@ toggle_sensitivity (GtkToggleButton *button, GtkWidget *target)
   gtk_widget_set_sensitive (target, state);
 }
 
-static void recode_dialog (struct data_editor *de, gboolean diff);
+static void recode_dialog (PsppireDataWindow *de, gboolean diff);
 
 
 /* Pops up the Recode Same version of the dialog box */
 void
 recode_same_dialog (GObject *o, gpointer data)
 {
-  struct data_editor *de = data;
+  PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
 
   recode_dialog (de, FALSE);
 }
@@ -487,7 +486,7 @@ recode_same_dialog (GObject *o, gpointer data)
 void
 recode_different_dialog (GObject *o, gpointer data)
 {
-  struct data_editor *de = data;
+  PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
 
   recode_dialog (de, TRUE);
 }
@@ -837,7 +836,7 @@ set_acr (struct recode_dialog *rd)
 }
 
 static void
-recode_dialog (struct data_editor *de, gboolean diff)
+recode_dialog (PsppireDataWindow *de, gboolean diff)
 {
   gint response;
 
@@ -884,7 +883,7 @@ recode_dialog (struct data_editor *de, gboolean diff)
 
   rd.different = diff;
 
-  gtk_window_set_transient_for (GTK_WINDOW (rd.dialog), de->parent.window);
+  gtk_window_set_transient_for (GTK_WINDOW (rd.dialog), GTK_WINDOW (de));
 
 
   attach_dictionary_to_treeview (GTK_TREE_VIEW (rd.dict_treeview),
@@ -995,7 +994,7 @@ recode_dialog (struct data_editor *de, gboolean diff)
       PSPPIRE_DIALOG (get_widget_assert (xml, "old-new-values-dialog"));
 
     gtk_window_set_transient_for (GTK_WINDOW (rd.old_and_new_dialog),
-                                 de->parent.window);
+                                 GTK_WINDOW (de));
 
     rd.acr = PSPPIRE_ACR (get_widget_assert (xml, "psppire-acr1"));
 
@@ -1086,6 +1085,7 @@ recode_dialog (struct data_editor *de, gboolean diff)
     case GTK_RESPONSE_OK:
       {
        gchar *syntax = generate_syntax (&rd);
+
        struct getl_interface *sss = create_syntax_string_source (syntax);
        execute_syntax (sss);
 
@@ -1095,11 +1095,7 @@ recode_dialog (struct data_editor *de, gboolean diff)
     case PSPPIRE_RESPONSE_PASTE:
       {
        gchar *syntax = generate_syntax (&rd);
-
-       struct syntax_editor *se =
-         (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
-
-       gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
+        paste_syntax_in_new_window (syntax);
 
        g_free (syntax);
       }
@@ -1339,9 +1335,8 @@ new_value_append_syntax (GString *str, const struct new_value *nv)
       break;
     case NV_STRING:
       {
-       struct string ds;
-       ds_init_cstr (&ds, nv->v.s);
-       gen_quoted_string (&ds);
+       struct string ds = DS_EMPTY_INITIALIZER;
+       syntax_gen_string (&ds, ss_cstr (nv->v.s));
        g_string_append (str, ds_cstr (&ds));
        ds_destroy (&ds);
       }
@@ -1372,9 +1367,8 @@ old_value_append_syntax (GString *str, const struct old_value *ov)
       break;
     case OV_STRING:
       {
-       struct string ds;
-       ds_init_cstr (&ds, ov->v.s);
-       gen_quoted_string (&ds);
+       struct string ds = DS_EMPTY_INITIALIZER;
+       syntax_gen_string (&ds, ss_cstr (ov->v.s));
        g_string_append (str, ds_cstr (&ds));
        ds_destroy (&ds);
       }
@@ -1538,9 +1532,9 @@ generate_syntax (const struct recode_dialog *rd)
              continue;
            }
 
-         ds_init_cstr (&ls, label);
+         ds_init_empty (&ls);
+         syntax_gen_string (&ls, ss_cstr (label));
          g_free (label);
-         gen_quoted_string (&ls);
 
          g_string_append_printf (str, "\nVARIABLE LABELS %s %s.",
                                  name, ds_cstr (&ls));