From 43f0e5bf6c53ee0ba31b259aab230861baa4eb7e Mon Sep 17 00:00:00 2001 From: John Darrington Date: Tue, 29 Dec 2015 15:17:21 +0100 Subject: [PATCH] Split File Dialog: Convert to PsppireDialogAction --- src/ui/gui/automake.mk | 4 +- src/ui/gui/data-editor.ui | 3 +- src/ui/gui/psppire-data-window.c | 2 - src/ui/gui/psppire-dialog-action-split.c | 187 ++++++++++++++++++++ src/ui/gui/psppire-dialog-action-split.h | 87 ++++++++++ src/ui/gui/split-file-dialog.c | 209 ----------------------- src/ui/gui/split-file-dialog.h | 27 --- src/ui/gui/split-file.ui | 14 +- src/ui/gui/widgets.c | 2 + 9 files changed, 287 insertions(+), 248 deletions(-) create mode 100644 src/ui/gui/psppire-dialog-action-split.c create mode 100644 src/ui/gui/psppire-dialog-action-split.h delete mode 100644 src/ui/gui/split-file-dialog.c delete mode 100644 src/ui/gui/split-file-dialog.h diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 9903fd229b..3e8bc25e61 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -251,6 +251,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-dialog-action-scatterplot.h \ src/ui/gui/psppire-dialog-action-sort.c \ src/ui/gui/psppire-dialog-action-sort.h \ + src/ui/gui/psppire-dialog-action-split.c \ + src/ui/gui/psppire-dialog-action-split.h \ src/ui/gui/psppire-dialog-action-tt1s.c \ src/ui/gui/psppire-dialog-action-tt1s.h \ src/ui/gui/psppire-dialog-action-two-sample.c \ @@ -309,8 +311,6 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/recode-dialog.h \ src/ui/gui/select-cases-dialog.c \ src/ui/gui/select-cases-dialog.h \ - src/ui/gui/split-file-dialog.c \ - src/ui/gui/split-file-dialog.h \ src/ui/gui/t-test-options.c \ src/ui/gui/t-test-options.h \ src/ui/gui/val-labs-dialog.c \ diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index 8b0a29f9a0..882e40ea2b 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -197,8 +197,9 @@ - + data_split-file + uimanager1 S_plit File... Split the active dataset data-split-file diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index edf8783128..b020d19ecf 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -39,7 +39,6 @@ #include "ui/gui/psppire.h" #include "ui/gui/recode-dialog.h" #include "ui/gui/select-cases-dialog.h" -#include "ui/gui/split-file-dialog.h" #include "ui/syntax-gen.h" #include "gl/c-strcase.h" @@ -1044,7 +1043,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_split-file", G_CALLBACK (split_file_dialog)); connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog)); connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog)); diff --git a/src/ui/gui/psppire-dialog-action-split.c b/src/ui/gui/psppire-dialog-action-split.c new file mode 100644 index 0000000000..f879a960e1 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-split.c @@ -0,0 +1,187 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2007, 2010, 2011, 2012, 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 "psppire-dialog-action-split.h" +#include "psppire-selector.h" +#include "psppire-var-view.h" +#include "dict-display.h" + +#include "psppire-dialog.h" +#include "builder-wrapper.h" + +#include +#define _(msgid) gettext (msgid) +#define N_(msgid) msgid + +static void psppire_dialog_action_split_init (PsppireDialogActionSplit *act); +static void psppire_dialog_action_split_class_init (PsppireDialogActionSplitClass *class); + +G_DEFINE_TYPE (PsppireDialogActionSplit, psppire_dialog_action_split, PSPPIRE_TYPE_DIALOG_ACTION); + + +static char * +generate_syntax (PsppireDialogAction *pda) +{ + PsppireDialogActionSplit *act = PSPPIRE_DIALOG_ACTION_SPLIT (pda); + gchar *text; + + GString *string = g_string_new ("SPLIT FILE OFF."); + + if ( ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (act->off))) + { + GString * varlist = g_string_sized_new (80); + gint n_vars = psppire_var_view_append_names (PSPPIRE_VAR_VIEW (act->tv), 0, varlist); + + if ( n_vars > 0 ) + { + g_string_assign (string, ""); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(act->sort))) + { + g_string_append (string, "SORT CASES BY"); + g_string_append (string, varlist->str); + g_string_append (string, ".\n"); + } + + g_string_append (string, "SPLIT FILE "); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (act->layered))) + g_string_append (string, "LAYERED "); + else + g_string_append (string, "SEPARATE "); + + g_string_append (string, "BY "); + g_string_append (string, varlist->str); + g_string_append (string, "."); + } + g_string_free (varlist, TRUE); + } + + text = string->str; + + g_string_free (string, FALSE); + + return text; +} + + +static gboolean +dialog_state_valid (gpointer data) +{ + return TRUE; +} + +static void +refresh (PsppireDialogAction *pda) +{ + PsppireDialogActionSplit *act = PSPPIRE_DIALOG_ACTION_SPLIT (pda); + + GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (act->tv)); + + gint n_vars = dict_get_split_cnt (pda->dict->dict); + + gtk_list_store_clear (GTK_LIST_STORE (liststore)); + + if ( n_vars == 0 ) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (act->off), TRUE); + else + { + GtkTreeIter iter; + gint i; + const struct variable *const *vars = dict_get_split_vars (pda->dict->dict); + + for (i = 0 ; i < n_vars; ++i ) + { + gtk_list_store_append (GTK_LIST_STORE (liststore), &iter); + + gtk_list_store_set (GTK_LIST_STORE (liststore), &iter, + 0, vars[i], + -1); + } + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (act->layered), TRUE); + } + + gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (act->off)); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (act->sort), TRUE); +} + +static void +on_off_toggled (GtkToggleButton *togglebutton, + gpointer user_data) +{ + PsppireDialogActionSplit *act = PSPPIRE_DIALOG_ACTION_SPLIT (user_data); + + gboolean state = !gtk_toggle_button_get_active (togglebutton); + + gtk_widget_set_sensitive (act->dest, state); + gtk_widget_set_sensitive (act->selector, state); + gtk_widget_set_sensitive (act->source, state); +} + +static void +psppire_dialog_action_split_activate (PsppireDialogAction *pda) +{ + PsppireDialogActionSplit *act = PSPPIRE_DIALOG_ACTION_SPLIT (pda); + + GHashTable *thing = psppire_dialog_action_get_hash_table (pda); + GtkBuilder *xml = g_hash_table_lookup (thing, pda); + if (!xml) + { + xml = builder_new ("split-file.ui"); + g_hash_table_insert (thing, pda, xml); + + pda->dialog = get_widget_assert (xml, "split-file-dialog"); + pda->source = get_widget_assert (xml, "split-file-dict-treeview"); + act->selector = get_widget_assert (xml, "split-file-selector"); + + act->dest = get_widget_assert (xml, "split-file-grouping-vars"); + act->source = get_widget_assert (xml, "split-file-dict-treeview"); + act->sort = get_widget_assert (xml, "split-sort"); + + act->off = get_widget_assert (xml, "split-off"); + act->layered = get_widget_assert (xml, "split-layered"); + + act->tv = get_widget_assert (xml, "split-file-grouping-vars"); + + g_signal_connect (act->off, "toggled", G_CALLBACK (on_off_toggled), pda); + g_signal_connect_swapped (pda->dialog, "show", G_CALLBACK (refresh), pda); + } + + psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid); + psppire_dialog_action_set_refresh (pda, refresh); + + if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_split_parent_class)->activate) + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_split_parent_class)->activate (pda); +} + +static void +psppire_dialog_action_split_class_init (PsppireDialogActionSplitClass *class) +{ + psppire_dialog_action_set_activation (class, psppire_dialog_action_split_activate); + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; +} + + +static void +psppire_dialog_action_split_init (PsppireDialogActionSplit *act) +{ +} + diff --git a/src/ui/gui/psppire-dialog-action-split.h b/src/ui/gui/psppire-dialog-action-split.h new file mode 100644 index 0000000000..05cca2bbb7 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-split.h @@ -0,0 +1,87 @@ +/* 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_SPLIT_H__ +#define __PSPPIRE_DIALOG_ACTION_SPLIT_H__ + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_SPLIT (psppire_dialog_action_split_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_SPLIT(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_SPLIT, PsppireDialogActionSplit)) + +#define PSPPIRE_DIALOG_ACTION_SPLIT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_SPLIT, \ + PsppireDialogActionSplitClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_SPLIT(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_SPLIT)) + +#define PSPPIRE_IS_DIALOG_ACTION_SPLIT_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_SPLIT)) + + +#define PSPPIRE_DIALOG_ACTION_SPLIT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_SPLIT, \ + PsppireDialogActionSplitClass)) + +typedef struct _PsppireDialogActionSplit PsppireDialogActionSplit; +typedef struct _PsppireDialogActionSplitClass PsppireDialogActionSplitClass; + + +struct _PsppireDialogActionSplit +{ + PsppireDialogAction parent; + + /*< private >*/ + /* The treeview widget containing the list of variables + upon which the file should be split */ + GtkWidget *tv; + + GtkWidget *selector; + + GtkWidget *dest ; + GtkWidget *source ; + + GtkWidget *sort ; + GtkWidget *layered ; + + GtkWidget *off ; +}; + + +struct _PsppireDialogActionSplitClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_split_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_SPLIT_H__ */ diff --git a/src/ui/gui/split-file-dialog.c b/src/ui/gui/split-file-dialog.c deleted file mode 100644 index 2cf10d5329..0000000000 --- a/src/ui/gui/split-file-dialog.c +++ /dev/null @@ -1,209 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007, 2010, 2011, 2012 Free Software Foundation - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -#include - -#include "split-file-dialog.h" -#include "psppire-selector.h" -#include "psppire-dialog.h" -#include "executor.h" -#include "psppire-data-window.h" -#include "dict-display.h" -#include "builder-wrapper.h" -#include "helper.h" - -#include - -#include "psppire-var-view.h" - -#include - - -#include "dialog-common.h" - - -struct split_file_dialog -{ - /* The XML that created the dialog */ - GtkBuilder *xml; - - /* The dictionary to which this dialog pertains */ - PsppireDict *dict; - - /* The treeview widget containing the list of variables - upon which the file should be split */ - GtkTreeView *tv; - - PsppireSelector *selector; -}; - - -static gchar * -generate_syntax (const struct split_file_dialog *sfd) -{ - gchar *text; - GtkWidget *off = get_widget_assert (sfd->xml, "split-radiobutton0"); - - GString *string = g_string_new ("SPLIT FILE OFF."); - - if ( ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (off))) - { - GString * varlist = g_string_sized_new (80); - GtkWidget *sort = get_widget_assert (sfd->xml, "split-radiobutton3"); - GtkWidget *layered = get_widget_assert (sfd->xml, "split-radiobutton1"); - gint n_vars = psppire_var_view_append_names (PSPPIRE_VAR_VIEW (sfd->tv), 0, varlist); - - if ( n_vars > 0 ) - { - g_string_assign (string, ""); - - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(sort))) - { - g_string_append (string, "SORT CASES BY"); - g_string_append (string, varlist->str); - g_string_append (string, ".\n"); - } - - g_string_append (string, "SPLIT FILE "); - - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (layered))) - g_string_append (string, "LAYERED "); - else - g_string_append (string, "SEPARATE "); - - g_string_append (string, "BY "); - g_string_append (string, varlist->str); - g_string_append (string, "."); - } - g_string_free (varlist, TRUE); - } - - text = string->str; - - g_string_free (string, FALSE); - - return text; -}; - - -static void -on_off_toggled (GtkToggleButton *togglebutton, - gpointer user_data) -{ - GtkBuilder *xml = user_data; - GtkWidget *dest = get_widget_assert (xml, "split-file-grouping-vars"); - GtkWidget *selector = get_widget_assert (xml, "split-file-selector"); - GtkWidget *source = get_widget_assert (xml, "split-file-dict-treeview"); - GtkWidget *button3 = get_widget_assert (xml, "split-radiobutton3"); - GtkWidget *button4 = get_widget_assert (xml, "split-radiobutton4"); - - gboolean state = !gtk_toggle_button_get_active (togglebutton); - - gtk_widget_set_sensitive (dest, state); - gtk_widget_set_sensitive (selector, state); - gtk_widget_set_sensitive (source, state); - gtk_widget_set_sensitive (button3, state); - gtk_widget_set_sensitive (button4, state); -} - -static void -refresh (PsppireDialog *dialog, struct split_file_dialog *d) -{ - GtkWidget *off = get_widget_assert (d->xml, "split-radiobutton0"); - GtkWidget *on = get_widget_assert (d->xml, "split-radiobutton1"); - - GtkTreeModel *liststore = gtk_tree_view_get_model (d->tv); - - gint n_vars = dict_get_split_cnt (d->dict->dict); - - gtk_list_store_clear (GTK_LIST_STORE (liststore)); - - if ( n_vars == 0 ) - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(off), TRUE); - else - { - GtkTreeIter iter; - gint i; - const struct variable *const *vars = dict_get_split_vars (d->dict->dict); - - for (i = 0 ; i < n_vars; ++i ) - { - gtk_list_store_append (GTK_LIST_STORE (liststore), &iter); - - gtk_list_store_set (GTK_LIST_STORE (liststore), &iter, - 0, vars[i], - -1); - } - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(on), TRUE); - } - - gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON(off)); -} - - - -/* Pops up the Split File dialog box */ -void -split_file_dialog (PsppireDataWindow *de) -{ - gint response; - struct split_file_dialog sfd; - - GtkWidget *dialog ; - GtkWidget *source ; - GtkWidget *selector ; - GtkWidget *on_off ; - - sfd.xml = builder_new ("split-file.ui"); - - dialog = get_widget_assert (sfd.xml, "split-file-dialog"); - source = get_widget_assert (sfd.xml, "split-file-dict-treeview"); - selector = get_widget_assert (sfd.xml, "split-file-selector"); - on_off = get_widget_assert (sfd.xml, "split-radiobutton0"); - - sfd.tv = GTK_TREE_VIEW (get_widget_assert (sfd.xml, "split-file-grouping-vars")); - - g_object_get (de->data_editor, "dictionary", &sfd.dict, NULL); - - sfd.selector = PSPPIRE_SELECTOR (selector); - - g_object_set (source, "model", sfd.dict, NULL); - - g_signal_connect (on_off, "toggled", G_CALLBACK(on_off_toggled), sfd.xml); - - g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &sfd); - - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - - response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); - - - switch (response) - { - case GTK_RESPONSE_OK: - g_free (execute_syntax_string (de, generate_syntax (&sfd))); - break; - case PSPPIRE_RESPONSE_PASTE: - g_free (paste_syntax_to_window (generate_syntax (&sfd))); - break; - default: - break; - } - - g_object_unref (sfd.xml); -} - diff --git a/src/ui/gui/split-file-dialog.h b/src/ui/gui/split-file-dialog.h deleted file mode 100644 index 13250ad447..0000000000 --- a/src/ui/gui/split-file-dialog.h +++ /dev/null @@ -1,27 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007 Free Software Foundation, Inc. - - 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 SPLIT_FILE_DIALOG_H -#define SPLIT_FILE_DIALOG_H - -#include "psppire-data-window.h" - -/* Pops up the Split File dialog box */ -void split_file_dialog (PsppireDataWindow * data); - - -#endif diff --git a/src/ui/gui/split-file.ui b/src/ui/gui/split-file.ui index 2765252e28..614d557b14 100644 --- a/src/ui/gui/split-file.ui +++ b/src/ui/gui/split-file.ui @@ -83,7 +83,7 @@ vertical spread - + Anal_yze all cases. Do not create groups. True True @@ -101,7 +101,7 @@ - + Compare _groups. True True @@ -111,7 +111,7 @@ 0.5 True True - split-radiobutton0 + split-off False @@ -130,7 +130,7 @@ 0.5 True True - split-radiobutton0 + split-off False @@ -235,7 +235,7 @@ True spread - + _Sort the file by grouping variables. True True @@ -253,7 +253,7 @@ - + _File is already sorted. True True @@ -262,7 +262,7 @@ True 0.5 True - split-radiobutton3 + split-sort False diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index 82e90ed88e..b192f7d7d1 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -48,6 +48,7 @@ #include "psppire-dialog-action-runs.h" #include "psppire-dialog-action-scatterplot.h" #include "psppire-dialog-action-sort.h" +#include "psppire-dialog-action-split.h" #include "psppire-dialog-action-tt1s.h" #include "psppire-dialog-action-two-sample.h" #include "psppire-dialog-action-univariate.h" @@ -108,6 +109,7 @@ preregister_widgets (void) psppire_dialog_action_runs_get_type (); psppire_dialog_action_scatterplot_get_type (); psppire_dialog_action_sort_get_type (); + psppire_dialog_action_split_get_type (); psppire_dialog_action_tt1s_get_type (); psppire_dialog_action_two_sample_get_type (); psppire_dialog_action_univariate_get_type (); -- 2.30.2