Converted the correlations dialog to a PsppireDialogAction object
authorJohn Darrington <john@darrington.wattle.id.au>
Sun, 29 Jan 2012 09:30:44 +0000 (10:30 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Sun, 29 Jan 2012 09:30:44 +0000 (10:30 +0100)
src/ui/gui/automake.mk
src/ui/gui/correlation-dialog.c [deleted file]
src/ui/gui/correlation-dialog.h [deleted file]
src/ui/gui/data-editor.ui
src/ui/gui/psppire-data-window.c
src/ui/gui/psppire-dialog-action-correlation.c [new file with mode: 0644]
src/ui/gui/psppire-dialog-action-correlation.h [new file with mode: 0644]
src/ui/gui/widgets.c

index 477010e7fa80838bb86ac71673f81c7a05c3a2e3..deafc52a5f606795695c04c013d6602c987cb350 100644 (file)
@@ -154,8 +154,6 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/compute-dialog.h \
        src/ui/gui/chi-square-dialog.c \
        src/ui/gui/chi-square-dialog.h \
-       src/ui/gui/correlation-dialog.c \
-       src/ui/gui/correlation-dialog.h \
        src/ui/gui/count-dialog.c \
        src/ui/gui/count-dialog.h \
        src/ui/gui/crosstabs-dialog.c \
@@ -212,6 +210,8 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/psppire-dialog.h \
        src/ui/gui/psppire-dialog-action.c \
        src/ui/gui/psppire-dialog-action.h \
+       src/ui/gui/psppire-dialog-action-correlation.c \
+       src/ui/gui/psppire-dialog-action-correlation.h \
        src/ui/gui/psppire-dialog-action-descriptives.c \
        src/ui/gui/psppire-dialog-action-descriptives.h \
        src/ui/gui/psppire-dialog-action-var-info.c \
diff --git a/src/ui/gui/correlation-dialog.c b/src/ui/gui/correlation-dialog.c
deleted file mode 100644 (file)
index 78510dc..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2009, 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 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 "dialog-common.h"
-#include <ui/syntax-gen.h>
-#include <libpspp/str.h>
-
-#include "correlation-dialog.h"
-#include "psppire-selector.h"
-#include "psppire-dictview.h"
-#include "psppire-dialog.h"
-
-#include "psppire-data-window.h"
-#include "psppire-var-view.h"
-
-#include "executor.h"
-#include "builder-wrapper.h"
-#include "helper.h"
-
-#include <gtk/gtk.h>
-
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
-
-
-struct correlation
-{
-  PsppireDict *dict;
-
-  GtkWidget *variables ;
-
-  GtkWidget *significant;
-  GtkWidget *two_tailed;
-};
-
-
-static char * generate_syntax (const struct correlation *rd);
-
-
-static void
-refresh (struct correlation *rd)
-{
-  GtkTreeModel *liststore =
-    gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables));
-  gtk_list_store_clear (GTK_LIST_STORE (liststore));
-
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->significant), FALSE);
-
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->two_tailed), TRUE);
-}
-
-
-static gboolean
-dialog_state_valid (gpointer data)
-{
-  struct correlation *corr = data;
-
-  GtkTreeModel *liststore =
-    gtk_tree_view_get_model (GTK_TREE_VIEW (corr->variables));
-
-  if  (gtk_tree_model_iter_n_children (liststore, NULL) > 1)
-    return TRUE;
-
-  return FALSE;
-}
-
-
-/* Pops up the Correlation dialog box */
-void
-correlation_dialog (PsppireDataWindow *de)
-{
-  struct correlation rd;
-  gint response;
-
-  GtkBuilder *xml = builder_new ("correlation.ui");
-  PsppireVarStore *vs;
-
-  GtkWidget *dialog = get_widget_assert   (xml, "correlation-dialog");
-  GtkWidget *source = get_widget_assert   (xml, "dict-view");
-
-  g_object_get (de->data_editor, "var-store", &vs, NULL);
-
-  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
-
-  g_object_get (vs, "dictionary", &rd.dict, NULL);
-  g_object_set (source,
-               "model", rd.dict, 
-               "predicate", var_is_numeric,
-               NULL);
-
-  rd.variables = get_widget_assert (xml, "psppire-var-view1");
-  rd.significant = get_widget_assert (xml, "button-flag-significants");
-  rd.two_tailed = get_widget_assert (xml, "button-two-tailed");
-
-  g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh),  &rd);
-
-  psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
-                                     dialog_state_valid, &rd);
-
-  response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
-
-  switch (response)
-    {
-    case GTK_RESPONSE_OK:
-      g_free (execute_syntax_string (de, generate_syntax (&rd)));
-      break;
-    case PSPPIRE_RESPONSE_PASTE:
-      g_free (paste_syntax_to_window (generate_syntax (&rd)));
-      break;
-    default:
-      break;
-    }
-
-  g_object_unref (xml);
-}
-
-
-\f
-
-static char *
-generate_syntax (const struct correlation *rd)
-{
-  gchar *text;
-  GString *string = g_string_new ("CORRELATION");
-  g_string_append (string, "\n\t/VARIABLES = ");
-
-  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->variables), 0, string);
-
-
-  g_string_append (string, "\n\t/PRINT =");
-
-  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->two_tailed)))
-    g_string_append (string, " TWOTAIL");
-  else
-    g_string_append (string, " ONETAIL");
-
-
-  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->significant)))
-    g_string_append (string, " NOSIG");
-  else
-    g_string_append (string, " SIG");
-
-
-  g_string_append (string, ".\n");
-
-  text = string->str;
-
-  g_string_free (string, FALSE);
-
-  return text;
-}
diff --git a/src/ui/gui/correlation-dialog.h b/src/ui/gui/correlation-dialog.h
deleted file mode 100644 (file)
index 9a05837..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2009, 2010  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 __CORRELATION_DIALOG_H
-#define __CORRELATION_DIALOG_H
-
-#include "psppire-data-window.h"
-
-void correlation_dialog (PsppireDataWindow * data);
-
-#endif
index d190a44cf8cbd1a30a7be0b28cd89e112946b622..8c77b9811b6f2c5a11fb07eea42bd567da61e980 100644 (file)
           </object>
         </child>
         <child>
-          <object class="GtkAction" id="correlation">
+          <object class="PsppireDialogActionCorrelation" id="correlation">
             <property name="name">correlation</property>
+            <property name="manager">uimanager1</property>
             <property name="label" translatable="yes">Bivariate _Correlation...</property>
           </object>
         </child>
index 7d58540425a586ecb77fd1380a22e6c129358fe5..8ee4cafeda143f870380f4c397dcdd15ec68175e 100644 (file)
@@ -31,7 +31,6 @@
 #include "ui/gui/chi-square-dialog.h"
 #include "ui/gui/comments-dialog.h"
 #include "ui/gui/compute-dialog.h"
-#include "ui/gui/correlation-dialog.h"
 #include "ui/gui/count-dialog.h"
 #include "ui/gui/crosstabs-dialog.h"
 #include "ui/gui/entry-dialog.h"
@@ -1116,8 +1115,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
 
   connect_action (de, "univariate", G_CALLBACK (univariate_dialog));
 
-  connect_action (de, "correlation", G_CALLBACK (correlation_dialog));
   connect_action (de, "factor-analysis", G_CALLBACK (factor_dialog));
 
   connect_action (de, "k-means", G_CALLBACK (k_means_dialog));
diff --git a/src/ui/gui/psppire-dialog-action-correlation.c b/src/ui/gui/psppire-dialog-action-correlation.c
new file mode 100644 (file)
index 0000000..c86dd51
--- /dev/null
@@ -0,0 +1,129 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 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 "psppire-dialog-action-correlation.h"
+
+#include "psppire-var-view.h"
+
+#include "psppire-dialog.h"
+#include "builder-wrapper.h"
+
+static void psppire_dialog_action_correlation_init            (PsppireDialogActionCorrelation      *act);
+static void psppire_dialog_action_correlation_class_init      (PsppireDialogActionCorrelationClass *class);
+
+G_DEFINE_TYPE (PsppireDialogActionCorrelation, psppire_dialog_action_correlation, PSPPIRE_TYPE_DIALOG_ACTION);
+
+static char *
+generate_syntax (PsppireDialogAction *act)
+{
+  PsppireDialogActionCorrelation *rd = PSPPIRE_DIALOG_ACTION_CORRELATION (act);
+  gchar *text;
+  GString *string = g_string_new ("CORRELATION");
+  g_string_append (string, "\n\t/VARIABLES = ");
+
+  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->variables), 0, string);
+
+
+  g_string_append (string, "\n\t/PRINT =");
+
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->two_tailed)))
+    g_string_append (string, " TWOTAIL");
+  else
+    g_string_append (string, " ONETAIL");
+
+
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->significant)))
+    g_string_append (string, " NOSIG");
+  else
+    g_string_append (string, " SIG");
+
+
+  g_string_append (string, ".\n");
+
+  text = string->str;
+
+  g_string_free (string, FALSE);
+
+  return text;
+}
+
+
+static gboolean
+dialog_state_valid (gpointer user_data)
+{
+  PsppireDialogActionCorrelation *corr = user_data;
+  GtkTreeModel *liststore =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (corr->variables));
+
+  if  (gtk_tree_model_iter_n_children (liststore, NULL) > 1)
+    return TRUE;
+
+  return FALSE;
+}
+
+static void
+refresh (PsppireDialogActionCorrelation *rd)
+{
+  GtkTreeModel *liststore =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables));
+  gtk_list_store_clear (GTK_LIST_STORE (liststore));
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->significant), FALSE);
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->two_tailed), TRUE);
+}
+
+static void
+psppire_dialog_action_correlation_activate (GtkAction *a)
+{
+  PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
+  PsppireDialogActionCorrelation *act = PSPPIRE_DIALOG_ACTION_CORRELATION (a);
+
+  GtkBuilder *xml = builder_new ("correlation.ui");
+  pda->dialog = get_widget_assert   (xml, "correlation-dialog");
+  pda->source = get_widget_assert   (xml, "dict-view");
+
+  act->variables = get_widget_assert (xml, "psppire-var-view1");
+  act->significant = get_widget_assert (xml, "button-flag-significants");
+  act->two_tailed = get_widget_assert (xml, "button-two-tailed");
+
+  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_correlation_parent_class)->activate)
+    PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_correlation_parent_class)->activate (pda);
+}
+
+static void
+psppire_dialog_action_correlation_class_init (PsppireDialogActionCorrelationClass *class)
+{
+  GtkActionClass *action_class = GTK_ACTION_CLASS (class);
+
+  action_class->activate = psppire_dialog_action_correlation_activate;
+  PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
+}
+
+
+static void
+psppire_dialog_action_correlation_init (PsppireDialogActionCorrelation *act)
+{
+}
+
diff --git a/src/ui/gui/psppire-dialog-action-correlation.h b/src/ui/gui/psppire-dialog-action-correlation.h
new file mode 100644 (file)
index 0000000..f4a4855
--- /dev/null
@@ -0,0 +1,81 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 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 <glib-object.h>
+#include <glib.h>
+
+#include "psppire-dialog-action.h"
+
+#ifndef __PSPPIRE_DIALOG_ACTION_CORRELATION_H__
+#define __PSPPIRE_DIALOG_ACTION_CORRELATION_H__
+
+G_BEGIN_DECLS
+
+
+#define PSPPIRE_TYPE_DIALOG_ACTION_CORRELATION (psppire_dialog_action_correlation_get_type ())
+
+#define PSPPIRE_DIALOG_ACTION_CORRELATION(obj) \
+                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                                                 PSPPIRE_TYPE_DIALOG_ACTION_CORRELATION, PsppireDialogActionCorrelation))
+
+#define PSPPIRE_DIALOG_ACTION_CORRELATION_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_CAST ((klass), \
+                                PSPPIRE_TYPE_DIALOG_ACTION_CORRELATION, \
+                                 PsppireDialogActionCorrelationClass))
+
+
+#define PSPPIRE_IS_DIALOG_ACTION_CORRELATION(obj) \
+                    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_CORRELATION))
+
+#define PSPPIRE_IS_DIALOG_ACTION_CORRELATION_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_CORRELATION))
+
+
+#define PSPPIRE_DIALOG_ACTION_CORRELATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                                  PSPPIRE_TYPE_DIALOG_ACTION_CORRELATION, \
+                                  PsppireDialogActionCorrelationClass))
+
+typedef struct _PsppireDialogActionCorrelation       PsppireDialogActionCorrelation;
+typedef struct _PsppireDialogActionCorrelationClass  PsppireDialogActionCorrelationClass;
+
+
+struct _PsppireDialogActionCorrelation
+{
+  PsppireDialogAction parent;
+
+  /*< private >*/
+  gboolean dispose_has_run ;
+
+
+  /* Treeview containing the selected variables */
+  GtkWidget *variables;
+  GtkWidget *significant;
+  GtkWidget *two_tailed;
+};
+
+
+struct _PsppireDialogActionCorrelationClass
+{
+  PsppireDialogActionClass parent_class;
+};
+
+
+GType psppire_dialog_action_correlation_get_type (void) ;
+
+G_END_DECLS
+
+#endif /* __PSPPIRE_DIALOG_ACTION_CORRELATION_H__ */
index cedab8c085ee0a7af26a776c534aebdd4b7e7aaf..3a0e338a89b870a9d65e17fca41933da4b3ad37e 100644 (file)
@@ -13,6 +13,7 @@
 #include "psppire-var-view.h"
 #include "psppire-val-chooser.h"
 
+#include "psppire-dialog-action-correlation.h"
 #include "psppire-dialog-action-descriptives.h"
 #include "psppire-dialog-action-var-info.h"
 
@@ -33,6 +34,7 @@ preregister_widgets (void)
   psppire_dict_view_get_type ();
   psppire_var_view_get_type ();
 
+  psppire_dialog_action_correlation_get_type ();
   psppire_dialog_action_descriptives_get_type ();
   psppire_dialog_action_var_info_get_type ();
 }