Make similar changes to account import CSV assistant

Remove the OK button from the file page.
This commit is contained in:
Robert Fewell 2018-11-26 14:14:25 +00:00
parent 1b2feacd4b
commit 92b587fa56
3 changed files with 37 additions and 47 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.20.4 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkAdjustment" id="num_hrows_adj">
@ -279,7 +279,6 @@ Enter file name and location for the Import...
</child>
</object>
<packing>
<property name="page_type">progress</property>
<property name="title" translatable="yes">Import Account Preview, first 10 rows only</property>
<property name="complete">True</property>
<property name="has_padding">False</property>

View File

@ -62,7 +62,7 @@ void csv_import_assistant_summary_page_prepare (GtkAssistant *assistant, gpointe
void csv_import_sep_cb (GtkWidget *radio, gpointer user_data );
void csv_import_hrows_cb (GtkWidget *spin, gpointer user_data );
void csv_import_file_chooser_confirm_cb (GtkWidget *button, CsvImportInfo *info);
void csv_import_file_chooser_selection_changed_cb (GtkFileChooser *chooser, CsvImportInfo *info);
static gchar *gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input);
@ -136,25 +136,22 @@ void create_regex (GString *regex_str, const gchar *sep)
/*************************************************************************/
/**************************************************
* csv_file_chooser_confirm_cb
* csv_import_file_chooser_selection_changed_cb
*
* call back for ok button in file chooser widget
* call back for file chooser widget
**************************************************/
void
csv_import_file_chooser_confirm_cb (GtkWidget *button, CsvImportInfo *info)
csv_import_file_chooser_selection_changed_cb (GtkFileChooser *chooser, CsvImportInfo *info)
{
GtkAssistant *assistant = GTK_ASSISTANT(info->window);
gint num = gtk_assistant_get_current_page (assistant);
GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
gchar *file_name;
csv_import_result res;
gtk_assistant_set_page_complete (assistant, page, FALSE);
gtk_assistant_set_page_complete (assistant, info->file_page, FALSE);
gtk_assistant_set_page_complete (assistant, info->account_page, FALSE);
file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(info->file_chooser));
if (file_name)
if (file_name && !g_file_test (file_name, G_FILE_TEST_IS_DIR))
{
gchar *filepath = gnc_uri_get_path (file_name);
gchar *filedir = g_path_get_dirname (filepath);
@ -164,25 +161,12 @@ csv_import_file_chooser_confirm_cb (GtkWidget *button, CsvImportInfo *info)
info->file_name = g_strdup (file_name);
// generate preview
gtk_list_store_clear (info->store);
res = csv_import_read_file (info->file_name, info->regexp->str, info->store, 1 );
if (res == RESULT_OPEN_FAILED)
gnc_error_dialog (GTK_WINDOW (info->window), _("The input file can not be opened."));
else if (res == RESULT_OK)
gtk_assistant_set_page_complete (assistant, page, TRUE);
else if (res == MATCH_FOUND)
gtk_assistant_set_page_complete (assistant, page, TRUE);
gtk_assistant_set_page_complete (assistant, info->file_page, TRUE);
}
g_free (file_name);
DEBUG("file_name selected is %s", info->file_name);
DEBUG("starting directory is %s", info->starting_dir);
/* Step to next page if page is complete */
if(gtk_assistant_get_page_complete (assistant, page))
gtk_assistant_set_current_page (assistant, num + 1);
}
@ -385,15 +369,13 @@ csv_import_assistant_file_page_prepare (GtkAssistant *assistant,
gpointer user_data)
{
CsvImportInfo *info = user_data;
gint num = gtk_assistant_get_current_page (assistant);
GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
/* Set the default directory */
if (info->starting_dir)
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(info->file_chooser), info->starting_dir);
/* Disable the Forward Assistant Button */
gtk_assistant_set_page_complete (assistant, page, FALSE);
gtk_assistant_set_page_complete (assistant, info->file_page, FALSE);
}
@ -402,7 +384,25 @@ csv_import_assistant_account_page_prepare (GtkAssistant *assistant,
gpointer user_data)
{
CsvImportInfo *info = user_data;
csv_import_result res;
/* Disable the Forward Assistant Button */
gtk_assistant_set_page_complete (assistant, info->account_page, FALSE);
/* test read one line */
gtk_list_store_clear (info->store);
res = csv_import_read_file (info->file_name, info->regexp->str, info->store, 1 );
if (res == RESULT_OPEN_FAILED)
{
gnc_error_dialog (GTK_WINDOW (info->window), _("The input file can not be opened."));
gtk_assistant_previous_page (assistant);
}
else if (res == RESULT_OK)
gtk_assistant_set_page_complete (assistant, info->account_page, TRUE);
else if (res == MATCH_FOUND)
gtk_assistant_set_page_complete (assistant, info->account_page, TRUE);
// generate preview
gtk_list_store_clear (info->store);
gtk_widget_set_sensitive (info->header_row_spin, TRUE);
@ -419,8 +419,6 @@ csv_import_assistant_finish_page_prepare (GtkAssistant *assistant,
gpointer user_data)
{
CsvImportInfo *info = user_data;
gint num = gtk_assistant_get_current_page (assistant);
GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
gchar *text;
/* Set Finish page text */
@ -441,7 +439,7 @@ csv_import_assistant_finish_page_prepare (GtkAssistant *assistant,
gnc_set_default_directory (GNC_PREFS_GROUP, info->starting_dir);
/* Enable the Assistant Buttons */
gtk_assistant_set_page_complete (assistant, page, TRUE);
gtk_assistant_set_page_complete (assistant, info->finish_label, TRUE);
}
@ -569,7 +567,6 @@ csv_import_assistant_create (CsvImportInfo *info)
{
GtkBuilder *builder;
GtkWidget *window;
GtkWidget *box, *h_box;
GtkWidget *button;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
@ -607,25 +604,16 @@ csv_import_assistant_create (CsvImportInfo *info)
/* Start Page */
/* File chooser Page */
info->file_page = GTK_WIDGET(gtk_builder_get_object(builder, "file_page"));
info->file_chooser = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN);
g_signal_connect (G_OBJECT(info->file_chooser), "file-activated",
G_CALLBACK(csv_import_file_chooser_confirm_cb), info);
button = gtk_button_new_with_mnemonic (_("_OK"));
gtk_widget_set_size_request (button, 100, -1);
gtk_widget_show (button);
h_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_set_homogeneous (GTK_BOX (h_box), TRUE);
gtk_widget_set_hexpand (GTK_WIDGET(h_box), TRUE);
gtk_box_pack_start (GTK_BOX(h_box), button, FALSE, FALSE, 0);
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(info->file_chooser), h_box);
g_signal_connect (G_OBJECT(button), "clicked",
G_CALLBACK(csv_import_file_chooser_confirm_cb), info);
g_signal_connect (G_OBJECT(info->file_chooser), "selection-changed",
G_CALLBACK(csv_import_file_chooser_selection_changed_cb), info);
box = GTK_WIDGET(gtk_builder_get_object(builder, "file_page"));
gtk_box_pack_start (GTK_BOX(box), info->file_chooser, TRUE, TRUE, 6);
gtk_box_pack_start (GTK_BOX(info->file_page), info->file_chooser, TRUE, TRUE, 6);
gtk_widget_show (info->file_chooser);
/* Account Tree Page */
info->account_page = GTK_WIDGET(gtk_builder_get_object(builder, "import_tree_page"));
info->header_row_spin = GTK_WIDGET(gtk_builder_get_object (builder, "num_hrows"));
info->tree_view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview"));

View File

@ -51,6 +51,9 @@ typedef struct
GtkWidget *summary_label;
GtkWidget *summary_error_view;
GtkWidget *file_page;
GtkWidget *account_page;
gchar *starting_dir;
gchar *file_name;
gchar *error;