Converted reliability dialog to a PsppireDialogAction object
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 30 Jan 2012 20:40:33 +0000 (21:40 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 30 Jan 2012 20:40:33 +0000 (21:40 +0100)
src/ui/gui/automake.mk
src/ui/gui/data-editor.ui
src/ui/gui/psppire-data-window.c
src/ui/gui/psppire-dialog-action-reliability.c [new file with mode: 0644]
src/ui/gui/psppire-dialog-action-reliability.h [new file with mode: 0644]
src/ui/gui/reliability-dialog.c [deleted file]
src/ui/gui/reliability-dialog.h [deleted file]
src/ui/gui/widgets.c

index 0dcd519ce775b14638dfe5cca921bdd80c376cb6..630a8d9974f13d34ea3514948be6e676c2a08608 100644 (file)
@@ -214,6 +214,8 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/psppire-dialog-action-descriptives.h \
        src/ui/gui/psppire-dialog-action-kmeans.c \
        src/ui/gui/psppire-dialog-action-kmeans.h \
+       src/ui/gui/psppire-dialog-action-reliability.c \
+       src/ui/gui/psppire-dialog-action-reliability.h \
        src/ui/gui/psppire-dialog-action-var-info.c \
        src/ui/gui/psppire-dialog-action-var-info.h \
        src/ui/gui/psppire-dialog-action-roc.c \
@@ -256,8 +258,6 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/recode-dialog.h \
        src/ui/gui/regression-dialog.c \
        src/ui/gui/regression-dialog.h \
-       src/ui/gui/reliability-dialog.c \
-       src/ui/gui/reliability-dialog.h \
        src/ui/gui/runs-dialog.c \
        src/ui/gui/runs-dialog.h \
        src/ui/gui/select-cases-dialog.c \
index 7762f584c6c45fd5f5e19cf2f9cdc3f164115e0d..46bb823bd22c55eb75f20429a8f7762909394a34 100644 (file)
           </object>
         </child>
         <child>
-          <object class="GtkAction" id="reliability">
+          <object class="PsppireDialogActionReliability" id="reliability">
             <property name="name">reliability</property>
+            <property name="manager">uimanager1</property>
             <property name="label" translatable="yes">Re_liability...</property>
           </object>
         </child>
index 3b9ad7da1a589d2f476bc02b3af9607d80daf80f..13e9614ca021223cbaaba02b59c871946fd7c097 100644 (file)
@@ -55,7 +55,6 @@
 #include "ui/gui/ks-one-sample-dialog.h"
 #include "ui/gui/recode-dialog.h"
 #include "ui/gui/regression-dialog.h"
-#include "ui/gui/reliability-dialog.h"
 #include "ui/gui/select-cases-dialog.h"
 #include "ui/gui/sort-cases-dialog.h"
 #include "ui/gui/split-file-dialog.h"
@@ -1105,8 +1104,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
  
   connect_action (de, "linear-regression", G_CALLBACK (regression_dialog));
  
-  connect_action (de, "reliability", G_CALLBACK (reliability_dialog));
   connect_action (de, "univariate", G_CALLBACK (univariate_dialog));
 
   connect_action (de, "factor-analysis", G_CALLBACK (factor_dialog));
diff --git a/src/ui/gui/psppire-dialog-action-reliability.c b/src/ui/gui/psppire-dialog-action-reliability.c
new file mode 100644 (file)
index 0000000..296d152
--- /dev/null
@@ -0,0 +1,148 @@
+/* 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-reliability.h"
+
+#include "psppire-var-view.h"
+
+#include "psppire-dialog.h"
+#include "builder-wrapper.h"
+
+static void psppire_dialog_action_reliability_init            (PsppireDialogActionReliability      *act);
+static void psppire_dialog_action_reliability_class_init      (PsppireDialogActionReliabilityClass *class);
+
+G_DEFINE_TYPE (PsppireDialogActionReliability, psppire_dialog_action_reliability, PSPPIRE_TYPE_DIALOG_ACTION);
+
+static char *
+generate_syntax (PsppireDialogAction *act)
+{
+  PsppireDialogActionReliability *rd = PSPPIRE_DIALOG_ACTION_RELIABILITY (act);
+  gchar *text;
+  GString *string = g_string_new ("RELIABILITY");
+
+  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/MODEL=");
+
+  if ( 0 == gtk_combo_box_get_active (GTK_COMBO_BOX (rd->model_combo)))
+    g_string_append (string, "ALPHA");
+  else
+    g_string_append_printf (string, "SPLIT (%d)",
+                           gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (rd->split_spinbutton))
+                           );
+
+  if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->scale_if_item_deleted_checkbutton)))
+    g_string_append (string, "\n\t/SUMMARY = TOTAL");
+
+  g_string_append (string, ".\n");
+
+  text = string->str;
+
+  g_string_free (string, FALSE);
+
+  return text;
+}
+
+
+static gboolean
+dialog_state_valid (gpointer user_data)
+{
+  PsppireDialogActionReliability *pda = user_data;
+  GtkTreeModel *liststore =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (pda->variables));
+
+  return (2 <= gtk_tree_model_iter_n_children (liststore, NULL));
+}
+
+static void
+on_method_change (PsppireDialogActionReliability *pda)
+{
+  gtk_widget_set_sensitive (pda->split_point_hbox,
+                           ( 1 == gtk_combo_box_get_active (GTK_COMBO_BOX (pda->model_combo))));
+}
+
+
+static void
+refresh (PsppireDialogActionReliability *pda)
+{
+  GtkTreeModel *liststore =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (pda->variables));
+  gtk_list_store_clear (GTK_LIST_STORE (liststore));
+
+  gtk_combo_box_set_active (GTK_COMBO_BOX (pda->model_combo), 0);
+
+  gtk_spin_button_set_value (GTK_SPIN_BUTTON (pda->split_spinbutton), 0);
+
+  gtk_spin_button_set_range (GTK_SPIN_BUTTON (pda->split_spinbutton),
+                            0, 0);
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pda->scale_if_item_deleted_checkbutton),
+                               FALSE);
+}
+
+static void
+psppire_dialog_action_reliability_activate (GtkAction *a)
+{
+  PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
+  PsppireDialogActionReliability *act = PSPPIRE_DIALOG_ACTION_RELIABILITY (a);
+
+  GtkBuilder *xml = builder_new ("reliability.ui");
+  pda->dialog = get_widget_assert   (xml, "reliability-dialog");
+  pda->source = get_widget_assert   (xml, "dict-view");
+
+  act->variables = get_widget_assert   (xml, "treeview2");
+
+  act->split_point_hbox = get_widget_assert (xml, "split-point-hbox");
+
+  act->variables = get_widget_assert   (xml, "treeview2");
+
+  act->model_combo = get_widget_assert   (xml, "combobox1");
+  act->split_spinbutton = get_widget_assert (xml, "spinbutton1");
+
+  act->scale_if_item_deleted_checkbutton = get_widget_assert (xml, "totals-checkbutton");
+
+  g_signal_connect_swapped (act->model_combo, "changed",
+                           G_CALLBACK (on_method_change), pda);
+
+  psppire_dialog_action_set_refresh (pda, refresh);
+  psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
+
+  if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_reliability_parent_class)->activate)
+    PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_reliability_parent_class)->activate (pda);
+}
+
+static void
+psppire_dialog_action_reliability_class_init (PsppireDialogActionReliabilityClass *class)
+{
+  GtkActionClass *action_class = GTK_ACTION_CLASS (class);
+  PsppireDialogActionClass *pdac = PSPPIRE_DIALOG_ACTION_CLASS (class);
+
+  action_class->activate = psppire_dialog_action_reliability_activate;
+
+  pdac->generate_syntax = generate_syntax;
+}
+
+
+static void
+psppire_dialog_action_reliability_init (PsppireDialogActionReliability *act)
+{
+}
+
diff --git a/src/ui/gui/psppire-dialog-action-reliability.h b/src/ui/gui/psppire-dialog-action-reliability.h
new file mode 100644 (file)
index 0000000..a75f621
--- /dev/null
@@ -0,0 +1,83 @@
+/* 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_RELIABILITY_H__
+#define __PSPPIRE_DIALOG_ACTION_RELIABILITY_H__
+
+G_BEGIN_DECLS
+
+
+#define PSPPIRE_TYPE_DIALOG_ACTION_RELIABILITY (psppire_dialog_action_reliability_get_type ())
+
+#define PSPPIRE_DIALOG_ACTION_RELIABILITY(obj) \
+                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                                                 PSPPIRE_TYPE_DIALOG_ACTION_RELIABILITY, PsppireDialogActionReliability))
+
+#define PSPPIRE_DIALOG_ACTION_RELIABILITY_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_CAST ((klass), \
+                                PSPPIRE_TYPE_DIALOG_ACTION_RELIABILITY, \
+                                 PsppireDialogActionReliabilityClass))
+
+
+#define PSPPIRE_IS_DIALOG_ACTION_RELIABILITY(obj) \
+                    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_RELIABILITY))
+
+#define PSPPIRE_IS_DIALOG_ACTION_RELIABILITY_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_RELIABILITY))
+
+
+#define PSPPIRE_DIALOG_ACTION_RELIABILITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                                  PSPPIRE_TYPE_DIALOG_ACTION_RELIABILITY, \
+                                  PsppireDialogActionReliabilityClass))
+
+typedef struct _PsppireDialogActionReliability       PsppireDialogActionReliability;
+typedef struct _PsppireDialogActionReliabilityClass  PsppireDialogActionReliabilityClass;
+
+
+struct _PsppireDialogActionReliability
+{
+  PsppireDialogAction parent;
+
+  /*< private >*/
+  gboolean dispose_has_run ;
+
+  /* Treeview containing the selected variables */
+  GtkWidget *variables;
+
+  GtkWidget *model_combo;
+  GtkWidget *split_point_hbox;
+  GtkWidget *split_spinbutton;
+  GtkWidget *scale_if_item_deleted_checkbutton;
+};
+
+
+struct _PsppireDialogActionReliabilityClass
+{
+  PsppireDialogActionClass parent_class;
+};
+
+
+GType psppire_dialog_action_reliability_get_type (void) ;
+
+G_END_DECLS
+
+#endif /* __PSPPIRE_DIALOG_ACTION_RELIABILITY_H__ */
diff --git a/src/ui/gui/reliability-dialog.c b/src/ui/gui/reliability-dialog.c
deleted file mode 100644 (file)
index c6433c1..0000000
+++ /dev/null
@@ -1,214 +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 "reliability-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 reliability
-{
-  PsppireDict *dict;
-  GtkWidget *model_combo;
-  GtkWidget *variables;
-  GtkWidget *split_point_hbox;
-  GtkWidget *split_spinbutton;
-  GtkWidget *scale_if_item_deleted_checkbutton;
-};
-
-
-static char * generate_syntax (const struct reliability *rd);
-
-
-static void
-on_vars_changed (struct reliability *rd)
-{
-  GtkTreeModel *tm =
-    gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables));
-
-  gint n_vars = gtk_tree_model_iter_n_children (tm, NULL);
-
-  gint current_value =
-    gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (rd->split_spinbutton));
-
-  gint new_value = current_value;
-
-  gtk_spin_button_set_range (GTK_SPIN_BUTTON (rd->split_spinbutton),
-                            0, n_vars - 1);
-
-  if ( current_value > n_vars - 1)
-    new_value = n_vars - 1;
-
-  gtk_spin_button_set_value (GTK_SPIN_BUTTON (rd->split_spinbutton),
-                            new_value);
-}
-
-static void
-on_method_change (struct reliability *rd)
-{
-  gtk_widget_set_sensitive (rd->split_point_hbox,
-                           ( 1 == gtk_combo_box_get_active (GTK_COMBO_BOX (rd->model_combo))));
-
-}
-
-static void
-refresh (PsppireDialog *dialog, struct reliability *rd)
-{
-  GtkTreeModel *liststore =
-    gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables));
-  gtk_list_store_clear (GTK_LIST_STORE (liststore));
-
-  gtk_combo_box_set_active (GTK_COMBO_BOX (rd->model_combo), 0);
-
-  gtk_spin_button_set_value (GTK_SPIN_BUTTON (rd->split_spinbutton), 0);
-
-  gtk_spin_button_set_range (GTK_SPIN_BUTTON (rd->split_spinbutton),
-                            0, 0);
-
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->scale_if_item_deleted_checkbutton),
-                               FALSE);
-}
-
-
-static gboolean
-dialog_state_valid (gpointer data)
-{
-  struct reliability *rd = data;
-
-  GtkTreeModel *liststore =
-    gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables));
-
-  return (2 <= gtk_tree_model_iter_n_children (liststore, NULL));
-}
-
-
-/* Pops up the Reliability dialog box */
-void
-reliability_dialog (PsppireDataWindow *de)
-{
-  struct reliability rd;
-  gint response;
-
-  GtkBuilder *xml = builder_new ("reliability.ui");
-  PsppireVarStore *vs;
-
-  GtkWidget *dialog = get_widget_assert   (xml, "reliability-dialog");
-  GtkWidget *source = get_widget_assert   (xml, "dict-view");
-
-  rd.split_point_hbox = get_widget_assert (xml, "split-point-hbox");
-
-  rd.variables = get_widget_assert   (xml, "treeview2");
-
-  rd.model_combo = get_widget_assert   (xml, "combobox1");
-  rd.split_spinbutton = get_widget_assert (xml, "spinbutton1");
-
-  rd.scale_if_item_deleted_checkbutton = get_widget_assert (xml, "totals-checkbutton");
-
-  g_signal_connect_swapped (rd.model_combo, "changed",
-                           G_CALLBACK (on_method_change), &rd);
-
-  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, NULL);
-
-  {
-    GtkTreeModel *tm =
-      gtk_tree_view_get_model (GTK_TREE_VIEW (rd.variables));
-
-
-    g_signal_connect_swapped (tm, "row-inserted",
-                     G_CALLBACK (on_vars_changed), &rd);
-
-    g_signal_connect_swapped (tm, "row-deleted",
-                     G_CALLBACK (on_vars_changed), &rd);
-  }
-
-  g_signal_connect (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 reliability *rd)
-{
-  gchar *text;
-  GString *string = g_string_new ("RELIABILITY");
-
-  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/MODEL=");
-
-  if ( 0 == gtk_combo_box_get_active (GTK_COMBO_BOX (rd->model_combo)))
-    g_string_append (string, "ALPHA");
-  else
-    g_string_append_printf (string, "SPLIT (%d)",
-                           gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (rd->split_spinbutton))
-                           );
-
-  if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->scale_if_item_deleted_checkbutton)))
-    g_string_append (string, "\n\t/SUMMARY = TOTAL");
-
-  g_string_append (string, ".\n");
-
-  text = string->str;
-
-  g_string_free (string, FALSE);
-
-  return text;
-}
diff --git a/src/ui/gui/reliability-dialog.h b/src/ui/gui/reliability-dialog.h
deleted file mode 100644 (file)
index b79483a..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2009  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 __RELIABILITY_DIALOG_H
-#define __RELIABILITY_DIALOG_H
-
-
-#include "psppire-data-window.h"
-
-void reliability_dialog (PsppireDataWindow * data);
-
-#endif
index 9d97dd3e678fdb97ed2590afc6b80891499630b5..9ea17e9f00195b8839abd27f026c1d6b08b8e7f7 100644 (file)
@@ -16,6 +16,7 @@
 #include "psppire-dialog-action-correlation.h"
 #include "psppire-dialog-action-descriptives.h"
 #include "psppire-dialog-action-kmeans.h"
+#include "psppire-dialog-action-reliability.h"
 #include "psppire-dialog-action-roc.h"
 #include "psppire-dialog-action-var-info.h"
 
@@ -40,5 +41,6 @@ preregister_widgets (void)
   psppire_dialog_action_descriptives_get_type ();
   psppire_dialog_action_kmeans_get_type ();
   psppire_dialog_action_var_info_get_type ();
+  psppire_dialog_action_reliability_get_type ();
   psppire_dialog_action_roc_get_type ();
 }