X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-import-assistant.c;h=9374f7f68e15fbb2ecc4d4c94e30ab3deddeeb26;hb=4246294842a8abedecaaf55aa87507225f03f58c;hp=a1cbfac51354f8b01628f2e585e350eda23d1979;hpb=e91cd51b61a2309df126a8731363b61174869c77;p=pspp diff --git a/src/ui/gui/psppire-import-assistant.c b/src/ui/gui/psppire-import-assistant.c index a1cbfac513..9374f7f68e 100644 --- a/src/ui/gui/psppire-import-assistant.c +++ b/src/ui/gui/psppire-import-assistant.c @@ -42,15 +42,12 @@ #include "builder-wrapper.h" #include "helper.h" -#include "pspp-sheet-view.h" -#include "pspp-sheet-selection.h" #include "psppire-import-assistant.h" #include "psppire-scanf.h" #include "psppire-dialog.h" #include "psppire-empty-list-store.h" #include "psppire-encoding-selector.h" #include "psppire-spreadsheet-model.h" -#include "psppire-var-sheet.h" #include "ui/syntax-gen.h" #include @@ -201,6 +198,7 @@ on_paste (GtkButton *button, PsppireImportAssistant *ia) close_assistant (ia, PSPPIRE_RESPONSE_PASTE); } + /* Revises the contents of the fields tree view based on the currently chosen set of separators. */ static void @@ -459,15 +457,6 @@ on_prepare (GtkAssistant *assistant, GtkWidget *page, PsppireImportAssistant *ia on_entering (ia, new_page); } -#if GTK3_TRANSITION - if (gtk_assistant_get_page_type (assistant, page) - == GTK_ASSISTANT_PAGE_CONFIRM) - gtk_widget_grab_focus (assistant->apply); - else - gtk_widget_grab_focus (assistant->forward); -#endif - - ia->current_page = pn; } @@ -607,6 +596,8 @@ process_file (PsppireImportAssistant *ia) return TRUE; } +#if SHEET_MERGE + static void render_line_number (PsppSheetViewColumn *tree_column, @@ -624,7 +615,6 @@ render_line_number (PsppSheetViewColumn *tree_column, } - static gint get_string_width (GtkWidget *treeview, GtkCellRenderer *renderer, const char *string) @@ -672,7 +662,7 @@ add_line_number_column (const PsppireImportAssistant *ia, static void -set_model_on_treeview (const PsppireImportAssistant *ia, GtkWidget *tree_view, size_t first_line) +set_model_on_treeview (PsppireImportAssistant *ia, GtkWidget *tree_view, size_t first_line) { GtkTreeModel *model = GTK_TREE_MODEL (psppire_empty_list_store_new (ia->line_cnt - first_line)); @@ -696,6 +686,8 @@ make_tree_view (const PsppireImportAssistant *ia) return tree_view; } +#endif + static GtkWidget * add_page_to_assistant (PsppireImportAssistant *ia, GtkWidget *page, GtkAssistantPageType type, const gchar *); @@ -733,7 +725,6 @@ prepare_sheet_spec_page (PsppireImportAssistant *ia) } - /* Initializes IA's sheet_spec substructure. */ static void sheet_spec_page_create (PsppireImportAssistant *ia) @@ -757,7 +748,6 @@ sheet_spec_page_create (PsppireImportAssistant *ia) g_object_set_data (G_OBJECT (page), "on-entering", prepare_sheet_spec_page); } - static void on_chosen (PsppireImportAssistant *ia, GtkWidget *page) { @@ -812,6 +802,8 @@ on_map (PsppireImportAssistant *ia, GtkWidget *page) on_chosen (ia, page); } + + static void chooser_page_enter (PsppireImportAssistant *ia, GtkWidget *page) { @@ -844,6 +836,8 @@ chooser_page_reset (PsppireImportAssistant *ia, GtkWidget *page) on_chosen (ia, page); } + + static void chooser_page_create (PsppireImportAssistant *ia) { @@ -918,6 +912,7 @@ chooser_page_create (PsppireImportAssistant *ia) } + static void psppire_import_assistant_init (PsppireImportAssistant *ia) { @@ -999,6 +994,8 @@ on_intro_amount_changed (PsppireImportAssistant *p) } +#if SHEET_MERGE + static void render_line (PsppSheetViewColumn *tree_column, GtkCellRenderer *cell, @@ -1015,17 +1012,19 @@ render_line (PsppSheetViewColumn *tree_column, g_object_set (cell, "text", ds_cstr (&lines[row]), NULL); } +#endif + /* Sets the widgets to match IA's first_line substructure. */ static void set_first_line (PsppireImportAssistant *ia) { GtkTreePath *path = gtk_tree_path_new_from_indices (ia->skip_lines, -1); - +#if SHEET_MERGE set_model_on_treeview (ia, ia->tree_view, 0); - pspp_sheet_view_set_cursor (PSPP_SHEET_VIEW (ia->tree_view), path, NULL, false); +#endif gtk_tree_path_free (path); gtk_toggle_button_set_active ( @@ -1035,6 +1034,7 @@ set_first_line (PsppireImportAssistant *ia) ia->skip_lines > 0); } +#if SHEET_MERGE /* Creates and returns a tree view that contains each of the lines in IA's file as a row. */ @@ -1080,6 +1080,7 @@ create_lines_tree_view (GtkContainer *parent, PsppireImportAssistant *ia) } + /* Sets IA's first_line substructure to match the widgets. */ static void set_first_line_options (PsppireImportAssistant *ia) @@ -1103,6 +1104,8 @@ set_first_line_options (PsppireImportAssistant *ia) gtk_widget_set_sensitive (ia->variable_names_cb, ia->skip_lines > 0); } + + static void reset_first_line_page (PsppireImportAssistant *ia) { @@ -1112,7 +1115,7 @@ reset_first_line_page (PsppireImportAssistant *ia) gtk_widget_set_sensitive (ia->variable_names_cb, FALSE); } - +#endif /* Initializes IA's first_line substructure. */ static void first_line_page_create (PsppireImportAssistant *ia) @@ -1124,6 +1127,8 @@ first_line_page_create (PsppireImportAssistant *ia) add_page_to_assistant (ia, w, GTK_ASSISTANT_PAGE_CONTENT, _("Select the First Line")); +#if SHEET_MERGE + ia->tree_view = GTK_WIDGET (create_lines_tree_view ( GTK_CONTAINER (get_widget_assert (ia->builder, "first-line-scroller")), ia)); ia->variable_names_cb = get_widget_assert (ia->builder, "variable-names"); @@ -1141,9 +1146,12 @@ first_line_page_create (PsppireImportAssistant *ia) g_object_set_data (G_OBJECT (w), "on-reset", reset_first_line_page); +#endif } + + static void intro_on_enter (PsppireImportAssistant *ia) { @@ -1272,6 +1280,8 @@ psppire_import_assistant_new (GtkWindow *toplevel) NULL)); } + + struct column @@ -1312,6 +1322,8 @@ destroy_columns (PsppireImportAssistant *ia) free (ia->columns); } +#if SHEET_MERGE + /* Called to render one of the cells in the fields preview tree view. */ static void @@ -1345,6 +1357,7 @@ render_input_cell (PsppSheetViewColumn *tree_column, GtkCellRenderer *cell, (void *) NULL); } +#endif /* Parses the contents of the field at (ROW,COLUMN) according to its variable format. If OUTPUTP is non-null, then *OUTPUTP @@ -1404,6 +1417,7 @@ parse_field (PsppireImportAssistant *ia, return ok; } +#if SHEET_MERGE /* Called to render one of the cells in the data preview tree view. */ @@ -1474,6 +1488,7 @@ get_tooltip_location (GtkWidget *widget, gint wx, gint wy, } + @@ -1522,7 +1537,7 @@ on_query_output_tooltip (GtkWidget *widget, gint wx, gint wy, free (text); return TRUE; } - +#endif @@ -1717,24 +1732,32 @@ split_fields (PsppireImportAssistant *ia) } } + +#if SHEET_MERGE static PsppSheetViewColumn * make_data_column (PsppireImportAssistant *ia, GtkWidget *tree_view, bool input, gint dict_idx) { struct variable *var = NULL; struct column *column = NULL; - size_t char_cnt; + size_t char_cnt = 0; gint content_width, header_width; PsppSheetViewColumn *tree_column; - char *name; + char *name = NULL; if (input) - column = &ia->columns[dict_idx]; + { + column = &ia->columns[dict_idx]; + name = escape_underscores (column->name); + char_cnt = column->width; + } else - var = dict_get_var (ia->dict, dict_idx); + { + var = dict_get_var (ia->dict, dict_idx); + name = escape_underscores (var_get_name (var)); + char_cnt = var_get_print_format (var)->w; + } - name = escape_underscores (input ? column->name : var_get_name (var)); - char_cnt = input ? column->width : var_get_print_format (var)->w; content_width = get_monospace_width (tree_view, ia->fixed_renderer, char_cnt); header_width = get_string_width (tree_view, ia->prop_renderer, @@ -1757,15 +1780,19 @@ make_data_column (PsppireImportAssistant *ia, GtkWidget *tree_view, return tree_column; } +#endif static GtkWidget * create_data_tree_view (gboolean input, GtkContainer *parent, PsppireImportAssistant *ia) { gint i; +#if SHEET_MERGE GtkWidget *tree_view = make_tree_view (ia); set_model_on_treeview (ia, tree_view, ia->skip_lines); + + pspp_sheet_selection_set_mode (pspp_sheet_view_get_selection (PSPP_SHEET_VIEW (tree_view)), PSPP_SHEET_SELECTION_NONE); @@ -1795,9 +1822,11 @@ create_data_tree_view (gboolean input, GtkContainer *parent, gtk_widget_show (tree_view); return tree_view; +#endif } + /* Chooses a name for each column on the separators page */ static void choose_column_names (PsppireImportAssistant *ia) @@ -1914,6 +1943,9 @@ separators_page_create (PsppireImportAssistant *ia) + +#if SHEET_MERGE + /* Called when the user changes one of the variables in the dictionary. */ static void @@ -1952,7 +1984,7 @@ on_variable_change (PsppireDict *dict, int dict_idx, pop_watch_cursor (ia); } - +#endif /* Called just before the formats page of the assistant is @@ -1960,200 +1992,6 @@ on_variable_change (PsppireDict *dict, int dict_idx, static void prepare_formats_page (PsppireImportAssistant *ia) { - PsppireDict *psppire_dict = NULL; - PsppireVarSheet *var_sheet; - GtkBin *vars_scroller; - GtkWidget *old_var_sheet; - - - push_watch_cursor (ia); - - if (ia->spreadsheet == NULL) - { - struct fmt_guesser *fg; - unsigned long int number = 0; - size_t column_idx; - - - ia->dict = dict_create (get_default_encoding ()); - fg = fmt_guesser_create (); - for (column_idx = 0; column_idx < ia->column_cnt; column_idx++) - { - struct variable *modified_var = - (column_idx < ia->modified_var_cnt ? ia->modified_vars[column_idx] : NULL); - - if (modified_var == NULL) - { - struct column *column = &ia->columns[column_idx]; - struct variable *var; - struct fmt_spec format; - char *name; - size_t row; - - /* Choose variable name. */ - name = dict_make_unique_var_name (ia->dict, column->name, &number); - - /* Choose variable format. */ - fmt_guesser_clear (fg); - for (row = ia->skip_lines; row < ia->line_cnt; row++) - fmt_guesser_add (fg, column->contents[row]); - fmt_guesser_guess (fg, &format); - fmt_fix_input (&format); - - /* Create variable. */ - var = dict_create_var_assert (ia->dict, name, fmt_var_width (&format)); - var_set_both_formats (var, &format); - - free (name); - } - else - { - char *name; - - name = dict_make_unique_var_name (ia->dict, var_get_name (modified_var), - &number); - dict_clone_var_as_assert (ia->dict, modified_var, name); - free (name); - } - } - fmt_guesser_destroy (fg); - } - else - { - int row_start = -1; - int row_stop = -1; - int col_start = -1; - int col_stop = -1; - - GtkBuilder *builder = ia->builder; - - struct casereader *reader = NULL; - - GtkWidget *readnames_checkbox = get_widget_assert (builder, "readnames-checkbox"); - GtkWidget *range_entry = get_widget_assert (builder, "cell-range-entry"); - const gchar *range = gtk_entry_get_text (GTK_ENTRY (range_entry)); - GtkWidget *combo_box = get_widget_assert (builder, "sheet-entry"); - - gint num = gtk_combo_box_get_active (GTK_COMBO_BOX (combo_box)); - - struct spreadsheet_read_options sro; - - sro.sheet_name = NULL; - sro.cell_range = NULL; - sro.sheet_index = num + 1; - - if ( convert_cell_ref (range, &col_start, &row_start, &col_stop, &row_stop)) - { - sro.cell_range = g_strdup (range); - } - - sro.read_names = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (readnames_checkbox)); - sro.asw = -1; - - switch (ia->spreadsheet->type) - { - case SPREADSHEET_ODS: - case SPREADSHEET_GNUMERIC: - { - reader = spreadsheet_make_reader (ia->spreadsheet, &sro); - ia->dict = ia->spreadsheet->dict; - } - break; - default: - g_assert_not_reached (); - break; - } - g_free (sro.cell_range); - - if (reader && ia->dict) - { - struct ccase *c; - int col; - - ia->column_cnt = dict_get_var_cnt (ia->dict); - ia->columns = xcalloc (ia->column_cnt, sizeof (*ia->columns)); - for (col = 0; col < ia->column_cnt ; ++col) - { - const struct variable *var = dict_get_var (ia->dict, col); - ia->columns[col].name = xstrdup (var_get_name (var)); - ia->columns[col].contents = NULL; - } - - casenumber rows = 0; - for (; (c = casereader_read (reader)) != NULL; case_unref (c)) - { - rows++; - for (col = 0; col < ia->column_cnt ; ++col) - { - char *ss; - const struct variable *var = dict_get_var (ia->dict, col); - - ia->columns[col].contents = xrealloc (ia->columns[col].contents, - sizeof (struct substring) * rows); - - ss = data_out (case_data (c, var), dict_get_encoding (ia->dict), - var_get_print_format (var)); - - ia->columns[col].contents[rows - 1] = ss_cstr (ss); - } - - if (rows > MAX_PREVIEW_LINES) - { - case_unref (c); - break; - } - } - casereader_destroy (reader); - ia->line_cnt = rows; - } - else - { - GtkWidget * dialog = gtk_message_dialog_new (NULL, - GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - _("An error occurred reading the spreadsheet file.")); - - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - } - } - - psppire_dict = psppire_dict_new_from_dict (ia->dict); - g_signal_connect (psppire_dict, "variable-changed", - G_CALLBACK (on_variable_change), ia); - ia->psppire_dict = psppire_dict; - - - /* XXX: PsppireVarStore doesn't hold a reference to - psppire_dict for now, but it should. After it does, we - should g_object_ref the psppire_dict here, since we also - hold a reference via ia->formats->dict. */ - var_sheet = PSPPIRE_VAR_SHEET (psppire_var_sheet_new ()); - g_object_set (var_sheet, - "dictionary", psppire_dict, - "may-create-vars", FALSE, - "may-delete-vars", FALSE, - "format-use", FMT_FOR_INPUT, - "enable-grid-lines", PSPP_SHEET_VIEW_GRID_LINES_BOTH, - (void *) NULL); - - vars_scroller = GTK_BIN (get_widget_assert (ia->builder, "vars-scroller")); - old_var_sheet = gtk_bin_get_child (GTK_BIN (vars_scroller)); - if (old_var_sheet != NULL) - gtk_container_remove (GTK_CONTAINER (vars_scroller), old_var_sheet); - gtk_container_add (GTK_CONTAINER (vars_scroller), GTK_WIDGET (var_sheet)); - gtk_widget_show (GTK_WIDGET (var_sheet)); - - ia->data_tree_view = - GTK_WIDGET (create_data_tree_view ( - FALSE, - GTK_CONTAINER (get_widget_assert (ia->builder, "data-scroller")), - ia)); - - gtk_widget_show (ia->paste_button); - - pop_watch_cursor (ia); } static void @@ -2368,11 +2206,13 @@ sheet_spec_gen_syntax (PsppireImportAssistant *ia) return ds_cstr (&s); } + gchar * psppire_import_assistant_generate_syntax (PsppireImportAssistant *ia) { struct string s = DS_EMPTY_INITIALIZER; +#if SHEET_MERGE if (!ia->spreadsheet) { if (ia->file_name == NULL) @@ -2401,6 +2241,8 @@ psppire_import_assistant_generate_syntax (PsppireImportAssistant *ia) { return sheet_spec_gen_syntax (ia); } + +#endif return ds_cstr (&s); }