gnucash stable: [import-main-matcher.cpp] refactor common code into gen_trans_common_toggled_cb
Christopher Lam
clam at code.gnucash.org
Thu Jul 27 09:09:19 EDT 2023
Updated via https://github.com/Gnucash/gnucash/commit/d6a025e1 (commit)
from https://github.com/Gnucash/gnucash/commit/91869d07 (commit)
commit d6a025e1539db7b608c0ffc15611b56698687c5d
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Thu Jul 27 19:50:44 2023 +0800
[import-main-matcher.cpp] refactor common code into gen_trans_common_toggled_cb
these callbacks handle the checkboxes being toggled.
diff --git a/gnucash/import-export/import-main-matcher.cpp b/gnucash/import-export/import-main-matcher.cpp
index 5ec961b489..76671173b6 100644
--- a/gnucash/import-export/import-main-matcher.cpp
+++ b/gnucash/import-export/import-main-matcher.cpp
@@ -673,28 +673,30 @@ run_match_dialog (GNCImportMainMatcher *info,
trans_info, info->pending_matches);
}
+static void
+gen_trans_common_toggled_cb (GtkCellRendererToggle *cell_renderer, gchar *path,
+ GNCImportMainMatcher *gui, GNCImportAction action)
+{
+ auto model = gtk_tree_view_get_model (gui->view);
+ GtkTreeIter tree_iter;
+ g_return_if_fail (gtk_tree_model_get_iter_from_string (model, &tree_iter, path));
+
+ GNCImportTransInfo *transaction_info;
+ gtk_tree_model_get (model, &tree_iter, DOWNLOADED_COL_DATA, &transaction_info, -1);
+ if (gnc_import_TransInfo_get_action (transaction_info) == action &&
+ gnc_import_Settings_get_action_skip_enabled (gui->user_settings))
+ gnc_import_TransInfo_set_action (transaction_info, GNCImport_SKIP);
+ else
+ gnc_import_TransInfo_set_action (transaction_info, action);
+ refresh_model_row (gui, model, &tree_iter, transaction_info);
+}
+
static void
gnc_gen_trans_add_toggled_cb (GtkCellRendererToggle *cell_renderer,
gchar *path,
GNCImportMainMatcher *gui)
{
- ENTER("");
-
- GtkTreeModel *model = gtk_tree_view_get_model (gui->view);
- GtkTreeIter iter;
- if (!gtk_tree_model_get_iter_from_string (model, &iter, path))
- return;
-
- GNCImportTransInfo *trans_info;
- gtk_tree_model_get (model, &iter, DOWNLOADED_COL_DATA, &trans_info, -1);
-
- if (gnc_import_TransInfo_get_action (trans_info) == GNCImport_ADD &&
- gnc_import_Settings_get_action_skip_enabled (gui->user_settings))
- gnc_import_TransInfo_set_action (trans_info, GNCImport_SKIP);
- else
- gnc_import_TransInfo_set_action (trans_info, GNCImport_ADD);
- refresh_model_row (gui, model, &iter, trans_info);
- LEAVE("");
+ gen_trans_common_toggled_cb (cell_renderer, path, gui, GNCImport_ADD);
}
static void
@@ -702,23 +704,7 @@ gnc_gen_trans_clear_toggled_cb (GtkCellRendererToggle *cell_renderer,
gchar *path,
GNCImportMainMatcher *gui)
{
- ENTER("");
-
- GtkTreeModel *model = gtk_tree_view_get_model (gui->view);
- GtkTreeIter iter;
- if (!gtk_tree_model_get_iter_from_string (model, &iter, path))
- return;
-
- GNCImportTransInfo *trans_info;
- gtk_tree_model_get (model, &iter, DOWNLOADED_COL_DATA, &trans_info, -1);
-
- if (gnc_import_TransInfo_get_action (trans_info) == GNCImport_CLEAR &&
- gnc_import_Settings_get_action_skip_enabled (gui->user_settings))
- gnc_import_TransInfo_set_action (trans_info, GNCImport_SKIP);
- else
- gnc_import_TransInfo_set_action (trans_info, GNCImport_CLEAR);
- refresh_model_row (gui, model, &iter, trans_info);
- LEAVE("");
+ gen_trans_common_toggled_cb (cell_renderer, path, gui, GNCImport_CLEAR);
}
static void
@@ -726,23 +712,7 @@ gnc_gen_trans_update_toggled_cb (GtkCellRendererToggle *cell_renderer,
gchar *path,
GNCImportMainMatcher *gui)
{
- ENTER("");
-
- GtkTreeModel *model = gtk_tree_view_get_model (gui->view);
- GtkTreeIter iter;
- if (!gtk_tree_model_get_iter_from_string (model, &iter, path))
- return;
-
- GNCImportTransInfo *trans_info;
- gtk_tree_model_get (model, &iter, DOWNLOADED_COL_DATA, &trans_info, -1);
-
- if (gnc_import_TransInfo_get_action (trans_info) == GNCImport_UPDATE &&
- gnc_import_Settings_get_action_skip_enabled (gui->user_settings))
- gnc_import_TransInfo_set_action (trans_info, GNCImport_SKIP);
- else
- gnc_import_TransInfo_set_action (trans_info, GNCImport_UPDATE);
- refresh_model_row (gui, model, &iter, trans_info);
- LEAVE("");
+ gen_trans_common_toggled_cb (cell_renderer, path, gui, GNCImport_UPDATE);
}
static void
Summary of changes:
gnucash/import-export/import-main-matcher.cpp | 72 ++++++++-------------------
1 file changed, 21 insertions(+), 51 deletions(-)
More information about the gnucash-changes
mailing list