gnucash master: Bug 797531 - Improve jumps to filtered registers

Robert Fewell bobit at code.gnucash.org
Wed Jun 10 08:41:51 EDT 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/cfc6a6e8 (commit)
	from  https://github.com/Gnucash/gnucash/commit/f749f136 (commit)



commit cfc6a6e8ef925c38f3d0d0403f2283d1b51bcd18
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Wed Jun 10 13:35:22 2020 +0100

    Bug 797531 - Improve jumps to filtered registers
    
    Currently if a jump to a filtered register is made, this could be from
    a report, other register, reconcile window and transaction associations
    and the destination split is not shown the jump will end up at the last
    active cell. This could be confusing so add a test for the destination
    split being visible and warn the user with an option to temporarily
    clear the filter.

diff --git a/gnucash/gnome/dialog-assoc.c b/gnucash/gnome/dialog-assoc.c
index cd761bcf6..84c0d55c5 100644
--- a/gnucash/gnome/dialog-assoc.c
+++ b/gnucash/gnome/dialog-assoc.c
@@ -607,6 +607,10 @@ row_selected_trans_cb (GtkTreeView *view, GtkTreePath *path,
         gsr = gnc_plugin_page_register_get_gsr (page);
         gnc_split_reg_raise (gsr);
 
+        // Test for visibility of split
+        if (gnc_split_reg_clear_filter_for_split (gsr, split))
+            gnc_plugin_page_register_clear_current_filter (GNC_PLUGIN_PAGE(page));
+
         gnc_split_reg_jump_to_split (gsr, split);
     }
 
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index 9d0c7ec33..8346f53b1 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -3035,6 +3035,22 @@ gnc_plugin_page_register_filter_select_range_cb (GtkRadioButton* button,
     LEAVE (" ");
 }
 
+void
+gnc_plugin_page_register_clear_current_filter (GncPluginPage* plugin_page)
+{
+    GncPluginPageRegisterPrivate* priv;
+
+    g_return_if_fail (GNC_IS_PLUGIN_PAGE_REGISTER (plugin_page));
+
+    priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE (plugin_page);
+
+    priv->fd.days = 0;
+    priv->fd.start_time = 0;
+    priv->fd.end_time = 0;
+    priv->fd.cleared_match = (gint)g_ascii_strtoll (DEFAULT_FILTER, NULL, 16);
+
+    gnc_ppr_update_date_query (GNC_PLUGIN_PAGE_REGISTER(plugin_page));
+}
 
 /** This function is called when the "number of days" spin button is
  *  changed which is then saved and updates the time limitation on
@@ -4008,6 +4024,11 @@ gnc_plugin_page_register_cmd_reverse_transaction (GtkAction* action,
     /* Now jump to new trans */
     gsr = gnc_plugin_page_register_get_gsr (GNC_PLUGIN_PAGE (page));
     split = xaccTransFindSplitByAccount(new_trans, account);
+
+    /* Test for visibility of split */
+    if (gnc_split_reg_clear_filter_for_split (gsr, split))
+        gnc_plugin_page_register_clear_current_filter (GNC_PLUGIN_PAGE(page));
+
     gnc_split_reg_jump_to_split (gsr, split);
     LEAVE (" ");
 }
@@ -4781,6 +4802,11 @@ gnc_plugin_page_register_cmd_jump (GtkAction* action,
 
     gnc_main_window_open_page (GNC_MAIN_WINDOW (window), new_page);
     gsr = gnc_plugin_page_register_get_gsr (new_page);
+
+    /* Test for visibility of split */
+    if (gnc_split_reg_clear_filter_for_split (gsr, split))
+        gnc_plugin_page_register_clear_current_filter (GNC_PLUGIN_PAGE(new_page));
+
     gnc_split_reg_jump_to_split (gsr, split);
     LEAVE (" ");
 }
diff --git a/gnucash/gnome/gnc-plugin-page-register.h b/gnucash/gnome/gnc-plugin-page-register.h
index 43b2b2e2f..1d11ca753 100644
--- a/gnucash/gnome/gnc-plugin-page-register.h
+++ b/gnucash/gnome/gnc-plugin-page-register.h
@@ -163,6 +163,16 @@ gnc_plugin_page_register_get_account (GncPluginPageRegister *page);
 Transaction *
 gnc_plugin_page_register_get_current_txn (GncPluginPageRegister *page);
 
+/** This function clears the registers current filter.
+ *  It is used so jumps to splits from other places can be completed 
+ *  otherwise the jump will be to the last active cell.
+ *
+ *  @param plugin_page A pointer to the GncPluginPageRegister.
+ */
+void
+gnc_plugin_page_register_clear_current_filter (GncPluginPage* plugin_page);
+
+
 G_END_DECLS
 /** @} */
 /** @} */
diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index 926d6e92d..5cae8dac6 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -1775,6 +1775,32 @@ gnc_split_reg_expand_trans_toolbar_cb (GtkWidget *widget, gpointer data)
     gsr_emit_simple_signal( gsr, "expand_ent" );
 }
 
+gboolean
+gnc_split_reg_clear_filter_for_split (GNCSplitReg *gsr, Split *split)
+{
+    VirtualCellLocation vcell_loc;
+    SplitRegister *reg;
+
+    if (!gsr)
+        return FALSE;
+
+    reg = gnc_ledger_display_get_split_register (gsr->ledger);
+
+    if (!gnc_split_register_get_split_virt_loc (reg, split, &vcell_loc))
+    {
+        gint response = gnc_ok_cancel_dialog (GTK_WINDOW(gsr->window),
+             GTK_RESPONSE_CANCEL,
+             (_("Target split is currently hidden in this register.\n\n%s\n\n"
+                "Select OK to temporarily clear filter and proceed,\n"
+                "otherwise the last active cell will be selected.")),
+             gsr->filter_text);
+
+        if (response == GTK_RESPONSE_OK)
+            return TRUE;
+    }
+    return FALSE;
+}
+
 /**
  * move the cursor to the split, if present in register
 **/
@@ -1799,7 +1825,6 @@ gnc_split_reg_jump_to_split(GNCSplitReg *gsr, Split *split)
     gnc_ledger_display_refresh( gsr->ledger );
 }
 
-
 /**
  * Move the cursor to the split in the non-blank amount column.
  **/
diff --git a/gnucash/gnome/gnc-split-reg.h b/gnucash/gnome/gnc-split-reg.h
index c7e0aa71b..70110593d 100644
--- a/gnucash/gnome/gnc-split-reg.h
+++ b/gnucash/gnome/gnc-split-reg.h
@@ -251,6 +251,17 @@ void gnc_split_reg_jump_to_blank (GNCSplitReg *gsr);
 void gnc_split_reg_jump_to_split(GNCSplitReg *gsr, Split *split);
 void gnc_split_reg_jump_to_split_amount(GNCSplitReg *gsr, Split *split);
 
+/** Check if the split is visible and ask if register filter should
+ *  be cleared if split is not visible.
+ *
+ *  @param gsr A pointer to GNCSplitReg
+ * 
+ *  @param split A pointer to the split to check visibility on
+ * 
+ *  @return TRUE if the register filter should be cleared
+ **/
+gboolean gnc_split_reg_clear_filter_for_split (GNCSplitReg *gsr, Split *split);
+
 /**
  * Set the focus of the register to the sheet
  **/
diff --git a/gnucash/gnome/top-level.c b/gnucash/gnome/top-level.c
index f7fdf34fa..0462c063e 100644
--- a/gnucash/gnome/top-level.c
+++ b/gnucash/gnome/top-level.c
@@ -197,10 +197,14 @@ gnc_html_register_url_cb (const char *location, const char *label,
     gnc_main_window_open_page (GNC_MAIN_WINDOW (result->parent), page);
     if (split)
     {
-        gsr = gnc_plugin_page_register_get_gsr(page);
-        gnc_split_reg_jump_to_split( gsr, split );
-    }
+        gsr = gnc_plugin_page_register_get_gsr (page);
+
+        /* Test for visibility of split */ 
+        if (gnc_split_reg_clear_filter_for_split (gsr, split))
+            gnc_plugin_page_register_clear_current_filter (page);
 
+        gnc_split_reg_jump_to_split (gsr, split);
+    }
     return TRUE;
 }
 
diff --git a/gnucash/gnome/window-reconcile.c b/gnucash/gnome/window-reconcile.c
index b61df7561..636aa1496 100644
--- a/gnucash/gnome/window-reconcile.c
+++ b/gnucash/gnome/window-reconcile.c
@@ -81,6 +81,7 @@ struct _RecnWindow
 
     GtkUIManager *ui_merge;
     GtkActionGroup *action_group;
+    GncPluginPage *page;
 
     GtkWidget *starting;         /* The starting balance                 */
     GtkWidget *ending;           /* The ending balance                   */
@@ -1019,7 +1020,6 @@ static GNCSplitReg *
 gnc_reconcile_window_open_register(RecnWindow *recnData)
 {
     Account *account = recn_get_account (recnData);
-    GncPluginPage *page;
     GNCSplitReg *gsr;
     gboolean include_children;
 
@@ -1027,10 +1027,10 @@ gnc_reconcile_window_open_register(RecnWindow *recnData)
         return(NULL);
 
     include_children = xaccAccountGetReconcileChildrenStatus (account);
-    page = gnc_plugin_page_register_new (account, include_children);
-    gnc_main_window_open_page (NULL, page);
-    gsr = gnc_plugin_page_register_get_gsr(page);
-    gnc_split_reg_raise(gsr);
+    recnData->page = gnc_plugin_page_register_new (account, include_children);
+    gnc_main_window_open_page (NULL, recnData->page);
+    gsr = gnc_plugin_page_register_get_gsr (recnData->page);
+    gnc_split_reg_raise (gsr);
     return gsr;
 }
 
@@ -1049,6 +1049,11 @@ gnc_reconcile_window_double_click_cb(GNCReconcileView *view, Split *split,
     gsr = gnc_reconcile_window_open_register(recnData);
     if (gsr == NULL)
         return;
+
+    /* Test for visibility of split */
+    if (gnc_split_reg_clear_filter_for_split (gsr, split))
+        gnc_plugin_page_register_clear_current_filter (GNC_PLUGIN_PAGE(recnData->page));
+
     gnc_split_reg_jump_to_split( gsr, split );
 }
 
@@ -1430,6 +1435,11 @@ gnc_ui_reconcile_window_edit_cb(GtkButton *button, gpointer data)
     gsr = gnc_reconcile_window_open_register(recnData);
     if (gsr == NULL)
         return;
+
+    /* Test for visibility of split */
+    if (gnc_split_reg_clear_filter_for_split (gsr, split))
+        gnc_plugin_page_register_clear_current_filter (GNC_PLUGIN_PAGE(recnData->page));
+
     gnc_split_reg_jump_to_split_amount( gsr, split );
 }
 



Summary of changes:
 gnucash/gnome/dialog-assoc.c             |  4 ++++
 gnucash/gnome/gnc-plugin-page-register.c | 26 ++++++++++++++++++++++++++
 gnucash/gnome/gnc-plugin-page-register.h | 10 ++++++++++
 gnucash/gnome/gnc-split-reg.c            | 27 ++++++++++++++++++++++++++-
 gnucash/gnome/gnc-split-reg.h            | 11 +++++++++++
 gnucash/gnome/top-level.c                | 10 +++++++---
 gnucash/gnome/window-reconcile.c         | 20 +++++++++++++++-----
 7 files changed, 99 insertions(+), 9 deletions(-)



More information about the gnucash-changes mailing list