X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpage-first-line.c;h=8d21e7c55c936e6d74a3a404d4e45205ed129803;hb=a3478d7d960ef11374f5d8fd6760d6219a392d1e;hp=2ccdb918b21c0d90540ea83063f34de90e3fcdb4;hpb=b0b67aa7a5225aa92bc3c9ecd1a12822f89d2c45;p=pspp diff --git a/src/ui/gui/page-first-line.c b/src/ui/gui/page-first-line.c index 2ccdb918b2..8d21e7c55c 100644 --- a/src/ui/gui/page-first-line.c +++ b/src/ui/gui/page-first-line.c @@ -16,11 +16,12 @@ #include +#include "page-first-line.h" + #include "ui/gui/text-data-import-dialog.h" #include #include -#include #include #include #include @@ -41,14 +42,15 @@ #include "ui/gui/executor.h" #include "ui/gui/helper.h" #include "ui/gui/builder-wrapper.h" +#include "ui/gui/pspp-sheet-selection.h" +#include "ui/gui/pspp-sheet-view-column.h" +#include "ui/gui/pspp-sheet-view.h" #include "ui/gui/psppire-data-window.h" #include "ui/gui/psppire-dialog.h" #include "ui/gui/psppire-encoding-selector.h" #include "ui/gui/psppire-empty-list-store.h" #include "ui/gui/psppire-var-sheet.h" -#include "ui/gui/psppire-var-store.h" #include "ui/gui/psppire-scanf.h" -#include "ui/syntax-gen.h" #include "gl/error.h" #include "gl/intprops.h" @@ -59,10 +61,19 @@ #define N_(msgid) msgid + /* The "first line" page of the assistant. */ -static GtkTreeView *create_lines_tree_view (GtkContainer *parent_window, - struct import_assistant *); +/* Page where the user chooses the first line of data. */ +struct first_line_page + { + GtkWidget *page; + PsppSheetView *tree_view; + GtkWidget *variable_names_cb; + }; + +static PsppSheetView *create_lines_tree_view (GtkContainer *parent_window, + struct import_assistant *); static void on_first_line_change (GtkTreeSelection *, struct import_assistant *); static void on_variable_names_cb_toggle (GtkToggleButton *, @@ -71,39 +82,42 @@ 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"), GTK_ASSISTANT_PAGE_CONTENT); + gtk_widget_destroy (get_widget_assert (builder, "first-line")); p->tree_view = create_lines_tree_view ( GTK_CONTAINER (get_widget_assert (builder, "first-line-scroller")), ia); p->variable_names_cb = get_widget_assert (builder, "variable-names"); - 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)), + pspp_sheet_selection_set_mode ( + pspp_sheet_view_get_selection (PSPP_SHEET_VIEW (p->tree_view)), + PSPP_SHEET_SELECTION_BROWSE); + pspp_sheet_view_set_rubber_banding (PSPP_SHEET_VIEW (p->tree_view), TRUE); + g_signal_connect (pspp_sheet_view_get_selection (PSPP_SHEET_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); } static void -render_line (GtkTreeViewColumn *tree_column, +render_line (PsppSheetViewColumn *tree_column, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, @@ -121,11 +135,11 @@ render_line (GtkTreeViewColumn *tree_column, /* Creates and returns a tree view that contains each of the lines in IA's file as a row. */ -static GtkTreeView * +static PsppSheetView * create_lines_tree_view (GtkContainer *parent, struct import_assistant *ia) { - GtkTreeView *tree_view; - GtkTreeViewColumn *column; + PsppSheetView *tree_view = NULL; + PsppSheetViewColumn *column; size_t max_line_length; gint content_width, header_width; size_t i; @@ -133,11 +147,11 @@ create_lines_tree_view (GtkContainer *parent, struct import_assistant *ia) make_tree_view (ia, 0, &tree_view); - column = gtk_tree_view_column_new_with_attributes ( + column = pspp_sheet_view_column_new_with_attributes ( title, ia->asst.fixed_renderer, (void *) NULL); - gtk_tree_view_column_set_cell_data_func (column, ia->asst.fixed_renderer, + pspp_sheet_view_column_set_cell_data_func (column, ia->asst.fixed_renderer, render_line, NULL, NULL); - gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_FIXED); + pspp_sheet_view_column_set_resizable (column, TRUE); max_line_length = 0; for (i = 0; i < ia->file.line_cnt; i++) @@ -149,11 +163,9 @@ create_lines_tree_view (GtkContainer *parent, struct import_assistant *ia) content_width = get_monospace_width (tree_view, ia->asst.fixed_renderer, max_line_length); header_width = get_string_width (tree_view, ia->asst.prop_renderer, title); - gtk_tree_view_column_set_fixed_width (column, MAX (content_width, + pspp_sheet_view_column_set_fixed_width (column, MAX (content_width, header_width)); - gtk_tree_view_append_column (tree_view, column); - - gtk_tree_view_set_fixed_height_mode (tree_view, true); + pspp_sheet_view_append_column (tree_view, column); gtk_container_add (parent, GTK_WIDGET (tree_view)); gtk_widget_show (GTK_WIDGET (tree_view)); @@ -185,39 +197,48 @@ set_first_line (struct import_assistant *ia) { GtkTreePath *path; - path = gtk_tree_path_new_from_indices (ia->first_line.skip_lines, -1); - gtk_tree_view_set_cursor (GTK_TREE_VIEW (ia->first_line.tree_view), + path = gtk_tree_path_new_from_indices (ia->skip_lines, -1); + pspp_sheet_view_set_cursor (PSPP_SHEET_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); - gtk_widget_set_sensitive (ia->first_line.variable_names_cb, - ia->first_line.skip_lines > 0); + GTK_TOGGLE_BUTTON (ia->first_line->variable_names_cb), + ia->variable_names); + gtk_widget_set_sensitive (ia->first_line->variable_names_cb, + ia->skip_lines > 0); } /* Sets IA's first_line substructure to match the widgets. */ static void get_first_line (struct import_assistant *ia) { - GtkTreeSelection *selection; + PsppSheetSelection *selection; GtkTreeIter iter; GtkTreeModel *model; - selection = gtk_tree_view_get_selection (ia->first_line.tree_view); - if (gtk_tree_selection_get_selected (selection, &model, &iter)) + selection = pspp_sheet_view_get_selection (ia->first_line->tree_view); + if (pspp_sheet_selection_get_selected (selection, &model, &iter)) { GtkTreePath *path = gtk_tree_model_get_path (model, &iter); 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_TOGGLE_BUTTON (ia->first_line->variable_names_cb))); } - gtk_widget_set_sensitive (ia->first_line.variable_names_cb, - ia->first_line.skip_lines > 0); + gtk_widget_set_sensitive (ia->first_line->variable_names_cb, + ia->skip_lines > 0); +} + + + +void +first_line_append_syntax (const struct import_assistant *ia, struct string *s) +{ + if (ia->skip_lines > 0) + ds_put_format (s, " /FIRSTCASE=%d\n", ia->skip_lines + 1); }