Convert Rank Dialog to PsppireDialogAction 20120429030503/pspp
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 28 Apr 2012 18:24:43 +0000 (20:24 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 28 Apr 2012 18:24:43 +0000 (20:24 +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-rank.c [new file with mode: 0644]
src/ui/gui/psppire-dialog-action-rank.h [new file with mode: 0644]
src/ui/gui/rank-dialog.c [deleted file]
src/ui/gui/rank-dialog.h [deleted file]
src/ui/gui/rank.ui
src/ui/gui/widgets.c

index cbeb490ea4f24ad23b0213d248fd0af7dabeece5..70e76a268b6b4a8bd62ad12b6f2093e31d6fe5b0 100644 (file)
@@ -233,6 +233,8 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/psppire-dialog-action-kmeans.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 \
+       src/ui/gui/psppire-dialog-action-rank.h \
        src/ui/gui/psppire-dialog-action-reliability.c \
        src/ui/gui/psppire-dialog-action-reliability.h \
        src/ui/gui/psppire-dialog-action-sort.c \
@@ -283,8 +285,6 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/psppire-window-base.h \
        src/ui/gui/psppire-window-register.c \
        src/ui/gui/psppire-window-register.h \
-       src/ui/gui/rank-dialog.c \
-       src/ui/gui/rank-dialog.h \
        src/ui/gui/recode-dialog.c \
        src/ui/gui/recode-dialog.h \
        src/ui/gui/regression-dialog.c \
index e568f2bc408c9c9534bf0f3701ce85f900f1bd07..10c0a2c000ec474d02377c2bf12bacf961aabeb7 100644 (file)
           </object>
         </child>
         <child>
-          <object class="GtkAction" id="transform_rank">
+          <object class="PsppireDialogActionRank" id="transform_rank">
             <property name="name">transform_rank</property>
+            <property name="manager">uimanager1</property>
             <property name="label" translatable="yes">Ran_k Cases...</property>
           </object>
         </child>
index 87a6bb69fca2206f9b239f801ef1c49e29afc2d3..7fa572a173debe43d6bf875538e7a310bba9f6cb 100644 (file)
@@ -49,7 +49,6 @@
 #include "ui/gui/psppire-syntax-window.h"
 #include "ui/gui/psppire-window.h"
 #include "ui/gui/psppire.h"
-#include "ui/gui/rank-dialog.h"
 #include "ui/gui/runs-dialog.h"
 #include "ui/gui/ks-one-sample-dialog.h"
 #include "ui/gui/recode-dialog.h"
@@ -1084,8 +1083,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
 
   connect_action (de, "utilities_comments", G_CALLBACK (comments_dialog));
  
-  connect_action (de, "transform_rank", G_CALLBACK (rank_dialog));
-
   connect_action (de, "transform_count", G_CALLBACK (count_dialog));
  
   connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog));
diff --git a/src/ui/gui/psppire-dialog-action-rank.c b/src/ui/gui/psppire-dialog-action-rank.c
new file mode 100644 (file)
index 0000000..bbf30a6
--- /dev/null
@@ -0,0 +1,315 @@
+/* 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 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-rank.h"
+
+#include "psppire-var-view.h"
+#include "dialog-common.h"
+#include "psppire-selector.h"
+#include "psppire-dict.h"
+#include "psppire-dialog.h"
+#include "builder-wrapper.h"
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
+static void psppire_dialog_action_rank_class_init      (PsppireDialogActionRankClass *class);
+
+G_DEFINE_TYPE (PsppireDialogActionRank, psppire_dialog_action_rank, PSPPIRE_TYPE_DIALOG_ACTION);
+
+
+static char *
+generate_syntax (PsppireDialogAction *act)
+{
+  PsppireDialogActionRank *rd  = PSPPIRE_DIALOG_ACTION_RANK (act);
+
+  gchar *text = NULL;
+  GtkTreeModel *gs = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->group_vars));
+
+  GtkTreeIter notused;
+
+  GString *str = g_string_new ("RANK VARIABLES=");
+
+  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->rank_vars), 0, str);
+
+  g_string_append_printf (str, " (%c)",
+                  gtk_toggle_button_get_active (rd->ascending_togglebutton)
+                  ?'A':'D');
+
+  if (  gtk_tree_model_get_iter_first (gs, &notused) )
+    {
+      g_string_append (str, "\n\tBY ");
+
+      psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->group_vars),  0, str);
+    }
+
+  g_string_append (str, "\n\t/PRINT = ");
+  if (gtk_toggle_button_get_active (rd->summary_togglebutton))
+    g_string_append (str, "YES");
+  else
+    g_string_append (str, "NO");
+
+
+  if (gtk_toggle_button_get_active (rd->func_button [RANK]))
+    g_string_append (str, "\n\t/RANK");
+  if (gtk_toggle_button_get_active (rd->func_button [NORMAL]))
+    g_string_append (str, "\n\t/NORMAL");
+  if (gtk_toggle_button_get_active (rd->func_button [PROPORTION]))
+    g_string_append (str, "\n\t/PROPORTION");
+  if (gtk_toggle_button_get_active (rd->func_button [PERCENT]))
+    g_string_append (str, "\n\t/PERCENT");
+  if (gtk_toggle_button_get_active (rd->func_button [RFRACTION]))
+    g_string_append (str, "\n\t/RFRACTION");
+  if (gtk_toggle_button_get_active (rd->func_button [N]))
+    g_string_append (str, "\n\t/N");
+  if (gtk_toggle_button_get_active (rd->func_button [SAVAGE]))
+    g_string_append (str, "\n\t/SAVAGE");
+  if (gtk_toggle_button_get_active (rd->func_button [NTILES]))
+    {
+      gint n = gtk_spin_button_get_value (GTK_SPIN_BUTTON (rd->ntiles_entry));
+      g_string_append_printf (str, "\n\t/NTILES(%d)", n);
+    }
+
+
+  if (gtk_toggle_button_get_active (rd->func_button [NORMAL])
+      ||
+      gtk_toggle_button_get_active (rd->func_button [PROPORTION]))
+    {
+      g_string_append (str, "\n\t/FRACTION=");
+
+      if ( gtk_toggle_button_get_active (rd->blom))
+       g_string_append (str, "BLOM");
+      else if ( gtk_toggle_button_get_active (rd->tukey))
+       g_string_append (str, "TUKEY");
+      else if ( gtk_toggle_button_get_active (rd->rankit))
+       g_string_append (str, "RANKIT");
+      else if ( gtk_toggle_button_get_active (rd->vw))
+       g_string_append (str, "VW");
+    }
+
+  g_string_append (str, "\n\t/TIES=");
+  if ( gtk_toggle_button_get_active (rd->mean))
+    g_string_append (str, "MEAN");
+  else if ( gtk_toggle_button_get_active (rd->low))
+    g_string_append (str, "LOW");
+  else if ( gtk_toggle_button_get_active (rd->high))
+    g_string_append (str, "HIGH");
+  else if ( gtk_toggle_button_get_active (rd->condense))
+    g_string_append (str, "CONDENSE");
+
+
+  g_string_append (str, ".");
+  text = str->str;
+
+  g_string_free (str, FALSE);
+
+  return text;
+}
+
+static gboolean
+dialog_state_valid (PsppireDialogAction *da)
+{
+  PsppireDialogActionRank *dar  = PSPPIRE_DIALOG_ACTION_RANK (da);
+  GtkTreeIter notused;
+  GtkTreeModel *vars = gtk_tree_view_get_model (GTK_TREE_VIEW (dar->rank_vars));
+
+  return gtk_tree_model_get_iter_first (vars, &notused);
+}
+
+static void
+dialog_refresh (PsppireDialogAction *act)
+{
+  PsppireDialogActionRank *dar  = PSPPIRE_DIALOG_ACTION_RANK (act);
+
+  GtkTreeModel *liststore;
+
+  liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (dar->rank_vars));
+  gtk_list_store_clear (GTK_LIST_STORE (liststore));
+
+  liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (dar->group_vars));
+  gtk_list_store_clear (GTK_LIST_STORE (liststore));
+
+  gtk_toggle_button_set_active (dar->ascending_togglebutton, TRUE);
+  gtk_toggle_button_set_active (dar->summary_togglebutton, FALSE);
+}
+
+static void
+types_dialog_reset (PsppireDialogActionRank *rd)
+{
+  gint i;
+
+  for (i = 0 ; i < n_RANK_FUNCS ; ++i )
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->func_button [i]),
+                                 FALSE);
+
+  gtk_widget_set_sensitive (rd->ntiles_entry, FALSE);
+
+  gtk_widget_set_sensitive (rd->formula_box, FALSE);
+}
+
+static void
+run_types_dialog (GtkButton *b, PsppireDialogActionRank *dar)
+{
+  PsppireDialogAction *act  = PSPPIRE_DIALOG_ACTION (dar);
+
+  gint response;
+
+  gtk_window_set_transient_for (GTK_WINDOW (dar->types_dialog),
+                               GTK_WINDOW (act->dialog));
+
+  types_dialog_reset (dar);
+
+  response = psppire_dialog_run (PSPPIRE_DIALOG (dar->types_dialog));
+}
+
+static void
+run_ties_dialog (GtkButton *b,  PsppireDialogActionRank *dar)
+{
+  PsppireDialogAction *act  = PSPPIRE_DIALOG_ACTION (dar);
+
+  gint response;
+
+  gtk_window_set_transient_for (GTK_WINDOW (dar->ties_dialog),
+                               GTK_WINDOW (act->dialog));
+
+  response = psppire_dialog_run (PSPPIRE_DIALOG (dar->ties_dialog));
+}
+
+static void
+on_ntiles_toggle (GtkToggleButton *toggle_button, PsppireDialogActionRank *dar)
+{
+  gboolean active = gtk_toggle_button_get_active (toggle_button);
+  gtk_widget_set_sensitive (GTK_WIDGET (dar), active);
+}
+
+static void
+set_sensitivity (PsppireDialogActionRank *dar)
+{
+  gboolean sens = gtk_toggle_button_get_active
+    (GTK_TOGGLE_BUTTON (dar->func_button[PROPORTION]))
+    ||
+    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dar->func_button[NORMAL]));
+
+  gtk_widget_set_sensitive (dar->formula_box, sens);
+}
+
+static void
+psppire_dialog_action_rank_activate (GtkAction *a)
+{
+  PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
+  PsppireDialogActionRank *act = PSPPIRE_DIALOG_ACTION_RANK (a);
+
+  GtkBuilder *xml = builder_new ("rank.ui");
+
+  GtkWidget *types_button = get_widget_assert (xml, "button1");
+  GtkWidget *ties_button = get_widget_assert (xml, "button2");
+
+  pda->dialog    = get_widget_assert   (xml, "rank-dialog");
+  pda->source    = get_widget_assert   (xml, "dict-treeview");
+  act->rank_vars = get_widget_assert   (xml, "variables-treeview");
+  act->group_vars =  get_widget_assert (xml, "group-vars-treeview");
+  act->ascending_togglebutton =
+    GTK_TOGGLE_BUTTON (get_widget_assert (xml, "radiobutton1"));
+
+  act->summary_togglebutton =
+    GTK_TOGGLE_BUTTON (get_widget_assert (xml, "summary-checkbutton"));
+
+  act->types_dialog = get_widget_assert (xml, "rank-types-dialog");
+
+
+  act->ntiles_entry  = get_widget_assert (xml, "ntiles-entry");
+
+  act->func_button[RANK]    =
+    GTK_TOGGLE_BUTTON (get_widget_assert (xml, "rank-checkbutton"));
+
+  act->func_button[SAVAGE]  =
+    GTK_TOGGLE_BUTTON (get_widget_assert (xml, "savage-checkbutton"));
+
+  act->func_button[RFRACTION] =
+    GTK_TOGGLE_BUTTON (get_widget_assert (xml, "rfrac-checkbutton"));
+
+  act->func_button[PERCENT] =
+    GTK_TOGGLE_BUTTON (get_widget_assert (xml, "percent-checkbutton"));
+
+  act->func_button[N]       =
+    GTK_TOGGLE_BUTTON (get_widget_assert (xml, "sum-checkbutton"));
+
+  act->func_button[NTILES] =
+    GTK_TOGGLE_BUTTON (get_widget_assert (xml, "ntiles-checkbutton"));
+
+  act->func_button[PROPORTION] =
+    GTK_TOGGLE_BUTTON (get_widget_assert (xml, "prop-checkbutton"));
+
+  act->func_button[NORMAL] =
+    GTK_TOGGLE_BUTTON (get_widget_assert (xml, "normal-checkbutton"));
+
+  act->formula_box = get_widget_assert (xml, "formula-frame");
+
+  act->blom = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "blom-button"));
+  act->tukey = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "tukey-button"));
+  act->rankit = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "rankit-button"));
+  act->vw = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "vw-button"));
+
+  /* Ties dialog */
+  act->ties_dialog = PSPPIRE_DIALOG (get_widget_assert (xml, "ties-dialog"));
+
+  act->mean = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "mean-button"));
+  act->low = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "low-button"));
+  act->high = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "high-button"));
+  act->condense = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "condense-button"));
+
+  g_signal_connect_swapped (act->func_button[PROPORTION], "toggled",
+                           G_CALLBACK (set_sensitivity),
+                           act);
+
+  g_signal_connect_swapped (act->func_button[NORMAL], "toggled",
+                           G_CALLBACK (set_sensitivity),
+                           act);
+
+  g_signal_connect (types_button, "clicked",
+                   G_CALLBACK (run_types_dialog),  act);
+
+  g_signal_connect (ties_button, "clicked",
+                   G_CALLBACK (run_ties_dialog),  act);
+
+  g_signal_connect (act->func_button[NTILES], "toggled",
+                   G_CALLBACK (on_ntiles_toggle),
+                   act->ntiles_entry);
+
+  psppire_dialog_action_set_valid_predicate (pda, (void *) dialog_state_valid);
+  psppire_dialog_action_set_refresh (pda, dialog_refresh);
+
+  PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_rank_parent_class)->activate (pda);
+  
+  g_object_unref (xml);
+}
+
+static void
+psppire_dialog_action_rank_class_init (PsppireDialogActionRankClass *class)
+{
+  GTK_ACTION_CLASS (class)->activate = psppire_dialog_action_rank_activate;
+
+  PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
+}
+
+static void
+psppire_dialog_action_rank_init (PsppireDialogActionRank *act)
+{
+}
diff --git a/src/ui/gui/psppire-dialog-action-rank.h b/src/ui/gui/psppire-dialog-action-rank.h
new file mode 100644 (file)
index 0000000..0827197
--- /dev/null
@@ -0,0 +1,114 @@
+/* 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/>. */
+
+
+#ifndef __PSPPIRE_DIALOG_ACTION_RANK_H__
+#define __PSPPIRE_DIALOG_ACTION_RANK_H__
+
+#include <glib-object.h>
+#include <glib.h>
+
+#include "psppire-dialog-action.h"
+
+G_BEGIN_DECLS
+
+
+#define PSPPIRE_TYPE_DIALOG_ACTION_RANK (psppire_dialog_action_rank_get_type ())
+
+#define PSPPIRE_DIALOG_ACTION_RANK(obj)        \
+                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                                                 PSPPIRE_TYPE_DIALOG_ACTION_RANK, PsppireDialogActionRank))
+
+#define PSPPIRE_DIALOG_ACTION_RANK_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_CAST ((klass), \
+                                PSPPIRE_TYPE_DIALOG_ACTION_RANK, \
+                                 PsppireDialogActionRankClass))
+
+
+#define PSPPIRE_IS_DIALOG_ACTION_RANK(obj) \
+                    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_RANK))
+
+#define PSPPIRE_IS_DIALOG_ACTION_RANK_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_RANK))
+
+
+#define PSPPIRE_DIALOG_ACTION_RANK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                                  PSPPIRE_TYPE_DIALOG_ACTION_RANK, \
+                                  PsppireDialogActionRankClass))
+
+typedef struct _PsppireDialogActionRank       PsppireDialogActionRank;
+typedef struct _PsppireDialogActionRankClass  PsppireDialogActionRankClass;
+
+
+enum RANK_FUNC
+  {
+    RANK,
+    NORMAL,
+    PERCENT,
+    RFRACTION,
+    PROPORTION,
+    N,
+    NTILES,
+    SAVAGE,
+    n_RANK_FUNCS
+  };
+
+struct _PsppireDialogActionRank
+{
+  PsppireDialogAction parent;
+
+  /*< private >*/
+  GtkWidget *rank_vars;
+  GtkWidget *group_vars;
+
+  GtkToggleButton *ascending_togglebutton;
+  GtkToggleButton *summary_togglebutton;
+
+
+  /* Types subdialog widgets */
+
+  GtkWidget *types_dialog;
+  GtkWidget *ntiles_entry;
+
+  GtkToggleButton *func_button[n_RANK_FUNCS];
+  GtkWidget *formula_box;
+
+  GtkToggleButton *blom;
+  GtkToggleButton *tukey;
+  GtkToggleButton *rankit;
+  GtkToggleButton *vw;
+
+  /* Ties subdialog widgets */
+
+  PsppireDialog *ties_dialog;
+  GtkToggleButton *mean;
+  GtkToggleButton *low;
+  GtkToggleButton *high;
+  GtkToggleButton *condense;
+};
+
+
+struct _PsppireDialogActionRankClass
+{
+  PsppireDialogActionClass parent_class;
+};
+
+
+GType psppire_dialog_action_rank_get_type (void) ;
+
+G_END_DECLS
+
+#endif /* __PSPPIRE_DIALOG_ACTION_RANK_H__ */
diff --git a/src/ui/gui/rank-dialog.c b/src/ui/gui/rank-dialog.c
deleted file mode 100644 (file)
index 23de30c..0000000
+++ /dev/null
@@ -1,388 +0,0 @@
-/* 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 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 "rank-dialog.h"
-
-#include <gtk/gtk.h>
-#include <stdlib.h>
-
-#include <ui/gui/psppire-data-window.h>
-#include <ui/gui/dialog-common.h>
-#include <ui/gui/dict-display.h>
-#include <ui/gui/builder-wrapper.h>
-#include <ui/gui/psppire-dialog.h>
-#include <ui/gui/psppire-var-store.h>
-#include <ui/gui/psppire-var-view.h>
-#include "executor.h"
-#include "helper.h"
-
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
-
-
-enum RANK_FUNC
-  {
-    RANK,
-    NORMAL,
-    PERCENT,
-    RFRACTION,
-    PROPORTION,
-    N,
-    NTILES,
-    SAVAGE,
-    n_RANK_FUNCS
-  };
-
-
-
-
-struct rank_dialog
-{
-  PsppireDict *dict;
-  GtkWidget *rank_vars;
-  GtkWidget *group_vars;
-  GtkWidget *dialog;
-
-  GtkToggleButton *ascending_togglebutton;
-  GtkToggleButton *summary_togglebutton;
-
-
-  /* Types subdialog widgets */
-
-  GtkWidget *types_dialog;
-  GtkWidget *ntiles_entry;
-
-  GtkToggleButton *func_button[n_RANK_FUNCS];
-  GtkWidget *formula_box;
-
-  GtkToggleButton *blom;
-  GtkToggleButton *tukey;
-  GtkToggleButton *rankit;
-  GtkToggleButton *vw;
-
-  /* Ties subdialog widgets */
-
-  PsppireDialog *ties_dialog;
-  GtkToggleButton *mean;
-  GtkToggleButton *low;
-  GtkToggleButton *high;
-  GtkToggleButton *condense;
-};
-
-static void
-refresh (PsppireDialog *dialog, struct rank_dialog *rd)
-{
-  GtkTreeModel *liststore;
-
-  liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->rank_vars));
-  gtk_list_store_clear (GTK_LIST_STORE (liststore));
-
-  liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->group_vars));
-  gtk_list_store_clear (GTK_LIST_STORE (liststore));
-
-  gtk_toggle_button_set_active (rd->ascending_togglebutton, TRUE);
-  gtk_toggle_button_set_active (rd->summary_togglebutton, FALSE);
-}
-
-static char *
-generate_syntax (const struct rank_dialog *rd)
-{
-  gchar *text;
-
-  GtkTreeModel *gs = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->group_vars));
-
-  GtkTreeIter notused;
-
-  GString *str = g_string_new ("RANK VARIABLES=");
-
-  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->rank_vars), 0, str);
-
-  g_string_append_printf (str, " (%c)",
-                  gtk_toggle_button_get_active (rd->ascending_togglebutton)
-                  ?'A':'D');
-
-  if (  gtk_tree_model_get_iter_first (gs, &notused) )
-    {
-      g_string_append (str, "\n\tBY ");
-
-      psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->group_vars),  0, str);
-    }
-
-  g_string_append (str, "\n\t/PRINT = ");
-  if (gtk_toggle_button_get_active (rd->summary_togglebutton))
-    g_string_append (str, "YES");
-  else
-    g_string_append (str, "NO");
-
-
-  if (gtk_toggle_button_get_active (rd->func_button [RANK]))
-    g_string_append (str, "\n\t/RANK");
-  if (gtk_toggle_button_get_active (rd->func_button [NORMAL]))
-    g_string_append (str, "\n\t/NORMAL");
-  if (gtk_toggle_button_get_active (rd->func_button [PROPORTION]))
-    g_string_append (str, "\n\t/PROPORTION");
-  if (gtk_toggle_button_get_active (rd->func_button [PERCENT]))
-    g_string_append (str, "\n\t/PERCENT");
-  if (gtk_toggle_button_get_active (rd->func_button [RFRACTION]))
-    g_string_append (str, "\n\t/RFRACTION");
-  if (gtk_toggle_button_get_active (rd->func_button [N]))
-    g_string_append (str, "\n\t/N");
-  if (gtk_toggle_button_get_active (rd->func_button [SAVAGE]))
-    g_string_append (str, "\n\t/SAVAGE");
-  if (gtk_toggle_button_get_active (rd->func_button [NTILES]))
-    {
-      gint n = gtk_spin_button_get_value (GTK_SPIN_BUTTON (rd->ntiles_entry));
-      g_string_append_printf (str, "\n\t/NTILES(%d)", n);
-    }
-
-
-  if (gtk_toggle_button_get_active (rd->func_button [NORMAL])
-      ||
-      gtk_toggle_button_get_active (rd->func_button [PROPORTION]))
-    {
-      g_string_append (str, "\n\t/FRACTION=");
-
-      if ( gtk_toggle_button_get_active (rd->blom))
-       g_string_append (str, "BLOM");
-      else if ( gtk_toggle_button_get_active (rd->tukey))
-       g_string_append (str, "TUKEY");
-      else if ( gtk_toggle_button_get_active (rd->rankit))
-       g_string_append (str, "RANKIT");
-      else if ( gtk_toggle_button_get_active (rd->vw))
-       g_string_append (str, "VW");
-    }
-
-  g_string_append (str, "\n\t/TIES=");
-  if ( gtk_toggle_button_get_active (rd->mean))
-    g_string_append (str, "MEAN");
-  else if ( gtk_toggle_button_get_active (rd->low))
-    g_string_append (str, "LOW");
-  else if ( gtk_toggle_button_get_active (rd->high))
-    g_string_append (str, "HIGH");
-  else if ( gtk_toggle_button_get_active (rd->condense))
-    g_string_append (str, "CONDENSE");
-
-
-  g_string_append (str, ".");
-
-  text = str->str;
-
-  g_string_free (str, FALSE);
-
-  return text;
-}
-
-/* Dialog is valid iff at least one variable has been selected */
-static gboolean
-dialog_state_valid (gpointer data)
-{
-  struct rank_dialog *rd = data;
-
-  GtkTreeModel *vars = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->rank_vars));
-
-  GtkTreeIter notused;
-
-  return gtk_tree_model_get_iter_first (vars, &notused);
-}
-
-static void on_ntiles_toggle (GtkToggleButton *, gpointer);
-static void run_types_dialog (GtkButton *, gpointer);
-static void run_ties_dialog (GtkButton *, gpointer );
-
-static void
-set_sensitivity (struct rank_dialog *rd)
-{
-  gboolean sens = gtk_toggle_button_get_active
-    (GTK_TOGGLE_BUTTON (rd->func_button[PROPORTION]))
-    ||
-    gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->func_button[NORMAL]));
-
-  gtk_widget_set_sensitive (rd->formula_box, sens);
-}
-
-/* Pops up the Rank dialog box */
-void
-rank_dialog (PsppireDataWindow *de)
-{
-  gint response;
-
-  struct rank_dialog rd;
-
-  GtkBuilder * builder = builder_new ("rank.ui");
-
-  GtkWidget *vars = get_widget_assert   (builder, "dict-treeview");
-
-  GtkWidget *types_button = get_widget_assert (builder, "button1");
-  GtkWidget *ties_button = get_widget_assert (builder, "button2");
-
-  PsppireVarStore *vs = NULL;
-
-  g_object_get (de->data_editor, "var-store", &vs, NULL);
-
-  g_object_get (vs, "dictionary", &rd.dict, NULL);
-  rd.rank_vars =   get_widget_assert (builder, "variables-treeview");
-  rd.group_vars =  get_widget_assert (builder, "group-vars-treeview");
-  rd.dialog = get_widget_assert   (builder, "rank-dialog");
-  rd.ascending_togglebutton =
-    GTK_TOGGLE_BUTTON (get_widget_assert (builder, "radiobutton1"));
-
-  rd.summary_togglebutton =
-    GTK_TOGGLE_BUTTON (get_widget_assert (builder, "summary-checkbutton"));
-
-  rd.types_dialog = get_widget_assert (builder, "rank-types-dialog");
-
-
-  rd.ntiles_entry  = get_widget_assert (builder, "ntiles-entry");
-
-  rd.func_button[RANK]    =
-    GTK_TOGGLE_BUTTON (get_widget_assert (builder, "rank-checkbutton"));
-
-  rd.func_button[SAVAGE]  =
-    GTK_TOGGLE_BUTTON (get_widget_assert (builder, "savage-checkbutton"));
-
-  rd.func_button[RFRACTION] =
-    GTK_TOGGLE_BUTTON (get_widget_assert (builder, "rfrac-checkbutton"));
-
-  rd.func_button[PERCENT] =
-    GTK_TOGGLE_BUTTON (get_widget_assert (builder, "percent-checkbutton"));
-
-  rd.func_button[N]       =
-    GTK_TOGGLE_BUTTON (get_widget_assert (builder, "sum-checkbutton"));
-
-  rd.func_button[NTILES] =
-    GTK_TOGGLE_BUTTON (get_widget_assert (builder, "ntiles-checkbutton"));
-
-  rd.func_button[PROPORTION] =
-    GTK_TOGGLE_BUTTON (get_widget_assert (builder, "prop-checkbutton"));
-
-  rd.func_button[NORMAL] =
-    GTK_TOGGLE_BUTTON (get_widget_assert (builder, "normal-checkbutton"));
-
-  rd.formula_box = get_widget_assert (builder, "formula-frame");
-
-  rd.blom = GTK_TOGGLE_BUTTON (get_widget_assert (builder, "blom-button"));
-  rd.tukey = GTK_TOGGLE_BUTTON (get_widget_assert (builder, "tukey-button"));
-  rd.rankit = GTK_TOGGLE_BUTTON (get_widget_assert (builder, "rankit-button"));
-  rd.vw = GTK_TOGGLE_BUTTON (get_widget_assert (builder, "vw-button"));
-
-  /* Ties dialog */
-  rd.ties_dialog = PSPPIRE_DIALOG (get_widget_assert (builder, "ties-dialog"));
-
-  rd.mean = GTK_TOGGLE_BUTTON (get_widget_assert (builder, "mean-button"));
-  rd.low = GTK_TOGGLE_BUTTON (get_widget_assert (builder, "low-button"));
-  rd.high = GTK_TOGGLE_BUTTON (get_widget_assert (builder, "high-button"));
-  rd.condense = GTK_TOGGLE_BUTTON (get_widget_assert (builder, "condense-button"));
-
-  g_signal_connect_swapped (rd.func_button[PROPORTION], "toggled",
-                           G_CALLBACK (set_sensitivity),
-                           &rd);
-
-  g_signal_connect_swapped (rd.func_button[NORMAL], "toggled",
-                           G_CALLBACK (set_sensitivity),
-                           &rd);
-
-  g_signal_connect (rd.func_button[NTILES], "toggled",
-                   G_CALLBACK (on_ntiles_toggle),
-                   rd.ntiles_entry);
-
-  gtk_window_set_transient_for (GTK_WINDOW (rd.dialog), GTK_WINDOW (de));
-
-  g_object_set (vars, "model", rd.dict, NULL);
-
-  g_signal_connect (types_button, "clicked",
-                   G_CALLBACK (run_types_dialog),  &rd);
-
-  g_signal_connect (ties_button, "clicked",
-                   G_CALLBACK (run_ties_dialog),  &rd);
-
-  g_signal_connect (rd.dialog, "refresh", G_CALLBACK (refresh),  &rd);
-
-  psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (rd.dialog),
-                                     dialog_state_valid, &rd);
-
-  response = psppire_dialog_run (PSPPIRE_DIALOG (rd.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 (builder);
-}
-
-
-static void
-types_dialog_reset (struct rank_dialog *rd)
-{
-  gint i;
-
-  for (i = 0 ; i < n_RANK_FUNCS ; ++i )
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->func_button [i]),
-                                 FALSE);
-
-  gtk_widget_set_sensitive (rd->ntiles_entry, FALSE);
-
-  gtk_widget_set_sensitive (rd->formula_box, FALSE);
-}
-
-
-
-static void
-run_types_dialog (GtkButton *b, gpointer data)
-{
-  struct rank_dialog *rd = data;
-  gint response;
-
-  gtk_window_set_transient_for (GTK_WINDOW (rd->types_dialog),
-                               GTK_WINDOW (rd->dialog));
-
-  types_dialog_reset (rd);
-
-  response = psppire_dialog_run (PSPPIRE_DIALOG (rd->types_dialog));
-}
-
-static void
-run_ties_dialog (GtkButton *b, gpointer data)
-{
-  struct rank_dialog *rd = data;
-  gint response;
-
-  gtk_window_set_transient_for (GTK_WINDOW (rd->ties_dialog),
-                               GTK_WINDOW (rd->dialog));
-
-
-  response = psppire_dialog_run (PSPPIRE_DIALOG (rd->ties_dialog));
-}
-
-
-static void
-on_ntiles_toggle (GtkToggleButton *toggle_button, gpointer data)
-{
-  GtkWidget *w = data;
-  gboolean active = gtk_toggle_button_get_active (toggle_button);
-  gtk_widget_set_sensitive (w, active);
-}
diff --git a/src/ui/gui/rank-dialog.h b/src/ui/gui/rank-dialog.h
deleted file mode 100644 (file)
index 8c21bd0..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2007  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 __RANK_DIALOG_H
-#define __RANK_DIALOG_H
-
-
-#include "psppire-data-window.h"
-
-void rank_dialog (PsppireDataWindow *);
-
-#endif
index 3dc0d283f57040b3f329cb4677cd13022e09d3e5..cfed4580629b288501366050cf6e52095121f243 100644 (file)
@@ -55,7 +55,9 @@
                         <property name="visible">True</property>
                         <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                         <property name="xalign">0</property>
-                        <property name="label" translatable="yes">By:</property>
+                        <property name="label" translatable="yes">_By:</property>
+                        <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">group-vars-treeview</property>
                       </object>
                       <packing>
                         <property name="expand">False</property>
                         <property name="visible">True</property>
                         <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                         <property name="xalign">0</property>
-                        <property name="label" translatable="yes">Variable(s):</property>
+                        <property name="label" translatable="yes">_Variable(s):</property>
+                        <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">variables-treeview</property>
                       </object>
                       <packing>
                         <property name="expand">False</property>
index 8c64f524bde3e108264d8e6019d8514d31b23046..2a0cc21bb4525c3cc82cecb0c72a09667803a73d 100644 (file)
@@ -19,6 +19,7 @@
 #include "psppire-dialog-action-kmeans.h"
 #include "psppire-dialog-action-means.h"
 #include "psppire-means-layer.h"
+#include "psppire-dialog-action-rank.h"
 #include "psppire-dialog-action-reliability.h"
 #include "psppire-dialog-action-roc.h"
 #include "psppire-dialog-action-sort.h"
@@ -50,6 +51,7 @@ preregister_widgets (void)
   psppire_dialog_action_means_get_type ();
   psppire_means_layer_get_type ();
   psppire_dialog_action_var_info_get_type ();
+  psppire_dialog_action_rank_get_type ();
   psppire_dialog_action_reliability_get_type ();
   psppire_dialog_action_roc_get_type ();
   psppire_dialog_action_sort_get_type ();