-/*
- 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 <http://www.gnu.org/licenses/>. */
#include <config.h>
#include "dict-display.h"
#include <language/syntax-string-source.h>
#include "syntax-editor.h"
+#include <data/dictionary.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
#include "psppire-var-store.h"
+struct split_file_dialog
+{
+ /* The XML that created the dialog */
+ GladeXML *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 )
{
}
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);
+
+
+ gtk_list_store_clear (GTK_LIST_STORE (liststore));
- g_print ("%s\n", __FUNCTION__);
+ 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_set_active (GTK_TOGGLE_BUTTON(off), 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;
+ 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 ;
- GtkSheet *var_sheet =
- GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
+ sfd.xml = XML_NEW ("psppire.glade");
- 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;
+ var_sheet = GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
+
+ vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
+
+ sfd.dict = vs->dict;
+ sfd.tv = GTK_TREE_VIEW (dest);
+ sfd.selector = PSPPIRE_SELECTOR (
+ get_widget_assert (sfd.xml, "split-file-selector"));
attach_dictionary_to_treeview (GTK_TREE_VIEW (source),
vs->dict,
GTK_SELECTION_MULTIPLE, 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);
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), de->parent.window);
response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
{
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);
break;
case PSPPIRE_RESPONSE_PASTE:
{
- gchar *syntax = generate_syntax (xml, dict);
+ gchar *syntax = generate_syntax (&sfd);
struct syntax_editor *se =
(struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
break;
}
- g_object_unref (xml);
+ g_object_unref (sfd.xml);
}