gnucash stable: [import-main-matcher.c] offer force edit non-identical fields
Christopher Lam
clam at code.gnucash.org
Mon Apr 24 01:01:35 EDT 2023
Updated via https://github.com/Gnucash/gnucash/commit/e754660d (commit)
from https://github.com/Gnucash/gnucash/commit/919bfa71 (commit)
commit e754660de8e1bda1837e135efb5cae9ce5cc1a01
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Mar 5 00:13:50 2023 +0800
[import-main-matcher.c] offer force edit non-identical fields
Previously, only identical Desc/Notes/Memo were unlocked for
editing. This commit allows editing selected transactions' textual
data, even if they are not identical.
diff --git a/gnucash/gtkbuilder/dialog-import.glade b/gnucash/gtkbuilder/dialog-import.glade
index 9662951915..19e07f5cf0 100644
--- a/gnucash/gtkbuilder/dialog-import.glade
+++ b/gnucash/gtkbuilder/dialog-import.glade
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.38.2 -->
+<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkImage" id="account_new_icon">
@@ -891,7 +891,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">0</property>
+ <property name="position">1</property>
</packing>
</child>
<child>
@@ -905,7 +905,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
</object>
@@ -916,7 +916,7 @@
</packing>
</child>
<child>
- <!-- n-columns=2 n-rows=3 -->
+ <!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
@@ -997,6 +997,42 @@
<property name="top-attach">2</property>
</packing>
</child>
+ <child>
+ <object class="GtkButton" id="desc_override">
+ <property name="label">Edit</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
+ </object>
+ <packing>
+ <property name="left-attach">2</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="notes_override">
+ <property name="label">Edit</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
+ </object>
+ <packing>
+ <property name="left-attach">2</property>
+ <property name="top-attach">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="memo_override">
+ <property name="label">Edit</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
+ </object>
+ <packing>
+ <property name="left-attach">2</property>
+ <property name="top-attach">2</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c
index ef306740a7..9a6c55b1ff 100644
--- a/gnucash/import-export/import-main-matcher.c
+++ b/gnucash/import-export/import-main-matcher.c
@@ -942,17 +942,43 @@ match_func (GtkEntryCompletion *completion, const char *entry_str,
return ret;
}
+typedef struct
+{
+ GtkWidget *entry;
+ GObject *override;
+ bool *can_edit;
+ GHashTable *hash;
+ const char *initial;
+} EntryInfo;
+
+static void override_clicked (GtkWidget *widget, EntryInfo *entryinfo)
+{
+ gtk_widget_set_visible (GTK_WIDGET (entryinfo->override), false);
+ gtk_widget_set_sensitive (entryinfo->entry, true);
+ gtk_entry_set_text (GTK_ENTRY (entryinfo->entry), "");
+ gtk_widget_grab_focus (entryinfo->entry);
+ *entryinfo->can_edit = true;
+}
+
static void
-setup_entry (GtkWidget *entry, bool sensitive, GHashTable *hash,
- const char *initial)
+setup_entry (EntryInfo *entryinfo)
{
+ bool sensitive = *entryinfo->can_edit;
+ GtkWidget *entry = entryinfo->entry;
+ GtkWidget *override = GTK_WIDGET (entryinfo->override);
+ GHashTable *hash = entryinfo->hash;
+ const char *initial = entryinfo->initial;
+
gtk_widget_set_sensitive (entry, sensitive);
+ gtk_widget_set_visible (override, !sensitive);
+
if (sensitive && initial && *initial)
gtk_entry_set_text (GTK_ENTRY (entry), initial);
else if (!sensitive)
{
- gtk_entry_set_text (GTK_ENTRY (entry), _("Disabled"));
- return;
+ gtk_entry_set_text (GTK_ENTRY (entry), _("Click Edit to modify"));
+ g_signal_connect (override, "clicked", G_CALLBACK (override_clicked),
+ entryinfo);
}
GtkListStore *list = gtk_list_store_new (NUM_COMPLETION_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
@@ -991,14 +1017,29 @@ input_new_fields (GNCImportMainMatcher *info, RowInfo *rowinfo,
Transaction *trans = gnc_import_TransInfo_get_trans (rowinfo->trans_info);
Split *split = gnc_import_TransInfo_get_fsplit (rowinfo->trans_info);
- setup_entry (desc_entry, info->can_edit_desc, info->desc_hash, xaccTransGetDescription (trans));
- setup_entry (notes_entry, info->can_edit_notes, info->notes_hash, xaccTransGetNotes (trans));
- setup_entry (memo_entry, info->can_edit_memo, info->memo_hash, xaccSplitGetMemo (split));
+
+ EntryInfo entries[] = {
+ { desc_entry, gtk_builder_get_object (builder, "desc_override"), &info->can_edit_desc, info->desc_hash, xaccTransGetDescription (trans) },
+ { notes_entry, gtk_builder_get_object (builder, "notes_override"), &info->can_edit_notes, info->notes_hash, xaccTransGetNotes (trans) },
+ { memo_entry, gtk_builder_get_object (builder, "memo_override"), &info->can_edit_memo, info->memo_hash, xaccSplitGetMemo (split) },
+ { NULL } };
+
+ for (guint i = 0; entries[i].entry; i++)
+ setup_entry (&entries[i]);
+
+ /* ensure that an override button doesn't have focus. find the
+ first available entry and give it focus. */
+ for (guint i = 0; entries[i].entry; i++)
+ if (*entries[i].can_edit)
+ {
+ gtk_widget_grab_focus (entries[i].entry);
+ break;
+ }
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (info->main_widget));
// run the dialog
- gtk_widget_show_all (dialog);
+ gtk_widget_show (dialog);
bool retval = false;
switch (gtk_dialog_run (GTK_DIALOG(dialog)))
Summary of changes:
gnucash/gtkbuilder/dialog-import.glade | 44 ++++++++++++++++++++--
gnucash/import-export/import-main-matcher.c | 57 +++++++++++++++++++++++++----
2 files changed, 89 insertions(+), 12 deletions(-)
More information about the gnucash-changes
mailing list