From d4dd289113452e2aceedbbecc3ef8ad837ce3859 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Thu, 18 Jul 2019 15:42:27 +0100 Subject: [PATCH] Error when cancelling the create a new account in register When you are asked whether you want to create a new account on the register, possibly due to a typo and you answer no, the same dialogue will appear another three times before resetting the account cell to the original value. These changes eliminate that by returning you back to the cell with the invalid entry so that you can amend / cancel or use the dialogue again to create a new account based on an amended entry. --- gnucash/gnome/gnc-split-reg.c | 14 ++++-- gnucash/register/ledger-core/split-register.c | 44 ++++++++++++------- .../register/register-gnome/gnucash-sheet.c | 5 +++ 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c index 628da74d5c..5291e41bb8 100644 --- a/gnucash/gnome/gnc-split-reg.c +++ b/gnucash/gnome/gnc-split-reg.c @@ -2268,7 +2268,7 @@ gnc_split_reg_set_sort_reversed(GNCSplitReg *gsr, gboolean rev, gboolean refresh gnc_ledger_display_refresh( gsr->ledger ); } -static void +static gboolean gnc_split_reg_record (GNCSplitReg *gsr) { SplitRegister *reg; @@ -2282,7 +2282,7 @@ gnc_split_reg_record (GNCSplitReg *gsr) if (!gnc_split_register_save (reg, TRUE)) { LEAVE("no save"); - return; + return FALSE; } gsr_emit_include_date_signal( gsr, xaccTransGetDate(trans) ); @@ -2291,6 +2291,7 @@ gnc_split_reg_record (GNCSplitReg *gsr) * since gui_refresh events should handle this. */ /* gnc_split_register_redraw (reg); */ LEAVE(" "); + return TRUE; } static gboolean @@ -2354,7 +2355,14 @@ gnc_split_reg_enter( GNCSplitReg *gsr, gboolean next_transaction ) } /* First record the transaction. This will perform a refresh. */ - gnc_split_reg_record( gsr ); + if (!gnc_split_reg_record (gsr)) + { + /* make sure the sheet has the focus if the record is FALSE + * which results in no cursor movement. */ + gnc_split_reg_focus_on_sheet (gsr); + LEAVE(" "); + return; + } if (!goto_blank && next_transaction) gnc_split_register_expand_current_trans (sr, FALSE); diff --git a/gnucash/register/ledger-core/split-register.c b/gnucash/register/ledger-core/split-register.c index 9fc109927e..a73ac93827 100644 --- a/gnucash/register/ledger-core/split-register.c +++ b/gnucash/register/ledger-core/split-register.c @@ -1735,8 +1735,12 @@ gnc_split_register_save (SplitRegister *reg, gboolean do_commit) blank_split, blank_trans, pending_trans, trans); /* Act on any changes to the current cell before the save. */ - (void) gnc_split_register_check_cell (reg, - gnc_table_get_current_cell_name (reg->table)); + if (!gnc_split_register_check_cell (reg, + gnc_table_get_current_cell_name (reg->table))) + { + LEAVE("need another go at changing cell"); + return FALSE; + } if (!gnc_split_register_auto_calc (reg, split)) { @@ -1945,6 +1949,10 @@ gnc_split_register_get_account_by_name (SplitRegister *reg, BasicCell * bcell, if (!account) account = gnc_account_lookup_by_code(gnc_get_current_root_account(), name); + /* if gnc_ui_new_accounts_from_name_window is used, there is a call to + * refresh which subsequently calls this function again, thats the + * reason for static creating_account. */ + if (!account && !creating_account) { /* Ask if they want to create a new one. */ @@ -1958,21 +1966,27 @@ gnc_split_register_get_account_by_name (SplitRegister *reg, BasicCell * bcell, return NULL; } - /* Now have the account. */ - account_name = gnc_get_account_name_for_split_register (account, reg->show_leaf_accounts); - if (g_strcmp0(account_name, gnc_basic_cell_get_value(bcell))) + if (!creating_account) { - /* The name has changed. Update the cell. */ - gnc_combo_cell_set_value (cell, account_name); - gnc_basic_cell_set_changed (&cell->cell, TRUE); - } - g_free (account_name); + /* Now have the account. */ + account_name = gnc_get_account_name_for_split_register (account, reg->show_leaf_accounts); + if (g_strcmp0(account_name, gnc_basic_cell_get_value(bcell))) + { + /* The name has changed. Update the cell. */ + gnc_combo_cell_set_value (cell, account_name); + gnc_basic_cell_set_changed (&cell->cell, TRUE); + } + g_free (account_name); - /* See if the account (either old or new) is a placeholder. */ - if (account && xaccAccountGetPlaceholder (account)) - { - gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)), - placeholder, name); + /* See if the account (either old or new) is a placeholder. */ + if (account && xaccAccountGetPlaceholder (account)) + { + gchar *fullname = gnc_account_get_full_name (account); + gnc_error_dialog (GTK_WINDOW (gnc_split_register_get_parent (reg)), + placeholder, fullname); + g_free (fullname); + return NULL; + } } /* Be seeing you. */ diff --git a/gnucash/register/register-gnome/gnucash-sheet.c b/gnucash/register/register-gnome/gnucash-sheet.c index abfaf6039d..683455b6c0 100644 --- a/gnucash/register/register-gnome/gnucash-sheet.c +++ b/gnucash/register/register-gnome/gnucash-sheet.c @@ -1855,7 +1855,12 @@ gnucash_sheet_key_press_event_internal (GtkWidget *widget, GdkEventKey *event) /* If that would leave the register, abort */ if (abort_move) + { + // Make sure the sheet is the focus + if (!gtk_widget_has_focus(GTK_WIDGET (sheet))) + gtk_widget_grab_focus (GTK_WIDGET (sheet)); return TRUE; + } /* Clear the saved selection for the new cell. */ sheet->end_sel = sheet->start_sel;