X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fsplit-file-dialog.c;h=613f8e91fe601cf544f32bb62933c00211c3869a;hb=66153a44d861ccddf6a176ec5a94ffb959232ad6;hp=35aaf701f9ff196b26516259c993285b229c3809;hpb=5d5b324c12dc799e6e4dc3230e93edaa7d0a0272;p=pspp-builds.git diff --git a/src/ui/gui/split-file-dialog.c b/src/ui/gui/split-file-dialog.c index 35aaf701..613f8e91 100644 --- a/src/ui/gui/split-file-dialog.c +++ b/src/ui/gui/split-file-dialog.c @@ -1,63 +1,75 @@ -/* - PSPPIRE --- A Graphical User Interface for PSPP - Copyright (C) 2007 Free Software Foundation +/* 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 2 of the License, or - (at your option) any later version. + 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. + 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, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ + 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 "helper.h" -#include "data-editor.h" +#include "executor.h" +#include "psppire-data-window.h" #include "dict-display.h" #include -#include "syntax-editor.h" +#include "helper.h" +#include #include -#include #include "dialog-common.h" /* FIXME: These shouldn't be here */ -#include #include "psppire-var-store.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 (GladeXML *xml, PsppireDict *dict) +generate_syntax (const struct split_file_dialog *sfd) { gchar *text; - GtkWidget *off = get_widget_assert (xml, "split-radiobutton0"); + GtkWidget *off = get_widget_assert (sfd->xml, "split-radiobutton0"); GtkWidget *vars = - get_widget_assert (xml, "split-file-grouping-vars"); + get_widget_assert (sfd->xml, "split-file-grouping-vars"); 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 (xml, "split-radiobutton3"); - GtkWidget *layered = get_widget_assert (xml, "split-radiobutton1"); + GtkWidget *sort = get_widget_assert (sfd->xml, "split-radiobutton3"); + GtkWidget *layered = get_widget_assert (sfd->xml, "split-radiobutton1"); gint n_vars = append_variable_names (varlist, - dict, GTK_TREE_VIEW (vars)); + sfd->dict, GTK_TREE_VIEW (vars), 0); if ( n_vars > 0 ) { @@ -96,7 +108,7 @@ static void on_off_toggled (GtkToggleButton *togglebutton, gpointer user_data) { - GladeXML *xml = 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"); @@ -113,58 +125,88 @@ on_off_toggled (GtkToggleButton *togglebutton, } static void -refresh (GladeXML *xml) +refresh (PsppireDialog *dialog, struct split_file_dialog *d) { - GtkWidget *off = get_widget_assert (xml, "split-radiobutton0"); + 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); - g_print ("%s\n", __FUNCTION__); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(off), TRUE); + 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 ) + { + gint idx = var_get_dict_index (vars[i]); + + gtk_list_store_append (GTK_LIST_STORE (liststore), &iter); + gtk_list_store_set (GTK_LIST_STORE (liststore), &iter, 0, idx, -1); + } + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(on), TRUE); + } + gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON(off)); } -/* Pops up the Weight Cases dialog box */ +/* Pops up the Split File dialog box */ void split_file_dialog (GObject *o, gpointer data) { gint response; - struct data_editor *de = data; - PsppireDict *dict; + PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data); + struct split_file_dialog sfd; + PsppireVarStore *vs ; - GladeXML *xml = XML_NEW ("psppire.glade"); + GtkWidget *dialog ; + GtkWidget *source ; + GtkWidget *dest ; + GtkWidget *selector ; + GtkWidget *on_off ; - GtkWidget *dialog = get_widget_assert (xml, "split-file-dialog"); - GtkWidget *source = get_widget_assert (xml, "split-file-dict-treeview"); - GtkWidget *dest = get_widget_assert (xml, "split-file-grouping-vars"); - GtkWidget *selector = get_widget_assert (xml, "split-file-selector"); - GtkWidget *on_off = get_widget_assert (xml, "split-radiobutton0"); - - GtkSheet *var_sheet = - GTK_SHEET (get_widget_assert (de->xml, "variable_sheet")); + sfd.xml = builder_new ("psppire.ui"); - PsppireVarStore *vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet)); + dialog = get_widget_assert (sfd.xml, "split-file-dialog"); + source = get_widget_assert (sfd.xml, "split-file-dict-treeview"); + dest = get_widget_assert (sfd.xml, "split-file-grouping-vars"); + selector = get_widget_assert (sfd.xml, "split-file-selector"); + on_off = get_widget_assert (sfd.xml, "split-radiobutton0"); - dict = vs->dict; + g_object_get (de->data_editor, "var-store", &vs, NULL); - attach_dictionary_to_treeview (GTK_TREE_VIEW (source), - vs->dict, - GTK_SELECTION_MULTIPLE, NULL); + g_object_get (vs, "dictionary", &sfd.dict, NULL); + sfd.tv = GTK_TREE_VIEW (dest); + sfd.selector = PSPPIRE_SELECTOR ( + get_widget_assert (sfd.xml, "split-file-selector")); + g_object_set (source, "dictionary", sfd.dict, NULL); - g_signal_connect (on_off, "toggled", G_CALLBACK(on_off_toggled), xml); + g_signal_connect (on_off, "toggled", G_CALLBACK(on_off_toggled), sfd.xml); - - set_dest_model (GTK_TREE_VIEW (dest), vs->dict); + set_dest_model (GTK_TREE_VIEW (dest), sfd.dict); psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector), source, dest, insert_source_row_into_tree_view, + NULL, NULL); - refresh (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)); @@ -173,7 +215,8 @@ split_file_dialog (GObject *o, gpointer data) { case GTK_RESPONSE_OK: { - gchar *syntax = generate_syntax (xml, dict); + gchar *syntax = generate_syntax (&sfd); + struct getl_interface *sss = create_syntax_string_source (syntax); execute_syntax (sss); @@ -182,12 +225,8 @@ split_file_dialog (GObject *o, gpointer data) break; case PSPPIRE_RESPONSE_PASTE: { - gchar *syntax = generate_syntax (xml, dict); - - struct syntax_editor *se = - (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL); - - gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1); + gchar *syntax = generate_syntax (&sfd); + paste_syntax_in_new_window (syntax); g_free (syntax); } @@ -196,6 +235,6 @@ split_file_dialog (GObject *o, gpointer data) break; } - g_object_unref (xml); + g_object_unref (sfd.xml); }