Transpose dialog: convert from old style to PsppireDialogAction
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 4 Oct 2013 11:59:51 +0000 (13:59 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sun, 6 Oct 2013 14:32:43 +0000 (16:32 +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-flip.c [new file with mode: 0644]
src/ui/gui/psppire-dialog-action-flip.h [new file with mode: 0644]
src/ui/gui/transpose-dialog.c [deleted file]
src/ui/gui/transpose-dialog.h [deleted file]
src/ui/gui/widgets.c

index be6ab05c04c22072a02b3406cc8422d06b5dffd7..9bc899520170359731ca84ef4b177f0eb74b7c29 100644 (file)
@@ -203,6 +203,8 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/psppire-dialog-action-examine.h \
        src/ui/gui/psppire-dialog-action-factor.c \
        src/ui/gui/psppire-dialog-action-factor.h \
+       src/ui/gui/psppire-dialog-action-flip.c \
+       src/ui/gui/psppire-dialog-action-flip.h \
        src/ui/gui/psppire-dialog-action-frequencies.c \
        src/ui/gui/psppire-dialog-action-frequencies.h \
        src/ui/gui/psppire-dialog-action-indep-samps.c \
@@ -289,8 +291,6 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/page-sheet-spec.h \
        src/ui/gui/text-data-import-dialog.c \
        src/ui/gui/text-data-import-dialog.h \
-       src/ui/gui/transpose-dialog.c \
-       src/ui/gui/transpose-dialog.h \
        src/ui/gui/t-test-one-sample.c \
        src/ui/gui/t-test-one-sample.h \
        src/ui/gui/t-test-options.c \
index 7cfbbd9bb62d938709e0b4b753c6319e226072ca..34f885da2271179a56e9c4e9369264bde1774faa 100644 (file)
           </object>
         </child>
         <child>
-          <object class="GtkAction" id="data_transpose">
+          <object class="PsppireDialogActionFlip" id="data_transpose">
            <property name="stock-id">data-transpose</property>
             <property name="name">data_transpose</property>
+            <property name="manager">uimanager1</property>
             <property name="label" translatable="yes">_Transpose...</property>
            <property name="tooltip" translatable="yes">Transpose the cases with the variables</property>
           </object>
index e5106b872681d2d911ae2092ea0dfd4aea8cedce..b4e87f0f213d446affbf406137815eed383aa0f6 100644 (file)
@@ -51,7 +51,6 @@
 #include "ui/gui/t-test-one-sample.h"
 #include "ui/gui/t-test-paired-samples.h"
 #include "ui/gui/text-data-import-dialog.h"
-#include "ui/gui/transpose-dialog.h"
 #include "ui/gui/univariate-dialog.h"
 #include "ui/gui/weight-cases-dialog.h"
 #include "ui/syntax-gen.h"
@@ -967,7 +966,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
 
   g_signal_connect_swapped (get_action_assert (de->builder, "view_value-labels"), "toggled", G_CALLBACK (toggle_value_labels), de);
 
-  connect_action (de, "data_transpose", G_CALLBACK (transpose_dialog));
   connect_action (de, "data_select-cases", G_CALLBACK (select_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-flip.c b/src/ui/gui/psppire-dialog-action-flip.c
new file mode 100644 (file)
index 0000000..2581a2f
--- /dev/null
@@ -0,0 +1,128 @@
+/* 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 <config.h>
+
+#include "psppire-dialog-action-flip.h"
+
+#include "psppire-var-view.h"
+
+#include "psppire-dialog.h"
+#include "builder-wrapper.h"
+
+static void psppire_dialog_action_flip_init            (PsppireDialogActionFlip      *act);
+static void psppire_dialog_action_flip_class_init      (PsppireDialogActionFlipClass *class);
+
+G_DEFINE_TYPE (PsppireDialogActionFlip, psppire_dialog_action_flip, PSPPIRE_TYPE_DIALOG_ACTION);
+
+
+/*
+     FLIP /VARIABLES=var_list /NEWNAMES=var_name.
+*/
+static char *
+generate_syntax (PsppireDialogAction *act)
+{
+  const gchar *text;
+  PsppireDialogActionFlip *rd = PSPPIRE_DIALOG_ACTION_FLIP (act);
+
+  GString *string = g_string_new ("FLIP");
+  gchar *syntax ;
+
+  g_string_append (string, " /VARIABLES = ");
+
+  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->dest), 0, string);
+
+  text = gtk_entry_get_text (GTK_ENTRY (rd->entry));
+
+  if ( text)
+    g_string_append_printf (string, " /NEWNAME = %s", text);
+
+  g_string_append (string, ".\n");
+
+  syntax = string->str;
+
+  g_string_free (string, FALSE);
+
+  return syntax;
+}
+
+
+static gboolean
+dialog_state_valid (gpointer a)
+{
+  PsppireDialogActionFlip *act = PSPPIRE_DIALOG_ACTION_FLIP (a);
+
+  GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (act->dest));
+
+  gint n_rows = gtk_tree_model_iter_n_children  (model, NULL);
+
+  if ( n_rows == 0 )
+    return FALSE;
+
+  if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (act->entry))))
+    return FALSE;
+
+  return TRUE;
+}
+
+static void
+refresh (PsppireDialogAction *rd_)
+{
+  PsppireDialogActionFlip *rd = PSPPIRE_DIALOG_ACTION_FLIP (rd_);
+  GtkTreeModel *dmodel = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->dest));
+
+  gtk_list_store_clear (GTK_LIST_STORE (dmodel));
+  gtk_entry_set_text (GTK_ENTRY (rd->entry), "");
+}
+
+static void
+psppire_dialog_action_flip_activate (GtkAction *a)
+{
+  PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
+  PsppireDialogActionFlip *act = PSPPIRE_DIALOG_ACTION_FLIP (a);
+
+  GtkBuilder *xml = builder_new ("psppire.ui");
+  pda->dialog = get_widget_assert   (xml, "transpose-dialog");
+  pda->source = get_widget_assert   (xml, "source-treeview");
+
+  act->dest = get_widget_assert (xml, "variables-treeview");
+  act->entry = get_widget_assert (xml, "new-name-entry");
+
+  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_flip_parent_class)->activate)
+    PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_flip_parent_class)->activate (pda);
+}
+
+static void
+psppire_dialog_action_flip_class_init (PsppireDialogActionFlipClass *class)
+{
+  GtkActionClass *action_class = GTK_ACTION_CLASS (class);
+
+  action_class->activate = psppire_dialog_action_flip_activate;
+  PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
+}
+
+
+static void
+psppire_dialog_action_flip_init (PsppireDialogActionFlip *act)
+{
+}
+
diff --git a/src/ui/gui/psppire-dialog-action-flip.h b/src/ui/gui/psppire-dialog-action-flip.h
new file mode 100644 (file)
index 0000000..b7a46e0
--- /dev/null
@@ -0,0 +1,78 @@
+/* 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_FLIP_H__
+#define __PSPPIRE_DIALOG_ACTION_FLIP_H__
+
+G_BEGIN_DECLS
+
+
+#define PSPPIRE_TYPE_DIALOG_ACTION_FLIP (psppire_dialog_action_flip_get_type ())
+
+#define PSPPIRE_DIALOG_ACTION_FLIP(obj)        \
+                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                                                 PSPPIRE_TYPE_DIALOG_ACTION_FLIP, PsppireDialogActionFlip))
+
+#define PSPPIRE_DIALOG_ACTION_FLIP_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_CAST ((klass), \
+                                PSPPIRE_TYPE_DIALOG_ACTION_FLIP, \
+                                 PsppireDialogActionFlipClass))
+
+
+#define PSPPIRE_IS_DIALOG_ACTION_FLIP(obj) \
+                    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_FLIP))
+
+#define PSPPIRE_IS_DIALOG_ACTION_FLIP_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_FLIP))
+
+
+#define PSPPIRE_DIALOG_ACTION_FLIP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                                  PSPPIRE_TYPE_DIALOG_ACTION_FLIP, \
+                                  PsppireDialogActionFlipClass))
+
+typedef struct _PsppireDialogActionFlip       PsppireDialogActionFlip;
+typedef struct _PsppireDialogActionFlipClass  PsppireDialogActionFlipClass;
+
+
+struct _PsppireDialogActionFlip
+{
+  PsppireDialogAction parent;
+
+  /*< private >*/
+  gboolean dispose_has_run ;
+
+  GtkWidget *dest;
+  GtkWidget *entry;
+};
+
+
+struct _PsppireDialogActionFlipClass
+{
+  PsppireDialogActionClass parent_class;
+};
+
+
+GType psppire_dialog_action_flip_get_type (void) ;
+
+G_END_DECLS
+
+#endif /* __PSPPIRE_DIALOG_ACTION_FLIP_H__ */
diff --git a/src/ui/gui/transpose-dialog.c b/src/ui/gui/transpose-dialog.c
deleted file mode 100644 (file)
index 742dff5..0000000
+++ /dev/null
@@ -1,153 +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 "transpose-dialog.h"
-#include "psppire-selector.h"
-#include "psppire-var-view.h"
-#include "psppire-dialog.h"
-#include "executor.h"
-#include "psppire-data-window.h"
-#include "dict-display.h"
-#include "builder-wrapper.h"
-#include "helper.h"
-
-#include "dialog-common.h"
-
-#include <gtk/gtk.h>
-
-#include <gettext.h>
-
-#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
-
-
-static gchar * generate_syntax (PsppireDict *dict, GtkBuilder *xml);
-
-static void
-refresh (PsppireDialog *dialog, gpointer data)
-{
-  GtkBuilder *xml = data;
-  GtkWidget *dest = get_widget_assert (xml, "variables-treeview");
-  GtkWidget *entry = get_widget_assert (xml, "new-name-entry");
-  GtkTreeModel *dmodel = gtk_tree_view_get_model (GTK_TREE_VIEW (dest));
-
-  gtk_list_store_clear (GTK_LIST_STORE (dmodel));
-  gtk_entry_set_text (GTK_ENTRY (entry), "");
-}
-
-static gboolean
-dialog_state_valid (gpointer data)
-{
-  GtkBuilder *xml = data;
-
-  GtkWidget *tv = get_widget_assert (xml, "variables-treeview");
-  GtkWidget *entry = get_widget_assert (xml, "new-name-entry");
-
-  GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (tv));
-
-  gint n_rows = gtk_tree_model_iter_n_children  (model, NULL);
-
-  if ( n_rows == 0 )
-    return FALSE;
-
-  if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))))
-    return FALSE;
-
-  return TRUE;
-}
-
-
-void
-transpose_dialog (PsppireDataWindow *de)
-{
-  gint response ;
-  PsppireDict *dict = NULL;
-
-  GtkBuilder *xml = builder_new ("psppire.ui");
-
-  GtkWidget *dialog = get_widget_assert (xml, "transpose-dialog");
-  GtkWidget *source = get_widget_assert (xml, "source-treeview");
-  GtkWidget *selector2 = get_widget_assert (xml, "psppire-selector3");
-
-  g_object_get (de->data_editor, "dictionary", &dict, NULL);
-  g_object_set (source, "model", dict, NULL);
-
-  psppire_selector_set_filter_func (PSPPIRE_SELECTOR (selector2),
-                                is_currently_in_entry);
-
-
-  g_signal_connect (dialog, "refresh", G_CALLBACK (refresh),  xml);
-
-  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
-
-  psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
-                                     dialog_state_valid, xml);
-
-  response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
-
-  switch (response)
-    {
-    case GTK_RESPONSE_OK:
-      g_free (execute_syntax_string (de, generate_syntax (dict, xml)));
-      break;
-    case PSPPIRE_RESPONSE_PASTE:
-      {
-       gchar *syntax = generate_syntax (dict, xml);
-        paste_syntax_to_window (syntax);
-
-       g_free (syntax);
-      }
-      break;
-    default:
-      break;
-    }
-
-  g_object_unref (xml);
-}
-
-
-  /*
-     FLIP /VARIABLES=var_list /NEWNAMES=var_name.
-  */
-static gchar *
-generate_syntax (PsppireDict *dict, GtkBuilder *xml)
-{
-  const gchar *text;
-  GString *string = g_string_new ("FLIP");
-  gchar *syntax ;
-
-  GtkWidget *dest = get_widget_assert (xml, "variables-treeview");
-  GtkWidget *entry = get_widget_assert (xml, "new-name-entry");
-
-  g_string_append (string, " /VARIABLES = ");
-
-  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (dest), 0, string);
-
-  text = gtk_entry_get_text (GTK_ENTRY (entry));
-
-  if ( text)
-    g_string_append_printf (string, " /NEWNAME = %s", text);
-
-  g_string_append (string, ".");
-
-  syntax = string->str;
-
-  g_string_free (string, FALSE);
-
-  return syntax;
-}
diff --git a/src/ui/gui/transpose-dialog.h b/src/ui/gui/transpose-dialog.h
deleted file mode 100644 (file)
index 91ab97d..0000000
+++ /dev/null
@@ -1,26 +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 TRANSPOSE_DIALOG_H
-#define TRANSPOSE_DIALOG_H
-
-#include "psppire-data-window.h"
-
-void transpose_dialog (PsppireDataWindow * data);
-
-
-#endif
index 55b74ac857f46a08b3640b43b3bb066dee1cf093..6d07bdfec7250a3c6017fbd48c6a8054ce278ed6 100644 (file)
@@ -21,6 +21,7 @@
 #include "psppire-dialog-action-crosstabs.h"
 #include "psppire-dialog-action-descriptives.h"
 #include "psppire-dialog-action-examine.h"
+#include "psppire-dialog-action-flip.h"
 #include "psppire-dialog-action-factor.h"
 #include "psppire-dialog-action-frequencies.h"
 #include "psppire-dialog-action-indep-samps.h"
@@ -63,6 +64,7 @@ preregister_widgets (void)
   psppire_dialog_action_descriptives_get_type ();
   psppire_dialog_action_examine_get_type ();
   psppire_dialog_action_factor_get_type ();
+  psppire_dialog_action_flip_get_type ();
   psppire_dialog_action_frequencies_get_type ();
   psppire_dialog_action_logistic_get_type ();
   psppire_dialog_action_kmeans_get_type ();