Clean up gnc_gen_trans_edit_fields.

This commit is contained in:
John Ralls 2022-03-08 12:35:01 -08:00
parent 2b2ad46401
commit 8f9b6b1ecc

View File

@ -882,84 +882,97 @@ gnc_gen_trans_assign_transfer_account_to_selection_cb (GtkMenuItem *menuitem,
typedef enum typedef enum
{ {
DESCRIPTION = 0, DESCRIPTION,
MEMO = 1, MEMO,
NOTES = 2, NOTES,
} edit_field; } edit_field;
static void static void
gnc_gen_trans_edit_fields (GtkMenuItem *menuitem, GNCImportMainMatcher *info, edit_field field) gnc_gen_trans_edit_fields (GtkMenuItem *menuitem, GNCImportMainMatcher *info,
edit_field field)
{ {
GtkTreeView *treeview; GtkTreeView *treeview;
GtkTreeSelection *selection; GtkTreeSelection *selection;
GtkTreeModel *model; GtkTreeModel *model;
GtkTreeIter iter;
GNCImportTransInfo *trans_info;
GList *selected_rows; GList *selected_rows;
gboolean first, is_selection;
GList *refs = NULL; GList *refs = NULL;
const gchar* messages[] = {_("Enter new Description"),_("Enter new Memo"),_("Enter new Notes")}; GtkTreeStore* store;
const gchar* message = messages[field]; GNCImportTransInfo *trans_info;
Transaction* trans;
GtkTreeIter iter;
g_return_if_fail (info != NULL);
ENTER("assign_transfer_account_to_selection_cb"); ENTER("assign_transfer_account_to_selection_cb");
treeview = GTK_TREE_VIEW(info->view); treeview = GTK_TREE_VIEW(info->view);
model = gtk_tree_view_get_model (treeview); model = gtk_tree_view_get_model (treeview);
store = GTK_TREE_STORE (model);
selection = gtk_tree_view_get_selection (treeview); selection = gtk_tree_view_get_selection (treeview);
selected_rows = gtk_tree_selection_get_selected_rows (selection, &model); selected_rows = gtk_tree_selection_get_selected_rows (selection, &model);
first = TRUE;
is_selection = TRUE;
DEBUG("Rows in selection = %i",
gtk_tree_selection_count_selected_rows (selection));
DEBUG("Entering loop over selection");
if (gtk_tree_selection_count_selected_rows (selection) > 0) if (!selected_rows)
{ {
GtkTreeStore* store = GTK_TREE_STORE (model); LEAVE ("No selected rows");
for (GList* l = selected_rows; l != NULL; l = l->next) return;
}
if (selected_rows->next)
{
LEAVE ("User selected multiple rows, not supported");
return;
}
g_return_if_fail (gtk_tree_model_get_iter (model, &iter,
selected_rows->data));
gtk_tree_model_get (model, &iter, DOWNLOADED_COL_DATA,
&trans_info, -1);
trans = gnc_import_TransInfo_get_trans (trans_info);
switch (field)
{
case DESCRIPTION:
{ {
gchar *path_str = gtk_tree_path_to_string (l->data); char* new_field =
GtkTreeRowReference *ref = gtk_tree_row_reference_new (model, l->data); gnc_input_dialog_with_entry(info->main_widget, "",
g_free (path_str); _("Enter new Description"),
refs = g_list_prepend (refs, ref); xaccTransGetDescription (trans));
if (gtk_tree_model_get_iter (model, &iter, l->data)) if (!new_field) break;
{ xaccTransSetDescription (trans, new_field);
Split* first_split; gtk_tree_store_set (store, &iter, DOWNLOADED_COL_DESCRIPTION,
Transaction* trans; new_field, -1);
gtk_tree_model_get (model, &iter, DOWNLOADED_COL_DATA, &trans_info, -1); g_free (new_field);
trans = gnc_import_TransInfo_get_trans (trans_info); break;
if (field == DESCRIPTION) }
{ case MEMO:
gchar* new_field = gnc_input_dialog_with_entry(info->main_widget, "", message, xaccTransGetDescription (trans)); {
if (!new_field) break; Split *first_split =
xaccTransSetDescription (trans, new_field); gnc_import_TransInfo_get_fsplit (trans_info);
gtk_tree_store_set (store, &iter, DOWNLOADED_COL_DESCRIPTION, new_field, -1); char *new_field =
g_free (new_field); gnc_input_dialog_with_entry(info->main_widget, "",
} _("Enter new Memo"),
else if (field == MEMO) xaccSplitGetMemo (first_split));
{ if (!new_field) break;
gchar* new_field; xaccSplitSetMemo (first_split, new_field);
first_split = gnc_import_TransInfo_get_fsplit (trans_info); gtk_tree_store_set (store, &iter,
new_field = gnc_input_dialog_with_entry(info->main_widget, "", message, xaccSplitGetMemo (first_split)); DOWNLOADED_COL_MEMO, new_field, -1);
if (!new_field) break; g_free (new_field);
xaccSplitSetMemo (first_split, new_field); break;
gtk_tree_store_set (store, &iter, DOWNLOADED_COL_MEMO, new_field, -1); }
g_free (new_field); case NOTES:
} {
else if (field == NOTES) char* new_field =
{ gnc_input_dialog_with_entry(info->main_widget, "",
gchar* new_field = gnc_input_dialog_with_entry(info->main_widget, "", message, xaccTransGetNotes (trans)); _("Enter new Notes"),
if (!new_field) break; xaccTransGetNotes (trans));
xaccTransSetNotes (trans, new_field); if (!new_field) break;
g_free (new_field); xaccTransSetNotes (trans, new_field);
} g_free (new_field);
} break;
} }
} }
g_list_free_full (selected_rows, (GDestroyNotify)gtk_tree_path_free); g_list_free_full (selected_rows, (GDestroyNotify)gtk_tree_path_free);
g_list_free (refs);
LEAVE(""); LEAVE("");
} }
static void static void