From 8aa1c70a718d6d0a0afc16718ceb27af407ad051 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Thu, 24 Jan 2013 19:33:59 +0100 Subject: [PATCH] First line page construction is initialisation --- src/ui/gui/page-assistant.c | 21 ++++++++------- src/ui/gui/page-first-line.c | 38 ++++++++++++++++++---------- src/ui/gui/page-formats.c | 2 +- src/ui/gui/page-separators.c | 3 +-- src/ui/gui/text-data-import-dialog.c | 9 +++---- src/ui/gui/text-data-import-dialog.h | 18 +++---------- 6 files changed, 45 insertions(+), 46 deletions(-) diff --git a/src/ui/gui/page-assistant.c b/src/ui/gui/page-assistant.c index f6ca9e8d10..480133046e 100644 --- a/src/ui/gui/page-assistant.c +++ b/src/ui/gui/page-assistant.c @@ -82,10 +82,21 @@ init_assistant (GtkWindow *parent_window) ia->intro = intro_page_create (ia); ia->separators = separators_page_create (ia); - ia->first_line = xzalloc (sizeof *ia->first_line); + + a->prop_renderer = gtk_cell_renderer_text_new (); + g_object_ref_sink (a->prop_renderer); + a->fixed_renderer = gtk_cell_renderer_text_new (); + g_object_ref_sink (a->fixed_renderer); + g_object_set (G_OBJECT (a->fixed_renderer), + "family", "Monospace", + (void *) NULL); + + ia->first_line = first_line_page_create (ia); + ia->formats = xzalloc (sizeof *ia->formats); + g_signal_connect (a->assistant, "prepare", G_CALLBACK (on_prepare), ia); g_signal_connect (a->assistant, "cancel", G_CALLBACK (on_cancel), ia); g_signal_connect (a->assistant, "close", G_CALLBACK (on_close), ia); @@ -100,14 +111,6 @@ init_assistant (GtkWindow *parent_window) gtk_window_set_transient_for (GTK_WINDOW (a->assistant), parent_window); gtk_window_set_icon_name (GTK_WINDOW (a->assistant), "pspp"); - a->prop_renderer = gtk_cell_renderer_text_new (); - g_object_ref_sink (a->prop_renderer); - a->fixed_renderer = gtk_cell_renderer_text_new (); - g_object_ref_sink (a->fixed_renderer); - g_object_set (G_OBJECT (a->fixed_renderer), - "family", "Monospace", - (void *) NULL); - return ia; } diff --git a/src/ui/gui/page-first-line.c b/src/ui/gui/page-first-line.c index 8f61b2efda..9865d90c38 100644 --- a/src/ui/gui/page-first-line.c +++ b/src/ui/gui/page-first-line.c @@ -59,8 +59,17 @@ #define N_(msgid) msgid + /* The "first line" page of the assistant. */ +/* Page where the user chooses the first line of data. */ +struct first_line_page + { + GtkWidget *page; + GtkTreeView *tree_view; + GtkWidget *variable_names_cb; + }; + static GtkTreeView *create_lines_tree_view (GtkContainer *parent_window, struct import_assistant *); static void on_first_line_change (GtkTreeSelection *, @@ -71,10 +80,11 @@ static void set_first_line (struct import_assistant *); static void get_first_line (struct import_assistant *); /* Initializes IA's first_line substructure. */ -void -init_first_line_page (struct import_assistant *ia) +struct first_line_page * +first_line_page_create (struct import_assistant *ia) { - struct first_line_page *p = ia->first_line; + struct first_line_page *p = xzalloc (sizeof *p); + GtkBuilder *builder = ia->asst.builder; p->page = add_page_to_assistant (ia, get_widget_assert (builder, "FirstLine"), @@ -86,19 +96,19 @@ init_first_line_page (struct import_assistant *ia) gtk_tree_selection_set_mode ( gtk_tree_view_get_selection (GTK_TREE_VIEW (p->tree_view)), GTK_SELECTION_BROWSE); - set_first_line (ia); g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (p->tree_view)), "changed", G_CALLBACK (on_first_line_change), ia); g_signal_connect (p->variable_names_cb, "toggled", G_CALLBACK (on_variable_names_cb_toggle), ia); + return p; } /* Resets the first_line page to its initial content. */ void reset_first_line_page (struct import_assistant *ia) { - ia->first_line->skip_lines = 0; - ia->first_line->variable_names = false; + ia->skip_lines = 0; + ia->variable_names = false; set_first_line (ia); } @@ -124,7 +134,7 @@ render_line (GtkTreeViewColumn *tree_column, static GtkTreeView * create_lines_tree_view (GtkContainer *parent, struct import_assistant *ia) { - GtkTreeView *tree_view; + GtkTreeView *tree_view = NULL; GtkTreeViewColumn *column; size_t max_line_length; gint content_width, header_width; @@ -185,16 +195,16 @@ set_first_line (struct import_assistant *ia) { GtkTreePath *path; - path = gtk_tree_path_new_from_indices (ia->first_line->skip_lines, -1); + path = gtk_tree_path_new_from_indices (ia->skip_lines, -1); gtk_tree_view_set_cursor (GTK_TREE_VIEW (ia->first_line->tree_view), path, NULL, false); gtk_tree_path_free (path); gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (ia->first_line->variable_names_cb), - ia->first_line->variable_names); + ia->variable_names); gtk_widget_set_sensitive (ia->first_line->variable_names_cb, - ia->first_line->skip_lines > 0); + ia->skip_lines > 0); } /* Sets IA's first_line substructure to match the widgets. */ @@ -212,12 +222,12 @@ get_first_line (struct import_assistant *ia) int row = gtk_tree_path_get_indices (path)[0]; gtk_tree_path_free (path); - ia->first_line->skip_lines = row; - ia->first_line->variable_names = - (ia->first_line->skip_lines > 0 + ia->skip_lines = row; + ia->variable_names = + (ia->skip_lines > 0 && gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON (ia->first_line->variable_names_cb))); } gtk_widget_set_sensitive (ia->first_line->variable_names_cb, - ia->first_line->skip_lines > 0); + ia->skip_lines > 0); } diff --git a/src/ui/gui/page-formats.c b/src/ui/gui/page-formats.c index 3edb9e1439..3a3df83a04 100644 --- a/src/ui/gui/page-formats.c +++ b/src/ui/gui/page-formats.c @@ -133,7 +133,7 @@ prepare_formats_page (struct import_assistant *ia) /* Choose variable format. */ fmt_guesser_clear (fg); - for (row = ia->first_line->skip_lines; row < ia->file.line_cnt; row++) + for (row = ia->skip_lines; row < ia->file.line_cnt; row++) fmt_guesser_add (fg, column->contents[row]); fmt_guesser_guess (fg, &format); fmt_fix_input (&format); diff --git a/src/ui/gui/page-separators.c b/src/ui/gui/page-separators.c index 999950bcaf..c62c3bb767 100644 --- a/src/ui/gui/page-separators.c +++ b/src/ui/gui/page-separators.c @@ -347,14 +347,13 @@ split_fields (struct import_assistant *ia) static void choose_column_names (struct import_assistant *ia) { - const struct first_line_page *f = ia->first_line; struct dictionary *dict; unsigned long int generated_name_count = 0; struct column *col; size_t name_row; dict = dict_create (get_default_encoding ()); - name_row = f->variable_names && f->skip_lines ? f->skip_lines : 0; + name_row = ia->variable_names && ia->skip_lines ? ia->skip_lines : 0; for (col = ia->columns; col < &ia->columns[ia->column_cnt]; col++) { char *hint, *name; diff --git a/src/ui/gui/text-data-import-dialog.c b/src/ui/gui/text-data-import-dialog.c index 6e978a3940..6d41b0f9c9 100644 --- a/src/ui/gui/text-data-import-dialog.c +++ b/src/ui/gui/text-data-import-dialog.c @@ -81,7 +81,6 @@ text_data_import_assistant (PsppireDataWindow *dw) } ssp = ia->sheet_spec; - init_first_line_page (ia); init_formats_page (ia); @@ -319,7 +318,7 @@ render_input_cell (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_column), "column-number")); - row = empty_list_store_iter_to_row (iter) + ia->first_line->skip_lines; + row = empty_list_store_iter_to_row (iter) + ia->skip_lines; field = ia->columns[column].contents[row]; if (field.string != NULL) { @@ -443,7 +442,7 @@ render_output_cell (GtkTreeViewColumn *tree_column, ok = parse_field (ia, (empty_list_store_iter_to_row (iter) - + ia->first_line->skip_lines), + + ia->skip_lines), GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_column), "column-number")), &output, NULL); @@ -526,7 +525,7 @@ get_tooltip_location (GtkWidget *widget, gint wx, gint wy, if (!ok) return FALSE; - *row = empty_list_store_iter_to_row (&iter) + ia->first_line->skip_lines; + *row = empty_list_store_iter_to_row (&iter) + ia->skip_lines; return TRUE; } @@ -658,7 +657,7 @@ create_data_tree_view (bool input, GtkContainer *parent, GtkTreeView *tree_view; gint i; - make_tree_view (ia, ia->first_line->skip_lines, &tree_view); + make_tree_view (ia, ia->skip_lines, &tree_view); gtk_tree_selection_set_mode (gtk_tree_view_get_selection (tree_view), GTK_SELECTION_NONE); diff --git a/src/ui/gui/text-data-import-dialog.h b/src/ui/gui/text-data-import-dialog.h index a0f2a1a797..60dced703d 100644 --- a/src/ui/gui/text-data-import-dialog.h +++ b/src/ui/gui/text-data-import-dialog.h @@ -59,18 +59,6 @@ struct assistant -/* Page where the user chooses the first line of data. */ -struct first_line_page - { - int skip_lines; /* Number of initial lines to skip? */ - bool variable_names; /* Variable names above first line of data? */ - - GtkWidget *page; - GtkTreeView *tree_view; - GtkWidget *variable_names_cb; - }; - - /* Page where the user verifies and adjusts input formats. */ struct formats_page { @@ -98,6 +86,9 @@ struct import_assistant /* The columns produced. */ struct column *columns; /* Information about each column. */ size_t column_cnt; /* Number of columns. */ + + int skip_lines; /* Number of initial lines to skip? */ + bool variable_names; /* Variable names above first line of data? */ }; @@ -162,8 +153,6 @@ void update_assistant (struct import_assistant *ia); bool init_file (struct import_assistant *ia, GtkWindow *parent_window); void destroy_file (struct import_assistant *ia); - -void init_sheet_spec_page (struct import_assistant *); void prepare_sheet_spec_page (struct import_assistant *ia); void reset_sheet_spec_page (struct import_assistant *); void post_sheet_spec_page (struct import_assistant *ia); @@ -172,7 +161,6 @@ void init_first_line_page (struct import_assistant *ia); void prepare_first_line_page (struct import_assistant *ia); void reset_first_line_page (struct import_assistant *); -void init_separators_page (struct import_assistant *ia); void prepare_separators_page (struct import_assistant *ia); void reset_separators_page (struct import_assistant *); void destroy_separators_page (struct import_assistant *ia); -- 2.30.2