From: John Darrington Date: Wed, 24 May 2017 05:12:29 +0000 (+0200) Subject: PsppireImportAssistant: New function psppire_import_assistant_run X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d383cf8b05093b2286a8a6122b91cec353e838db;p=pspp PsppireImportAssistant: New function psppire_import_assistant_run --- diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index a6a9b241cd..7b13b8198a 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -971,14 +971,9 @@ file_import (PsppireDataWindow *dw) PsppireImportAssistant *asst = PSPPIRE_IMPORT_ASSISTANT (w); gtk_widget_show_all (w); - asst->main_loop = g_main_loop_new (NULL, TRUE); - g_main_loop_run (asst->main_loop); - g_main_loop_unref (asst->main_loop); + int response = psppire_import_assistant_run (asst); - if (!asst->file_name) - goto end; - - switch (asst->response) + switch (response) { case GTK_RESPONSE_APPLY: { @@ -994,7 +989,6 @@ file_import (PsppireDataWindow *dw) break; } - end: gtk_widget_destroy (GTK_WIDGET (asst)); } diff --git a/src/ui/gui/psppire-import-assistant.c b/src/ui/gui/psppire-import-assistant.c index c043b33201..2eecd7a105 100644 --- a/src/ui/gui/psppire-import-assistant.c +++ b/src/ui/gui/psppire-import-assistant.c @@ -122,7 +122,6 @@ psppire_import_assistant_finalize (GObject *object) { PsppireImportAssistant *ia = PSPPIRE_IMPORT_ASSISTANT (object); - if (ia->spreadsheet) spreadsheet_unref (ia->spreadsheet); @@ -130,6 +129,9 @@ psppire_import_assistant_finalize (GObject *object) g_object_unref (ia->builder); + ia->response = -1; + g_main_loop_unref (ia->main_loop); + if (G_OBJECT_CLASS (parent_class)->finalize) G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -724,6 +726,8 @@ psppire_import_assistant_init (PsppireImportAssistant *ia) ia->spreadsheet = NULL; + ia->main_loop = g_main_loop_new (NULL, TRUE); + g_signal_connect (ia, "prepare", G_CALLBACK (on_prepare), ia); g_signal_connect (ia, "cancel", G_CALLBACK (on_cancel), ia); g_signal_connect (ia, "close", G_CALLBACK (on_close), ia); @@ -1033,8 +1037,6 @@ choose_column_names (PsppireImportAssistant *ia) unsigned long int generated_name_count = 0; dict_clear (ia->dict); - g_print ("%s:%d XXX %d\n", __FILE__, __LINE__, gtk_tree_model_get_n_columns (ia->delimiters_model)); - for (i = 0; i < gtk_tree_model_get_n_columns (ia->delimiters_model) - 1; ++i) { const gchar *candidate_name = NULL; @@ -1044,12 +1046,10 @@ choose_column_names (PsppireImportAssistant *ia) candidate_name = psppire_delimited_text_get_header_title (PSPPIRE_DELIMITED_TEXT (ia->delimiters_model), i); } - g_print ("%s:%d CN is %s\n", __FILE__, __LINE__, candidate_name); - char *name = dict_make_unique_var_name (ia->dict, candidate_name, &generated_name_count); - + dict_create_var_assert (ia->dict, name, 0); free (name); } @@ -1613,3 +1613,12 @@ psppire_import_assistant_generate_syntax (PsppireImportAssistant *ia) return ds_cstr (&s); } + + +int +psppire_import_assistant_run (PsppireImportAssistant *asst) +{ + g_main_loop_run (asst->main_loop); + return asst->response; +} + diff --git a/src/ui/gui/psppire-import-assistant.h b/src/ui/gui/psppire-import-assistant.h index 0a87892a77..0610fad29b 100644 --- a/src/ui/gui/psppire-import-assistant.h +++ b/src/ui/gui/psppire-import-assistant.h @@ -89,7 +89,6 @@ struct _PsppireImportAssistant /* START Page where the user chooses field separators. */ /* How to break lines into columns. */ - // struct string separators; /* Field separators. */ struct string quotes; /* Quote characters. */ GtkWidget *custom_cb; @@ -139,6 +138,8 @@ GtkWidget *psppire_import_assistant_new (GtkWindow *toplevel); gchar *psppire_import_assistant_generate_syntax (PsppireImportAssistant *); +int psppire_import_assistant_run (PsppireImportAssistant *asst); + G_END_DECLS #endif /* __PSPPIRE_IMPORT_ASSISTANT_H__ */