From 068af51fd4b0ca77b07cf85870c41a5db8bd5da2 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 4 Oct 2013 12:24:33 +0200 Subject: [PATCH] Runs 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 - ...-dialog.c => psppire-dialog-action-runs.c} | 202 +++++++----------- src/ui/gui/psppire-dialog-action-runs.h | 79 +++++++ src/ui/gui/runs-dialog.h | 24 --- src/ui/gui/widgets.c | 2 + 7 files changed, 166 insertions(+), 150 deletions(-) rename src/ui/gui/{runs-dialog.c => psppire-dialog-action-runs.c} (53%) create mode 100644 src/ui/gui/psppire-dialog-action-runs.h delete mode 100644 src/ui/gui/runs-dialog.h diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index f5bd07bee3..be6ab05c04 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -221,6 +221,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-dialog-action-reliability.h \ src/ui/gui/psppire-dialog-action-roc.c \ src/ui/gui/psppire-dialog-action-roc.h \ + src/ui/gui/psppire-dialog-action-runs.c \ + src/ui/gui/psppire-dialog-action-runs.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 \ @@ -269,8 +271,6 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-window-register.h \ src/ui/gui/recode-dialog.c \ src/ui/gui/recode-dialog.h \ - src/ui/gui/runs-dialog.c \ - src/ui/gui/runs-dialog.h \ src/ui/gui/select-cases-dialog.c \ src/ui/gui/select-cases-dialog.h \ src/ui/gui/split-file-dialog.c \ diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index d5da4457b9..7cfbbd9bb6 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -432,8 +432,9 @@ - + runs + uimanager1 R_uns... diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index bb6c1ac892..e5106b8726 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -44,7 +44,6 @@ #include "ui/gui/psppire-syntax-window.h" #include "ui/gui/psppire-window.h" #include "ui/gui/psppire.h" -#include "ui/gui/runs-dialog.h" #include "ui/gui/ks-one-sample-dialog.h" #include "ui/gui/recode-dialog.h" #include "ui/gui/select-cases-dialog.h" @@ -984,7 +983,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog)); connect_action (de, "univariate", G_CALLBACK (univariate_dialog)); connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog)); - connect_action (de, "runs", G_CALLBACK (runs_dialog)); connect_action (de, "ks-one-sample", G_CALLBACK (ks_one_sample_dialog)); connect_action (de, "k-related-samples", G_CALLBACK (k_related_dialog)); connect_action (de, "two-related-samples", G_CALLBACK (two_related_dialog)); diff --git a/src/ui/gui/runs-dialog.c b/src/ui/gui/psppire-dialog-action-runs.c similarity index 53% rename from src/ui/gui/runs-dialog.c rename to src/ui/gui/psppire-dialog-action-runs.c index bfbfc834cb..d1cd70ce84 100644 --- a/src/ui/gui/runs-dialog.c +++ b/src/ui/gui/psppire-dialog-action-runs.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2011, 2012 Free Software Foundation + Copyright (C) 2012, 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 @@ -14,30 +14,20 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include -#include "dialog-common.h" -#include -#include +#include -#include "runs-dialog.h" -#include "psppire-selector.h" -#include "psppire-dictview.h" -#include "psppire-dialog.h" +#include "psppire-dialog-action-runs.h" -#include "psppire-data-window.h" #include "psppire-var-view.h" -#include "executor.h" +#include "psppire-dialog.h" #include "builder-wrapper.h" -#include "helper.h" -#include - -#include "gettext.h" -#define _(msgid) gettext (msgid) -#define N_(msgid) msgid +static void psppire_dialog_action_runs_init (PsppireDialogActionRuns *act); +static void psppire_dialog_action_runs_class_init (PsppireDialogActionRunsClass *class); +G_DEFINE_TYPE (PsppireDialogActionRuns, psppire_dialog_action_runs, PSPPIRE_TYPE_DIALOG_ACTION); enum { @@ -47,32 +37,49 @@ enum CB_CUSTOM }; -struct runs -{ - GtkBuilder *xml; - PsppireDict *dict; - GtkWidget *variables; - PsppireDataWindow *de ; +static void +append_fragment (GString *string, const gchar *cut, PsppireVarView *vv) +{ + g_string_append (string, "\n\t/RUNS"); - GtkWidget *entry; - GtkWidget *cb[4]; -}; + g_string_append (string, " ( "); + g_string_append (string, cut); + g_string_append (string, " ) = "); -static char * generate_syntax (const struct runs *rd); + psppire_var_view_append_names (vv, 0, string); +} -static void -refresh (struct runs *fd) +static char * +generate_syntax (PsppireDialogAction *act) { - int i; - GtkTreeModel *liststore = - gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables)); - gtk_list_store_clear (GTK_LIST_STORE (liststore)); + PsppireDialogActionRuns *rd = PSPPIRE_DIALOG_ACTION_RUNS (act); + gchar *text; - gtk_entry_set_text (GTK_ENTRY (fd->entry), ""); + GString *string = g_string_new ("NPAR TEST"); - for (i = 0; i < 4; ++i) - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd->cb[i]), FALSE); + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MEAN]))) + append_fragment (string, "MEAN", PSPPIRE_VAR_VIEW (rd->variables)); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MEDIAN]))) + append_fragment (string, "MEDIAN", PSPPIRE_VAR_VIEW (rd->variables)); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MODE]))) + append_fragment (string, "MODE", PSPPIRE_VAR_VIEW (rd->variables)); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_CUSTOM]))) + { + const char *text = gtk_entry_get_text (GTK_ENTRY (rd->entry)); + append_fragment (string, text, PSPPIRE_VAR_VIEW (rd->variables)); + } + + g_string_append (string, ".\n"); + + text = string->str; + + g_string_free (string, FALSE); + + return text; } @@ -80,7 +87,7 @@ static gboolean dialog_state_valid (gpointer data) { int i; - struct runs *fd = data; + PsppireDialogActionRuns *fd = PSPPIRE_DIALOG_ACTION_RUNS (data); GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables)); @@ -105,107 +112,60 @@ dialog_state_valid (gpointer data) return TRUE; } - -/* Pops up the Runs dialog box */ -void -runs_dialog (PsppireDataWindow *dw) +static void +refresh (PsppireDialogAction *rd_) { - struct runs fd; - gint response; - - GtkWidget *dialog ; - GtkWidget *source ; - - fd.xml = builder_new ("runs.ui"); - - dialog = get_widget_assert (fd.xml, "runs-dialog"); - source = get_widget_assert (fd.xml, "dict-view"); - - fd.entry = get_widget_assert (fd.xml, "entry1"); - fd.cb[CB_MEDIAN] = get_widget_assert (fd.xml, "checkbutton1"); - fd.cb[CB_MEAN] = get_widget_assert (fd.xml, "checkbutton2"); - fd.cb[CB_MODE] = get_widget_assert (fd.xml, "checkbutton4"); - fd.cb[CB_CUSTOM] = get_widget_assert (fd.xml, "checkbutton3"); - - fd.de = dw; - - g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &fd); + PsppireDialogActionRuns *rd = PSPPIRE_DIALOG_ACTION_RUNS (rd_); + int i; + GtkTreeModel *liststore = + gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables)); + gtk_list_store_clear (GTK_LIST_STORE (liststore)); + gtk_entry_set_text (GTK_ENTRY (rd->entry), ""); - fd.variables = get_widget_assert (fd.xml, "psppire-var-view1"); + for (i = 0; i < 4; ++i) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->cb[i]), FALSE); +} - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (fd.de)); +static void +psppire_dialog_action_runs_activate (GtkAction *a) +{ + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); + PsppireDialogActionRuns *act = PSPPIRE_DIALOG_ACTION_RUNS (a); - g_object_get (fd.de->data_editor, "dictionary", &fd.dict, NULL); - g_object_set (source, "model", fd.dict, - "predicate", var_is_numeric, - NULL); + GtkBuilder *xml = builder_new ("runs.ui"); + pda->dialog = get_widget_assert (xml, "runs-dialog"); + pda->source = get_widget_assert (xml, "dict-view"); - g_signal_connect (fd.cb[CB_CUSTOM], "toggled", - G_CALLBACK (set_sensitivity_from_toggle), fd.entry); + act->entry = get_widget_assert (xml, "entry1"); + act->cb[CB_MEDIAN] = get_widget_assert (xml, "checkbutton1"); + act->cb[CB_MEAN] = get_widget_assert (xml, "checkbutton2"); + act->cb[CB_MODE] = get_widget_assert (xml, "checkbutton4"); + act->cb[CB_CUSTOM] = get_widget_assert (xml, "checkbutton3"); + act->variables = get_widget_assert (xml, "psppire-var-view1"); - psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), - dialog_state_valid, &fd); - response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); + psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid); + psppire_dialog_action_set_refresh (pda, refresh); - switch (response) - { - case GTK_RESPONSE_OK: - g_free (execute_syntax_string (dw, generate_syntax (&fd))); - break; - case PSPPIRE_RESPONSE_PASTE: - g_free (paste_syntax_to_window (generate_syntax (&fd))); - break; - default: - break; - } + g_object_unref (xml); - g_object_unref (fd.xml); + if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_runs_parent_class)->activate) + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_runs_parent_class)->activate (pda); } - - static void -append_fragment (GString *string, const gchar *cut, PsppireVarView *vv) +psppire_dialog_action_runs_class_init (PsppireDialogActionRunsClass *class) { - g_string_append (string, "\n\t/RUNS"); - - g_string_append (string, " ( "); - g_string_append (string, cut); - g_string_append (string, " ) = "); + GtkActionClass *action_class = GTK_ACTION_CLASS (class); - psppire_var_view_append_names (vv, 0, string); + action_class->activate = psppire_dialog_action_runs_activate; + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; } -char * -generate_syntax (const struct runs *rd) +static void +psppire_dialog_action_runs_init (PsppireDialogActionRuns *act) { - gchar *text; - - GString *string = g_string_new ("NPAR TEST"); - - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MEAN]))) - append_fragment (string, "MEAN", PSPPIRE_VAR_VIEW (rd->variables)); - - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MEDIAN]))) - append_fragment (string, "MEDIAN", PSPPIRE_VAR_VIEW (rd->variables)); - - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MODE]))) - append_fragment (string, "MODE", PSPPIRE_VAR_VIEW (rd->variables)); - - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_CUSTOM]))) - { - const char *text = gtk_entry_get_text (GTK_ENTRY (rd->entry)); - append_fragment (string, text, PSPPIRE_VAR_VIEW (rd->variables)); - } - - g_string_append (string, ".\n"); - - text = string->str; - - g_string_free (string, FALSE); - - return text; } + diff --git a/src/ui/gui/psppire-dialog-action-runs.h b/src/ui/gui/psppire-dialog-action-runs.h new file mode 100644 index 0000000000..84e796b19a --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-runs.h @@ -0,0 +1,79 @@ +/* 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_RUNS_H__ +#define __PSPPIRE_DIALOG_ACTION_RUNS_H__ + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_RUNS (psppire_dialog_action_runs_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_RUNS(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_RUNS, PsppireDialogActionRuns)) + +#define PSPPIRE_DIALOG_ACTION_RUNS_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_RUNS, \ + PsppireDialogActionRunsClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_RUNS(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_RUNS)) + +#define PSPPIRE_IS_DIALOG_ACTION_RUNS_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_RUNS)) + + +#define PSPPIRE_DIALOG_ACTION_RUNS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_RUNS, \ + PsppireDialogActionRunsClass)) + +typedef struct _PsppireDialogActionRuns PsppireDialogActionRuns; +typedef struct _PsppireDialogActionRunsClass PsppireDialogActionRunsClass; + + +struct _PsppireDialogActionRuns +{ + PsppireDialogAction parent; + + /*< private >*/ + gboolean dispose_has_run ; + + GtkWidget *cb[4]; + GtkWidget *entry; + GtkWidget *variables; +}; + + +struct _PsppireDialogActionRunsClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_runs_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_RUNS_H__ */ diff --git a/src/ui/gui/runs-dialog.h b/src/ui/gui/runs-dialog.h deleted file mode 100644 index f34b48d1bc..0000000000 --- a/src/ui/gui/runs-dialog.h +++ /dev/null @@ -1,24 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2011 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 __RUNS_DIALOG_H -#define __RUNS_DIALOG_H - -#include "psppire-data-window.h" - -void runs_dialog (PsppireDataWindow * data); - -#endif diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index 7046df8c93..55b74ac857 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -32,6 +32,7 @@ #include "psppire-dialog-action-regression.h" #include "psppire-dialog-action-reliability.h" #include "psppire-dialog-action-roc.h" +#include "psppire-dialog-action-runs.h" #include "psppire-dialog-action-sort.h" #include "psppire-dialog-action-var-info.h" #include "psppire-value-entry.h" @@ -73,6 +74,7 @@ preregister_widgets (void) psppire_dialog_action_reliability_get_type (); psppire_dialog_action_regression_get_type (); psppire_dialog_action_roc_get_type (); + psppire_dialog_action_runs_get_type (); psppire_dialog_action_sort_get_type (); /* This seems to be necessary on Cygwin. -- 2.30.2