K-Related Samples Test Dialog: Convert from old style to PsppireDialogAction
authorJohn Darrington <john@darrington.wattle.id.au>
Wed, 9 Oct 2013 10:20:08 +0000 (12:20 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Wed, 9 Oct 2013 10:20:08 +0000 (12:20 +0200)
src/ui/gui/automake.mk
src/ui/gui/data-editor.ui
src/ui/gui/k-related-dialog.c [deleted file]
src/ui/gui/k-related-dialog.h [deleted file]
src/ui/gui/psppire-data-window.c
src/ui/gui/psppire-dialog-action-k-related.c [new file with mode: 0644]
src/ui/gui/psppire-dialog-action-k-related.h [new file with mode: 0644]
src/ui/gui/widgets.c

index 5d10360e8b7394f843d1656e5626f9531b3f796a..bd1ae5280af92da497198984b81dafabb42e1c18 100644 (file)
@@ -159,8 +159,6 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/help-menu.c \
        src/ui/gui/help-menu.h \
        src/ui/gui/helper.h \
-       src/ui/gui/k-related-dialog.c \
-       src/ui/gui/k-related-dialog.h \
        src/ui/gui/main.c \
        src/ui/gui/missing-val-dialog.c \
        src/ui/gui/missing-val-dialog.h \
@@ -213,6 +211,8 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/psppire-dialog-action-kmeans.h \
        src/ui/gui/psppire-dialog-action-logistic.c \
        src/ui/gui/psppire-dialog-action-logistic.h \
+       src/ui/gui/psppire-dialog-action-k-related.c \
+       src/ui/gui/psppire-dialog-action-k-related.h \
        src/ui/gui/psppire-dialog-action-means.c \
        src/ui/gui/psppire-dialog-action-means.h \
        src/ui/gui/psppire-dialog-action-rank.c \
index ba059b43c06ab5cf71c2c355e8fa30e6d4a8b632..5e944575e62c0014f97e7959f072e8937533e4eb 100644 (file)
           </object>
         </child>
         <child>
-          <object class="GtkAction" id="k-related-samples">
+          <object class="PsppireDialogActionKRelated" id="k-related-samples">
             <property name="name">"k-related-samples"></property>
+            <property name="manager">uimanager1</property>
             <property name="label" translatable="yes">K Related _Samples...</property>
           </object>
         </child>
diff --git a/src/ui/gui/k-related-dialog.c b/src/ui/gui/k-related-dialog.c
deleted file mode 100644 (file)
index 867583a..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-/* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 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 "k-related-dialog.h"
-
-#include "psppire-dialog.h"
-#include "psppire-var-view.h"
-#include "psppire-acr.h"
-#include "dialog-common.h"
-
-#include "builder-wrapper.h"
-#include "executor.h"
-#include "helper.h"
-
-#include <gtk/gtk.h>
-
-struct k_related_dialog
-{
-  PsppireDict *dict;
-  GtkWidget *var_view;
-
-  GtkWidget *friedman;
-  GtkWidget *kendal;
-  GtkWidget *cochran;
-};
-
-static gboolean
-dialog_state_valid (gpointer data)
-{
-  struct k_related_dialog *krd = data;
-
-  GtkTreeModel *vars =
-    gtk_tree_view_get_model (GTK_TREE_VIEW (krd->var_view));
-
-  /* Tests using less than 3 variables are not useful */
-  if (gtk_tree_model_iter_n_children (vars, NULL) < 3)
-    return FALSE;
-
-  /* At least one checkbutton must be active */
-  if ( 
-      ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->friedman))
-      && 
-      ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->kendal))
-      && 
-      ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->cochran))
-       )
-    return FALSE;
-
-  return TRUE;
-}
-
-
-static void
-refresh (struct k_related_dialog *krd)
-{
-  GtkTreeModel *liststore =
-    gtk_tree_view_get_model (GTK_TREE_VIEW (krd->var_view));
-
-  gtk_list_store_clear (GTK_LIST_STORE (liststore));
-
-
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (krd->friedman), TRUE);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (krd->kendal), FALSE);
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (krd->cochran), FALSE);
-}
-
-
-static char *
-generate_syntax (const struct k_related_dialog *krd)
-{
-  gchar *text;
-  GString *string;
-
-  string = g_string_new ("NPAR TEST");
-
-  if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->friedman)))
-    {
-      g_string_append (string, "\n\t/FRIEDMAN = ");
-      psppire_var_view_append_names (PSPPIRE_VAR_VIEW (krd->var_view), 0, string);
-    }
-
-  if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->kendal)))
-    {
-      g_string_append (string, "\n\t/KENDALL = ");
-      psppire_var_view_append_names (PSPPIRE_VAR_VIEW (krd->var_view), 0, string);
-    }
-
-  if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->cochran)))
-    {
-      g_string_append (string, "\n\t/COCHRAN = ");
-      psppire_var_view_append_names (PSPPIRE_VAR_VIEW (krd->var_view), 0, string);
-    }
-
-  g_string_append (string, ".\n");
-
-  text = string->str;
-
-  g_string_free (string, FALSE);
-
-  return text;
-}
-
-
-
-/* Pops up the K-Related dialog box */
-void
-k_related_dialog (PsppireDataWindow *dw)
-{
-  gint response;
-
-  struct k_related_dialog krd;
-
-  GtkBuilder *xml = builder_new ("k-related.ui");
-
-  GtkWidget *dialog = get_widget_assert   (xml, "k-related-dialog");
-
-  GtkWidget *dict_view = get_widget_assert   (xml, "dict-view");
-
-  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (dw));
-
-  krd.var_view  = get_widget_assert (xml, "variables-treeview");
-
-  krd.friedman =  get_widget_assert (xml, "friedman-checkbutton");
-  krd.kendal =  get_widget_assert (xml, "kendal-checkbutton");
-  krd.cochran =  get_widget_assert (xml, "cochran-checkbutton");
-
-  g_object_get (dw->data_editor, "dictionary", &krd.dict, NULL);
-  g_object_set (dict_view,
-               "model", krd.dict, 
-               "predicate", var_is_numeric,
-               NULL);
-
-
-  g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh),  &krd);
-
-  psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
-                                     dialog_state_valid, &krd);
-
-  response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
-
-
-  switch (response)
-    {
-    case GTK_RESPONSE_OK:
-      g_free (execute_syntax_string (dw, generate_syntax (&krd)));
-      break;
-    case PSPPIRE_RESPONSE_PASTE:
-      g_free (paste_syntax_to_window (generate_syntax (&krd)));
-      break;
-    default:
-      break;
-    }
-
-  g_object_unref (xml);
-}
diff --git a/src/ui/gui/k-related-dialog.h b/src/ui/gui/k-related-dialog.h
deleted file mode 100644 (file)
index 73288b6..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 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 K_RELATED_DIALOG
-#define K_RELATED_DIALOG 1
-
-#include "psppire-data-window.h"
-
-void k_related_dialog (PsppireDataWindow *dw);
-
-
-#endif
index 069a3e841357277ac11be78bc40f685d92d42ee4..fd2f4ff055adce55c53d89ec17cf6519e3ad4176 100644 (file)
@@ -35,7 +35,6 @@
 #include "ui/gui/help-menu.h"
 #include "ui/gui/helper.h"
 #include "ui/gui/helper.h"
-#include "ui/gui/k-related-dialog.h"
 #include "ui/gui/npar-two-sample-related.h"
 #include "ui/gui/oneway-anova-dialog.h"
 #include "ui/gui/psppire-data-window.h"
@@ -967,7 +966,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, "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-k-related.c b/src/ui/gui/psppire-dialog-action-k-related.c
new file mode 100644 (file)
index 0000000..9f1b588
--- /dev/null
@@ -0,0 +1,149 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2010, 2011, 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-k-related.h"
+
+#include "psppire-var-view.h"
+
+#include "psppire-dialog.h"
+#include "builder-wrapper.h"
+
+static void psppire_dialog_action_k_related_init            (PsppireDialogActionKRelated      *act);
+static void psppire_dialog_action_k_related_class_init      (PsppireDialogActionKRelatedClass *class);
+
+G_DEFINE_TYPE (PsppireDialogActionKRelated, psppire_dialog_action_k_related, PSPPIRE_TYPE_DIALOG_ACTION);
+
+static char *
+generate_syntax (PsppireDialogAction *act)
+{
+  PsppireDialogActionKRelated *krd = PSPPIRE_DIALOG_ACTION_K_RELATED (act);
+  gchar *text;
+
+  GString *string = g_string_new ("NPAR TEST");
+
+  if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->friedman)))
+    {
+      g_string_append (string, "\n\t/FRIEDMAN = ");
+      psppire_var_view_append_names (PSPPIRE_VAR_VIEW (krd->var_view), 0, string);
+    }
+
+  if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->kendal)))
+    {
+      g_string_append (string, "\n\t/KENDALL = ");
+      psppire_var_view_append_names (PSPPIRE_VAR_VIEW (krd->var_view), 0, string);
+    }
+
+  if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->cochran)))
+    {
+      g_string_append (string, "\n\t/COCHRAN = ");
+      psppire_var_view_append_names (PSPPIRE_VAR_VIEW (krd->var_view), 0, string);
+    }
+
+  g_string_append (string, ".\n");
+
+  text = string->str;
+
+  g_string_free (string, FALSE);
+
+  return text;
+}
+
+
+static gboolean
+dialog_state_valid (gpointer data)
+{
+  PsppireDialogActionKRelated *krd = PSPPIRE_DIALOG_ACTION_K_RELATED (data);
+
+  GtkTreeModel *vars =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (krd->var_view));
+
+  /* Tests using less than 3 variables are not useful */
+  if (gtk_tree_model_iter_n_children (vars, NULL) < 3)
+    return FALSE;
+
+  /* At least one checkbutton must be active */
+  if ( 
+      ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->friedman))
+      && 
+      ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->kendal))
+      && 
+      ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->cochran))
+       )
+    return FALSE;
+
+  return TRUE;
+}
+
+static void
+refresh (PsppireDialogAction *rd_)
+{
+  PsppireDialogActionKRelated *krd = PSPPIRE_DIALOG_ACTION_K_RELATED (rd_);
+  GtkTreeModel *liststore =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (krd->var_view));
+
+  gtk_list_store_clear (GTK_LIST_STORE (liststore));
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (krd->friedman), TRUE);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (krd->kendal), FALSE);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (krd->cochran), FALSE);
+}
+
+static void
+psppire_dialog_action_k_related_activate (GtkAction *a)
+{
+  PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
+  PsppireDialogActionKRelated *act = PSPPIRE_DIALOG_ACTION_K_RELATED (a);
+
+  GtkBuilder *xml = builder_new ("k-related.ui");
+  pda->dialog = get_widget_assert   (xml, "k-related-dialog");
+  pda->source = get_widget_assert   (xml, "dict-view");
+
+  act->var_view  = get_widget_assert (xml, "variables-treeview");
+  act->friedman =  get_widget_assert (xml, "friedman-checkbutton");
+  act->kendal =  get_widget_assert (xml, "kendal-checkbutton");
+  act->cochran =  get_widget_assert (xml, "cochran-checkbutton");
+
+  psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
+  psppire_dialog_action_set_refresh (pda, refresh);
+
+  g_object_set (pda->source,
+               "predicate", var_is_numeric,
+               NULL);
+
+  g_object_unref (xml);
+
+  if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_k_related_parent_class)->activate)
+    PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_k_related_parent_class)->activate (pda);
+}
+
+static void
+psppire_dialog_action_k_related_class_init (PsppireDialogActionKRelatedClass *class)
+{
+  GtkActionClass *action_class = GTK_ACTION_CLASS (class);
+
+  action_class->activate = psppire_dialog_action_k_related_activate;
+  PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
+}
+
+
+static void
+psppire_dialog_action_k_related_init (PsppireDialogActionKRelated *act)
+{
+}
+
diff --git a/src/ui/gui/psppire-dialog-action-k-related.h b/src/ui/gui/psppire-dialog-action-k-related.h
new file mode 100644 (file)
index 0000000..c92c06b
--- /dev/null
@@ -0,0 +1,81 @@
+/* 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_K_RELATED_H__
+#define __PSPPIRE_DIALOG_ACTION_K_RELATED_H__
+
+G_BEGIN_DECLS
+
+
+#define PSPPIRE_TYPE_DIALOG_ACTION_K_RELATED (psppire_dialog_action_k_related_get_type ())
+
+#define PSPPIRE_DIALOG_ACTION_K_RELATED(obj)   \
+                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                                                 PSPPIRE_TYPE_DIALOG_ACTION_K_RELATED, PsppireDialogActionKRelated))
+
+#define PSPPIRE_DIALOG_ACTION_K_RELATED_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_CAST ((klass), \
+                                PSPPIRE_TYPE_DIALOG_ACTION_K_RELATED, \
+                                 PsppireDialogActionKRelatedClass))
+
+
+#define PSPPIRE_IS_DIALOG_ACTION_K_RELATED(obj) \
+                    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_K_RELATED))
+
+#define PSPPIRE_IS_DIALOG_ACTION_K_RELATED_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_K_RELATED))
+
+
+#define PSPPIRE_DIALOG_ACTION_K_RELATED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                                  PSPPIRE_TYPE_DIALOG_ACTION_K_RELATED, \
+                                  PsppireDialogActionKRelatedClass))
+
+typedef struct _PsppireDialogActionKRelated       PsppireDialogActionKRelated;
+typedef struct _PsppireDialogActionKRelatedClass  PsppireDialogActionKRelatedClass;
+
+
+struct _PsppireDialogActionKRelated
+{
+  PsppireDialogAction parent;
+
+  /*< private >*/
+  gboolean dispose_has_run ;
+
+  GtkWidget *var_view;
+  GtkWidget *friedman;
+  GtkWidget *kendal ;
+  GtkWidget *cochran;
+};
+
+
+
+struct _PsppireDialogActionKRelatedClass
+{
+  PsppireDialogActionClass parent_class;
+};
+
+
+GType psppire_dialog_action_k_related_get_type (void) ;
+
+G_END_DECLS
+
+#endif /* __PSPPIRE_DIALOG_ACTION_K_RELATED_H__ */
index b61f13247a8410c8e450a3762c1ec3b81f190ebb..9a4c766d1677c2fcfaa1cf84a34bf60a6f441e70 100644 (file)
@@ -26,6 +26,7 @@
 #include "psppire-dialog-action-factor.h"
 #include "psppire-dialog-action-frequencies.h"
 #include "psppire-dialog-action-indep-samps.h"
+#include "psppire-dialog-action-k-related.h"
 #include "psppire-dialog-action-1sks.h"
 #include "psppire-dialog-action-kmeans.h"
 #include "psppire-dialog-action-logistic.h"
@@ -74,6 +75,7 @@ preregister_widgets (void)
   psppire_dialog_action_frequencies_get_type ();
   psppire_dialog_action_logistic_get_type ();
   psppire_dialog_action_kmeans_get_type ();
+  psppire_dialog_action_k_related_get_type ();
   psppire_dialog_action_means_get_type ();
   psppire_dialog_action_indep_samps_get_type ();
   psppire_means_layer_get_type ();