From 53508ccb5785dfcad8080d9dcdacdf3b7af5be76 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Wed, 25 Jan 2012 21:02:18 +0100 Subject: [PATCH] New abstract class PsppireDialogAction Added a new object PsppireDialogAction which abstracts the behaviour of dialog boxes. Converted the Descriptived Dialog and the Variable Info Dialog to use this new abstraction. Reviewed-by: Ben Pfaff --- src/ui/gui/automake.mk | 10 +- src/ui/gui/data-editor.ui | 6 +- src/ui/gui/descriptives-dialog.h | 24 --- src/ui/gui/psppire-data-window.c | 7 - ...c => psppire-dialog-action-descriptives.c} | 152 ++++++-------- .../gui/psppire-dialog-action-descriptives.h | 83 ++++++++ ...log.c => psppire-dialog-action-var-info.c} | 156 ++++++++------- src/ui/gui/psppire-dialog-action-var-info.h | 78 ++++++++ src/ui/gui/psppire-dialog-action.c | 188 ++++++++++++++++++ src/ui/gui/psppire-dialog-action.h | 101 ++++++++++ src/ui/gui/psppire-dialog.c | 15 ++ src/ui/gui/variable-info-dialog.h | 24 --- src/ui/gui/widgets.c | 6 + 13 files changed, 624 insertions(+), 226 deletions(-) delete mode 100644 src/ui/gui/descriptives-dialog.h rename src/ui/gui/{descriptives-dialog.c => psppire-dialog-action-descriptives.c} (70%) create mode 100644 src/ui/gui/psppire-dialog-action-descriptives.h rename src/ui/gui/{variable-info-dialog.c => psppire-dialog-action-var-info.c} (63%) create mode 100644 src/ui/gui/psppire-dialog-action-var-info.h create mode 100644 src/ui/gui/psppire-dialog-action.c create mode 100644 src/ui/gui/psppire-dialog-action.h delete mode 100644 src/ui/gui/variable-info-dialog.h diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index d64d6df8..477010e7 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -162,8 +162,6 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/crosstabs-dialog.h \ src/ui/gui/customentry.c \ src/ui/gui/customentry.h \ - src/ui/gui/descriptives-dialog.c \ - src/ui/gui/descriptives-dialog.h \ src/ui/gui/dialog-common.c \ src/ui/gui/dialog-common.h \ src/ui/gui/dict-display.h \ @@ -212,6 +210,12 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-data-window.c \ src/ui/gui/psppire-data-window.h \ 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-descriptives.c \ + src/ui/gui/psppire-dialog-action-descriptives.h \ + src/ui/gui/psppire-dialog-action-var-info.c \ + src/ui/gui/psppire-dialog-action-var-info.h \ src/ui/gui/psppire-dict.c \ src/ui/gui/psppire-dict.h \ src/ui/gui/psppire-dictview.c \ @@ -282,8 +286,6 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/val-labs-dialog.h \ src/ui/gui/var-display.c \ src/ui/gui/var-display.h \ - src/ui/gui/variable-info-dialog.c \ - src/ui/gui/variable-info-dialog.h \ src/ui/gui/var-type-dialog.c \ src/ui/gui/var-type-dialog.h \ src/ui/gui/weight-cases-dialog.c \ diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index fcfc8c20..d190a44c 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -350,7 +350,8 @@ - + + uimanager1 analyze_descriptives _Descriptives... @@ -489,7 +490,8 @@ - + + uimanager1 utilities_variables _Variables... Jump to variable diff --git a/src/ui/gui/descriptives-dialog.h b/src/ui/gui/descriptives-dialog.h deleted file mode 100644 index 18195761..00000000 --- a/src/ui/gui/descriptives-dialog.h +++ /dev/null @@ -1,24 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007, 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 __DESCRIPTIVES_DIALOG_H -#define __DESCRIPTIVES_DIALOG_H - -#include "psppire-data-window.h" - -void descriptives_dialog (PsppireDataWindow * data); - -#endif diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index b2607a0c..7d585404 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -34,7 +34,6 @@ #include "ui/gui/correlation-dialog.h" #include "ui/gui/count-dialog.h" #include "ui/gui/crosstabs-dialog.h" -#include "ui/gui/descriptives-dialog.h" #include "ui/gui/entry-dialog.h" #include "ui/gui/examine-dialog.h" #include "ui/gui/executor.h" @@ -69,7 +68,6 @@ #include "ui/gui/text-data-import-dialog.h" #include "ui/gui/transpose-dialog.h" #include "ui/gui/univariate-dialog.h" -#include "ui/gui/variable-info-dialog.h" #include "ui/gui/weight-cases-dialog.h" #include "ui/syntax-gen.h" @@ -1084,9 +1082,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "data_weight-cases", G_CALLBACK (weight_cases_dialog)); - - connect_action (de, "utilities_variables", G_CALLBACK (variable_info_dialog)); - connect_action (de, "oneway-anova", G_CALLBACK (oneway_anova_dialog)); connect_action (de, "indep-t-test", G_CALLBACK (t_test_independent_samples_dialog)); @@ -1105,8 +1100,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog)); - connect_action (de, "analyze_descriptives", G_CALLBACK (descriptives_dialog)); - connect_action (de, "analyze_frequencies", G_CALLBACK (frequencies_dialog)); connect_action (de, "crosstabs", G_CALLBACK (crosstabs_dialog)); diff --git a/src/ui/gui/descriptives-dialog.c b/src/ui/gui/psppire-dialog-action-descriptives.c similarity index 70% rename from src/ui/gui/descriptives-dialog.c rename to src/ui/gui/psppire-dialog-action-descriptives.c index 670f14ba..170604c9 100644 --- a/src/ui/gui/descriptives-dialog.c +++ b/src/ui/gui/psppire-dialog-action-descriptives.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007, 2010, 2011, 2012 Free Software Foundation + Copyright (C) 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 @@ -14,28 +14,27 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ + #include -#include "checkbox-treeview.h" -#include "descriptives-dialog.h" -#include "psppire-var-view.h" +#include "psppire-dialog-action-descriptives.h" -#include -#include +#include "checkbox-treeview.h" -#include -#include -#include -#include -#include -#include -#include "executor.h" -#include "helper.h" +#include "psppire-var-view.h" +#include "psppire-dict.h" +#include "psppire-dialog.h" +#include "builder-wrapper.h" #include "gettext.h" #define _(msgid) gettext (msgid) #define N_(msgid) msgid +static void psppire_dialog_action_descriptives_class_init (PsppireDialogActionDescriptivesClass *class); + +G_DEFINE_TYPE (PsppireDialogActionDescriptives, psppire_dialog_action_descriptives, PSPPIRE_TYPE_DIALOG_ACTION); + + #define DESCRIPTIVE_STATS \ DS (MEAN, N_("Mean")) \ DS (STDDEV, N_("Standard deviation")) \ @@ -73,41 +72,11 @@ static const struct checkbox_entry_item stats[] = #undef DS }; -struct descriptives_dialog -{ - GtkTreeView *stat_vars; - GtkTreeModel *stats; - PsppireDict *dict; - GtkToggleButton *exclude_missing_listwise; - GtkToggleButton *include_user_missing; - GtkToggleButton *save_z_scores; -}; - -static void -refresh (PsppireDialog *dialog, struct descriptives_dialog *scd) -{ - GtkTreeModel *liststore; - GtkTreeIter iter; - size_t i; - bool ok; - - liststore = gtk_tree_view_get_model (scd->stat_vars); - gtk_list_store_clear (GTK_LIST_STORE (liststore)); - - for (i = 0, ok = gtk_tree_model_get_iter_first (scd->stats, &iter); ok; - i++, ok = gtk_tree_model_iter_next (scd->stats, &iter)) - gtk_list_store_set (GTK_LIST_STORE (scd->stats), &iter, - CHECKBOX_COLUMN_SELECTED, - (B_DS_DEFAULT & (1u << i)) ? true : false, -1); - - gtk_toggle_button_set_active (scd->exclude_missing_listwise, false); - gtk_toggle_button_set_active (scd->include_user_missing, false); - gtk_toggle_button_set_active (scd->save_z_scores, false); -} static char * -generate_syntax (const struct descriptives_dialog *scd) +generate_syntax (PsppireDialogAction *act) { + PsppireDialogActionDescriptives *scd = PSPPIRE_DIALOG_ACTION_DESCRIPTIVES (act); gchar *text; GString *string; GtkTreeIter iter; @@ -187,12 +156,10 @@ generate_syntax (const struct descriptives_dialog *scd) return text; } - -/* Dialog is valid iff at least one variable has been selected */ static gboolean dialog_state_valid (gpointer data) { - struct descriptives_dialog *dd = data; + PsppireDialogActionDescriptives *dd = data; GtkTreeModel *vars = gtk_tree_view_get_model (dd->stat_vars); @@ -201,71 +168,74 @@ dialog_state_valid (gpointer data) return gtk_tree_model_get_iter_first (vars, ¬used); } -/* Pops up the Descriptives dialog box */ -void -descriptives_dialog (PsppireDataWindow *de) +static void +dialog_refresh (PsppireDialogActionDescriptives *scd) { - gint response; + GtkTreeModel *liststore; + GtkTreeIter iter; + size_t i; + bool ok; - struct descriptives_dialog scd; + liststore = gtk_tree_view_get_model (scd->stat_vars); + gtk_list_store_clear (GTK_LIST_STORE (liststore)); - GtkBuilder *xml = builder_new ("descriptives.ui"); + for (i = 0, ok = gtk_tree_model_get_iter_first (scd->stats, &iter); ok; + i++, ok = gtk_tree_model_iter_next (scd->stats, &iter)) + gtk_list_store_set (GTK_LIST_STORE (scd->stats), &iter, + CHECKBOX_COLUMN_SELECTED, + (B_DS_DEFAULT & (1u << i)) ? true : false, -1); - GtkWidget *dialog = get_widget_assert (xml, "descriptives-dialog"); + gtk_toggle_button_set_active (scd->exclude_missing_listwise, false); + gtk_toggle_button_set_active (scd->include_user_missing, false); + gtk_toggle_button_set_active (scd->save_z_scores, false); +} +static void +psppire_dialog_action_descriptives_activate (GtkAction *a) +{ + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); + PsppireDialogActionDescriptives *act = PSPPIRE_DIALOG_ACTION_DESCRIPTIVES (a); - GtkWidget *source = get_widget_assert (xml, "all-variables"); - GtkWidget *dest = get_widget_assert (xml, "stat-variables"); + GtkBuilder *xml = builder_new ("descriptives.ui"); GtkWidget *stats_treeview = get_widget_assert (xml, "statistics"); - PsppireVarStore *vs = NULL; - PsppireDict *dict; - - g_object_get (de->data_editor, "var-store", &vs, NULL); - g_object_get (vs, "dictionary", &dict, NULL); + pda->dialog = get_widget_assert (xml, "descriptives-dialog"); + pda->source = get_widget_assert (xml, "all-variables"); + act->variables = get_widget_assert (xml, "stat-variables"); - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - - - g_object_set (source, "model", dict, + g_object_set (pda->source, "model", pda->dict, "predicate", var_is_numeric, NULL); put_checkbox_items_in_treeview (GTK_TREE_VIEW (stats_treeview), B_DS_DEFAULT, N_DESCRIPTIVE_STATS, stats); - scd.stat_vars = GTK_TREE_VIEW (dest); - scd.stats = gtk_tree_view_get_model (GTK_TREE_VIEW (stats_treeview)); + act->stat_vars = GTK_TREE_VIEW (act->variables); + act->stats = gtk_tree_view_get_model (GTK_TREE_VIEW (stats_treeview)); - g_object_get (vs, "dictionary", &scd.dict, NULL); - - scd.include_user_missing = + act->include_user_missing = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "include_user_missing")); - scd.exclude_missing_listwise = + act->exclude_missing_listwise = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "exclude_missing_listwise")); - scd.save_z_scores = + act->save_z_scores = GTK_TOGGLE_BUTTON (get_widget_assert (xml, "save_z_scores")); - g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &scd); - - psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), - dialog_state_valid, &scd); + psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid); + psppire_dialog_action_set_refresh (pda, dialog_refresh); - response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_descriptives_parent_class)->activate (pda); +} +static void +psppire_dialog_action_descriptives_class_init (PsppireDialogActionDescriptivesClass *class) +{ + GTK_ACTION_CLASS (class)->activate = psppire_dialog_action_descriptives_activate; - switch (response) - { - case GTK_RESPONSE_OK: - g_free (execute_syntax_string (de, generate_syntax (&scd))); - break; - case PSPPIRE_RESPONSE_PASTE: - g_free (paste_syntax_to_window (generate_syntax (&scd))); - break; - default: - break; - } + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; +} - g_object_unref (xml); +static void +psppire_dialog_action_descriptives_init (PsppireDialogActionDescriptives *act) +{ } diff --git a/src/ui/gui/psppire-dialog-action-descriptives.h b/src/ui/gui/psppire-dialog-action-descriptives.h new file mode 100644 index 00000000..f39aedb4 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-descriptives.h @@ -0,0 +1,83 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 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 . */ + + +#ifndef __PSPPIRE_DIALOG_ACTION_DESCRIPTIVES_H__ +#define __PSPPIRE_DIALOG_ACTION_DESCRIPTIVES_H__ + +#include +#include + +#include "psppire-dialog-action.h" + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_DESCRIPTIVES (psppire_dialog_action_descriptives_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_DESCRIPTIVES(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_DESCRIPTIVES, PsppireDialogActionDescriptives)) + +#define PSPPIRE_DIALOG_ACTION_DESCRIPTIVES_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_DESCRIPTIVES, \ + PsppireDialogActionDescriptivesClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_DESCRIPTIVES(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_DESCRIPTIVES)) + +#define PSPPIRE_IS_DIALOG_ACTION_DESCRIPTIVES_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_DESCRIPTIVES)) + + +#define PSPPIRE_DIALOG_ACTION_DESCRIPTIVES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_DESCRIPTIVES, \ + PsppireDialogActionDescriptivesClass)) + +typedef struct _PsppireDialogActionDescriptives PsppireDialogActionDescriptives; +typedef struct _PsppireDialogActionDescriptivesClass PsppireDialogActionDescriptivesClass; + + +struct _PsppireDialogActionDescriptives +{ + PsppireDialogAction parent; + + /*< private >*/ + gboolean dispose_has_run ; + + GtkWidget *variables; + GtkTreeView *stat_vars; + GtkTreeModel *stats; + + GtkToggleButton *exclude_missing_listwise; + GtkToggleButton *include_user_missing; + GtkToggleButton *save_z_scores; +}; + + +struct _PsppireDialogActionDescriptivesClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_descriptives_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_DESCRIPTIVES_H__ */ diff --git a/src/ui/gui/variable-info-dialog.c b/src/ui/gui/psppire-dialog-action-var-info.c similarity index 63% rename from src/ui/gui/variable-info-dialog.c rename to src/ui/gui/psppire-dialog-action-var-info.c index 1cd9b1d7..226fc58a 100644 --- a/src/ui/gui/variable-info-dialog.c +++ b/src/ui/gui/psppire-dialog-action-var-info.c @@ -1,6 +1,7 @@ /* PSPPIRE - a graphical user interface for PSPP. Copyright (C) 2007, 2009, 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 @@ -14,25 +15,29 @@ 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-var-info.h" #include #include #include #include -#include "variable-info-dialog.h" #include "var-display.h" +#include "helper.h" +#include "psppire-var-view.h" +#include "psppire-dictview.h" -#include "psppire-data-window.h" #include "psppire-dialog.h" -#include "psppire-dictview.h" -#include "psppire-var-store.h" #include "builder-wrapper.h" -#include "helper.h" +#include "psppire-data-window.h" +static void psppire_dialog_action_var_info_init (PsppireDialogActionVarInfo *act); +static void psppire_dialog_action_var_info_class_init (PsppireDialogActionVarInfoClass *class); +G_DEFINE_TYPE (PsppireDialogActionVarInfo, psppire_dialog_action_var_info, PSPPIRE_TYPE_DIALOG_ACTION); #include #define _(msgid) gettext (msgid) @@ -53,6 +58,36 @@ label_to_string (const struct variable *var) } +static gboolean +treeview_item_selected (gpointer data) +{ + PsppireDialogAction *pda = data; + GtkTreeView *tv = GTK_TREE_VIEW (pda->source); + GtkTreeModel *model = gtk_tree_view_get_model (tv); + + gint n_rows = gtk_tree_model_iter_n_children (model, NULL); + + if ( n_rows == 0 ) + return FALSE; + + return TRUE; +} + +static gchar * +generate_syntax (PsppireDialogAction *act) + +{ + const struct variable *var = + psppire_dict_view_get_selected_variable (PSPPIRE_DICT_VIEW (act->source)); + + if ( NULL == var) + return g_strdup (""); + + return g_strdup (var_get_name (var)); +} + + + static void populate_text (PsppireDictView *treeview, gpointer data) { @@ -125,99 +160,72 @@ populate_text (PsppireDictView *treeview, gpointer data) g_string_free (gstring, TRUE); } -static gboolean -treeview_item_selected (gpointer data) -{ - GtkTreeView *tv = GTK_TREE_VIEW (data); - GtkTreeModel *model = gtk_tree_view_get_model (tv); - gint n_rows = gtk_tree_model_iter_n_children (model, NULL); +static void +jump_to (PsppireDialog *d, gint response, gpointer data) +{ + PsppireDataWindow *dw; + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (data); + const struct variable *var; - if ( n_rows == 0 ) - return FALSE; + if (response != PSPPIRE_RESPONSE_GOTO) + return; - return TRUE; -} + var = psppire_dict_view_get_selected_variable (PSPPIRE_DICT_VIEW (pda->source)); + if ( NULL == var) + return; -static gchar * generate_syntax (PsppireDictView *treeview); + g_object_get (pda, "top-level", &dw, NULL); + g_object_set (dw->data_editor, + "current-variable", var_get_dict_index (var), + NULL); +} -void -variable_info_dialog (PsppireDataWindow *de) +static void +psppire_dialog_action_var_info_activate (GtkAction *a) { - gint response ; + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); GtkBuilder *xml = builder_new ("variable-info.ui"); + GtkWidget *textview = get_widget_assert (xml, "textview1"); - GtkWidget *dialog = get_widget_assert (xml, "variable-info-dialog"); - GtkWidget *treeview = get_widget_assert (xml, "treeview2"); - GtkWidget *textview = get_widget_assert (xml, "textview1"); - - PsppireVarStore *vs = NULL; - PsppireDict *dict = NULL; - - g_object_get (de->data_editor, "var-store", &vs, NULL); + pda->dialog = get_widget_assert (xml, "variable-info-dialog"); + pda->source = get_widget_assert (xml, "treeview2"); - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - - g_object_get (vs, "dictionary", &dict, NULL); - g_object_set (treeview, "model", dict, + g_object_set (pda->source, "selection-mode", GTK_SELECTION_SINGLE, NULL); - g_signal_connect (treeview, "cursor-changed", G_CALLBACK (populate_text), + g_signal_connect (pda->source, "cursor-changed", G_CALLBACK (populate_text), textview); - gtk_text_view_set_indent (GTK_TEXT_VIEW (textview), -5); - - psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), - treeview_item_selected, treeview); - - response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); + g_signal_connect (pda->dialog, "response", G_CALLBACK (jump_to), + pda); - switch (response) - { - case PSPPIRE_RESPONSE_GOTO: - { - const struct variable *var = - psppire_dict_view_get_selected_variable (PSPPIRE_DICT_VIEW (treeview)); - - if ( NULL == var) - goto done; - - g_object_set (de->data_editor, - "current-variable", var_get_dict_index (var), - NULL); - } - - break; - case PSPPIRE_RESPONSE_PASTE: - { - gchar *syntax = generate_syntax (PSPPIRE_DICT_VIEW (treeview)); - paste_syntax_to_window (syntax); - - g_free (syntax); - } - break; - default: - break; - } + psppire_dialog_action_set_valid_predicate (pda, + treeview_item_selected); - done: g_object_unref (xml); + + if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_var_info_parent_class)->activate) + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_var_info_parent_class)->activate (pda); } -static gchar * -generate_syntax (PsppireDictView *treeview) +static void +psppire_dialog_action_var_info_class_init (PsppireDialogActionVarInfoClass *class) { - const struct variable *var = - psppire_dict_view_get_selected_variable (treeview); + GtkActionClass *action_class = GTK_ACTION_CLASS (class); - if ( NULL == var) - return g_strdup (""); + action_class->activate = psppire_dialog_action_var_info_activate; + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; +} - return g_strdup (var_get_name (var)); + +static void +psppire_dialog_action_var_info_init (PsppireDialogActionVarInfo *act) +{ } diff --git a/src/ui/gui/psppire-dialog-action-var-info.h b/src/ui/gui/psppire-dialog-action-var-info.h new file mode 100644 index 00000000..90c80076 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-var-info.h @@ -0,0 +1,78 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 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 + +#include "psppire-dialog-action.h" + +#ifndef __PSPPIRE_DIALOG_ACTION_VAR_INFO_H__ +#define __PSPPIRE_DIALOG_ACTION_VAR_INFO_H__ + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_VAR_INFO (psppire_dialog_action_var_info_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_VAR_INFO(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_VAR_INFO, PsppireDialogActionVarInfo)) + +#define PSPPIRE_DIALOG_ACTION_VAR_INFO_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_VAR_INFO, \ + PsppireDialogActionVarInfoClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_VAR_INFO(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_VAR_INFO)) + +#define PSPPIRE_IS_DIALOG_ACTION_VAR_INFO_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_VAR_INFO)) + + +#define PSPPIRE_DIALOG_ACTION_VAR_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_VAR_INFO, \ + PsppireDialogActionVarInfoClass)) + +typedef struct _PsppireDialogActionVarInfo PsppireDialogActionVarInfo; +typedef struct _PsppireDialogActionVarInfoClass PsppireDialogActionVarInfoClass; + + +struct _PsppireDialogActionVarInfo +{ + PsppireDialogAction parent; + + /*< private >*/ + gboolean dispose_has_run ; + + /* Treeview containing the selected variables */ + GtkWidget *variables; +}; + + +struct _PsppireDialogActionVarInfoClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_var_info_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_VAR_INFO_H__ */ diff --git a/src/ui/gui/psppire-dialog-action.c b/src/ui/gui/psppire-dialog-action.c new file mode 100644 index 00000000..e3ee25be --- /dev/null +++ b/src/ui/gui/psppire-dialog-action.c @@ -0,0 +1,188 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 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 "psppire-dialog-action.h" +#include "psppire-dialog.h" +#include "executor.h" +#include "helper.h" +#include "psppire-data-window.h" + +static void psppire_dialog_action_init (PsppireDialogAction *act); +static void psppire_dialog_action_class_init (PsppireDialogActionClass *class); + +G_DEFINE_ABSTRACT_TYPE (PsppireDialogAction, psppire_dialog_action, GTK_TYPE_ACTION); + +/* Properties */ +enum +{ + PROP_0, + PROP_MANAGER, + PROP_TOPLEVEL, +}; + +static void +psppire_dialog_action_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PsppireDialogAction *act = PSPPIRE_DIALOG_ACTION (object); + + switch (prop_id) + { + case PROP_MANAGER: + { + + GObject *p = g_value_get_object (value); + act->uim = GTK_UI_MANAGER (p); + } + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + }; +} + + +static void +psppire_dialog_action_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PsppireDialogAction *dialog_action = PSPPIRE_DIALOG_ACTION (object); + + switch (prop_id) + { + case PROP_MANAGER: + g_value_take_object (value, dialog_action->uim); + break; + case PROP_TOPLEVEL: + g_value_take_object (value, dialog_action->toplevel); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + }; +} + + +static void +psppire_dialog_action_activate (PsppireDialogAction *act) +{ + gint response; + + PsppireVarStore *vs; + PsppireDialogActionClass *class = PSPPIRE_DIALOG_ACTION_GET_CLASS (act); + + GSList *sl = gtk_ui_manager_get_toplevels (act->uim, GTK_UI_MANAGER_MENUBAR | GTK_UI_MANAGER_TOOLBAR); + g_return_if_fail (sl); + + act->toplevel = gtk_widget_get_toplevel (GTK_WIDGET (sl->data)); + g_slist_free (sl); + + vs = PSPPIRE_DATA_WINDOW(act->toplevel)->var_store; + + g_object_get (vs, "dictionary", &act->dict, NULL); + + g_object_set (act->source, "model", act->dict, NULL); + + gtk_window_set_transient_for (GTK_WINDOW (act->dialog), GTK_WINDOW (act->toplevel)); + + + if (GTK_ACTION_CLASS (psppire_dialog_action_parent_class)->activate) + GTK_ACTION_CLASS (psppire_dialog_action_parent_class)->activate ( GTK_ACTION (act)); + + response = psppire_dialog_run (PSPPIRE_DIALOG (act->dialog)); + + if ( class->generate_syntax ) + { + switch (response) + { + case GTK_RESPONSE_OK: + g_free (execute_syntax_string (PSPPIRE_DATA_WINDOW (act->toplevel), + class->generate_syntax (act))); + break; + case PSPPIRE_RESPONSE_PASTE: + g_free (paste_syntax_to_window (class->generate_syntax (act))); + break; + default: + break; + } + } +} + +static void +psppire_dialog_action_class_init (PsppireDialogActionClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + GParamSpec *manager_spec = + g_param_spec_object ("manager", + "Manager", + "The GtkUIManager which created this object", + GTK_TYPE_UI_MANAGER, + G_PARAM_CONSTRUCT_ONLY |G_PARAM_READWRITE); + + GParamSpec *toplevel_spec = + g_param_spec_object ("top-level", + "Top Level", + "The top level widget to which this dialog action belongs", + GTK_TYPE_WINDOW, + G_PARAM_READABLE); + + object_class->set_property = psppire_dialog_action_set_property; + object_class->get_property = psppire_dialog_action_get_property; + + class->generate_syntax = NULL; + + class->activate = psppire_dialog_action_activate; + + g_object_class_install_property (object_class, + PROP_MANAGER, + manager_spec); + + g_object_class_install_property (object_class, + PROP_TOPLEVEL, + toplevel_spec); +} + + +static void +psppire_dialog_action_init (PsppireDialogAction *act) +{ + act->toplevel = NULL; + act->dict = NULL; +} + + +void +psppire_dialog_action_set_valid_predicate (PsppireDialogAction *act, + ContentsAreValid dialog_state_valid) +{ + psppire_dialog_set_valid_predicate (act->dialog, dialog_state_valid, act); +} + +void +psppire_dialog_action_set_refresh (PsppireDialogAction *pda, + PsppireDialogActionRefresh refresh) +{ + g_signal_connect_swapped (pda->dialog, "refresh", G_CALLBACK (refresh), pda); +} + diff --git a/src/ui/gui/psppire-dialog-action.h b/src/ui/gui/psppire-dialog-action.h new file mode 100644 index 00000000..c0bab64e --- /dev/null +++ b/src/ui/gui/psppire-dialog-action.h @@ -0,0 +1,101 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 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 . */ + +/* + This is a an abstract base class, deriving from GtkAction. + It's purpose is to abstract the way in which dialog boxes behave. + That is, this action will fire whenever a dialog box is to be + popped up. + + Additionally, most dialog boxes generate syntax to + be run by the pspp back-end. This provides an abstraction + to do that. The programmer needs only to provide the function + to generate the syntax. This base class looks after the rest. +*/ + +#ifndef __PSPPIRE_DIALOG_ACTION_H__ +#define __PSPPIRE_DIALOG_ACTION_H__ + +#include +#include + +#include "psppire-dict.h" +#include "psppire-dialog.h" +#include + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION (psppire_dialog_action_get_type ()) + +#define PSPPIRE_DIALOG_ACTION(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION, PsppireDialogAction)) + +#define PSPPIRE_DIALOG_ACTION_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION, \ + PsppireDialogActionClass)) + +#define PSPPIRE_IS_DIALOG_ACTION(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION)) + +#define PSPPIRE_IS_DIALOG_ACTION_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION)) + + +#define PSPPIRE_DIALOG_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION, \ + PsppireDialogActionClass)) + +typedef struct _PsppireDialogAction PsppireDialogAction; +typedef struct _PsppireDialogActionClass PsppireDialogActionClass; + + +struct _PsppireDialogAction +{ + GtkAction parent; + + /*< private >*/ + GtkUIManager *uim; + + GtkWidget *source; + GtkWidget *dialog; + + GtkWidget *toplevel; + PsppireDict *dict; +}; + +struct _PsppireDialogActionClass +{ + GtkActionClass parent_class; + void (*activate) (PsppireDialogAction *); + char * (*generate_syntax) (PsppireDialogAction *); +}; + +GType psppire_dialog_action_get_type (void) ; + +typedef void (*PsppireDialogActionRefresh) (PsppireDialogAction *) ; + +void psppire_dialog_action_set_refresh (PsppireDialogAction *pda, + PsppireDialogActionRefresh refresh); + +void psppire_dialog_action_set_valid_predicate (PsppireDialogAction *act, + ContentsAreValid dialog_state_valid); + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_H__ */ diff --git a/src/ui/gui/psppire-dialog.c b/src/ui/gui/psppire-dialog.c index c5ac30b2..c365ab4b 100644 --- a/src/ui/gui/psppire-dialog.c +++ b/src/ui/gui/psppire-dialog.c @@ -31,6 +31,7 @@ static void psppire_dialog_init (PsppireDialog *); enum {DIALOG_REFRESH, + RESPONSE, VALIDITY_CHANGED, DIALOG_HELP, n_SIGNALS}; @@ -248,6 +249,18 @@ psppire_dialog_class_init (PsppireDialogClass *class) 0); + signals [RESPONSE] = + g_signal_new ("response", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, + 1, + G_TYPE_INT); + + signals [VALIDITY_CHANGED] = g_signal_new ("validity-changed", G_TYPE_FROM_CLASS (class), @@ -524,6 +537,8 @@ psppire_dialog_run (PsppireDialog *dialog) g_main_loop_unref (dialog->loop); + g_signal_emit (dialog, signals [RESPONSE], 0, dialog->response); + return dialog->response; } diff --git a/src/ui/gui/variable-info-dialog.h b/src/ui/gui/variable-info-dialog.h deleted file mode 100644 index c08f6c99..00000000 --- a/src/ui/gui/variable-info-dialog.h +++ /dev/null @@ -1,24 +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 __VARIABLE_DIALOG_H -#define __VARIABLE_DIALOG_H - -#include "psppire-data-window.h" - -void variable_info_dialog (PsppireDataWindow * data); - -#endif diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index 9a634f73..cedab8c0 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -13,6 +13,9 @@ #include "psppire-var-view.h" #include "psppire-val-chooser.h" +#include "psppire-dialog-action-descriptives.h" +#include "psppire-dialog-action-var-info.h" + /* Any custom widgets which are to be used in GtkBuilder ui files need to be preregistered, otherwise GtkBuilder refuses to @@ -29,4 +32,7 @@ preregister_widgets (void) psppire_acr_get_type (); psppire_dict_view_get_type (); psppire_var_view_get_type (); + + psppire_dialog_action_descriptives_get_type (); + psppire_dialog_action_var_info_get_type (); } -- 2.30.2