From 731134f6eec60db6615fbb2a0e36323588422df3 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 11 Oct 2013 09:24:34 +0200 Subject: [PATCH] Convert count dialog to PsppireDialogAction --- src/ui/gui/automake.mk | 4 +- src/ui/gui/count-dialog.h | 24 -- src/ui/gui/data-editor.ui | 3 +- src/ui/gui/psppire-data-window.c | 2 - ...dialog.c => psppire-dialog-action-count.c} | 290 +++++++++--------- src/ui/gui/psppire-dialog-action-count.h | 82 +++++ src/ui/gui/widgets.c | 2 + 7 files changed, 231 insertions(+), 176 deletions(-) delete mode 100644 src/ui/gui/count-dialog.h rename src/ui/gui/{count-dialog.c => psppire-dialog-action-count.c} (67%) create mode 100644 src/ui/gui/psppire-dialog-action-count.h diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index addbbe2cad..9722010256 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -139,8 +139,6 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/builder-wrapper.h \ src/ui/gui/comments-dialog.c \ src/ui/gui/comments-dialog.h \ - src/ui/gui/count-dialog.c \ - src/ui/gui/count-dialog.h \ src/ui/gui/dialog-common.c \ src/ui/gui/dialog-common.h \ src/ui/gui/dict-display.h \ @@ -191,6 +189,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-dialog-action-chisquare.h \ src/ui/gui/psppire-dialog-action-compute.c \ src/ui/gui/psppire-dialog-action-compute.h \ + src/ui/gui/psppire-dialog-action-count.c \ + src/ui/gui/psppire-dialog-action-count.h \ src/ui/gui/psppire-dialog-action-correlation.c \ src/ui/gui/psppire-dialog-action-correlation.h \ src/ui/gui/psppire-dialog-action-crosstabs.c \ diff --git a/src/ui/gui/count-dialog.h b/src/ui/gui/count-dialog.h deleted file mode 100644 index d97765d6dc..0000000000 --- a/src/ui/gui/count-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 __COUNT_DIALOG_H -#define __COUNT_DIALOG_H - -#include "psppire-data-window.h" - -void count_dialog (PsppireDataWindow * data); - -#endif diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index 850f318a06..658116092c 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -230,8 +230,9 @@ - + transform_count + uimanager1 Cou_nt... transform-count diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index f756586a25..7979257b5d 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -28,7 +28,6 @@ #include "ui/gui/autorecode-dialog.h" #include "ui/gui/builder-wrapper.h" #include "ui/gui/comments-dialog.h" -#include "ui/gui/count-dialog.h" #include "ui/gui/entry-dialog.h" #include "ui/gui/executor.h" #include "ui/gui/help-menu.h" @@ -961,7 +960,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "oneway-anova", G_CALLBACK (oneway_anova_dialog)); connect_action (de, "paired-t-test", G_CALLBACK (t_test_paired_samples_dialog)); connect_action (de, "utilities_comments", G_CALLBACK (comments_dialog)); - connect_action (de, "transform_count", G_CALLBACK (count_dialog)); connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog)); connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog)); connect_action (de, "two-related-samples", G_CALLBACK (two_related_dialog)); diff --git a/src/ui/gui/count-dialog.c b/src/ui/gui/psppire-dialog-action-count.c similarity index 67% rename from src/ui/gui/count-dialog.c rename to src/ui/gui/psppire-dialog-action-count.c index c73032292b..a439e1a764 100644 --- a/src/ui/gui/count-dialog.c +++ b/src/ui/gui/psppire-dialog-action-count.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2011, 2012 Free Software Foundation + Copyright (C) 2011, 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 @@ -17,84 +17,102 @@ #include -#include "count-dialog.h" +#include "psppire-dialog-action-count.h" + +#include "psppire-var-view.h" -#include -#include "builder-wrapper.h" #include "psppire-dialog.h" #include "psppire-selector.h" -#include "psppire-val-chooser.h" -#include "psppire-var-view.h" +#include "builder-wrapper.h" #include "psppire-acr.h" #include "dialog-common.h" - #include -#include "executor.h" + +#include "psppire-val-chooser.h" #include "helper.h" -struct cnt_dialog -{ - PsppireDict *dict; - GtkWidget *dialog; +static void values_dialog (PsppireDialogActionCount *cd); - GtkListStore *value_list; - GtkWidget *chooser; - GtkWidget *target; - GtkWidget *label; - GtkWidget *variable_treeview; -}; +static void psppire_dialog_action_count_init (PsppireDialogActionCount *act); +static void psppire_dialog_action_count_class_init (PsppireDialogActionCountClass *class); -/* Callback which gets called when a new row is selected - in the acr's variable treeview. - We use if to set the togglebuttons and entries to correspond to the - selected row. -*/ -static void -on_acr_selection_change (GtkTreeSelection *selection, gpointer data) +G_DEFINE_TYPE (PsppireDialogActionCount, psppire_dialog_action_count, PSPPIRE_TYPE_DIALOG_ACTION); + + +static char * +generate_syntax (PsppireDialogAction *act) { + PsppireDialogActionCount *cnt = PSPPIRE_DIALOG_ACTION_COUNT (act); + gchar *text = NULL; + const gchar *s = NULL; + gboolean ok; GtkTreeIter iter; - struct old_value *ov = NULL; - GtkTreeModel *model = NULL; - struct cnt_dialog *cnt = data; - GValue ov_value = {0}; + struct string dds; + + ds_init_empty (&dds); - if ( ! gtk_tree_selection_get_selected (selection, &model, &iter) ) - return; + ds_put_cstr (&dds, "\nCOUNT "); - gtk_tree_model_get_value (GTK_TREE_MODEL (model), &iter, - 0, &ov_value); + ds_put_cstr (&dds, gtk_entry_get_text (GTK_ENTRY (cnt->target))); - ov = g_value_get_boxed (&ov_value); - psppire_val_chooser_set_status (PSPPIRE_VAL_CHOOSER (cnt->chooser), ov); -} + ds_put_cstr (&dds, " ="); + + psppire_var_view_append_names_str (PSPPIRE_VAR_VIEW (cnt->variable_treeview), 0, &dds); + + ds_put_cstr (&dds, "("); + for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (cnt->value_list), + &iter); + ok; + ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (cnt->value_list), &iter)) + { + GValue a_value = {0}; + struct old_value *ov; + gtk_tree_model_get_value (GTK_TREE_MODEL (cnt->value_list), &iter, + 0, &a_value); + ov = g_value_get_boxed (&a_value); -static char * generate_syntax (const struct cnt_dialog *cnt); + ds_put_cstr (&dds, " "); + old_value_append_syntax (&dds, ov); + } + ds_put_cstr (&dds, ")."); -static void values_dialog (struct cnt_dialog *cd); -static void -refresh (PsppireDialog *dialog, struct cnt_dialog *cnt) -{ - GtkTreeModel *vars = - gtk_tree_view_get_model (GTK_TREE_VIEW (cnt->variable_treeview)); + s = gtk_entry_get_text (GTK_ENTRY (cnt->label)); + if (0 != strcmp (s, "")) + { + ds_put_cstr (&dds, "\nVARIABLE LABELS "); - gtk_list_store_clear (GTK_LIST_STORE (vars)); + ds_put_cstr (&dds, gtk_entry_get_text (GTK_ENTRY (cnt->target))); - gtk_entry_set_text (GTK_ENTRY (cnt->target), ""); - gtk_entry_set_text (GTK_ENTRY (cnt->label), ""); - gtk_list_store_clear (GTK_LIST_STORE (cnt->value_list)); + ds_put_cstr (&dds, " "); + + syntax_gen_string (&dds, ss_cstr (s)); + + ds_put_cstr (&dds, "."); + } + + ds_put_cstr (&dds, "\nEXECUTE.\n"); + + text = ds_steal_cstr (&dds); + + ds_destroy (&dds); + + return text; } + static gboolean dialog_state_valid (gpointer data) { + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (data); + PsppireDialogActionCount *cnt = PSPPIRE_DIALOG_ACTION_COUNT (pda); + GtkTreeIter iter; - struct cnt_dialog *cnt = data; if (! cnt->value_list) return FALSE; @@ -111,66 +129,105 @@ dialog_state_valid (gpointer data) return TRUE; } -void count_dialog (PsppireDataWindow *de) +static void +refresh (PsppireDialogAction *rd_) { - gint response; - struct cnt_dialog cnt; + PsppireDialogActionCount *cnt = PSPPIRE_DIALOG_ACTION_COUNT (rd_); - GtkBuilder *builder = builder_new ("count.ui"); + GtkTreeModel *vars = + gtk_tree_view_get_model (GTK_TREE_VIEW (cnt->variable_treeview)); - GtkWidget *selector = get_widget_assert (builder, "count-selector1"); + gtk_list_store_clear (GTK_LIST_STORE (vars)); - GtkWidget *dict_view = get_widget_assert (builder, "dict-view"); - GtkWidget *button = get_widget_assert (builder, "button1"); + gtk_entry_set_text (GTK_ENTRY (cnt->target), ""); + gtk_entry_set_text (GTK_ENTRY (cnt->label), ""); + gtk_list_store_clear (GTK_LIST_STORE (cnt->value_list)); +} - cnt.target = get_widget_assert (builder, "entry1"); - cnt.label = get_widget_assert (builder, "entry2"); - cnt.variable_treeview = get_widget_assert (builder, "treeview2"); +static void +psppire_dialog_action_count_activate (GtkAction *a) +{ + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); + PsppireDialogActionCount *act = PSPPIRE_DIALOG_ACTION_COUNT (a); - g_signal_connect_swapped (button, "clicked", G_CALLBACK (values_dialog), &cnt); + GtkBuilder *xml = builder_new ("count.ui"); + GtkWidget *selector = get_widget_assert (xml, "count-selector1"); + GtkWidget *button = get_widget_assert (xml, "button1"); - cnt.value_list = gtk_list_store_new (1,old_value_get_type ()); + pda->dialog = get_widget_assert (xml, "count-dialog"); + pda->source = get_widget_assert (xml, "dict-view"); - cnt.dialog = get_widget_assert (builder, "count-dialog"); - g_signal_connect (cnt.dialog, "refresh", G_CALLBACK (refresh), &cnt); + act->target = get_widget_assert (xml, "entry1"); + act->label = get_widget_assert (xml, "entry2"); + act->variable_treeview = get_widget_assert (xml, "treeview2"); + act->value_list = gtk_list_store_new (1, old_value_get_type ()); - g_object_get (de->data_editor, "dictionary", &cnt.dict, NULL); + psppire_selector_set_allow (PSPPIRE_SELECTOR (selector), numeric_only); - gtk_window_set_transient_for (GTK_WINDOW (cnt.dialog), GTK_WINDOW (de)); + g_signal_connect_swapped (button, "clicked", G_CALLBACK (values_dialog), act); - g_object_set (dict_view, "model", cnt.dict, NULL); - psppire_selector_set_allow (PSPPIRE_SELECTOR (selector), numeric_only); + psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid); + psppire_dialog_action_set_refresh (pda, refresh); - psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (cnt.dialog), - dialog_state_valid, &cnt); + g_object_unref (xml); - response = psppire_dialog_run (PSPPIRE_DIALOG (cnt.dialog)); + if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_count_parent_class)->activate) + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_count_parent_class)->activate (pda); +} - switch (response) - { - case GTK_RESPONSE_OK: - g_free (execute_syntax_string (de, generate_syntax (&cnt))); - break; - case PSPPIRE_RESPONSE_PASTE: - g_free (paste_syntax_to_window (generate_syntax (&cnt))); - break; - default: - break; - } +static void +psppire_dialog_action_count_class_init (PsppireDialogActionCountClass *class) +{ + GtkActionClass *action_class = GTK_ACTION_CLASS (class); + action_class->activate = psppire_dialog_action_count_activate; + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; +} - g_object_unref (cnt.value_list); - g_object_unref (builder); + +static void +psppire_dialog_action_count_init (PsppireDialogActionCount *act) +{ +} + + + + + + +/* Callback which gets called when a new row is selected + in the acr's variable treeview. + We use if to set the togglebuttons and entries to correspond to the + selected row. +*/ +static void +on_acr_selection_change (GtkTreeSelection *selection, gpointer data) +{ + GtkTreeIter iter; + struct old_value *ov = NULL; + GtkTreeModel *model = NULL; + PsppireDialogActionCount *cnt = PSPPIRE_DIALOG_ACTION_COUNT (data); + GValue ov_value = {0}; + + if ( ! gtk_tree_selection_get_selected (selection, &model, &iter) ) + return; + + gtk_tree_model_get_value (GTK_TREE_MODEL (model), &iter, + 0, &ov_value); + + ov = g_value_get_boxed (&ov_value); + psppire_val_chooser_set_status (PSPPIRE_VAL_CHOOSER (cnt->chooser), ov); } + /* A function to set a value in a column in the ACR */ static gboolean set_value (gint col, GValue *val, gpointer data) { - struct cnt_dialog *cnt = data; + PsppireDialogActionCount *cnt = PSPPIRE_DIALOG_ACTION_COUNT (data); PsppireValChooser *vc = PSPPIRE_VAL_CHOOSER (cnt->chooser); struct old_value ov; @@ -186,8 +243,9 @@ set_value (gint col, GValue *val, gpointer data) static void -values_dialog (struct cnt_dialog *cd) +values_dialog (PsppireDialogActionCount *cd) { + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (cd); gint response; GtkListStore *local_store = clone_list_store (cd->value_list); GtkBuilder *builder = builder_new ("count.ui"); @@ -220,71 +278,9 @@ values_dialog (struct cnt_dialog *cd) g_object_unref (local_store); } - psppire_dialog_notify_change (PSPPIRE_DIALOG (cd->dialog)); + psppire_dialog_notify_change (PSPPIRE_DIALOG (pda->dialog)); g_object_unref (builder); } - -static char * -generate_syntax (const struct cnt_dialog *cnt) -{ - gchar *text = NULL; - const gchar *s = NULL; - gboolean ok; - GtkTreeIter iter; - struct string dds; - - ds_init_empty (&dds); - - ds_put_cstr (&dds, "\nCOUNT "); - - ds_put_cstr (&dds, gtk_entry_get_text (GTK_ENTRY (cnt->target))); - - ds_put_cstr (&dds, " ="); - - psppire_var_view_append_names_str (PSPPIRE_VAR_VIEW (cnt->variable_treeview), 0, &dds); - - ds_put_cstr (&dds, "("); - for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (cnt->value_list), - &iter); - ok; - ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (cnt->value_list), &iter)) - { - GValue a_value = {0}; - struct old_value *ov; - - gtk_tree_model_get_value (GTK_TREE_MODEL (cnt->value_list), &iter, - 0, &a_value); - - ov = g_value_get_boxed (&a_value); - - ds_put_cstr (&dds, " "); - old_value_append_syntax (&dds, ov); - } - ds_put_cstr (&dds, ")."); - - - s = gtk_entry_get_text (GTK_ENTRY (cnt->label)); - if (0 != strcmp (s, "")) - { - ds_put_cstr (&dds, "\nVARIABLE LABELS "); - - ds_put_cstr (&dds, gtk_entry_get_text (GTK_ENTRY (cnt->target))); - - ds_put_cstr (&dds, " "); - - syntax_gen_string (&dds, ss_cstr (s)); - - ds_put_cstr (&dds, "."); - } - - ds_put_cstr (&dds, "\nEXECUTE.\n"); - - text = ds_steal_cstr (&dds); - - ds_destroy (&dds); - - return text; -} diff --git a/src/ui/gui/psppire-dialog-action-count.h b/src/ui/gui/psppire-dialog-action-count.h new file mode 100644 index 0000000000..af4bdcecd3 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-count.h @@ -0,0 +1,82 @@ +/* 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_COUNT_H__ +#define __PSPPIRE_DIALOG_ACTION_COUNT_H__ + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_COUNT (psppire_dialog_action_count_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_COUNT(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_COUNT, PsppireDialogActionCount)) + +#define PSPPIRE_DIALOG_ACTION_COUNT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_COUNT, \ + PsppireDialogActionCountClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_COUNT(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_COUNT)) + +#define PSPPIRE_IS_DIALOG_ACTION_COUNT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_COUNT)) + + +#define PSPPIRE_DIALOG_ACTION_COUNT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_COUNT, \ + PsppireDialogActionCountClass)) + +typedef struct _PsppireDialogActionCount PsppireDialogActionCount; +typedef struct _PsppireDialogActionCountClass PsppireDialogActionCountClass; + + +struct _PsppireDialogActionCount +{ + PsppireDialogAction parent; + + /*< private >*/ + gboolean dispose_has_run ; + + GtkWidget *target ; + GtkWidget *label ; + GtkWidget *variable_treeview ; + GtkWidget *chooser; + + GtkListStore *value_list; +}; + + +struct _PsppireDialogActionCountClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_count_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_COUNT_H__ */ diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index 220de39642..93257e5b08 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -20,6 +20,7 @@ #include "psppire-dialog-action-chisquare.h" #include "psppire-dialog-action-compute.h" #include "psppire-dialog-action-correlation.h" +#include "psppire-dialog-action-count.h" #include "psppire-dialog-action-crosstabs.h" #include "psppire-dialog-action-descriptives.h" #include "psppire-dialog-action-examine.h" @@ -69,6 +70,7 @@ preregister_widgets (void) psppire_dialog_action_chisquare_get_type (); psppire_dialog_action_compute_get_type (); psppire_dialog_action_correlation_get_type (); + psppire_dialog_action_count_get_type (); psppire_dialog_action_crosstabs_get_type (); psppire_dialog_action_descriptives_get_type (); psppire_dialog_action_examine_get_type (); -- 2.30.2