Add an appropriate help page for the Variable Info dialog box
[pspp] / src / ui / gui / split-file-dialog.c
index 35aaf701f9ff196b26516259c993285b229c3809..2cf10d532945d837965b4861a837ec3a86e5f39d 100644 (file)
@@ -1,63 +1,70 @@
-/*
-    PSPPIRE --- A Graphical User Interface for PSPP
-    Copyright (C) 2007  Free Software Foundation
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2007, 2010, 2011, 2012  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 "split-file-dialog.h"
 #include "psppire-selector.h"
 #include "psppire-dialog.h"
-#include "helper.h"
-#include "data-editor.h"
+#include "executor.h"
+#include "psppire-data-window.h"
 #include "dict-display.h"
-#include <language/syntax-string-source.h>
-#include "syntax-editor.h"
+#include "builder-wrapper.h"
+#include "helper.h"
+
+#include <data/dictionary.h>
+
+#include "psppire-var-view.h"
 
 #include <gtk/gtk.h>
-#include <glade/glade.h>
 
 
 #include "dialog-common.h"
 
-/* FIXME: These shouldn't be here */
-#include <gtksheet/gtksheet.h>
-#include "psppire-var-store.h"
 
+struct split_file_dialog
+{
+  /* The XML that created the dialog */
+  GtkBuilder *xml;
+
+  /* The dictionary to which this dialog pertains */
+  PsppireDict *dict;
+
+  /* The treeview widget containing the list of variables
+     upon which the file should be split */
+  GtkTreeView *tv;
+
+  PsppireSelector *selector;
+};
 
 
 static gchar *
-generate_syntax (GladeXML *xml, PsppireDict *dict)
+generate_syntax (const struct split_file_dialog *sfd)
 {
   gchar *text;
-  GtkWidget *off = get_widget_assert (xml, "split-radiobutton0");
-
-  GtkWidget *vars =
-    get_widget_assert (xml, "split-file-grouping-vars");
+  GtkWidget *off = get_widget_assert (sfd->xml, "split-radiobutton0");
 
   GString *string = g_string_new ("SPLIT FILE OFF.");
 
   if ( ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (off)))
     {
       GString * varlist = g_string_sized_new (80);
-      GtkWidget *sort = get_widget_assert (xml, "split-radiobutton3");
-      GtkWidget *layered = get_widget_assert (xml, "split-radiobutton1");
-      gint n_vars = append_variable_names (varlist,
-                                          dict, GTK_TREE_VIEW (vars));
+      GtkWidget *sort = get_widget_assert (sfd->xml, "split-radiobutton3");
+      GtkWidget *layered = get_widget_assert (sfd->xml, "split-radiobutton1");
+      gint n_vars = psppire_var_view_append_names (PSPPIRE_VAR_VIEW (sfd->tv), 0, varlist);
 
       if ( n_vars > 0 )
        {
@@ -96,7 +103,7 @@ static void
 on_off_toggled (GtkToggleButton *togglebutton,
                gpointer         user_data)
 {
-  GladeXML *xml = user_data;
+  GtkBuilder *xml = user_data;
   GtkWidget *dest =   get_widget_assert (xml, "split-file-grouping-vars");
   GtkWidget *selector = get_widget_assert (xml, "split-file-selector");
   GtkWidget *source = get_widget_assert (xml, "split-file-dict-treeview");
@@ -113,58 +120,74 @@ on_off_toggled (GtkToggleButton *togglebutton,
 }
 
 static void
-refresh (GladeXML *xml)
+refresh (PsppireDialog *dialog, struct split_file_dialog *d)
 {
-  GtkWidget *off = get_widget_assert (xml, "split-radiobutton0");
+  GtkWidget *off = get_widget_assert (d->xml, "split-radiobutton0");
+  GtkWidget *on = get_widget_assert (d->xml, "split-radiobutton1");
+
+  GtkTreeModel *liststore = gtk_tree_view_get_model (d->tv);
 
-  g_print ("%s\n", __FUNCTION__);
+  gint n_vars = dict_get_split_cnt (d->dict->dict);
+
+  gtk_list_store_clear (GTK_LIST_STORE (liststore));
+
+  if ( n_vars == 0 )
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(off), TRUE);
+  else
+    {
+      GtkTreeIter iter;
+      gint i;
+      const struct variable *const *vars = dict_get_split_vars (d->dict->dict);
+
+      for (i = 0 ; i < n_vars; ++i )
+       {
+         gtk_list_store_append (GTK_LIST_STORE (liststore), &iter);
+
+         gtk_list_store_set (GTK_LIST_STORE (liststore), &iter,
+                             0, vars[i],
+                             -1);
+       }
+
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(on), TRUE);
+    }
 
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(off), TRUE);
   gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON(off));
 }
 
 
 
-/* Pops up the Weight Cases dialog box */
+/* Pops up the Split File dialog box */
 void
-split_file_dialog (GObject *o, gpointer data)
+split_file_dialog (PsppireDataWindow *de)
 {
   gint response;
-  struct data_editor *de = data;
-  PsppireDict *dict;
+  struct split_file_dialog sfd;
 
-  GladeXML *xml = XML_NEW ("psppire.glade");
+  GtkWidget *dialog   ;
+  GtkWidget *source   ;
+  GtkWidget *selector ;
+  GtkWidget *on_off   ;
 
-  GtkWidget *dialog = get_widget_assert   (xml, "split-file-dialog");
-  GtkWidget *source = get_widget_assert   (xml, "split-file-dict-treeview");
-  GtkWidget *dest =   get_widget_assert   (xml, "split-file-grouping-vars");
-  GtkWidget *selector = get_widget_assert (xml, "split-file-selector");
-  GtkWidget *on_off = get_widget_assert   (xml, "split-radiobutton0");
-
-  GtkSheet *var_sheet =
-    GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
+  sfd.xml = builder_new ("split-file.ui");
 
-  PsppireVarStore *vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
+  dialog = get_widget_assert   (sfd.xml, "split-file-dialog");
+  source = get_widget_assert   (sfd.xml, "split-file-dict-treeview");
+  selector = get_widget_assert (sfd.xml, "split-file-selector");
+  on_off = get_widget_assert   (sfd.xml, "split-radiobutton0");
 
-  dict = vs->dict;
+  sfd.tv = GTK_TREE_VIEW (get_widget_assert (sfd.xml, "split-file-grouping-vars"));
 
-  attach_dictionary_to_treeview (GTK_TREE_VIEW (source),
-                                vs->dict,
-                                GTK_SELECTION_MULTIPLE, NULL);
+  g_object_get (de->data_editor, "dictionary", &sfd.dict, NULL);
 
+  sfd.selector = PSPPIRE_SELECTOR (selector);
 
-  g_signal_connect (on_off, "toggled", G_CALLBACK(on_off_toggled),  xml);
+  g_object_set (source, "model", sfd.dict, NULL);
 
+  g_signal_connect (on_off, "toggled", G_CALLBACK(on_off_toggled),  sfd.xml);
 
-  set_dest_model (GTK_TREE_VIEW (dest), vs->dict);
+  g_signal_connect (dialog, "refresh", G_CALLBACK (refresh),  &sfd);
 
-  psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
-                                source,
-                                dest,
-                                insert_source_row_into_tree_view,
-                                NULL);
-
-  refresh (xml);
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
 
   response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
 
@@ -172,30 +195,15 @@ split_file_dialog (GObject *o, gpointer data)
   switch (response)
     {
     case GTK_RESPONSE_OK:
-      {
-       gchar *syntax = generate_syntax (xml, dict);
-       struct getl_interface *sss = create_syntax_string_source (syntax);
-       execute_syntax (sss);
-
-       g_free (syntax);
-      }
+      g_free (execute_syntax_string (de, generate_syntax (&sfd)));
       break;
     case PSPPIRE_RESPONSE_PASTE:
-      {
-       gchar *syntax = generate_syntax (xml, dict);
-
-       struct syntax_editor *se =
-         (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
-
-       gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
-
-       g_free (syntax);
-      }
+      g_free (paste_syntax_to_window (generate_syntax (&sfd)));
       break;
     default:
       break;
     }
 
-  g_object_unref (xml);
+  g_object_unref (sfd.xml);
 }