PsppireImportAssistant: New function psppire_import_assistant_run
authorJohn Darrington <john@darrington.wattle.id.au>
Wed, 24 May 2017 05:12:29 +0000 (07:12 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Wed, 24 May 2017 05:58:45 +0000 (07:58 +0200)
src/ui/gui/psppire-data-window.c
src/ui/gui/psppire-import-assistant.c
src/ui/gui/psppire-import-assistant.h

index a6a9b241cdefb7271e894a6ba379324437fb906c..7b13b8198a364749b454f4b0fa485b7e6adf6a25 100644 (file)
@@ -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));
 }
 
index c043b33201813b0d68ed321e509ceccf4bb61331..2eecd7a10589180cb819700b0bee0e9e436cf745 100644 (file)
@@ -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;
+}
+
index 0a87892a77ff70b8a0bf60e4c3416804358b2dbf..0610fad29ba548d4712d2a9282698962276aa77e 100644 (file)
@@ -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__ */