Univariate Dialog: Convert from old style to PsppireDialogAction
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 4 Oct 2013 15:01:05 +0000 (17:01 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sun, 6 Oct 2013 14:32:43 +0000 (16:32 +0200)
src/ui/gui/automake.mk
src/ui/gui/data-editor.ui
src/ui/gui/psppire-data-window.c
src/ui/gui/psppire-dialog-action-univariate.c [new file with mode: 0644]
src/ui/gui/psppire-dialog-action-univariate.h [new file with mode: 0644]
src/ui/gui/univariate-dialog.c [deleted file]
src/ui/gui/univariate-dialog.h [deleted file]
src/ui/gui/widgets.c

index 06825dd568855c095aa29cbe6ceb19d604a400ee..d25b28ff5fa37ca92cafc1d407dce57f6861d499 100644 (file)
@@ -227,6 +227,8 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/psppire-dialog-action-runs.h \
        src/ui/gui/psppire-dialog-action-sort.c \
        src/ui/gui/psppire-dialog-action-sort.h \
+       src/ui/gui/psppire-dialog-action-univariate.c \
+       src/ui/gui/psppire-dialog-action-univariate.h \
        src/ui/gui/psppire-dialog-action-var-info.c \
        src/ui/gui/psppire-dialog-action-var-info.h \
        src/ui/gui/psppire-dict.c \
@@ -299,8 +301,6 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/t-test-paired-samples.h \
        src/ui/gui/npar-two-sample-related.c \
        src/ui/gui/npar-two-sample-related.h \
-       src/ui/gui/univariate-dialog.c \
-       src/ui/gui/univariate-dialog.h \
        src/ui/gui/val-labs-dialog.c \
        src/ui/gui/val-labs-dialog.h \
        src/ui/gui/var-display.c \
index 9fe45ecaa6dd1f5522a5133f1303338b729f844f..99ddbfa446516500ed9cee96158f4598b77a3a4c 100644 (file)
           </object>
         </child>
         <child>
-          <object class="GtkAction" id="univariate">
+          <object class="PsppireDialogActionUnivariate" id="univariate">
             <property name="name">univariate</property>
+            <property name="manager">uimanager1</property>
             <property name="label" translatable="yes">_Univariate Analysis...</property>
             <property name="visible">False</property>
           </object>
index 69a8c6385f499aa0994ce6a9e0e08c0cdd80389e..890d795543578b31c3379c92e6ffbc7fa2e41b98 100644 (file)
@@ -50,7 +50,6 @@
 #include "ui/gui/t-test-one-sample.h"
 #include "ui/gui/t-test-paired-samples.h"
 #include "ui/gui/text-data-import-dialog.h"
-#include "ui/gui/univariate-dialog.h"
 #include "ui/gui/weight-cases-dialog.h"
 #include "ui/syntax-gen.h"
 
@@ -948,19 +947,12 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
   enable_save (de);
 
   connect_action (de, "file_new_data", G_CALLBACK (create_data_window));
-
   connect_action (de, "file_import", G_CALLBACK (text_data_import_assistant));
-
   connect_action (de, "file_save", G_CALLBACK (psppire_window_save));
   connect_action (de, "file_open", G_CALLBACK (psppire_window_open));
-
   connect_action (de, "file_save_as", G_CALLBACK (psppire_window_save_as));
-
   connect_action (de, "rename_dataset", G_CALLBACK (on_rename_dataset));
-
   connect_action (de, "file_information_working-file", G_CALLBACK (display_dict));
-
   connect_action (de, "file_information_external-file", G_CALLBACK (sysfile_info));
 
   g_signal_connect_swapped (get_action_assert (de->builder, "view_value-labels"), "toggled", G_CALLBACK (toggle_value_labels), de);
@@ -978,7 +970,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
   connect_action (de, "transform_count", G_CALLBACK (count_dialog));
   connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog));
   connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog));
-  connect_action (de, "univariate", G_CALLBACK (univariate_dialog));
   connect_action (de, "ks-one-sample", G_CALLBACK (ks_one_sample_dialog));
   connect_action (de, "k-related-samples", G_CALLBACK (k_related_dialog));
   connect_action (de, "two-related-samples", G_CALLBACK (two_related_dialog));
diff --git a/src/ui/gui/psppire-dialog-action-univariate.c b/src/ui/gui/psppire-dialog-action-univariate.c
new file mode 100644 (file)
index 0000000..79bf5ee
--- /dev/null
@@ -0,0 +1,121 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2012, 2013  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 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.
+
+   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 "psppire-dialog-action-univariate.h"
+
+#include "psppire-var-view.h"
+
+#include "psppire-dialog.h"
+#include "builder-wrapper.h"
+
+static void psppire_dialog_action_univariate_init            (PsppireDialogActionUnivariate      *act);
+static void psppire_dialog_action_univariate_class_init      (PsppireDialogActionUnivariateClass *class);
+
+G_DEFINE_TYPE (PsppireDialogActionUnivariate, psppire_dialog_action_univariate, PSPPIRE_TYPE_DIALOG_ACTION);
+
+static char *
+generate_syntax (PsppireDialogAction *act)
+{
+  PsppireDialogActionUnivariate *uvd = PSPPIRE_DIALOG_ACTION_UNIVARIATE (act);
+
+  gchar *text = NULL;
+  GString *str = g_string_new ("GLM ");
+
+  g_string_append (str, gtk_entry_get_text (GTK_ENTRY (uvd->dep_entry)));
+  
+  g_string_append (str, " BY ");
+
+  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (uvd->factor_list), 0, str);
+
+  g_string_append (str, ".\n");
+
+  text = str->str;
+
+  g_string_free (str, FALSE);
+
+  return text;
+}
+
+
+static gboolean
+dialog_state_valid (gpointer data)
+{
+  PsppireDialogActionUnivariate *ud = PSPPIRE_DIALOG_ACTION_UNIVARIATE (data);
+  GtkTreeModel *vars;
+  GtkTreeIter notused;
+
+  if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (ud->dep_entry))))
+    return false;
+
+  vars =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (ud->factor_list));
+
+  return gtk_tree_model_get_iter_first (vars, &notused);
+}
+
+static void
+refresh (PsppireDialogAction *rd_)
+{
+  PsppireDialogActionUnivariate *uv = PSPPIRE_DIALOG_ACTION_UNIVARIATE (rd_);
+  GtkTreeModel *liststore ;
+
+  gtk_entry_set_text (GTK_ENTRY (uv->dep_entry), "");
+
+  liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (uv->factor_list));
+
+  gtk_list_store_clear (GTK_LIST_STORE (liststore));
+}
+
+static void
+psppire_dialog_action_univariate_activate (GtkAction *a)
+{
+  PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
+  PsppireDialogActionUnivariate *act = PSPPIRE_DIALOG_ACTION_UNIVARIATE (a);
+
+  GtkBuilder *xml = builder_new ("univariate.ui");
+  pda->dialog = get_widget_assert   (xml, "univariate-dialog");
+  pda->source = get_widget_assert   (xml, "dict-view");
+
+  act->dep_entry = get_widget_assert (xml, "dep-entry");
+  act->factor_list = get_widget_assert (xml, "factors-view");
+
+  psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
+  psppire_dialog_action_set_refresh (pda, refresh);
+
+  g_object_unref (xml);
+
+  if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_univariate_parent_class)->activate)
+    PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_univariate_parent_class)->activate (pda);
+}
+
+static void
+psppire_dialog_action_univariate_class_init (PsppireDialogActionUnivariateClass *class)
+{
+  GtkActionClass *action_class = GTK_ACTION_CLASS (class);
+
+  action_class->activate = psppire_dialog_action_univariate_activate;
+  PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
+}
+
+
+static void
+psppire_dialog_action_univariate_init (PsppireDialogActionUnivariate *act)
+{
+}
+
diff --git a/src/ui/gui/psppire-dialog-action-univariate.h b/src/ui/gui/psppire-dialog-action-univariate.h
new file mode 100644 (file)
index 0000000..be43ab3
--- /dev/null
@@ -0,0 +1,79 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2013  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 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.
+
+   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 <glib-object.h>
+#include <glib.h>
+
+#include "psppire-dialog-action.h"
+
+#ifndef __PSPPIRE_DIALOG_ACTION_UNIVARIATE_H__
+#define __PSPPIRE_DIALOG_ACTION_UNIVARIATE_H__
+
+G_BEGIN_DECLS
+
+
+#define PSPPIRE_TYPE_DIALOG_ACTION_UNIVARIATE (psppire_dialog_action_univariate_get_type ())
+
+#define PSPPIRE_DIALOG_ACTION_UNIVARIATE(obj)  \
+                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                                                 PSPPIRE_TYPE_DIALOG_ACTION_UNIVARIATE, PsppireDialogActionUnivariate))
+
+#define PSPPIRE_DIALOG_ACTION_UNIVARIATE_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_CAST ((klass), \
+                                PSPPIRE_TYPE_DIALOG_ACTION_UNIVARIATE, \
+                                 PsppireDialogActionUnivariateClass))
+
+
+#define PSPPIRE_IS_DIALOG_ACTION_UNIVARIATE(obj) \
+                    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_UNIVARIATE))
+
+#define PSPPIRE_IS_DIALOG_ACTION_UNIVARIATE_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_UNIVARIATE))
+
+
+#define PSPPIRE_DIALOG_ACTION_UNIVARIATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                                  PSPPIRE_TYPE_DIALOG_ACTION_UNIVARIATE, \
+                                  PsppireDialogActionUnivariateClass))
+
+typedef struct _PsppireDialogActionUnivariate       PsppireDialogActionUnivariate;
+typedef struct _PsppireDialogActionUnivariateClass  PsppireDialogActionUnivariateClass;
+
+
+struct _PsppireDialogActionUnivariate
+{
+  PsppireDialogAction parent;
+
+  /*< private >*/
+  gboolean dispose_has_run ;
+
+  /* Entry box for the dependent variable */
+  GtkWidget *dep_entry;
+  GtkWidget *factor_list;
+};
+
+
+struct _PsppireDialogActionUnivariateClass
+{
+  PsppireDialogActionClass parent_class;
+};
+
+
+GType psppire_dialog_action_univariate_get_type (void) ;
+
+G_END_DECLS
+
+#endif /* __PSPPIRE_DIALOG_ACTION_UNIVARIATE_H__ */
diff --git a/src/ui/gui/univariate-dialog.c b/src/ui/gui/univariate-dialog.c
deleted file mode 100644 (file)
index 2f24149..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-/* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 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 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.
-
-   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 <gtk/gtk.h>
-#include <ui/gui/builder-wrapper.h>
-#include "psppire-dialog.h"
-#include "dict-display.h"
-
-#include "psppire-var-view.h"
-#include "psppire-selector.h"
-#include "psppire-dictview.h"
-#include <ui/gui/dialog-common.h>
-
-#include "executor.h"
-#include "helper.h"
-
-#include "univariate-dialog.h"
-
-struct uni_dialog
-{
-  struct dictionary *dict;
-
-  /* Entry box for the dependent variable */
-  GtkWidget *dep_entry;
-
-  GtkWidget *factor_list;
-};
-
-
-/* Dialog is valid iff at least one variable has been selected in both
-   the dependent variable box and the factor list. */
-static gboolean
-dialog_state_valid (gpointer data)
-{
-  struct uni_dialog *uv_d = data;
-  GtkTreeModel *vars;
-  GtkTreeIter notused;
-
-  if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (uv_d->dep_entry))))
-    return false;
-
-  vars =
-    gtk_tree_view_get_model (GTK_TREE_VIEW (uv_d->factor_list));
-
-  return gtk_tree_model_get_iter_first (vars, &notused);
-}
-
-/* Reset the dialog to its default state */
-static void
-refresh (PsppireDialog *dialog, struct uni_dialog *uv_d)
-{
-  GtkTreeModel *liststore ;
-
-  gtk_entry_set_text (GTK_ENTRY (uv_d->dep_entry), "");
-
-  liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (uv_d->factor_list));
-
-  gtk_list_store_clear (GTK_LIST_STORE (liststore));
-}
-
-
-static char *
-generate_syntax (const struct uni_dialog *uvd)
-{
-  gchar *text = NULL;
-  GString *str = g_string_new ("GLM ");
-
-
-  g_string_append (str, gtk_entry_get_text (GTK_ENTRY (uvd->dep_entry)));
-  
-
-  g_string_append (str, " BY ");
-
-  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (uvd->factor_list), 0, str);
-
-
-  g_string_append (str, ".");
-
-  text = str->str;
-
-  g_string_free (str, FALSE);
-
-  return text;
-}
-
-void 
-univariate_dialog (PsppireDataWindow * de)
-{
-  struct uni_dialog uv_d;
-
-  gint response;
-
-  GtkBuilder *xml = builder_new ("univariate.ui");
-
-  GtkWidget *dialog = get_widget_assert   (xml, "univariate-dialog");
-  GtkWidget *source = get_widget_assert   (xml, "dict-view");
-
-  GtkWidget *dep_selector = get_widget_assert (xml, "dep-selector");
-  GtkWidget *factor_selector = get_widget_assert (xml, "factor-selector");
-
-
-  uv_d.dep_entry = get_widget_assert (xml, "dep-entry");
-  uv_d.factor_list = get_widget_assert (xml, "factors-view");
-
-  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
-  g_signal_connect (dialog, "refresh", G_CALLBACK (refresh),  &uv_d);
-
-  psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
-                                     dialog_state_valid, &uv_d);
-
-
-  g_object_get (de->data_editor, "dictionary", &uv_d.dict, NULL);
-  g_object_set (source, "model", uv_d.dict, NULL);
-
-  psppire_selector_set_allow (PSPPIRE_SELECTOR (dep_selector),
-                             numeric_only);
-
-  psppire_selector_set_filter_func (PSPPIRE_SELECTOR (dep_selector),
-                                   is_currently_in_entry);
-
-
-  psppire_selector_set_filter_func (PSPPIRE_SELECTOR (factor_selector),
-                                   is_currently_in_varview);
-
-  response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
-
-
-  switch (response)
-    {
-    case GTK_RESPONSE_OK:
-      g_free (execute_syntax_string (de, generate_syntax (&uv_d)));
-      break;
-    case PSPPIRE_RESPONSE_PASTE:
-      g_free (paste_syntax_to_window (generate_syntax (&uv_d)));
-      break;
-    default:
-      break;
-    }
-
-  g_object_unref (xml);
-}
-
-
diff --git a/src/ui/gui/univariate-dialog.h b/src/ui/gui/univariate-dialog.h
deleted file mode 100644 (file)
index 5fef0ba..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2011  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 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.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef __UNIVARIATE_DIALOG_H
-#define __UNIVARIATE_DIALOG_H
-
-#include "psppire-data-window.h"
-
-void univariate_dialog (PsppireDataWindow * data);
-
-#endif
index 00942a4a6752b6dbf7801e50b18191d5eac496f1..62790a2d818539025714e046874f6bd501f5c9d6 100644 (file)
@@ -36,6 +36,7 @@
 #include "psppire-dialog-action-roc.h"
 #include "psppire-dialog-action-runs.h"
 #include "psppire-dialog-action-sort.h"
+#include "psppire-dialog-action-univariate.h"
 #include "psppire-dialog-action-var-info.h"
 #include "psppire-value-entry.h"
 
@@ -80,6 +81,7 @@ preregister_widgets (void)
   psppire_dialog_action_roc_get_type ();
   psppire_dialog_action_runs_get_type ();
   psppire_dialog_action_sort_get_type ();
+  psppire_dialog_action_univariate_get_type ();
 
   /* This seems to be necessary on Cygwin.
      It ought not to be necessary.  Having it here can't do any harm. */