Converted Sort dialog to a PsppireDialogAction object
authorJohn Darrington <john@darrington.wattle.id.au>
Tue, 31 Jan 2012 20:19:41 +0000 (21:19 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 31 Jan 2012 20:19:41 +0000 (21:19 +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-sort.c [new file with mode: 0644]
src/ui/gui/psppire-dialog-action-sort.h [new file with mode: 0644]
src/ui/gui/sort-cases-dialog.c [deleted file]
src/ui/gui/sort-cases-dialog.h [deleted file]
src/ui/gui/widgets.c

index 630a8d9974f13d34ea3514948be6e676c2a08608..770a5a9a012635dff906690f47ec351a57252714 100644 (file)
@@ -216,6 +216,8 @@ src_ui_gui_psppire_SOURCES = \
        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-sort.c \
+       src/ui/gui/psppire-dialog-action-sort.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 \
@@ -262,8 +264,6 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/runs-dialog.h \
        src/ui/gui/select-cases-dialog.c \
        src/ui/gui/select-cases-dialog.h \
-       src/ui/gui/sort-cases-dialog.c \
-       src/ui/gui/sort-cases-dialog.h \
        src/ui/gui/split-file-dialog.c \
        src/ui/gui/split-file-dialog.h \
        src/ui/gui/text-data-import-dialog.c \
index 46bb823bd22c55eb75f20429a8f7762909394a34..88449fb7039c552dfbcfb8778c0eb7ae4ac540c0 100644 (file)
           </object>
         </child>
         <child>
-          <object class="GtkAction" id="data_sort-cases">
+          <object class="PsppireDialogActionSort" id="data_sort-cases">
             <property name="label" translatable="yes">_Sort Cases...</property>
             <property name="name">data_sort-cases</property>
+            <property name="manager">uimanager1</property>
            <property name="stock-id">gtk-sort-ascending</property>
            <property name="tooltip" translatable="yes">Sort cases in the active dataset</property>
           </object>
index 13e9614ca021223cbaaba02b59c871946fd7c097..1ca71f79e661ba9460d05bc0c29654252f42e561 100644 (file)
@@ -56,7 +56,6 @@
 #include "ui/gui/recode-dialog.h"
 #include "ui/gui/regression-dialog.h"
 #include "ui/gui/select-cases-dialog.h"
-#include "ui/gui/sort-cases-dialog.h"
 #include "ui/gui/split-file-dialog.h"
 #include "ui/gui/t-test-independent-samples-dialog.h"
 #include "ui/gui/t-test-one-sample.h"
@@ -1064,8 +1063,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
 
   connect_action (de, "data_select-cases", G_CALLBACK (select_cases_dialog));
  
-  connect_action (de, "data_sort-cases", G_CALLBACK (sort_cases_dialog));
-
   connect_action (de, "data_aggregate", G_CALLBACK (aggregate_dialog));
 
   connect_action (de, "transform_compute", G_CALLBACK (compute_dialog));
diff --git a/src/ui/gui/psppire-dialog-action-sort.c b/src/ui/gui/psppire-dialog-action-sort.c
new file mode 100644 (file)
index 0000000..2a80a6e
--- /dev/null
@@ -0,0 +1,128 @@
+/* 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-sort.h"
+
+#include "psppire-var-view.h"
+
+#include "psppire-dialog.h"
+#include "builder-wrapper.h"
+
+static void psppire_dialog_action_sort_init            (PsppireDialogActionSort      *act);
+static void psppire_dialog_action_sort_class_init      (PsppireDialogActionSortClass *class);
+
+G_DEFINE_TYPE (PsppireDialogActionSort, psppire_dialog_action_sort, PSPPIRE_TYPE_DIALOG_ACTION);
+
+static char *
+generate_syntax (PsppireDialogAction *act)
+{
+  PsppireDialogActionSort *scd = PSPPIRE_DIALOG_ACTION_SORT (act);
+  gchar *text;
+  GString *string = g_string_new ("SORT CASES BY ");
+
+  gint n_vars = psppire_var_view_append_names (scd->variables, 0, string);
+
+  if ( n_vars == 0 )
+    {
+      g_string_assign (string, "");
+    }
+  else
+    {
+      const char up_down =
+       gtk_toggle_button_get_active (scd->ascending) ? 'A' : 'D';
+      g_string_append_printf (string, "(%c)", up_down);
+      g_string_append (string, ".");
+    }
+
+  text = string->str;
+
+  g_string_free (string, FALSE);
+
+  return text;
+}
+
+static void
+reset (PsppireDialogAction *act)
+{
+  PsppireDialogActionSort *scd = PSPPIRE_DIALOG_ACTION_SORT (act);
+
+  GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (scd->variables));
+
+  gtk_list_store_clear (GTK_LIST_STORE (liststore));
+
+  gtk_toggle_button_set_active (scd->ascending, TRUE);
+}
+
+
+
+
+static gboolean
+dialog_state_valid (PsppireDialogAction *act)
+{
+  PsppireDialogActionSort *scd = PSPPIRE_DIALOG_ACTION_SORT (act);
+  GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (scd->variables));
+
+  gint n_rows = gtk_tree_model_iter_n_children  (model, NULL);
+
+  if ( n_rows == 0 )
+    return FALSE;
+
+  return TRUE;
+}
+
+
+static void
+psppire_dialog_action_sort_activate (GtkAction *a)
+{
+  PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
+  PsppireDialogActionSort *act = PSPPIRE_DIALOG_ACTION_SORT (a);
+
+  GtkBuilder *xml = builder_new ("sort.ui");
+  pda->dialog = get_widget_assert   (xml, "sort-cases-dialog");
+  pda->source = get_widget_assert   (xml, "sort-cases-treeview1");
+  
+  act->variables =  get_widget_assert   (xml, "sort-cases-treeview2");
+  act->ascending = get_widget_assert (xml, "sort-cases-radiobutton0");
+
+  psppire_dialog_action_set_refresh (pda, reset);
+
+  psppire_dialog_action_set_valid_predicate (pda,
+                                     dialog_state_valid);
+
+  if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_sort_parent_class)->activate)
+    PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_sort_parent_class)->activate (pda);
+}
+
+static void
+psppire_dialog_action_sort_class_init (PsppireDialogActionSortClass *class)
+{
+  GtkActionClass *action_class = GTK_ACTION_CLASS (class);
+  PsppireDialogActionClass *pdac = PSPPIRE_DIALOG_ACTION_CLASS (class);
+
+  action_class->activate = psppire_dialog_action_sort_activate;
+
+  pdac->generate_syntax = generate_syntax;
+}
+
+
+static void
+psppire_dialog_action_sort_init (PsppireDialogActionSort *act)
+{
+}
+
diff --git a/src/ui/gui/psppire-dialog-action-sort.h b/src/ui/gui/psppire-dialog-action-sort.h
new file mode 100644 (file)
index 0000000..3ab6699
--- /dev/null
@@ -0,0 +1,78 @@
+/* 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_SORT_H__
+#define __PSPPIRE_DIALOG_ACTION_SORT_H__
+
+G_BEGIN_DECLS
+
+
+#define PSPPIRE_TYPE_DIALOG_ACTION_SORT (psppire_dialog_action_sort_get_type ())
+
+#define PSPPIRE_DIALOG_ACTION_SORT(obj)        \
+                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                                                 PSPPIRE_TYPE_DIALOG_ACTION_SORT, PsppireDialogActionSort))
+
+#define PSPPIRE_DIALOG_ACTION_SORT_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_CAST ((klass), \
+                                PSPPIRE_TYPE_DIALOG_ACTION_SORT, \
+                                 PsppireDialogActionSortClass))
+
+
+#define PSPPIRE_IS_DIALOG_ACTION_SORT(obj) \
+                    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_SORT))
+
+#define PSPPIRE_IS_DIALOG_ACTION_SORT_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_SORT))
+
+
+#define PSPPIRE_DIALOG_ACTION_SORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                                  PSPPIRE_TYPE_DIALOG_ACTION_SORT, \
+                                  PsppireDialogActionSortClass))
+
+typedef struct _PsppireDialogActionSort       PsppireDialogActionSort;
+typedef struct _PsppireDialogActionSortClass  PsppireDialogActionSortClass;
+
+
+struct _PsppireDialogActionSort
+{
+  PsppireDialogAction parent;
+
+  /*< private >*/
+  gboolean dispose_has_run ;
+
+  GtkWidget *variables;
+  GtkWidget *ascending;
+};
+
+
+struct _PsppireDialogActionSortClass
+{
+  PsppireDialogActionClass parent_class;
+};
+
+
+GType psppire_dialog_action_sort_get_type (void) ;
+
+G_END_DECLS
+
+#endif /* __PSPPIRE_DIALOG_ACTION_SORT_H__ */
diff --git a/src/ui/gui/sort-cases-dialog.c b/src/ui/gui/sort-cases-dialog.c
deleted file mode 100644 (file)
index 62d738c..0000000
+++ /dev/null
@@ -1,143 +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 <gtk/gtk.h>
-#include "sort-cases-dialog.h"
-#include "executor.h"
-#include "psppire-dialog.h"
-#include "psppire-data-window.h"
-#include "psppire-var-store.h"
-#include "dialog-common.h"
-#include "psppire-selector.h"
-#include "dict-display.h"
-#include "psppire-var-view.h"
-
-#include "builder-wrapper.h"
-#include "helper.h"
-
-
-static void
-refresh (PsppireDialog *dialog, GtkTreeView *dest)
-{
-  GtkTreeModel *liststore = gtk_tree_view_get_model (dest);
-
-  gtk_list_store_clear (GTK_LIST_STORE (liststore));
-}
-
-
-struct sort_cases_dialog
-{
-  PsppireVarView *tv;
-  PsppireDict *dict;
-  GtkToggleButton *ascending;
-};
-
-
-static gboolean
-dialog_state_valid (gpointer data)
-{
-  struct sort_cases_dialog *scd = data;
-  GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (scd->tv));
-
-  gint n_rows = gtk_tree_model_iter_n_children  (model, NULL);
-
-  if ( n_rows == 0 )
-    return FALSE;
-
-  return TRUE;
-}
-
-static char *
-generate_syntax (const struct sort_cases_dialog *scd)
-{
-  gchar *text;
-  GString *string = g_string_new ("SORT CASES BY ");
-
-  gint n_vars = psppire_var_view_append_names (scd->tv, 0, string);
-
-  if ( n_vars == 0 )
-    g_string_assign (string, "");
-  else
-    {
-      const char up_down =
-       gtk_toggle_button_get_active (scd->ascending) ? 'A' : 'D';
-      g_string_append_printf (string, "(%c)", up_down);
-      g_string_append (string, ".");
-    }
-
-
-  text = string->str;
-
-  g_string_free (string, FALSE);
-
-  return text;
-}
-
-
-/* Pops up the Sort Cases dialog box */
-void
-sort_cases_dialog (PsppireDataWindow *de)
-{
-  gint response;
-
-  struct sort_cases_dialog scd;
-
-  GtkBuilder *xml = builder_new ("sort.ui");
-
-  GtkWidget *dialog = get_widget_assert   (xml, "sort-cases-dialog");
-
-
-  GtkWidget *source = get_widget_assert   (xml, "sort-cases-treeview1");
-  GtkWidget *dest =   get_widget_assert   (xml, "sort-cases-treeview2");
-  PsppireVarStore *vs = NULL;
-
-  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", &scd.dict, NULL);
-  g_object_set (source, "model", scd.dict, NULL);
-
-  g_signal_connect (dialog, "refresh", G_CALLBACK (refresh),  dest);
-
-  scd.tv = PSPPIRE_VAR_VIEW (dest);
-  scd.ascending =
-    GTK_TOGGLE_BUTTON (get_widget_assert (xml, "sort-cases-radiobutton0"));
-
-
-  psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
-                                     dialog_state_valid, &scd);
-
-
-  response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
-
-
-  switch (response)
-    {
-    case GTK_RESPONSE_OK:
-      g_free (execute_syntax_string (de, generate_syntax (&scd)));
-      break;
-    case PSPPIRE_RESPONSE_PASTE:
-      g_free (paste_syntax_to_window (generate_syntax (&scd)));
-      break;
-    default:
-      break;
-    }
-
-  g_object_unref (xml);
-}
-
diff --git a/src/ui/gui/sort-cases-dialog.h b/src/ui/gui/sort-cases-dialog.h
deleted file mode 100644 (file)
index 0c2814f..0000000
+++ /dev/null
@@ -1,24 +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 __SORT_CASES_DIALOG_H
-#define __SORT_CASES_DIALOG_H
-
-#include "psppire-data-window.h"
-
-void sort_cases_dialog (PsppireDataWindow * data);
-
-#endif
index 9ea17e9f00195b8839abd27f026c1d6b08b8e7f7..9f21486f70db0ff376688977b71460827a7dd78a 100644 (file)
@@ -18,6 +18,7 @@
 #include "psppire-dialog-action-kmeans.h"
 #include "psppire-dialog-action-reliability.h"
 #include "psppire-dialog-action-roc.h"
+#include "psppire-dialog-action-sort.h"
 #include "psppire-dialog-action-var-info.h"
 
 
@@ -43,4 +44,5 @@ preregister_widgets (void)
   psppire_dialog_action_var_info_get_type ();
   psppire_dialog_action_reliability_get_type ();
   psppire_dialog_action_roc_get_type ();
+  psppire_dialog_action_sort_get_type ();
 }