X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Ftext-data-import-dialog.c;h=d24a23242d7a03810de1fff1545cbd679d82767d;hb=7640d70ac1a3641869d8de331594c340c9568ea2;hp=ed7f8f4a4f44dd35c132e17d1d98cd01de10efa4;hpb=b241f1232945bfc913633c3ecec68e997500e065;p=pspp diff --git a/src/ui/gui/text-data-import-dialog.c b/src/ui/gui/text-data-import-dialog.c index ed7f8f4a4f..d24a23242d 100644 --- a/src/ui/gui/text-data-import-dialog.c +++ b/src/ui/gui/text-data-import-dialog.c @@ -18,6 +18,12 @@ #include "ui/gui/text-data-import-dialog.h" +#include "page-intro.h" +#include "page-sheet-spec.h" +#include "page-first-line.h" +#include "page-separators.h" +#include "page-formats.h" + #include #include #include @@ -72,7 +78,6 @@ text_data_import_assistant (PsppireDataWindow *dw) { GtkWindow *parent_window = GTK_WINDOW (dw); struct import_assistant *ia = init_assistant (parent_window); - GtkBuilder *builder = ia->asst.builder; struct sheet_spec_page *ssp ; if (!init_file (ia, parent_window)) @@ -83,17 +88,35 @@ text_data_import_assistant (PsppireDataWindow *dw) ssp = ia->sheet_spec; - add_page_to_assistant (ia, get_widget_assert (builder, "Sheet"), - GTK_ASSISTANT_PAGE_INTRO); - - add_page_to_assistant (ia, get_widget_assert (builder, "Formats"), - GTK_ASSISTANT_PAGE_CONFIRM); - + if (ia->spreadsheet) + { + ia->sheet_spec = sheet_spec_page_create (ia); + } + else + { + ia->intro = intro_page_create (ia); + ia->first_line = first_line_page_create (ia); + ia->separators = separators_page_create (ia); + } + ia->formats = formats_page_create (ia); gtk_widget_show_all (GTK_WIDGET (ia->asst.assistant)); ia->asst.main_loop = g_main_loop_new (NULL, false); - g_main_loop_run (ia->asst.main_loop); + + { + /* + Instead of this block, + A simple g_main_loop_run (ia->asst.main_loop); should work here. But it seems to crash. + I have no idea why. + */ + GMainContext *ctx = g_main_loop_get_context (ia->asst.main_loop); + ia->asst.loop_done = false; + while (! ia->asst.loop_done) + { + g_main_context_iteration (ctx, TRUE); + } + } g_main_loop_unref (ia->asst.main_loop); switch (ia->asst.response) @@ -108,8 +131,11 @@ text_data_import_assistant (PsppireDataWindow *dw) break; } - destroy_formats_page (ia); - destroy_separators_page (ia); + if (ssp) + { + destroy_formats_page (ia); + destroy_separators_page (ia); + } destroy_assistant (ia); destroy_file (ia); @@ -206,11 +232,8 @@ generate_syntax (const struct import_assistant *ia) { struct string s = DS_EMPTY_INITIALIZER; -#if 0 - if (ssp->spreadsheet == NULL) + if (ia->spreadsheet == NULL) { - size_t var_cnt; - size_t i; syntax_gen_pspp (&s, "GET DATA" "\n /TYPE=TXT" @@ -221,78 +244,21 @@ generate_syntax (const struct import_assistant *ia) intro_append_syntax (ia->intro, &s); + ds_put_cstr (&s, " /ARRANGEMENT=DELIMITED\n" " /DELCASE=LINE\n"); - if (ia->first_line->skip_lines > 0) - ds_put_format (&s, " /FIRSTCASE=%d\n", ia->first_line->skip_lines + 1); - ds_put_cstr (&s, " /DELIMITERS=\""); - if (ds_find_byte (&ia->separators->separators, '\t') != SIZE_MAX) - ds_put_cstr (&s, "\\t"); - if (ds_find_byte (&ia->separators->separators, '\\') != SIZE_MAX) - ds_put_cstr (&s, "\\\\"); - for (i = 0; i < ds_length (&ia->separators->separators); i++) - { - char c = ds_at (&ia->separators->separators, i); - if (c == '"') - ds_put_cstr (&s, "\"\""); - else if (c != '\t' && c != '\\') - ds_put_byte (&s, c); - } - ds_put_cstr (&s, "\"\n"); - if (!ds_is_empty (&ia->separators->quotes)) - syntax_gen_pspp (&s, " /QUALIFIER=%sq\n", ds_cstr (&ia->separators->quotes)); - if (!ds_is_empty (&ia->separators->quotes) && ia->separators->escape) - ds_put_cstr (&s, " /ESCAPE\n"); - ds_put_cstr (&s, " /VARIABLES=\n"); - - var_cnt = dict_get_var_cnt (ia->formats->dict); - for (i = 0; i < var_cnt; i++) - { - struct variable *var = dict_get_var (ia->formats->dict, i); - char format_string[FMT_STRING_LEN_MAX + 1]; - fmt_to_string (var_get_print_format (var), format_string); - ds_put_format (&s, " %s %s%s\n", - var_get_name (var), format_string, - i == var_cnt - 1 ? "." : ""); - } - - apply_dict (ia->formats->dict, &s); + + first_line_append_syntax (ia, &s); + separators_append_syntax (ia, &s); + formats_append_syntax (ia, &s); + apply_dict (ia->dict, &s); } else - { - const struct sheet_spec_page *ssp = ia->sheet_spec; - - syntax_gen_pspp (&s, - "GET DATA" - "\n /TYPE=%ss" - "\n /FILE=%sq" - "\n /SHEET=index %d" - "\n /READNAMES=%ss", - (ssp->spreadsheet->type == SPREADSHEET_GNUMERIC) ? "GNM" : "ODS", - ia->file.file_name, - ssp->opts.sheet_index, - ssp->sri.read_names ? "ON" : "OFF"); - - - if ( ssp->opts.cell_range) - { - syntax_gen_pspp (&s, - "\n /CELLRANGE=RANGE %sq", - ssp->opts.cell_range); - } - else - { - syntax_gen_pspp (&s, - "\n /CELLRANGE=FULL"); - } - - - syntax_gen_pspp (&s, "."); + return sheet_spec_gen_syntax (ia); } - -#endif + return ds_cstr (&s); }