From af81cedbd19fc8a129acf19fb74815ca28c700f1 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 4 Oct 2013 13:59:51 +0200 Subject: [PATCH] Transpose dialog: convert from old style to PsppireDialogAction --- src/ui/gui/automake.mk | 4 +- src/ui/gui/data-editor.ui | 3 +- src/ui/gui/psppire-data-window.c | 2 - src/ui/gui/psppire-dialog-action-flip.c | 128 ++++++++++++++++++++ src/ui/gui/psppire-dialog-action-flip.h | 78 ++++++++++++ src/ui/gui/transpose-dialog.c | 153 ------------------------ src/ui/gui/transpose-dialog.h | 26 ---- src/ui/gui/widgets.c | 2 + 8 files changed, 212 insertions(+), 184 deletions(-) create mode 100644 src/ui/gui/psppire-dialog-action-flip.c create mode 100644 src/ui/gui/psppire-dialog-action-flip.h delete mode 100644 src/ui/gui/transpose-dialog.c delete mode 100644 src/ui/gui/transpose-dialog.h diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index be6ab05c04..9bc8995201 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -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 \ diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index 7cfbbd9bb6..34f885da22 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -176,9 +176,10 @@ - + data-transpose data_transpose + uimanager1 _Transpose... Transpose the cases with the variables diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index e5106b8726..b4e87f0f21 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -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 index 0000000000..2581a2fad7 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-flip.c @@ -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 . */ + + +#include + +#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 index 0000000000..b7a46e0912 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-flip.h @@ -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 . */ + + +#include +#include + +#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 index 742dff527b..0000000000 --- a/src/ui/gui/transpose-dialog.c +++ /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 . */ - -#include - -#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 - -#include - -#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 index 91ab97db5d..0000000000 --- a/src/ui/gui/transpose-dialog.h +++ /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 . */ - - -#ifndef TRANSPOSE_DIALOG_H -#define TRANSPOSE_DIALOG_H - -#include "psppire-data-window.h" - -void transpose_dialog (PsppireDataWindow * data); - - -#endif diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index 55b74ac857..6d07bdfec7 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -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 (); -- 2.30.2