mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Only reset csv importer internal state if new file is selected
The changes from8ed40078b0
and78c8e8f3af
caused the importers to reset everything in the preview page whenever opening this page, including when navigating back from a future page. This can be very frustrating if many settings were adjusted but one went back just to tweak a single one. With these changes the importer will only be reset whenever the user selects a different file in the file chooser. So even navigating back to the file chooser, but not changing files will keep the import state.
This commit is contained in:
parent
0c3807414a
commit
66660c02fb
@ -145,7 +145,8 @@ private:
|
||||
|
||||
GtkWidget *file_page; /**< Assistant file page widget */
|
||||
GtkWidget *file_chooser; /**< The widget for the file chooser */
|
||||
std::string m_file_name; /**< The import file name */
|
||||
std::string m_fc_file_name; /**< The file name currently selected in the file chooser */
|
||||
std::string m_final_file_name; /**< The name of the import file effectively to use */
|
||||
|
||||
GtkWidget *preview_page; /**< Assistant preview page widget */
|
||||
GtkComboBox *settings_combo; /**< The Settings Combo */
|
||||
@ -744,10 +745,10 @@ CsvImpPriceAssist::check_for_valid_filename ()
|
||||
auto filepath = gnc_uri_get_path (file_name);
|
||||
auto starting_dir = g_path_get_dirname (filepath);
|
||||
|
||||
m_file_name = file_name;
|
||||
m_fc_file_name = file_name;
|
||||
gnc_set_default_directory (GNC_PREFS_GROUP, starting_dir);
|
||||
|
||||
DEBUG("file_name selected is %s", m_file_name.c_str());
|
||||
DEBUG("file_name selected is %s", m_fc_file_name.c_str());
|
||||
DEBUG("starting directory is %s", starting_dir);
|
||||
|
||||
g_free (filepath);
|
||||
@ -1839,6 +1840,11 @@ CsvImpPriceAssist::assist_file_page_prepare ()
|
||||
gtk_assistant_set_page_complete (csv_imp_asst, preview_page, false);
|
||||
|
||||
/* Set the default directory */
|
||||
if (!m_final_file_name.empty())
|
||||
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(file_chooser),
|
||||
m_final_file_name.c_str());
|
||||
else
|
||||
{
|
||||
auto starting_dir = gnc_get_default_directory (GNC_PREFS_GROUP);
|
||||
if (starting_dir)
|
||||
{
|
||||
@ -1846,24 +1852,31 @@ CsvImpPriceAssist::assist_file_page_prepare ()
|
||||
g_free (starting_dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CsvImpPriceAssist::assist_preview_page_prepare ()
|
||||
{
|
||||
auto go_back = false;
|
||||
|
||||
/* Load the file into parse_data, reset it if altrady loaded. */
|
||||
if (price_imp)
|
||||
price_imp.reset();
|
||||
|
||||
if (m_final_file_name != m_fc_file_name)
|
||||
{
|
||||
/* Load the file into parse_data. */
|
||||
price_imp = std::unique_ptr<GncPriceImport>(new GncPriceImport);
|
||||
/* Assume data is CSV. User can later override to Fixed Width if needed */
|
||||
try
|
||||
{
|
||||
price_imp->file_format (GncImpFileFormat::CSV);
|
||||
price_imp->load_file (m_file_name);
|
||||
price_imp->load_file (m_final_file_name);
|
||||
price_imp->tokenize (true);
|
||||
|
||||
/* Get settings store and populate */
|
||||
preview_populate_settings_combo();
|
||||
gtk_combo_box_set_active (settings_combo, 0);
|
||||
|
||||
// set over_write to false as default
|
||||
price_imp->over_write (false);
|
||||
}
|
||||
catch (std::ifstream::failure& e)
|
||||
{
|
||||
@ -1877,18 +1890,12 @@ CsvImpPriceAssist::assist_preview_page_prepare ()
|
||||
gnc_error_dialog (GTK_WINDOW(csv_imp_asst), "%s", _(e.what()));
|
||||
go_back = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (go_back)
|
||||
gtk_assistant_previous_page (csv_imp_asst);
|
||||
else
|
||||
{
|
||||
/* Get settings store and populate */
|
||||
preview_populate_settings_combo();
|
||||
gtk_combo_box_set_active (settings_combo, 0);
|
||||
|
||||
// set over_write to false as default
|
||||
price_imp->over_write (false);
|
||||
|
||||
/* Disable the "Next" Assistant Button */
|
||||
gtk_assistant_set_page_complete (csv_imp_asst, preview_page, false);
|
||||
|
||||
@ -1928,7 +1935,7 @@ CsvImpPriceAssist::assist_summary_page_prepare ()
|
||||
"- %s\n"
|
||||
"- %s\n"
|
||||
"- %s"),
|
||||
m_file_name.c_str(), added_str, dupl_str,repl_str);
|
||||
m_final_file_name.c_str(), added_str, dupl_str,repl_str);
|
||||
text += msg;
|
||||
text += "</b></span>";
|
||||
|
||||
|
@ -216,7 +216,8 @@ private:
|
||||
|
||||
GtkWidget *file_page; /**< Assistant file page widget */
|
||||
GtkWidget *file_chooser; /**< The widget for the file chooser */
|
||||
std::string m_file_name; /**< The import file name */
|
||||
std::string m_fc_file_name; /**< The file name currently selected in the file chooser */
|
||||
std::string m_final_file_name; /**< The name of the import file effectively to use */
|
||||
|
||||
GtkWidget *preview_page; /**< Assistant preview page widget */
|
||||
GtkComboBox *settings_combo; /**< The Settings Combo */
|
||||
@ -707,10 +708,10 @@ CsvImpTransAssist::check_for_valid_filename ()
|
||||
auto filepath = gnc_uri_get_path (file_name);
|
||||
auto starting_dir = g_path_get_dirname (filepath);
|
||||
|
||||
m_file_name = file_name;
|
||||
m_fc_file_name = file_name;
|
||||
gnc_set_default_directory (GNC_PREFS_GROUP, starting_dir);
|
||||
|
||||
DEBUG("file_name selected is %s", m_file_name.c_str());
|
||||
DEBUG("file_name selected is %s", m_fc_file_name.c_str());
|
||||
DEBUG("starting directory is %s", starting_dir);
|
||||
|
||||
g_free (filepath);
|
||||
@ -1891,12 +1892,18 @@ void
|
||||
CsvImpTransAssist::assist_file_page_prepare ()
|
||||
{
|
||||
/* Set the default directory */
|
||||
if (!m_final_file_name.empty())
|
||||
gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(file_chooser),
|
||||
m_final_file_name.c_str());
|
||||
else
|
||||
{
|
||||
auto starting_dir = gnc_get_default_directory (GNC_PREFS_GROUP);
|
||||
if (starting_dir)
|
||||
{
|
||||
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(file_chooser), starting_dir);
|
||||
g_free (starting_dir);
|
||||
}
|
||||
}
|
||||
|
||||
/* Disable the "Next" Assistant Button */
|
||||
gtk_assistant_set_page_complete (csv_imp_asst, account_match_page, false);
|
||||
@ -1908,18 +1915,24 @@ CsvImpTransAssist::assist_preview_page_prepare ()
|
||||
{
|
||||
auto go_back = false;
|
||||
|
||||
/* Load the file into parse_data, reset if already loaded. */
|
||||
if (tx_imp)
|
||||
tx_imp.reset();
|
||||
|
||||
if (m_final_file_name != m_fc_file_name)
|
||||
{
|
||||
tx_imp = std::unique_ptr<GncTxImport>(new GncTxImport);
|
||||
|
||||
/* Assume data is CSV. User can later override to Fixed Width if needed */
|
||||
try
|
||||
{
|
||||
tx_imp->file_format (GncImpFileFormat::CSV);
|
||||
tx_imp->load_file (m_file_name);
|
||||
tx_imp->load_file (m_fc_file_name);
|
||||
tx_imp->tokenize (true);
|
||||
tx_imp->req_mapped_accts (false);
|
||||
|
||||
/* Get settings store and populate */
|
||||
preview_populate_settings_combo();
|
||||
gtk_combo_box_set_active (settings_combo, 0);
|
||||
|
||||
/* Disable the "Next" Assistant Button */
|
||||
gtk_assistant_set_page_complete (csv_imp_asst, preview_page, false);
|
||||
}
|
||||
catch (std::ifstream::failure& e)
|
||||
{
|
||||
@ -1933,22 +1946,15 @@ CsvImpTransAssist::assist_preview_page_prepare ()
|
||||
gnc_error_dialog (GTK_WINDOW (csv_imp_asst), "%s", _(e.what()));
|
||||
go_back = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (go_back)
|
||||
gtk_assistant_previous_page (csv_imp_asst);
|
||||
else
|
||||
{
|
||||
m_final_file_name = m_fc_file_name;
|
||||
preview_refresh ();
|
||||
|
||||
/* Get settings store and populate */
|
||||
preview_populate_settings_combo();
|
||||
gtk_combo_box_set_active (settings_combo, 0);
|
||||
|
||||
tx_imp->req_mapped_accts (false);
|
||||
|
||||
/* Disable the "Next" Assistant Button */
|
||||
gtk_assistant_set_page_complete (csv_imp_asst, preview_page, false);
|
||||
|
||||
/* Load the data into the treeview. */
|
||||
g_idle_add ((GSourceFunc)csv_imp_preview_queue_rebuild_table, this);
|
||||
}
|
||||
@ -2127,7 +2133,7 @@ CsvImpTransAssist::assist_summary_page_prepare ()
|
||||
try
|
||||
{
|
||||
/* Translators: {1} will be replaced with a filename */
|
||||
text += (bl::format (std::string{_("The transactions were imported from file '{1}'.")}) % m_file_name).str();
|
||||
text += (bl::format (std::string{_("The transactions were imported from file '{1}'.")}) % m_final_file_name).str();
|
||||
text += "</b></span>";
|
||||
}
|
||||
catch (const bl::conv::conversion_error& err)
|
||||
|
Loading…
Reference in New Issue
Block a user