Skip to content

Commit

Permalink
[import-main-matcher.cpp] tidy entry setup
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Aug 11, 2024
1 parent da1f29f commit 29b6034
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions gnucash/import-export/import-main-matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ typedef struct
{
GtkWidget *entry;
GObject *override_widget;
bool *can_edit;
bool& can_edit;
GHashTable *hash;
const char *initial;
} EntryInfo;
Expand All @@ -981,17 +981,17 @@ static void override_widget_clicked (GtkWidget *widget, EntryInfo *entryinfo)
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;
entryinfo->can_edit = true;
}

static void
setup_entry (EntryInfo *entryinfo)
setup_entry (EntryInfo& entryinfo)
{
bool sensitive = *entryinfo->can_edit;
GtkWidget *entry = entryinfo->entry;
GtkWidget *override_widget = GTK_WIDGET (entryinfo->override_widget);
GHashTable *hash = entryinfo->hash;
const char *initial = entryinfo->initial;
auto sensitive = entryinfo.can_edit;
auto entry = entryinfo.entry;
auto override_widget = GTK_WIDGET (entryinfo.override_widget);
auto hash = entryinfo.hash;
auto initial = entryinfo.initial;

gtk_widget_set_sensitive (entry, sensitive);
gtk_widget_set_visible (override_widget, !sensitive);
Expand All @@ -1002,7 +1002,7 @@ setup_entry (EntryInfo *entryinfo)
{
gtk_entry_set_text (GTK_ENTRY (entry), _("Click Edit to modify"));
g_signal_connect (override_widget, "clicked", G_CALLBACK (override_widget_clicked),
entryinfo);
&entryinfo);
}

GtkListStore *list = gtk_list_store_new (NUM_COMPLETION_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
Expand Down Expand Up @@ -1043,22 +1043,19 @@ input_new_fields (GNCImportMainMatcher *info, RowInfo& rowinfo,
auto split = gnc_import_TransInfo_get_fsplit (rowinfo.get_trans_info ());

std::vector<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) },
{ 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) },
};

for (auto& entryinfo : entries)
setup_entry (&entryinfo);
std::for_each (entries.begin(), entries.end(), setup_entry);

/* ensure that an override button doesn't have focus. find the
first available entry and give it focus. */
for (const auto& entryinfo : entries)
if (entryinfo.can_edit)
{
gtk_widget_grab_focus (entryinfo.entry);
break;
}
if (auto it = std::find_if (entries.begin(), entries.end(),
[](auto info){ return info.can_edit; });
it != entries.end())
gtk_widget_grab_focus (it->entry);

gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (info->main_widget));

Expand Down

0 comments on commit 29b6034

Please sign in to comment.