Merge branch 'maint-edit-multiple-rows' into maint #1371

This commit is contained in:
Christopher Lam 2022-07-21 07:35:25 +08:00
commit 74525e91f3
2 changed files with 563 additions and 132 deletions

View File

@ -866,6 +866,151 @@
<action-widget response="-7">matcher_help_close</action-widget> <action-widget response="-7">matcher_help_close</action-widget>
</action-widgets> </action-widgets>
</object> </object>
<object class="GtkDialog" id="transaction_edit_dialog">
<property name="can-focus">False</property>
<property name="title" translatable="yes">Edit imported transaction details</property>
<property name="default-width">320</property>
<property name="type-hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">_Cancel</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-underline">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button2">
<property name="label" translatable="yes">_OK</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-underline">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=3 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="row-spacing">3</property>
<property name="column-spacing">6</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">_Description</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">desc_entry</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">_Notes</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">notes_entry</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">_Memo</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">memo_entry</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="desc_entry">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="notes_entry">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="memo_entry">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">button1</action-widget>
<action-widget response="-5">button2</action-widget>
</action-widgets>
</object>
<object class="GtkBox" id="transaction_matcher_content"> <object class="GtkBox" id="transaction_matcher_content">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">False</property> <property name="can-focus">False</property>

View File

@ -80,6 +80,17 @@ struct _main_matcher_info
GSList* temp_trans_list; // Temporary list of imported transactions GSList* temp_trans_list; // Temporary list of imported transactions
GHashTable* acct_id_hash; // Hash table, per account, of list of transaction IDs. GHashTable* acct_id_hash; // Hash table, per account, of list of transaction IDs.
GSList* edited_accounts; // List of accounts currently edited. GSList* edited_accounts; // List of accounts currently edited.
/* only when editing fields */
gboolean edit_desc;
gboolean edit_notes;
gboolean edit_memo;
GHashTable *desc_hash;
GHashTable *notes_hash;
GHashTable *memo_hash;
GList *new_strings;
}; };
enum downloaded_cols enum downloaded_cols
@ -90,7 +101,12 @@ enum downloaded_cols
DOWNLOADED_COL_AMOUNT, DOWNLOADED_COL_AMOUNT,
DOWNLOADED_COL_AMOUNT_DOUBLE, // used only for sorting DOWNLOADED_COL_AMOUNT_DOUBLE, // used only for sorting
DOWNLOADED_COL_DESCRIPTION, DOWNLOADED_COL_DESCRIPTION,
DOWNLOADED_COL_DESCRIPTION_ORIGINAL,
DOWNLOADED_COL_DESCRIPTION_STYLE,
DOWNLOADED_COL_MEMO, DOWNLOADED_COL_MEMO,
DOWNLOADED_COL_MEMO_ORIGINAL,
DOWNLOADED_COL_MEMO_STYLE,
DOWNLOADED_COL_NOTES_ORIGINAL,
DOWNLOADED_COL_ACTION_ADD, DOWNLOADED_COL_ACTION_ADD,
DOWNLOADED_COL_ACTION_CLEAR, DOWNLOADED_COL_ACTION_CLEAR,
DOWNLOADED_COL_ACTION_UPDATE, DOWNLOADED_COL_ACTION_UPDATE,
@ -111,6 +127,8 @@ enum downloaded_cols
/*static QofLogModule log_module = GNC_MOD_IMPORT;*/ /*static QofLogModule log_module = GNC_MOD_IMPORT;*/
static QofLogModule log_module = G_MOD_IMPORT_MATCHER; static QofLogModule log_module = G_MOD_IMPORT_MATCHER;
static const gpointer one = GINT_TO_POINTER (1);
void on_matcher_ok_clicked (GtkButton *button, GNCImportMainMatcher *info); void on_matcher_ok_clicked (GtkButton *button, GNCImportMainMatcher *info);
void on_matcher_cancel_clicked (GtkButton *button, gpointer user_data); void on_matcher_cancel_clicked (GtkButton *button, gpointer user_data);
gboolean on_matcher_delete_event (GtkWidget *widget, GdkEvent *event, gpointer data); gboolean on_matcher_delete_event (GtkWidget *widget, GdkEvent *event, gpointer data);
@ -130,8 +148,7 @@ static void gnc_gen_trans_assign_transfer_account_to_selection_cb (GtkMenuItem *
GNCImportMainMatcher *info); GNCImportMainMatcher *info);
static void gnc_gen_trans_view_popup_menu (GtkTreeView *treeview, static void gnc_gen_trans_view_popup_menu (GtkTreeView *treeview,
GdkEvent *event, GdkEvent *event,
GNCImportMainMatcher *info, GNCImportMainMatcher *info);
gboolean show_edit_actions);
static gboolean gnc_gen_trans_onButtonPressed_cb (GtkTreeView *treeview, static gboolean gnc_gen_trans_onButtonPressed_cb (GtkTreeView *treeview,
GdkEvent *event, GdkEvent *event,
GNCImportMainMatcher *info); GNCImportMainMatcher *info);
@ -147,14 +164,6 @@ static gboolean query_tooltip_tree_view_cb (GtkWidget *widget, gint x, gint y,
gpointer user_data); gpointer user_data);
/* end local prototypes */ /* end local prototypes */
static
gboolean delete_hash (gpointer key, gpointer value, gpointer user_data)
{
// Value is a hash table that needs to be destroyed.
g_hash_table_destroy (value);
return TRUE;
}
static void static void
update_all_balances (GNCImportMainMatcher *info) update_all_balances (GNCImportMainMatcher *info)
{ {
@ -222,9 +231,13 @@ gnc_gen_trans_list_delete (GNCImportMainMatcher *info)
update_all_balances (info); update_all_balances (info);
gnc_import_PendingMatches_delete (info->pending_matches); gnc_import_PendingMatches_delete (info->pending_matches);
g_hash_table_foreach_remove (info->acct_id_hash, delete_hash, NULL);
g_hash_table_destroy (info->acct_id_hash); g_hash_table_destroy (info->acct_id_hash);
info->acct_id_hash = NULL; g_hash_table_destroy (info->desc_hash);
g_hash_table_destroy (info->notes_hash);
g_hash_table_destroy (info->memo_hash);
g_list_free_full (info->new_strings, (GDestroyNotify)g_free);
g_free (info); g_free (info);
} }
@ -446,6 +459,47 @@ resolve_conflicts (GNCImportMainMatcher *info)
} }
} }
static void
load_hash_tables (GNCImportMainMatcher *info)
{
GtkTreeModel *model = gtk_tree_view_get_model (info->view);
GtkTreeIter import_iter;
GList *accounts_list = NULL;
gboolean valid = gtk_tree_model_get_iter_first (model, &import_iter);
while (valid)
{
GNCImportTransInfo *trans_info = get_trans_info (model, &import_iter);
Split *s = gnc_import_TransInfo_get_fsplit (trans_info);
Account *acc = xaccSplitGetAccount (s);
if (!g_list_find (accounts_list, acc))
accounts_list = g_list_prepend (accounts_list, acc);
valid = gtk_tree_model_iter_next (model, &import_iter);
}
for (GList *m = accounts_list; m; m = m->next)
{
for (GList *n = xaccAccountGetSplitList (m->data); n; n = n->next)
{
const Split *s = n->data;
const Transaction *t = xaccSplitGetParent (s);
const gchar *key;
key = xaccTransGetDescription (t);
if (key && *key)
g_hash_table_insert (info->desc_hash, (gpointer)key, one);
key = xaccTransGetNotes (t);
if (key && *key)
g_hash_table_insert (info->notes_hash, (gpointer)key, one);
key = xaccSplitGetMemo (s);
if (key && *key)
g_hash_table_insert (info->memo_hash, (gpointer)key, one);
}
}
g_list_free (accounts_list);
}
void void
gnc_gen_trans_list_show_all (GNCImportMainMatcher *info) gnc_gen_trans_list_show_all (GNCImportMainMatcher *info)
{ {
@ -471,6 +525,7 @@ gnc_gen_trans_list_show_all (GNCImportMainMatcher *info)
xaccAccountGetAppendText(account)); xaccAccountGetAppendText(account));
gnc_gen_trans_list_create_matches (info); gnc_gen_trans_list_create_matches (info);
load_hash_tables (info);
resolve_conflicts (info); resolve_conflicts (info);
gtk_widget_show_all (GTK_WIDGET(info->main_widget)); gtk_widget_show_all (GTK_WIDGET(info->main_widget));
gnc_gen_trans_list_show_accounts_column (info); gnc_gen_trans_list_show_accounts_column (info);
@ -887,26 +942,162 @@ gnc_gen_trans_assign_transfer_account_to_selection_cb (GtkMenuItem *menuitem,
LEAVE(""); LEAVE("");
} }
typedef enum typedef struct
{ {
DESCRIPTION, Split *split;
MEMO, Transaction *trans;
NOTES, GtkTreeIter iter;
} edit_field; char *orig_desc, *orig_notes, *orig_memo;
} RowInfo;
static void rowinfo_free (RowInfo* info)
{
g_free (info->orig_desc);
g_free (info->orig_notes);
g_free (info->orig_memo);
g_free (info);
}
static RowInfo * row_get_info (gpointer row, GNCImportMainMatcher *info)
{
GNCImportTransInfo *trans_info;
GtkTreeModel *model = gtk_tree_view_get_model (info->view);
RowInfo *retval = g_new (RowInfo, 1);
gtk_tree_model_get_iter (model, &retval->iter, row);
gtk_tree_model_get (model, &retval->iter,
DOWNLOADED_COL_DATA, &trans_info,
DOWNLOADED_COL_DESCRIPTION_ORIGINAL, &retval->orig_desc,
DOWNLOADED_COL_NOTES_ORIGINAL, &retval->orig_notes,
DOWNLOADED_COL_MEMO_ORIGINAL, &retval->orig_memo,
-1);
retval->trans = gnc_import_TransInfo_get_trans (trans_info);
retval->split = gnc_import_TransInfo_get_fsplit (trans_info);
return retval;
}
enum
{
COMPLETION_LIST_ORIGINAL,
COMPLETION_LIST_COLLATED,
COMPLETION_LIST_NORMALIZED_FOLDED,
};
static void populate_list (gpointer key, gpointer value, GtkListStore *list)
{
GtkTreeIter iter;
const char *original = key;
char *collated = g_utf8_collate_key (original, -1);
char *normalized = collated ? g_utf8_normalize (original, -1, G_NORMALIZE_ALL) : NULL;
char *normalized_folded = normalized ? g_utf8_casefold (normalized, -1) : NULL;
gtk_list_store_append (list, &iter);
gtk_list_store_set (list, &iter,
COMPLETION_LIST_ORIGINAL, original,
COMPLETION_LIST_COLLATED, collated,
COMPLETION_LIST_NORMALIZED_FOLDED, normalized_folded,
-1);
g_free (normalized_folded);
g_free (normalized);
g_free (collated);
}
static gboolean
match_func (GtkEntryCompletion *completion, const char *entry_str,
GtkTreeIter *iter, gpointer user_data)
{
GtkTreeModel *model = user_data;
gchar *existing_str = NULL;
gboolean ret = FALSE;
gtk_tree_model_get (model, iter,
COMPLETION_LIST_NORMALIZED_FOLDED, &existing_str,
-1);
if (existing_str && *existing_str && strstr (existing_str, entry_str))
ret = TRUE;
g_free (existing_str);
return ret;
}
static void static void
gnc_gen_trans_edit_fields (GtkMenuItem *menuitem, GNCImportMainMatcher *info, setup_entry (GtkWidget *entry, gboolean sensitive, GHashTable *hash,
edit_field field) const char *initial)
{
GtkEntryCompletion* completion;
GtkListStore *list;
gtk_entry_set_text (GTK_ENTRY (entry), sensitive ? initial : _("Disabled"));
gtk_widget_set_sensitive (entry, sensitive);
if (!sensitive)
return;
list = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
g_hash_table_foreach (hash, (GHFunc)populate_list, list);
if (!g_hash_table_lookup (hash, (gpointer)initial))
populate_list ((gpointer)initial, NULL, list);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list),
COMPLETION_LIST_COLLATED,
GTK_SORT_ASCENDING);
completion = gtk_entry_completion_new ();
gtk_entry_completion_set_model (completion, GTK_TREE_MODEL(list));
gtk_entry_completion_set_text_column (completion, COMPLETION_LIST_ORIGINAL);
gtk_entry_completion_set_match_func (completion,
(GtkEntryCompletionMatchFunc)match_func,
GTK_TREE_MODEL(list), NULL);
gtk_entry_set_completion (GTK_ENTRY (entry), completion);
}
static gboolean
input_new_fields (GNCImportMainMatcher *info, RowInfo *rowinfo,
char **new_desc, char **new_notes, char **new_memo)
{
GtkWidget *desc_entry, *notes_entry, *memo_entry, *label;
GtkWidget *dialog;
GtkBuilder *builder;
gboolean retval = FALSE;
builder = gtk_builder_new ();
gnc_builder_add_from_file (builder, "dialog-import.glade", "transaction_edit_dialog");
dialog = GTK_WIDGET(gtk_builder_get_object (builder, "transaction_edit_dialog"));
desc_entry = GTK_WIDGET(gtk_builder_get_object (builder, "desc_entry"));
memo_entry = GTK_WIDGET(gtk_builder_get_object (builder, "memo_entry"));
notes_entry = GTK_WIDGET(gtk_builder_get_object (builder, "notes_entry"));
setup_entry (desc_entry, info->edit_desc, info->desc_hash, xaccTransGetDescription (rowinfo->trans));
setup_entry (notes_entry, info->edit_notes, info->notes_hash, xaccTransGetNotes (rowinfo->trans));
setup_entry (memo_entry, info->edit_memo, info->memo_hash, xaccSplitGetMemo (rowinfo->split));
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (info->main_widget));
// run the dialog
gtk_widget_show_all (dialog);
switch (gtk_dialog_run (GTK_DIALOG(dialog)))
{
case GTK_RESPONSE_OK:
*new_desc = g_strdup (gtk_entry_get_text (GTK_ENTRY (desc_entry)));
*new_notes = g_strdup (gtk_entry_get_text (GTK_ENTRY (notes_entry)));
*new_memo = g_strdup (gtk_entry_get_text (GTK_ENTRY (memo_entry)));
retval = TRUE;
break;
default:
break;
}
gtk_widget_destroy (dialog);
g_object_unref (G_OBJECT(builder));
return retval;
}
static void
gnc_gen_trans_edit_fields (GtkMenuItem *menuitem, GNCImportMainMatcher *info)
{ {
GtkTreeView *treeview; GtkTreeView *treeview;
GtkTreeSelection *selection; GtkTreeSelection *selection;
GtkTreeModel *model; GtkTreeModel *model;
GList *selected_rows; GList *selected_rows, *row_info_list;
GList *refs = NULL;
GtkTreeStore* store; GtkTreeStore* store;
GNCImportTransInfo *trans_info; char *new_desc = NULL, *new_notes = NULL, *new_memo = NULL;
Transaction* trans;
GtkTreeIter iter;
g_return_if_fail (info != NULL); g_return_if_fail (info != NULL);
ENTER("assign_transfer_account_to_selection_cb"); ENTER("assign_transfer_account_to_selection_cb");
@ -923,81 +1114,108 @@ gnc_gen_trans_edit_fields (GtkMenuItem *menuitem, GNCImportMainMatcher *info,
return; return;
} }
if (selected_rows->next) row_info_list = gnc_g_list_map (selected_rows, (GncGMapFunc) row_get_info, info);
if (input_new_fields (info, row_info_list->data,
&new_desc, &new_notes, &new_memo))
{ {
LEAVE ("User selected multiple rows, not supported"); for (GList *n = row_info_list; n; n = g_list_next (n))
return; {
} RowInfo *row = n->data;
if (info->edit_desc)
g_return_if_fail (gtk_tree_model_get_iter (model, &iter, {
selected_rows->data)); guint64 style = g_strcmp0 (new_desc, row->orig_desc) ?
PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL;
gtk_tree_model_get (model, &iter, DOWNLOADED_COL_DATA, gtk_tree_store_set (store, &row->iter,
&trans_info, -1); DOWNLOADED_COL_DESCRIPTION, new_desc,
trans = gnc_import_TransInfo_get_trans (trans_info); DOWNLOADED_COL_DESCRIPTION_STYLE, style,
-1);
switch (field) xaccTransSetDescription (row->trans, new_desc);
{ if (*new_desc && !g_hash_table_lookup (info->desc_hash, new_desc))
case DESCRIPTION: {
{ char *new_string = g_strdup (new_desc);
char* new_field = info->new_strings = g_list_prepend (info->new_strings, new_string);
gnc_input_dialog_with_entry(info->main_widget, "", g_hash_table_insert (info->desc_hash, new_string, one);
_("Enter new Description"), }
xaccTransGetDescription (trans)); }
if (!new_field) break;
xaccTransSetDescription (trans, new_field); if (info->edit_notes)
gtk_tree_store_set (store, &iter, DOWNLOADED_COL_DESCRIPTION, {
new_field, -1); xaccTransSetNotes (row->trans, new_notes);
g_free (new_field); if (*new_notes && !g_hash_table_lookup (info->notes_hash, new_notes))
break; {
} char *new_string = g_strdup (new_notes);
case MEMO: info->new_strings = g_list_prepend (info->new_strings, new_string);
{ g_hash_table_insert (info->notes_hash, new_string, one);
Split *first_split = }
gnc_import_TransInfo_get_fsplit (trans_info); }
char *new_field =
gnc_input_dialog_with_entry(info->main_widget, "", if (info->edit_memo)
_("Enter new Memo"), {
xaccSplitGetMemo (first_split)); guint64 style = g_strcmp0 (new_memo, row->orig_memo) ?
if (!new_field) break; PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL;
xaccSplitSetMemo (first_split, new_field); gtk_tree_store_set (store, &row->iter,
gtk_tree_store_set (store, &iter, DOWNLOADED_COL_MEMO, new_memo,
DOWNLOADED_COL_MEMO, new_field, -1); DOWNLOADED_COL_MEMO_STYLE, style,
g_free (new_field); -1);
break; xaccSplitSetMemo (row->split, new_memo);
} if (*new_memo && !g_hash_table_lookup (info->memo_hash, new_memo))
case NOTES: {
{ char *new_string = g_strdup (new_memo);
char* new_field = info->new_strings = g_list_prepend (info->new_strings, new_string);
gnc_input_dialog_with_entry(info->main_widget, "", g_hash_table_insert (info->memo_hash, new_string, one);
_("Enter new Notes"), }
xaccTransGetNotes (trans)); }
if (!new_field) break; }
xaccTransSetNotes (trans, new_field); g_free (new_desc);
g_free (new_field); g_free (new_memo);
break; g_free (new_notes);
}
} }
g_list_free_full (row_info_list, (GDestroyNotify)rowinfo_free);
g_list_free_full (selected_rows, (GDestroyNotify)gtk_tree_path_free); g_list_free_full (selected_rows, (GDestroyNotify)gtk_tree_path_free);
LEAVE(""); LEAVE("");
} }
static void static void
gnc_gen_trans_edit_description_cb (GtkMenuItem *menuitem, GNCImportMainMatcher *info) gnc_gen_trans_reset_edits_cb (GtkMenuItem *menuitem, GNCImportMainMatcher *info)
{ {
gnc_gen_trans_edit_fields (menuitem, info, DESCRIPTION); GtkTreeView *treeview;
} GtkTreeModel *model;
GtkTreeStore *store;
GtkTreeSelection *selection;
GList *selected_rows, *row_info_list;
static void g_return_if_fail (info != NULL);
gnc_gen_trans_edit_memo_cb (GtkMenuItem *menuitem, GNCImportMainMatcher *info) ENTER("gnc_gen_trans_reset_edits_cb");
{
gnc_gen_trans_edit_fields (menuitem, info, MEMO);
}
static void treeview = GTK_TREE_VIEW(info->view);
gnc_gen_trans_edit_notes_cb (GtkMenuItem *menuitem, GNCImportMainMatcher *info) model = gtk_tree_view_get_model (treeview);
{ store = GTK_TREE_STORE (model);
gnc_gen_trans_edit_fields (menuitem, info, NOTES); selection = gtk_tree_view_get_selection (treeview);
selected_rows = gtk_tree_selection_get_selected_rows (selection, &model);
if (!selected_rows)
{
LEAVE ("No selected rows");
return;
}
for (GList *n = selected_rows; n; n = g_list_next (n))
{
RowInfo *rowinfo = row_get_info (n->data, info);
xaccTransSetDescription (rowinfo->trans, rowinfo->orig_desc);
xaccTransSetNotes (rowinfo->trans, rowinfo->orig_notes);
xaccSplitSetMemo (rowinfo->split, rowinfo->orig_memo);
gtk_tree_store_set (store, &rowinfo->iter,
DOWNLOADED_COL_DESCRIPTION, rowinfo->orig_desc,
DOWNLOADED_COL_MEMO, rowinfo->orig_memo,
DOWNLOADED_COL_DESCRIPTION_STYLE, PANGO_STYLE_NORMAL,
DOWNLOADED_COL_MEMO_STYLE, PANGO_STYLE_NORMAL,
-1);
rowinfo_free (rowinfo);
};
g_list_free_full (selected_rows, (GDestroyNotify)gtk_tree_path_free);
LEAVE("");
} }
static void static void
@ -1087,16 +1305,19 @@ gnc_gen_trans_row_changed_cb (GtkTreeSelection *selection,
static void static void
gnc_gen_trans_view_popup_menu (GtkTreeView *treeview, gnc_gen_trans_view_popup_menu (GtkTreeView *treeview,
GdkEvent *event, GdkEvent *event,
GNCImportMainMatcher *info, GNCImportMainMatcher *info)
gboolean show_edit_actions)
{ {
GtkWidget *menu, *menuitem; GtkWidget *menu, *menuitem;
GdkEventButton *event_button; GtkTreeModel *model;
GtkTreeSelection *selection;
GList *selected_rows;
const char *desc = NULL, *memo = NULL, *notes = NULL;
gboolean has_edits = FALSE;
ENTER (""); ENTER ("");
menu = gtk_menu_new(); menu = gtk_menu_new();
menuitem = gtk_menu_item_new_with_label ( menuitem = gtk_menu_item_new_with_mnemonic
_("Assign a transfer account to the selection.")); (_("_Assign a transfer account to the selection"));
g_signal_connect (menuitem, "activate", g_signal_connect (menuitem, "activate",
G_CALLBACK( G_CALLBACK(
gnc_gen_trans_assign_transfer_account_to_selection_cb), gnc_gen_trans_assign_transfer_account_to_selection_cb),
@ -1104,37 +1325,66 @@ gnc_gen_trans_view_popup_menu (GtkTreeView *treeview,
DEBUG("Callback to assign destination account to selection connected"); DEBUG("Callback to assign destination account to selection connected");
gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
if (show_edit_actions) model = gtk_tree_view_get_model (treeview);
selection = gtk_tree_view_get_selection (treeview);
selected_rows = gtk_tree_selection_get_selected_rows (selection, &model);
/* initialise */
info->edit_desc = TRUE;
info->edit_notes = TRUE;
info->edit_memo = TRUE;
for (GList *n = selected_rows;
(!has_edits || info->edit_desc || info->edit_notes || info->edit_memo) && n;
n = g_list_next(n))
{ {
menuitem = gtk_menu_item_new_with_label ( RowInfo *rowinfo = row_get_info (n->data, info);
_("Edit description."));
g_signal_connect (menuitem, "activate",
G_CALLBACK (gnc_gen_trans_edit_description_cb),
info);
DEBUG("Callback to edit description");
gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
menuitem = gtk_menu_item_new_with_label ( if (!has_edits &&
_("Edit memo.")); (g_strcmp0 (xaccSplitGetMemo (rowinfo->split), rowinfo->orig_memo) ||
g_signal_connect (menuitem, "activate", g_strcmp0 (xaccTransGetNotes (rowinfo->trans), rowinfo->orig_notes) ||
G_CALLBACK (gnc_gen_trans_edit_memo_cb), g_strcmp0 (xaccTransGetDescription (rowinfo->trans), rowinfo->orig_desc)))
info); has_edits = TRUE;
DEBUG("Callback to edit memo");
gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
menuitem = gtk_menu_item_new_with_label ( if (!n->prev) /* only the first row */
_("Edit notes.")); {
g_signal_connect (menuitem, "activate", desc = xaccTransGetDescription (rowinfo->trans);
G_CALLBACK (gnc_gen_trans_edit_notes_cb), notes = xaccTransGetNotes (rowinfo->trans);
info); memo = xaccSplitGetMemo (rowinfo->split);
DEBUG("Callback to edit notes"); rowinfo_free (rowinfo);
gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem); continue;
}
if (info->edit_desc && g_strcmp0 (desc, xaccTransGetDescription (rowinfo->trans)))
info->edit_desc = FALSE;
if (info->edit_notes && g_strcmp0 (notes, xaccTransGetNotes (rowinfo->trans)))
info->edit_notes = FALSE;
if (info->edit_memo && g_strcmp0 (memo, xaccSplitGetMemo (rowinfo->split)))
info->edit_memo = FALSE;
rowinfo_free (rowinfo);
} }
menuitem = gtk_menu_item_new_with_mnemonic (_("_Edit description, notes, memo"));
gtk_widget_set_sensitive (menuitem,
info->edit_desc || info->edit_notes || info->edit_memo);
g_signal_connect (menuitem, "activate",
G_CALLBACK (gnc_gen_trans_edit_fields),
info);
gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
menuitem = gtk_menu_item_new_with_mnemonic (_("_Reset all edits"));
gtk_widget_set_sensitive (menuitem, has_edits);
g_signal_connect (menuitem, "activate",
G_CALLBACK (gnc_gen_trans_reset_edits_cb),
info);
gtk_menu_shell_append (GTK_MENU_SHELL(menu), menuitem);
gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (treeview), NULL);
gtk_widget_show_all (menu); gtk_widget_show_all (menu);
event_button = (GdkEventButton *) event;
/* Note: event can be NULL here when called from view_onPopupMenu; */ /* Note: event can be NULL here when called from view_onPopupMenu; */
gtk_menu_popup_at_pointer (GTK_MENU(menu), (GdkEvent*)event); gtk_menu_popup_at_pointer (GTK_MENU(menu), (GdkEvent*)event);
g_list_free_full (selected_rows, (GDestroyNotify)gtk_tree_path_free);
LEAVE (""); LEAVE ("");
} }
@ -1160,15 +1410,13 @@ gnc_gen_trans_onButtonPressed_cb (GtkTreeView *treeview,
// or the selected transaction is an ADD. // or the selected transaction is an ADD.
selection = gtk_tree_view_get_selection (treeview); selection = gtk_tree_view_get_selection (treeview);
count = gtk_tree_selection_count_selected_rows (selection); count = gtk_tree_selection_count_selected_rows (selection);
if (count > 1) if (count > 0)
gnc_gen_trans_view_popup_menu (treeview, event, info, FALSE);
else if (count > 0)
{ {
GList* selected; GList* selected;
GtkTreeModel *model; GtkTreeModel *model;
selected = gtk_tree_selection_get_selected_rows (selection, &model); selected = gtk_tree_selection_get_selected_rows (selection, &model);
if (get_action_for_path (selected->data, model) == GNCImport_ADD) if (get_action_for_path (selected->data, model) == GNCImport_ADD)
gnc_gen_trans_view_popup_menu (treeview, event, info, TRUE); gnc_gen_trans_view_popup_menu (treeview, event, info);
g_list_free_full (selected, (GDestroyNotify)gtk_tree_path_free); g_list_free_full (selected, (GDestroyNotify)gtk_tree_path_free);
} }
LEAVE("return TRUE"); LEAVE("return TRUE");
@ -1189,7 +1437,7 @@ gnc_gen_trans_onPopupMenu_cb (GtkTreeView *treeview,
selection = gtk_tree_view_get_selection (treeview); selection = gtk_tree_view_get_selection (treeview);
if (gtk_tree_selection_count_selected_rows (selection) > 0) if (gtk_tree_selection_count_selected_rows (selection) > 0)
{ {
gnc_gen_trans_view_popup_menu (treeview, NULL, info, TRUE); gnc_gen_trans_view_popup_menu (treeview, NULL, info);
LEAVE ("TRUE"); LEAVE ("TRUE");
return TRUE; return TRUE;
} }
@ -1225,6 +1473,12 @@ add_text_column (GtkTreeView *view, const gchar *title, int col_num, gboolean el
else else
gtk_tree_view_column_set_sort_column_id (column, col_num); gtk_tree_view_column_set_sort_column_id (column, col_num);
if (col_num == DOWNLOADED_COL_DESCRIPTION)
gtk_tree_view_column_add_attribute (column, renderer, "style", DOWNLOADED_COL_DESCRIPTION_STYLE);
if (col_num == DOWNLOADED_COL_MEMO)
gtk_tree_view_column_add_attribute (column, renderer, "style", DOWNLOADED_COL_MEMO_STYLE);
g_object_set (G_OBJECT(column), g_object_set (G_OBJECT(column),
"reorderable", TRUE, "reorderable", TRUE,
"resizable", TRUE, "resizable", TRUE,
@ -1268,7 +1522,9 @@ gnc_gen_trans_init_view (GNCImportMainMatcher *info,
view = info->view; view = info->view;
store = gtk_tree_store_new (NUM_DOWNLOADED_COLS, G_TYPE_STRING, G_TYPE_INT64, store = gtk_tree_store_new (NUM_DOWNLOADED_COLS, G_TYPE_STRING, G_TYPE_INT64,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_DOUBLE,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, //description stuff
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, //memo stuff
G_TYPE_STRING, G_TYPE_BOOLEAN,
G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING,
GDK_TYPE_PIXBUF, G_TYPE_POINTER, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_POINTER, G_TYPE_STRING,
G_TYPE_BOOLEAN); G_TYPE_BOOLEAN);
@ -1328,7 +1584,8 @@ gnc_gen_trans_init_view (GNCImportMainMatcher *info,
g_signal_connect (view, "popup-menu", g_signal_connect (view, "popup-menu",
G_CALLBACK(gnc_gen_trans_onPopupMenu_cb), info); G_CALLBACK(gnc_gen_trans_onPopupMenu_cb), info);
info->acct_id_hash = g_hash_table_new (g_direct_hash, g_direct_equal); info->acct_id_hash = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
(GDestroyNotify)g_hash_table_destroy);
} }
static void static void
@ -1472,6 +1729,12 @@ gnc_gen_trans_list_new (GtkWidget *parent,
info); info);
// This ensure this dialog is closed when the session is closed. // This ensure this dialog is closed when the session is closed.
gnc_gui_component_set_session (info->id, gnc_get_current_session()); gnc_gui_component_set_session (info->id, gnc_get_current_session());
info->desc_hash = g_hash_table_new (g_str_hash, g_str_equal);
info->notes_hash = g_hash_table_new (g_str_hash, g_str_equal);
info->memo_hash = g_hash_table_new (g_str_hash, g_str_equal);
info->new_strings = NULL;
return info; return info;
} }
@ -1598,9 +1861,19 @@ update_child_row (GNCImportMatchInfo *sel_match, GtkTreeModel *model, GtkTreeIte
ro_text = xaccPrintAmount (xaccSplitGetAmount (sel_match->split), ro_text = xaccPrintAmount (xaccSplitGetAmount (sel_match->split),
gnc_split_amount_print_info (sel_match->split, TRUE)); gnc_split_amount_print_info (sel_match->split, TRUE));
gtk_tree_store_set (store, &child, DOWNLOADED_COL_AMOUNT, ro_text, -1); gtk_tree_store_set (store, &child,
gtk_tree_store_set (store, &child, DOWNLOADED_COL_MEMO, memo, -1); DOWNLOADED_COL_AMOUNT, ro_text,
gtk_tree_store_set (store, &child, DOWNLOADED_COL_DESCRIPTION, desc, -1); -1);
gtk_tree_store_set (store, &child,
DOWNLOADED_COL_MEMO, memo,
DOWNLOADED_COL_MEMO_STYLE, PANGO_STYLE_NORMAL,
-1);
gtk_tree_store_set (store, &child,
DOWNLOADED_COL_DESCRIPTION, desc,
DOWNLOADED_COL_DESCRIPTION_STYLE, PANGO_STYLE_NORMAL,
-1);
gtk_tree_store_set (store, &child, DOWNLOADED_COL_ENABLE, FALSE, -1); gtk_tree_store_set (store, &child, DOWNLOADED_COL_ENABLE, FALSE, -1);
g_free (text); g_free (text);
@ -1682,13 +1955,22 @@ refresh_model_row (GNCImportMainMatcher *gui,
gtk_tree_store_set (store, iter, DOWNLOADED_COL_AMOUNT, ro_text, -1); gtk_tree_store_set (store, iter, DOWNLOADED_COL_AMOUNT, ro_text, -1);
gtk_tree_store_set (store, iter, DOWNLOADED_COL_AMOUNT_DOUBLE, gnc_numeric_to_double (amount), -1); gtk_tree_store_set (store, iter, DOWNLOADED_COL_AMOUNT_DOUBLE, gnc_numeric_to_double (amount), -1);
/* Notes */
ro_text = xaccTransGetNotes (gnc_import_TransInfo_get_trans (info));
gtk_tree_store_set (store, iter, DOWNLOADED_COL_NOTES_ORIGINAL, ro_text, -1);
/*Description*/ /*Description*/
ro_text = xaccTransGetDescription (gnc_import_TransInfo_get_trans (info) ); ro_text = xaccTransGetDescription (gnc_import_TransInfo_get_trans (info) );
gtk_tree_store_set (store, iter, DOWNLOADED_COL_DESCRIPTION, ro_text, -1); gtk_tree_store_set (store, iter,
DOWNLOADED_COL_DESCRIPTION, ro_text,
DOWNLOADED_COL_DESCRIPTION_ORIGINAL, ro_text,
-1);
/*Memo*/ /*Memo*/
ro_text = xaccSplitGetMemo (split); ro_text = xaccSplitGetMemo (split);
gtk_tree_store_set (store, iter, DOWNLOADED_COL_MEMO, ro_text, -1); gtk_tree_store_set (store, iter,
DOWNLOADED_COL_MEMO, ro_text,
DOWNLOADED_COL_MEMO_ORIGINAL, ro_text,
-1);
/*Actions*/ /*Actions*/
@ -2159,10 +2441,14 @@ query_tooltip_tree_view_cb (GtkWidget *widget, gint x, gint y,
switch (num_col) switch (num_col)
{ {
case DOWNLOADED_COL_DESCRIPTION: case DOWNLOADED_COL_DESCRIPTION:
gtk_tree_model_get (model, &iter, DOWNLOADED_COL_DESCRIPTION, &tooltip_text, -1); gtk_tree_model_get (model, &iter,
DOWNLOADED_COL_DESCRIPTION_ORIGINAL, &tooltip_text,
-1);
break; break;
case DOWNLOADED_COL_MEMO: case DOWNLOADED_COL_MEMO:
gtk_tree_model_get (model, &iter, DOWNLOADED_COL_MEMO, &tooltip_text, -1); gtk_tree_model_get (model, &iter,
DOWNLOADED_COL_MEMO_ORIGINAL, &tooltip_text,
-1);
break; break;
default: default:
break; break;