From 6d82ab433f298bcf1f0e6615c801d47b9738701a Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 12 Dec 2015 14:03:37 +0100 Subject: [PATCH] Aggregate Dialog: Convert from old fashioned method to PsppireDialogAction paradigm --- src/ui/gui/aggregate-dialog.h | 24 - src/ui/gui/aggregate.ui | 3 +- src/ui/gui/automake.mk | 4 +- src/ui/gui/data-editor.ui | 4 +- src/ui/gui/psppire-data-window.c | 2 - ...og.c => psppire-dialog-action-aggregate.c} | 669 ++++++++---------- src/ui/gui/psppire-dialog-action-aggregate.h | 104 +++ src/ui/gui/widgets.c | 2 + 8 files changed, 424 insertions(+), 388 deletions(-) delete mode 100644 src/ui/gui/aggregate-dialog.h rename src/ui/gui/{aggregate-dialog.c => psppire-dialog-action-aggregate.c} (64%) create mode 100644 src/ui/gui/psppire-dialog-action-aggregate.h diff --git a/src/ui/gui/aggregate-dialog.h b/src/ui/gui/aggregate-dialog.h deleted file mode 100644 index 4ebfecfcdd..0000000000 --- a/src/ui/gui/aggregate-dialog.h +++ /dev/null @@ -1,24 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2010 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 __AGGREGATE_DIALOG_H -#define __AGGREGATE_DIALOG_H - -#include "psppire-data-window.h" - -void aggregate_dialog (PsppireDataWindow * data); - -#endif diff --git a/src/ui/gui/aggregate.ui b/src/ui/gui/aggregate.ui index 80e2b153e6..f5372c0d81 100644 --- a/src/ui/gui/aggregate.ui +++ b/src/ui/gui/aggregate.ui @@ -3,7 +3,7 @@ - + False Aggregate Data True @@ -227,6 +227,7 @@ True False True + 5 True diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index afae3aec3e..f19bff0d42 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -149,8 +149,6 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-acr.c \ src/ui/gui/autorecode-dialog.c \ src/ui/gui/autorecode-dialog.h \ - src/ui/gui/aggregate-dialog.c \ - src/ui/gui/aggregate-dialog.h \ src/ui/gui/builder-wrapper.c \ src/ui/gui/builder-wrapper.h \ src/ui/gui/comments-dialog.c \ @@ -193,6 +191,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-dialog.h \ src/ui/gui/psppire-dialog-action.c \ src/ui/gui/psppire-dialog-action.h \ + src/ui/gui/psppire-dialog-action-aggregate.c \ + src/ui/gui/psppire-dialog-action-aggregate.h \ src/ui/gui/psppire-dialog-action-1sks.c \ src/ui/gui/psppire-dialog-action-1sks.h \ src/ui/gui/psppire-dialog-action-barchart.c \ diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index ae4ba2b4ef..dbb4d1772c 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -188,10 +188,12 @@ - + data-aggregate data_aggregate + uimanager1 _Aggregate... + Aggregate the case values into a new variable diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index c68f65e129..3dabaef8b2 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -24,7 +24,6 @@ #include "language/lexer/lexer.h" #include "libpspp/message.h" #include "libpspp/str.h" -#include "ui/gui/aggregate-dialog.h" #include "ui/gui/autorecode-dialog.h" #include "ui/gui/builder-wrapper.h" #include "ui/gui/comments-dialog.h" @@ -1011,7 +1010,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_select-cases", G_CALLBACK (select_cases_dialog)); - connect_action (de, "data_aggregate", G_CALLBACK (aggregate_dialog)); connect_action (de, "transform_autorecode", G_CALLBACK (autorecode_dialog)); connect_action (de, "data_split-file", G_CALLBACK (split_file_dialog)); connect_action (de, "data_weight-cases", G_CALLBACK (weight_cases_dialog)); diff --git a/src/ui/gui/aggregate-dialog.c b/src/ui/gui/psppire-dialog-action-aggregate.c similarity index 64% rename from src/ui/gui/aggregate-dialog.c rename to src/ui/gui/psppire-dialog-action-aggregate.c index 65addea3e2..e62d02bf0c 100644 --- a/src/ui/gui/aggregate-dialog.c +++ b/src/ui/gui/psppire-dialog-action-aggregate.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2010, 2011, 2012, 2013, 2014 Free Software Foundation + Copyright (C) 2015 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,93 +14,143 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ + #include +#include "psppire-dialog-action-aggregate.h" + #include "dialog-common.h" -#include -#include #include -#include -#include - -#include "aggregate-dialog.h" +#include "psppire-var-view.h" #include "psppire-selector.h" -#include "psppire-dictview.h" +#include "psppire-acr.h" +#include #include "psppire-dialog.h" +#include "builder-wrapper.h" -#include "psppire-data-window.h" -#include "psppire-var-view.h" -#include "psppire-acr.h" +#include +#include -#include "dict-display.h" -#include "executor.h" -#include "builder-wrapper.h" -#include "helper.h" +#include -#include #include "gettext.h" #define _(msgid) gettext (msgid) #define N_(msgid) msgid -enum - { - COMBO_MODEL_COL_DESC = 0, - COMBO_MODEL_COL_SYNTAX, - COMBO_MODEL_COL_SRC_VARS, - COMBO_MODEL_COL_ARITY - }; +static void psppire_dialog_action_aggregate_init (PsppireDialogActionAggregate *act); +static void psppire_dialog_action_aggregate_class_init (PsppireDialogActionAggregateClass *class); -struct aggregate +G_DEFINE_TYPE (PsppireDialogActionAggregate, psppire_dialog_action_aggregate, PSPPIRE_TYPE_DIALOG_ACTION); + +static void append_summary_spec (const PsppireDialogActionAggregate *agg, GtkTreeIter *iter, GString *string); + +static void +append_summary_variable_syntax (const PsppireDialogActionAggregate *agg, GString *string) { - GtkBuilder *xml; - PsppireDataWindow *de ; - PsppireDict *dict; - GtkWidget *break_variables; + GtkTreeIter iter; + GtkTreeModel *acr_model = GTK_TREE_MODEL (PSPPIRE_ACR (agg->summary_acr)->list_store); - GtkWidget *replace_radiobutton; - GtkWidget *add_radiobutton; - GtkWidget *filename_radiobutton; - GtkWidget *filename_button; - GtkWidget *filename_box; - GtkWidget *filename_label; - GtkWidget *function_combo; + gboolean ok; - GtkWidget *summary_acr; - GtkWidget *summary_var_name_entry; - GtkWidget *summary_var_label_entry; + for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (acr_model), &iter); + ok ; + ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (acr_model), &iter) + ) + { + g_string_append (string, "\n\t/"); - GtkWidget *summary_sv; - GtkWidget *summary_sv_entry; + append_summary_spec (agg, &iter, string); + } +} - GtkWidget *summary_arg1; - GtkWidget *summary_arg2; +static void +append_destination_filename (const PsppireDialogActionAggregate *agg, GString *gs) +{ + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (agg->filename_radiobutton))) + { + struct string ss; + const gchar *s = gtk_label_get_text (GTK_LABEL (agg->filename_label)); + ds_init_empty (&ss); + syntax_gen_string (&ss, ss_cstr (s)); + g_string_append (gs, ds_cstr (&ss)); + ds_destroy (&ss); + } + else + { + g_string_append (gs, "* "); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (agg->replace_radiobutton))) + g_string_append (gs, "MODE=REPLACE"); + else + g_string_append (gs, "MODE=ADDVARIABLES"); + } +} + + +static char * +generate_syntax (PsppireDialogAction *act) +{ + PsppireDialogActionAggregate *agg = PSPPIRE_DIALOG_ACTION_AGGREGATE (act); + + gchar *text; + + GString *string = g_string_new ("AGGREGATE OUTFILE="); + + append_destination_filename (agg, string); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (agg->sorted_button))) + g_string_append (string, "\n\t/PRESORTED"); + + g_string_append (string, "\n\t/BREAK="); - GtkWidget *summary_arg1_entry; - GtkWidget *summary_arg2_entry; + psppire_var_view_append_names (PSPPIRE_VAR_VIEW (agg->break_variables), 0, string); + + append_summary_variable_syntax (agg, string); + + g_string_append (string, ".\n"); + + text = string->str; + + g_string_free (string, FALSE); + + return text; +} - GtkWidget *sorted_button; - GtkWidget *needs_sort_button; - GtkWidget *pane; -}; +static gboolean +dialog_state_valid (gpointer user_data) +{ + PsppireDialogActionAggregate *agg = user_data; + GtkTreeIter iter; + GtkTreeModel *liststore = + gtk_tree_view_get_model (GTK_TREE_VIEW (agg->break_variables)); + if ( ! gtk_tree_model_get_iter_first (liststore, &iter)) + return FALSE; -static char * generate_syntax (const struct aggregate *rd); + liststore = GTK_TREE_MODEL (PSPPIRE_ACR (agg->summary_acr)->list_store); + + if ( ! gtk_tree_model_get_iter_first (liststore, &iter)) + return FALSE; + return TRUE; +} -static void update_arguments (struct aggregate *agg); +static void update_arguments (PsppireDialogActionAggregate *agg); static void -refresh (struct aggregate *agg) +refresh (PsppireDialogAction *fd_) { + PsppireDialogActionAggregate *agg = PSPPIRE_DIALOG_ACTION_AGGREGATE (fd_); + GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (agg->break_variables)); gtk_list_store_clear (GTK_LIST_STORE (liststore)); @@ -125,35 +175,43 @@ refresh (struct aggregate *agg) update_arguments (agg); } +enum + { + COMBO_MODEL_COL_DESC = 0, + COMBO_MODEL_COL_SYNTAX, + COMBO_MODEL_COL_SRC_VARS, + COMBO_MODEL_COL_ARITY + }; -static gboolean -dialog_state_valid (gpointer data) -{ - GtkTreeIter iter; - const struct aggregate *agg = data; - GtkTreeModel *liststore = - gtk_tree_view_get_model (GTK_TREE_VIEW (agg->break_variables)); - if ( ! gtk_tree_model_get_iter_first (liststore, &iter)) - return FALSE; - liststore = GTK_TREE_MODEL (PSPPIRE_ACR (agg->summary_acr)->list_store); +static void +render_summary (GtkTreeViewColumn *tree_column, + GtkCellRenderer *cell, + GtkTreeModel *tree_model, + GtkTreeIter *iter, + gpointer data) +{ + PsppireDialogActionAggregate *agg = data; - if ( ! gtk_tree_model_get_iter_first (liststore, &iter)) - return FALSE; + GString *string = g_string_new (""); - return TRUE; -} + append_summary_spec (agg, iter, string); + + + g_object_set (cell, "text", string->str, NULL); + g_string_free (string, TRUE); +} static void -choose_filename (struct aggregate *fd) +choose_filename (PsppireDialogActionAggregate *fd) { GtkFileFilter *filter; GtkWidget *dialog = gtk_file_chooser_dialog_new (_("Aggregate destination file"), - GTK_WINDOW (fd->de), + GTK_WINDOW (PSPPIRE_DIALOG_ACTION (fd)->toplevel), GTK_FILE_CHOOSER_ACTION_SAVE, _("Cancel"), GTK_RESPONSE_CANCEL, _("Save"), GTK_RESPONSE_ACCEPT, @@ -229,11 +287,66 @@ populate_combo_model (GtkComboBox *cb) } +enum + { + SUMMARY_COL_VARNAME = 0, + SUMMARY_COL_VARLABEL, + SUMMARY_COL_FUNCIDX, + SUMMARY_COL_SRCVAR, + SUMMARY_COL_ARG1, + SUMMARY_COL_ARG2 + }; + +/* Set VAL to the value appropriate for COL according to the + current state of the dialog */ +static gboolean +get_summary_spec (gint col, GValue *val, gpointer data) +{ + PsppireDialogActionAggregate *agg = PSPPIRE_DIALOG_ACTION_AGGREGATE (data); + switch (col) + { + case SUMMARY_COL_VARNAME: + g_value_init (val, G_TYPE_STRING); + g_value_set_string (val, gtk_entry_get_text (GTK_ENTRY (agg->summary_var_name_entry))); + break; + case SUMMARY_COL_VARLABEL: + g_value_init (val, G_TYPE_STRING); + g_value_set_string (val, gtk_entry_get_text (GTK_ENTRY (agg->summary_var_label_entry))); + break; + case SUMMARY_COL_SRCVAR: + g_value_init (val, G_TYPE_STRING); + g_value_set_string (val, gtk_entry_get_text (GTK_ENTRY (agg->summary_sv_entry))); + break; + case SUMMARY_COL_FUNCIDX: + g_value_init (val, G_TYPE_INT); + g_value_set_int (val, gtk_combo_box_get_active (GTK_COMBO_BOX (agg->function_combo))); + break; + case SUMMARY_COL_ARG1: + { + const gchar *text = gtk_entry_get_text (GTK_ENTRY (agg->summary_arg1_entry)); + g_value_init (val, G_TYPE_DOUBLE); + g_value_set_double (val, g_strtod (text, 0)); + } + break; + case SUMMARY_COL_ARG2: + { + const gchar *text = gtk_entry_get_text (GTK_ENTRY (agg->summary_arg2_entry)); + g_value_init (val, G_TYPE_DOUBLE); + g_value_set_double (val, g_strtod (text, 0)); + } + break; + default: + g_assert_not_reached (); + break; + } + + return TRUE; +} /* Returns TRUE iff all the necessary controls have been set to completely specify a summary function */ static gboolean -summary_complete (const struct aggregate *agg) +summary_complete (const PsppireDialogActionAggregate *agg) { GtkTreeIter iter; int n_args; @@ -280,43 +393,65 @@ summary_complete (const struct aggregate *agg) } -static void -append_summary_spec (const struct aggregate *agg, GtkTreeIter *iter, GString *string); - +/* Enable/Disable the summary variable ACR */ static void -render_summary (GtkTreeViewColumn *tree_column, - GtkCellRenderer *cell, - GtkTreeModel *tree_model, - GtkTreeIter *iter, - gpointer data) +update_acr (PsppireDialogActionAggregate *agg) { - struct aggregate *agg = data; - - GString *string = g_string_new (""); - - append_summary_spec (agg, iter, string); - - - g_object_set (cell, "text", string->str, NULL); + gboolean ready = summary_complete (agg); - g_string_free (string, TRUE); + psppire_acr_set_enabled (PSPPIRE_ACR (agg->summary_acr), ready); } -/* Enable/Disable the summary variable ACR */ -static void -update_acr (struct aggregate *agg) +/* Update the status of the dialog box according to what row of the ACR's treeview + is selected */ +static void +on_acr_change (const PsppireDialogActionAggregate *agg, GtkTreeView *tv) { - gboolean ready = summary_complete (agg); + const gchar *varname = ""; + const gchar *label = ""; + const gchar *srcvar = ""; + gint f_idx = 0; + double arg1, arg2; + gchar *text1 = g_strdup (""); + gchar *text2 = g_strdup (""); + + GtkTreeIter iter; + GtkTreeModel *model = gtk_tree_view_get_model (tv); + GtkTreeSelection *sel = gtk_tree_view_get_selection (tv); - psppire_acr_set_enabled (PSPPIRE_ACR (agg->summary_acr), ready); + if (gtk_tree_selection_get_selected (sel, &model, &iter)) + { + gtk_tree_model_get (model, &iter, + SUMMARY_COL_VARNAME, &varname, + SUMMARY_COL_VARLABEL, &label, + SUMMARY_COL_FUNCIDX, &f_idx, + SUMMARY_COL_SRCVAR, &srcvar, + SUMMARY_COL_ARG1, &arg1, + SUMMARY_COL_ARG2, &arg2, -1); + + gtk_entry_set_text (GTK_ENTRY (agg->summary_var_name_entry), varname); + gtk_entry_set_text (GTK_ENTRY (agg->summary_var_label_entry), label); + gtk_entry_set_text (GTK_ENTRY (agg->summary_sv_entry), srcvar); + + text1 = c_xasprintf ("%.*g", DBL_DIG + 1, arg1); + text2 = c_xasprintf ("%.*g", DBL_DIG + 1, arg2); + } + + gtk_entry_set_text (GTK_ENTRY (agg->summary_arg1_entry), text1); + g_free (text1); + + gtk_entry_set_text (GTK_ENTRY (agg->summary_arg2_entry), text2); + g_free (text2); + + gtk_combo_box_set_active (GTK_COMBO_BOX (agg->function_combo), f_idx); } /* Update the sensitivity of the summary variable argument fields */ static void -update_arguments (struct aggregate *agg) +update_arguments (PsppireDialogActionAggregate *agg) { GtkTreeIter iter; @@ -345,273 +480,141 @@ update_arguments (struct aggregate *agg) } } -enum - { - SUMMARY_COL_VARNAME = 0, - SUMMARY_COL_VARLABEL, - SUMMARY_COL_FUNCIDX, - SUMMARY_COL_SRCVAR, - SUMMARY_COL_ARG1, - SUMMARY_COL_ARG2 - }; - -/* Set VAL to the value appropriate for COL according to the - current state of the dialog */ -static gboolean -get_summary_spec (gint col, GValue *val, gpointer data) -{ - const struct aggregate *agg = data; - switch (col) - { - case SUMMARY_COL_VARNAME: - g_value_init (val, G_TYPE_STRING); - g_value_set_string (val, gtk_entry_get_text (GTK_ENTRY (agg->summary_var_name_entry))); - break; - case SUMMARY_COL_VARLABEL: - g_value_init (val, G_TYPE_STRING); - g_value_set_string (val, gtk_entry_get_text (GTK_ENTRY (agg->summary_var_label_entry))); - break; - case SUMMARY_COL_SRCVAR: - g_value_init (val, G_TYPE_STRING); - g_value_set_string (val, gtk_entry_get_text (GTK_ENTRY (agg->summary_sv_entry))); - break; - case SUMMARY_COL_FUNCIDX: - g_value_init (val, G_TYPE_INT); - g_value_set_int (val, gtk_combo_box_get_active (GTK_COMBO_BOX (agg->function_combo))); - break; - case SUMMARY_COL_ARG1: - { - const gchar *text = gtk_entry_get_text (GTK_ENTRY (agg->summary_arg1_entry)); - g_value_init (val, G_TYPE_DOUBLE); - g_value_set_double (val, g_strtod (text, 0)); - } - break; - case SUMMARY_COL_ARG2: - { - const gchar *text = gtk_entry_get_text (GTK_ENTRY (agg->summary_arg2_entry)); - g_value_init (val, G_TYPE_DOUBLE); - g_value_set_double (val, g_strtod (text, 0)); - } - break; - default: - g_assert_not_reached (); - break; - } - - return TRUE; -} -/* Update the status of the dialog box according to what row of the ACR's treeview - is selected */ -static void -on_acr_change (const struct aggregate *agg, GtkTreeView *tv) +static void +psppire_dialog_action_aggregate_activate (GtkAction *a) { - const gchar *varname; - const gchar *label; - const gchar *srcvar; - gint f_idx; - double arg1, arg2; - gchar *text = NULL; - - GtkTreeIter iter; - GtkTreePath *path = NULL; - GtkTreeModel *model = gtk_tree_view_get_model (tv); - gtk_tree_view_get_cursor (tv, &path, NULL); - - gtk_tree_model_get_iter (model, &iter, path); - - gtk_tree_model_get (model, &iter, - SUMMARY_COL_VARNAME, &varname, - SUMMARY_COL_VARLABEL, &label, - SUMMARY_COL_FUNCIDX, &f_idx, - SUMMARY_COL_SRCVAR, &srcvar, - SUMMARY_COL_ARG1, &arg1, - SUMMARY_COL_ARG2, &arg2, - -1); - - gtk_entry_set_text (GTK_ENTRY (agg->summary_var_name_entry), varname); - gtk_entry_set_text (GTK_ENTRY (agg->summary_var_label_entry), label); - gtk_entry_set_text (GTK_ENTRY (agg->summary_sv_entry), srcvar); - - text = c_xasprintf ("%.*g", DBL_DIG + 1, arg1); - gtk_entry_set_text (GTK_ENTRY (agg->summary_arg1_entry), text); - g_free (text); + PsppireDialogActionAggregate *act = PSPPIRE_DIALOG_ACTION_AGGREGATE (a); + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); - text = c_xasprintf ("%.*g", DBL_DIG + 1, arg2); - gtk_entry_set_text (GTK_ENTRY (agg->summary_arg2_entry), text); - g_free (text); - - gtk_combo_box_set_active (GTK_COMBO_BOX (agg->function_combo), f_idx); -} - - -/* Pops up the Aggregate dialog box */ -void -aggregate_dialog (PsppireDataWindow *dw) -{ - struct aggregate fd; - gint response; + GHashTable *thing = psppire_dialog_action_get_hash_table (pda); + GtkBuilder *xml = g_hash_table_lookup (thing, a); + if (!xml) + { + xml = builder_new ("aggregate.ui"); + g_hash_table_insert (thing, a, xml); - GtkWidget *dialog ; - GtkWidget *source ; - GtkWidget *break_selector ; + pda->dialog = get_widget_assert (xml, "aggregate-dialog"); + pda->source = get_widget_assert (xml, "dict-view"); - fd.xml = builder_new ("aggregate.ui"); - fd.de = dw; - dialog = get_widget_assert (fd.xml, "psppire-dialog1"); - source = get_widget_assert (fd.xml, "dict-view"); - break_selector = get_widget_assert (fd.xml, "break-selector"); + GtkWidget *break_selector = get_widget_assert (xml, "break-selector"); - fd.pane = get_widget_assert (fd.xml, "hbox1"); + act->pane = get_widget_assert (xml, "hbox1"); - fd.break_variables = get_widget_assert (fd.xml, "psppire-var-view1"); - fd.filename_radiobutton = get_widget_assert (fd.xml, "filename-radiobutton"); - fd.filename_button = get_widget_assert (fd.xml, "filename-button"); - fd.filename_box = get_widget_assert (fd.xml, "filename-box"); - fd.filename_label = get_widget_assert (fd.xml, "filename-label"); - fd.replace_radiobutton = get_widget_assert (fd.xml, "replace-radiobutton"); - fd.add_radiobutton = get_widget_assert (fd.xml, "add-radiobutton"); - fd.function_combo = get_widget_assert (fd.xml, "function-combo"); + act->break_variables = get_widget_assert (xml, "psppire-var-view1"); + act->filename_radiobutton = get_widget_assert (xml, "filename-radiobutton"); + act->filename_button = get_widget_assert (xml, "filename-button"); + act->filename_box = get_widget_assert (xml, "filename-box"); + act->filename_label = get_widget_assert (xml, "filename-label"); + act->replace_radiobutton = get_widget_assert (xml, "replace-radiobutton"); + act->add_radiobutton = get_widget_assert (xml, "add-radiobutton"); + act->function_combo = get_widget_assert (xml, "function-combo"); - fd.summary_acr = get_widget_assert (fd.xml, "psppire-acr1"); - fd.summary_var_name_entry = get_widget_assert (fd.xml, "summary-var-name-entry"); + act->summary_acr = get_widget_assert (xml, "psppire-acr1"); + act->summary_var_name_entry = get_widget_assert (xml, "summary-var-name-entry"); - fd.summary_arg1 = get_widget_assert (fd.xml, "summary-arg1"); - fd.summary_arg2 = get_widget_assert (fd.xml, "summary-arg2"); + act->summary_arg1 = get_widget_assert (xml, "summary-arg1"); + act->summary_arg2 = get_widget_assert (xml, "summary-arg2"); - fd.summary_arg1_entry = get_widget_assert (fd.xml, "summary-arg-entry1"); - fd.summary_arg2_entry = get_widget_assert (fd.xml, "summary-arg-entry2"); + act->summary_arg1_entry = get_widget_assert (xml, "summary-arg-entry1"); + act->summary_arg2_entry = get_widget_assert (xml, "summary-arg-entry2"); - fd.summary_var_label_entry = get_widget_assert (fd.xml, "summary-var-label-entry"); + act->summary_var_label_entry = get_widget_assert (xml, "summary-var-label-entry"); - fd.summary_sv = get_widget_assert (fd.xml, "source-var"); - fd.summary_sv_entry = get_widget_assert (fd.xml, "source-var-entry"); + act->summary_sv = get_widget_assert (xml, "source-var"); + act->summary_sv_entry = get_widget_assert (xml, "source-var-entry"); - fd.sorted_button = get_widget_assert (fd.xml, "sorted-radiobutton"); - fd.needs_sort_button = get_widget_assert (fd.xml, "needs-sort-radiobutton"); + act->sorted_button = get_widget_assert (xml, "sorted-radiobutton"); + act->needs_sort_button = get_widget_assert (xml, "needs-sort-radiobutton"); - { - GtkTreeViewColumn *column ; + { + GtkTreeViewColumn *column ; - GList *l ; + GList *l ; - GtkCellRenderer *cell_renderer ; + GtkCellRenderer *cell_renderer ; - GtkListStore *list = gtk_list_store_new (6, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_INT, - G_TYPE_STRING, - G_TYPE_DOUBLE, - G_TYPE_DOUBLE); + GtkListStore *list = gtk_list_store_new (6, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_INT, + G_TYPE_STRING, + G_TYPE_DOUBLE, + G_TYPE_DOUBLE); - psppire_acr_set_model (PSPPIRE_ACR (fd.summary_acr), list); - g_object_unref (list); + psppire_acr_set_model (PSPPIRE_ACR (act->summary_acr), list); + g_object_unref (list); - psppire_acr_set_get_value_func (PSPPIRE_ACR (fd.summary_acr), - get_summary_spec, &fd); + psppire_acr_set_get_value_func (PSPPIRE_ACR (act->summary_acr), + get_summary_spec, act); - column = gtk_tree_view_get_column (PSPPIRE_ACR (fd.summary_acr)->tv, 0); + column = gtk_tree_view_get_column (PSPPIRE_ACR (act->summary_acr)->tv, 0); - l = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column)); + l = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column)); - cell_renderer = l->data; + cell_renderer = l->data; - gtk_tree_view_column_set_cell_data_func (column, - cell_renderer, - render_summary, - &fd, - NULL); + gtk_tree_view_column_set_cell_data_func (column, + cell_renderer, + render_summary, + act, + NULL); - g_signal_connect_swapped (PSPPIRE_ACR (fd.summary_acr)->tv, - "cursor-changed", G_CALLBACK (on_acr_change), &fd); - } + g_signal_connect_swapped (PSPPIRE_ACR (act->summary_acr)->tv, + "cursor-changed", G_CALLBACK (on_acr_change), act); + } - g_signal_connect_swapped (fd.summary_var_name_entry, "changed", G_CALLBACK (update_acr), &fd); - g_signal_connect_swapped (fd.function_combo, "changed", G_CALLBACK (update_acr), &fd); - g_signal_connect_swapped (fd.summary_sv_entry, "changed", G_CALLBACK (update_acr), &fd); - g_signal_connect_swapped (fd.summary_arg1_entry, "changed", G_CALLBACK (update_acr), &fd); - g_signal_connect_swapped (fd.summary_arg2_entry, "changed", G_CALLBACK (update_acr), &fd); - - - - - g_signal_connect_swapped (fd.function_combo, "changed", - G_CALLBACK (update_arguments), &fd); - - populate_combo_model (GTK_COMBO_BOX (fd.function_combo)); + g_signal_connect_swapped (act->summary_var_name_entry, "changed", G_CALLBACK (update_acr), act); + g_signal_connect_swapped (act->function_combo, "changed", G_CALLBACK (update_acr), act); + g_signal_connect_swapped (act->summary_sv_entry, "changed", G_CALLBACK (update_acr), act); + g_signal_connect_swapped (act->summary_arg1_entry, "changed", G_CALLBACK (update_acr), act); + g_signal_connect_swapped (act->summary_arg2_entry, "changed", G_CALLBACK (update_acr), act); - g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &fd); - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (fd.de)); + g_signal_connect_swapped (act->function_combo, "changed", + G_CALLBACK (update_arguments), act); - g_object_get (fd.de->data_editor, "dictionary", &fd.dict, NULL); - g_object_set (source, "model", fd.dict, NULL); + populate_combo_model (GTK_COMBO_BOX (act->function_combo)); - psppire_selector_set_filter_func (PSPPIRE_SELECTOR (break_selector), NULL); + psppire_selector_set_filter_func (PSPPIRE_SELECTOR (break_selector), NULL); - psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), - dialog_state_valid, &fd); + g_signal_connect (act->filename_radiobutton, "toggled", + G_CALLBACK (set_sensitivity_from_toggle), act->filename_box ); - g_signal_connect (fd.filename_radiobutton, "toggled", - G_CALLBACK (set_sensitivity_from_toggle), fd.filename_box ); + g_signal_connect_swapped (act->filename_button, "clicked", + G_CALLBACK (choose_filename), act); - g_signal_connect_swapped (fd.filename_button, "clicked", - G_CALLBACK (choose_filename), &fd); - - - response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); - - 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; + psppire_dialog_action_set_refresh (pda, refresh); + psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid); } - g_object_unref (fd.xml); + if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_aggregate_parent_class)->activate) + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_aggregate_parent_class)->activate (pda); } +static void +psppire_dialog_action_aggregate_class_init (PsppireDialogActionAggregateClass *class) +{ + psppire_dialog_action_set_activation (class, psppire_dialog_action_aggregate_activate); + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; +} - static void -append_destination_filename (const struct aggregate *agg, GString *gs) +psppire_dialog_action_aggregate_init (PsppireDialogActionAggregate *act) { - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (agg->filename_radiobutton))) - { - struct string ss; - const gchar *s = gtk_label_get_text (GTK_LABEL (agg->filename_label)); - ds_init_empty (&ss); - syntax_gen_string (&ss, ss_cstr (s)); - g_string_append (gs, ds_cstr (&ss)); - ds_destroy (&ss); - } - else - { - g_string_append (gs, "* "); - - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (agg->replace_radiobutton))) - g_string_append (gs, "MODE=REPLACE"); - else - g_string_append (gs, "MODE=ADDVARIABLES"); - } } + /* Append the syntax of the summary function pointed to by ITER to STRING */ static void -append_summary_spec (const struct aggregate *agg, GtkTreeIter *iter, GString *string) +append_summary_spec (const PsppireDialogActionAggregate *agg, GtkTreeIter *iter, GString *string) { GtkTreeIter combo_iter; char *varname = NULL; @@ -685,53 +688,3 @@ append_summary_spec (const struct aggregate *agg, GtkTreeIter *iter, GString *st free (varname); free (funcname); } - - - -static void -append_summary_variable_syntax (const struct aggregate *agg, GString *string) -{ - GtkTreeIter iter; - GtkTreeModel *acr_model = GTK_TREE_MODEL (PSPPIRE_ACR (agg->summary_acr)->list_store); - - - gboolean ok; - - for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (acr_model), &iter); - ok ; - ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (acr_model), &iter) - ) - { - g_string_append (string, "\n\t/"); - - append_summary_spec (agg, &iter, string); - } -} - - -static char * -generate_syntax (const struct aggregate *agg) -{ - gchar *text; - - GString *string = g_string_new ("AGGREGATE OUTFILE="); - - append_destination_filename (agg, string); - - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (agg->sorted_button))) - g_string_append (string, "\n\t/PRESORTED"); - - g_string_append (string, "\n\t/BREAK="); - - psppire_var_view_append_names (PSPPIRE_VAR_VIEW (agg->break_variables), 0, string); - - append_summary_variable_syntax (agg, string); - - g_string_append (string, ".\n"); - - text = string->str; - - g_string_free (string, FALSE); - - return text; -} diff --git a/src/ui/gui/psppire-dialog-action-aggregate.h b/src/ui/gui/psppire-dialog-action-aggregate.h new file mode 100644 index 0000000000..0a60954cd9 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-aggregate.h @@ -0,0 +1,104 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2015 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_AGGREGATE_H__ +#define __PSPPIRE_DIALOG_ACTION_AGGREGATE_H__ + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_AGGREGATE (psppire_dialog_action_aggregate_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_AGGREGATE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_AGGREGATE, PsppireDialogActionAggregate)) + +#define PSPPIRE_DIALOG_ACTION_AGGREGATE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_AGGREGATE, \ + PsppireDialogActionAggregateClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_AGGREGATE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_AGGREGATE)) + +#define PSPPIRE_IS_DIALOG_ACTION_AGGREGATE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_AGGREGATE)) + + +#define PSPPIRE_DIALOG_ACTION_AGGREGATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_AGGREGATE, \ + PsppireDialogActionAggregateClass)) + +typedef struct _PsppireDialogActionAggregate PsppireDialogActionAggregate; +typedef struct _PsppireDialogActionAggregateClass PsppireDialogActionAggregateClass; + + +struct _PsppireDialogActionAggregate +{ + PsppireDialogAction parent; + + /*< private >*/ + gboolean dispose_has_run ; + + GtkWidget *break_variables; + + GtkWidget *replace_radiobutton; + GtkWidget *add_radiobutton; + GtkWidget *filename_radiobutton; + GtkWidget *filename_button; + GtkWidget *filename_box; + GtkWidget *filename_label; + + GtkWidget *function_combo; + + GtkWidget *summary_acr; + GtkWidget *summary_var_name_entry; + GtkWidget *summary_var_label_entry; + + GtkWidget *summary_sv; + GtkWidget *summary_sv_entry; + + GtkWidget *summary_arg1; + GtkWidget *summary_arg2; + + GtkWidget *summary_arg1_entry; + GtkWidget *summary_arg2_entry; + + GtkWidget *sorted_button; + GtkWidget *needs_sort_button; + + GtkWidget *pane; +}; + + +struct _PsppireDialogActionAggregateClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_aggregate_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_AGGREGATE_H__ */ diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index 71c472d548..485f28be7a 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -16,6 +16,7 @@ #include "psppire-val-chooser.h" #include "psppire-checkbox-treeview.h" +#include "psppire-dialog-action-aggregate.h" #include "psppire-dialog-action-barchart.h" #include "psppire-dialog-action-binomial.h" #include "psppire-dialog-action-chisquare.h" @@ -72,6 +73,7 @@ preregister_widgets (void) psppire_checkbox_treeview_get_type (); psppire_dialog_action_1sks_get_type (); + psppire_dialog_action_aggregate_get_type (); psppire_dialog_action_binomial_get_type (); psppire_dialog_action_barchart_get_type (); psppire_dialog_action_chisquare_get_type (); -- 2.30.2