gnucash maint: Multiple changes pushed

Robert Fewell bobit at code.gnucash.org
Sat Jan 25 07:33:12 EST 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/ffe3aa79 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/94cb9650 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/7ee3f430 (commit)
	from  https://github.com/Gnucash/gnucash/commit/a9d51dd9 (commit)



commit ffe3aa792cd236890a9295b762e1a9d3a01ef2de
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sat Jan 11 14:10:41 2020 +0000

    Bug 797522 - Focus after reconcile jumps to a different account
    
    After the use of the reconcile window, the keyboard focus may not be
    on the current account register. This is due to the call for a gui
    refresh which refreshes the pages in reverse qofinstance order and as
    part of this there is a call to grab the keyboard focus on the register
    sheet so the last one will have the keyboard focus which may not be the
    current register, just depends on the order of creation.
    
    To fix this, as part of the main window page changed callback a flag is
    set on the current sheet to indicate it can grab the focus on refresh.

diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index ace2c379d..1d1958698 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -566,6 +566,7 @@ typedef struct GncPluginPageRegisterPrivate
 
     gint lines_default;
     gboolean read_only;
+    gboolean page_focus;
     gboolean enable_refresh; // used to reduce ledger display refreshes
     Query *search_query;     // saved search query for comparison
     Query *filter_query;     // saved filter query for comparison
@@ -1150,6 +1151,7 @@ gnc_plugin_register_main_window_page_changed (GncMainWindow *window,
                                               GncPluginPage *register_plugin_page)
 {
     GncPluginPageRegisterPrivate *priv;
+    GNCSplitReg *gsr;
 
     // We continue only if the plugin_page is a valid
     if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_REGISTER(current_plugin_page) ||
@@ -1157,15 +1159,23 @@ gnc_plugin_register_main_window_page_changed (GncMainWindow *window,
         return;
 
     priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(register_plugin_page);
+    gsr = gnc_plugin_page_register_get_gsr (GNC_PLUGIN_PAGE(register_plugin_page));
 
     if (current_plugin_page == register_plugin_page)
     {
+        priv->page_focus = TRUE;
+
         // The page changed signal is emitted multiple times so we need
         // to use an idle_add to change the focus to the register
         g_idle_remove_by_data (GNC_PLUGIN_PAGE_REGISTER (register_plugin_page));
         g_idle_add ((GSourceFunc)gnc_plugin_page_register_focus,
                       GNC_PLUGIN_PAGE_REGISTER (register_plugin_page));
     }
+    else
+        priv->page_focus = FALSE;
+
+    // set the sheet focus setting
+    gnc_split_reg_set_sheet_focus (gsr, priv->page_focus);
 }
 
 static GtkWidget *
@@ -1194,6 +1204,8 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
         LEAVE("existing widget %p", priv->widget);
         return priv->widget;
     }
+    // on create, the page will be the current page so set the focus flag
+    priv->page_focus = TRUE;
 
     priv->widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
     gtk_box_set_homogeneous (GTK_BOX (priv->widget), FALSE);
diff --git a/gnucash/gnome/gnc-split-reg.c b/gnucash/gnome/gnc-split-reg.c
index f8c3db9ed..599a16705 100644
--- a/gnucash/gnome/gnc-split-reg.c
+++ b/gnucash/gnome/gnc-split-reg.c
@@ -1930,6 +1930,14 @@ gnc_split_reg_focus_on_sheet (GNCSplitReg *gsr)
         gtk_widget_grab_focus (GTK_WIDGET (sheet));
 }
 
+void
+gnc_split_reg_set_sheet_focus (GNCSplitReg *gsr, gboolean has_focus)
+{
+    GnucashRegister *reg = gsr->reg;
+    GnucashSheet *sheet = gnucash_register_get_sheet (reg);
+    gnucash_sheet_set_has_focus (sheet, has_focus);
+}
+
 void
 gnc_split_reg_balancing_entry(GNCSplitReg *gsr, Account *account,
                               time64 statement_date, gnc_numeric balancing_amount)
diff --git a/gnucash/gnome/gnc-split-reg.h b/gnucash/gnome/gnc-split-reg.h
index d54372c8e..8c0f78c24 100644
--- a/gnucash/gnome/gnc-split-reg.h
+++ b/gnucash/gnome/gnc-split-reg.h
@@ -248,6 +248,7 @@ void gnc_split_reg_jump_to_split_amount(GNCSplitReg *gsr, Split *split);
  * Set the focus of the register to the sheet
  **/
 void gnc_split_reg_focus_on_sheet (GNCSplitReg *gsr);
+void gnc_split_reg_set_sheet_focus (GNCSplitReg *gsr, gboolean has_focus);
 
 /*
  * Create a transaction entry with given amount and date. One account is
diff --git a/gnucash/register/register-gnome/gnucash-sheet.c b/gnucash/register/register-gnome/gnucash-sheet.c
index 049411737..36bd9c652 100644
--- a/gnucash/register/register-gnome/gnucash-sheet.c
+++ b/gnucash/register/register-gnome/gnucash-sheet.c
@@ -407,8 +407,10 @@ gnucash_sheet_activate_cursor_cell (GnucashSheet *sheet,
         sheet->direct_update_cell =
             gnucash_sheet_check_direct_update_cell (sheet, virt_loc);
     }
-
-    gtk_widget_grab_focus (GTK_WIDGET(sheet));
+    // when a gui refresh is called, we end up here so only grab the focus
+    // if the sheet is showing on the current plugin_page
+    if (sheet->sheet_has_focus)
+        gtk_widget_grab_focus (GTK_WIDGET(sheet));
 }
 
 
@@ -757,6 +759,12 @@ gnucash_sheet_is_read_only (GnucashSheet *sheet)
     return gnc_table_model_read_only (sheet->table->model);
 }
 
+void
+gnucash_sheet_set_has_focus (GnucashSheet *sheet, gboolean has_focus)
+{
+    sheet->sheet_has_focus = has_focus;
+}
+
 static void
 gnucash_sheet_finalize (GObject *object)
 {
@@ -2764,6 +2772,9 @@ gnucash_sheet_new (Table *table)
 
     sheet = gnucash_sheet_create (table);
 
+    /* on create, the sheet can grab the focus */
+    sheet->sheet_has_focus = TRUE;
+
     /* The cursor */
     sheet->cursor = gnucash_cursor_new (sheet);
 
diff --git a/gnucash/register/register-gnome/gnucash-sheet.h b/gnucash/register/register-gnome/gnucash-sheet.h
index 907cd34e9..c24fe2c19 100644
--- a/gnucash/register/register-gnome/gnucash-sheet.h
+++ b/gnucash/register/register-gnome/gnucash-sheet.h
@@ -112,5 +112,7 @@ gint gnucash_sheet_get_text_offset (GnucashSheet *sheet, const VirtualLocation v
 
 gboolean gnucash_sheet_is_read_only (GnucashSheet *sheet);
 
+void gnucash_sheet_set_has_focus (GnucashSheet *sheet, gboolean has_focus);
+
 /** @} */
 #endif
diff --git a/gnucash/register/register-gnome/gnucash-sheetP.h b/gnucash/register/register-gnome/gnucash-sheetP.h
index 888106832..1c2d96c1d 100644
--- a/gnucash/register/register-gnome/gnucash-sheetP.h
+++ b/gnucash/register/register-gnome/gnucash-sheetP.h
@@ -80,6 +80,8 @@ struct _GnucashSheet
 
     gint editing;
 
+    gboolean sheet_has_focus;
+
     guint button; /* mouse button being held down */
     gboolean grabbed; /* has the grab */
     gdouble button_x, button_y;

commit 94cb96501e4e3a405cd5f059ebb75f0b49c020a4
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sat Jan 11 14:06:13 2020 +0000

    Change the way the focus is added to plugin_pages
    
    This change corrects a previous commit and makes all the plugin_pages
    follow the same format. In the previous commit a test was made for the
    plugin_page to be equal to one returned from get_current_page which
    would always be the case. With this change the respective plugin_page
    is passed as a parameter to the 'page_changed' call back and it is this
    that is tested against the current plugin_page.

diff --git a/gnucash/gnome/gnc-plugin-account-tree.c b/gnucash/gnome/gnc-plugin-account-tree.c
index abe3e5a65..fec9c2f4c 100644
--- a/gnucash/gnome/gnc-plugin-account-tree.c
+++ b/gnucash/gnome/gnc-plugin-account-tree.c
@@ -44,8 +44,6 @@
 static void gnc_plugin_account_tree_class_init (GncPluginAccountTreeClass *klass);
 static void gnc_plugin_account_tree_init (GncPluginAccountTree *plugin);
 static void gnc_plugin_account_tree_finalize (GObject *object);
-static void gnc_plugin_account_tree_add_to_window (GncPlugin *plugin,
-                                                   GncMainWindow *window, GQuark type);
 
 /* Command callbacks */
 static void gnc_plugin_account_tree_cmd_new_account_tree (GtkAction *action, GncMainWindowActionData *data);
@@ -97,26 +95,6 @@ gnc_plugin_account_tree_new (void)
     return GNC_PLUGIN (plugin);
 }
 
-static void
-gnc_plugin_account_tree_main_window_page_changed (GncMainWindow *window,
-        GncPluginPage *plugin_page, gpointer user_data)
-{
-    // We continue only if the plugin_page is a valid
-    if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
-        return;
-
-    if (gnc_main_window_get_current_page (window) == plugin_page)
-    {
-        if (!GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(plugin_page))
-            return;
-
-        // The page changed signal is emitted multiple times so we need
-        // to use an idle_add to change the focus to the tree view
-        g_idle_remove_by_data (GNC_PLUGIN_PAGE_ACCOUNT_TREE (plugin_page));
-        g_idle_add ((GSourceFunc)gnc_plugin_page_account_tree_focus,
-                      GNC_PLUGIN_PAGE_ACCOUNT_TREE (plugin_page));
-    }
-}
 
 /** Initialize the class for a new account tree plugin.  This will set
  *  up any function pointers that override functions in the parent
@@ -138,9 +116,6 @@ gnc_plugin_account_tree_class_init (GncPluginAccountTreeClass *klass)
     /* plugin info */
     plugin_class->plugin_name  = GNC_PLUGIN_ACCOUNT_TREE_NAME;
 
-    /* function overrides */
-    plugin_class->add_to_window = gnc_plugin_account_tree_add_to_window;
-
     /* widget addition/removal */
     plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
     plugin_class->actions      = gnc_plugin_actions;
@@ -176,20 +151,6 @@ gnc_plugin_account_tree_finalize (GObject *object)
     G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
-
-/**
- * Called when this plugin is added to a main window.  Connect a few callbacks
- * here to track page changes.
- *
- */
-static void gnc_plugin_account_tree_add_to_window (GncPlugin *plugin,
-        GncMainWindow *mainwindow,
-        GQuark type)
-{
-    g_signal_connect(mainwindow, "page_changed",
-                     G_CALLBACK(gnc_plugin_account_tree_main_window_page_changed),
-                     plugin);
-}
 /************************************************************
  *                    Command Callbacks                     *
  ************************************************************/
diff --git a/gnucash/gnome/gnc-plugin-budget.c b/gnucash/gnome/gnc-plugin-budget.c
index 0f767047f..2056afe2a 100644
--- a/gnucash/gnome/gnc-plugin-budget.c
+++ b/gnucash/gnome/gnc-plugin-budget.c
@@ -101,28 +101,6 @@ GncPlugin * gnc_plugin_budget_new (void)
     return GNC_PLUGIN(plugin);
 }
 
-static void
-gnc_plugin_budget_main_window_page_changed (GncMainWindow *window,
-                                            GncPluginPage *plugin_page,
-                                            gpointer user_data)
-{
-    // We continue only if the plugin_page is a valid
-    if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
-        return;
-
-    if (gnc_main_window_get_current_page (window) == plugin_page)
-    {
-        if (!GNC_IS_PLUGIN_PAGE_BUDGET(plugin_page))
-            return;
-
-        // The page changed signal is emitted multiple times so we need
-        // to use an idle_add to change the focus to the tree view
-        g_idle_remove_by_data (GNC_PLUGIN_PAGE_BUDGET(plugin_page));
-        g_idle_add ((GSourceFunc)gnc_plugin_page_budget_focus,
-                      GNC_PLUGIN_PAGE_BUDGET(plugin_page));
-    }
-}
-
 G_DEFINE_TYPE_WITH_PRIVATE(GncPluginBudget, gnc_plugin_budget, GNC_TYPE_PLUGIN)
 
 static void
@@ -135,9 +113,6 @@ gnc_plugin_budget_class_init (GncPluginBudgetClass *klass)
     parent_class = g_type_class_peek_parent (klass);
     object_class->finalize = gnc_plugin_budget_finalize;
 
-    /* function overrides */
-    plugin_class->add_to_window = gnc_plugin_budget_add_to_window;
-
     plugin_class->plugin_name  = GNC_PLUGIN_BUDGET_NAME;
     plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
     plugin_class->actions      = gnc_plugin_actions;
@@ -163,20 +138,6 @@ gnc_plugin_budget_finalize (GObject *object)
 
 }
 
-/**
- * Called when this plugin is added to a main window.  Connect a few callbacks
- * here to track page changes.
- *
- */
-static void gnc_plugin_budget_add_to_window (GncPlugin *plugin,
-                                             GncMainWindow *mainwindow,
-                                             GQuark type)
-{
-    g_signal_connect (mainwindow, "page_changed",
-                      G_CALLBACK(gnc_plugin_budget_main_window_page_changed),
-                      plugin);
-}
-
 /************************************************************
  *                    Command Callbacks                     *
  ************************************************************/
diff --git a/gnucash/gnome/gnc-plugin-page-account-tree.c b/gnucash/gnome/gnc-plugin-page-account-tree.c
index ecd5a2369..1f70ad94a 100644
--- a/gnucash/gnome/gnc-plugin-page-account-tree.c
+++ b/gnucash/gnome/gnc-plugin-page-account-tree.c
@@ -636,11 +636,32 @@ gnc_plugin_page_account_editing_finished_cb (gpointer various, GncPluginPageRegi
         gtk_action_set_sensitive (action, TRUE);
 }
 
+static void
+gnc_plugin_account_tree_main_window_page_changed (GncMainWindow *window,
+                                                  GncPluginPage *current_plugin_page,
+                                                  GncPluginPage *account_plugin_page)
+{
+    // We continue only if the plugin_page is a valid
+    if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(current_plugin_page)||
+        !account_plugin_page || !GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(account_plugin_page))
+        return;
+
+    if (current_plugin_page == account_plugin_page)
+    {
+        // The page changed signal is emitted multiple times so we need
+        // to use an idle_add to change the focus to the tree view
+        g_idle_remove_by_data (GNC_PLUGIN_PAGE_ACCOUNT_TREE (account_plugin_page));
+        g_idle_add ((GSourceFunc)gnc_plugin_page_account_tree_focus,
+                      GNC_PLUGIN_PAGE_ACCOUNT_TREE (account_plugin_page));
+    }
+}
+
 static GtkWidget *
 gnc_plugin_page_account_tree_create_widget (GncPluginPage *plugin_page)
 {
     GncPluginPageAccountTree *page;
     GncPluginPageAccountTreePrivate *priv;
+    GncMainWindow *window;
     GtkTreeSelection *selection;
     GtkTreeView *tree_view;
     GtkWidget *scrolled_window;
@@ -738,6 +759,11 @@ gnc_plugin_page_account_tree_create_widget (GncPluginPage *plugin_page)
                            gnc_plugin_page_account_tree_summarybar_position_changed,
                            page);
 
+    window = GNC_MAIN_WINDOW(GNC_PLUGIN_PAGE(page)->window);
+    g_signal_connect (window, "page_changed",
+                      G_CALLBACK(gnc_plugin_account_tree_main_window_page_changed),
+                      plugin_page);
+
     // Read account filter state information from account section
     gnc_tree_view_account_restore_filter (GNC_TREE_VIEW_ACCOUNT(priv->tree_view), &priv->fd,
        gnc_state_get_current(), gnc_tree_view_get_state_section (GNC_TREE_VIEW(priv->tree_view)));
diff --git a/gnucash/gnome/gnc-plugin-page-budget.c b/gnucash/gnome/gnc-plugin-page-budget.c
index 5e5e6dedb..3449f289d 100644
--- a/gnucash/gnome/gnc-plugin-page-budget.c
+++ b/gnucash/gnome/gnc-plugin-page-budget.c
@@ -423,6 +423,27 @@ gnc_plugin_page_budget_refresh_cb (GHashTable *changes, gpointer user_data)
 }
 
 
+static void
+gnc_plugin_budget_main_window_page_changed (GncMainWindow *window,
+                                            GncPluginPage *current_plugin_page,
+                                            GncPluginPage *budget_plugin_page)
+{
+    // We continue only if the plugin_page is a valid
+    if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_BUDGET(current_plugin_page) ||
+        !budget_plugin_page || !GNC_IS_PLUGIN_PAGE_BUDGET(budget_plugin_page))
+        return;
+
+    if (current_plugin_page == budget_plugin_page)
+    {
+        // The page changed signal is emitted multiple times so we need
+        // to use an idle_add to change the focus to the tree view
+        g_idle_remove_by_data (GNC_PLUGIN_PAGE_BUDGET(budget_plugin_page));
+        g_idle_add ((GSourceFunc)gnc_plugin_page_budget_focus,
+                      GNC_PLUGIN_PAGE_BUDGET(budget_plugin_page));
+    }
+}
+
+
 /****************************
  * GncPluginPage Functions  *
  ***************************/
@@ -431,6 +452,7 @@ gnc_plugin_page_budget_create_widget (GncPluginPage *plugin_page)
 {
     GncPluginPageBudget *page;
     GncPluginPageBudgetPrivate *priv;
+    GncMainWindow *window;
 
     ENTER("page %p", plugin_page);
     page = GNC_PLUGIN_PAGE_BUDGET(plugin_page);
@@ -465,6 +487,11 @@ gnc_plugin_page_budget_create_widget (GncPluginPage *plugin_page)
                                     gnc_budget_get_guid (priv->budget),
                                     QOF_EVENT_DESTROY | QOF_EVENT_MODIFY);
 
+    window = GNC_MAIN_WINDOW(GNC_PLUGIN_PAGE(page)->window);
+    g_signal_connect (window, "page_changed",
+                      G_CALLBACK(gnc_plugin_budget_main_window_page_changed),
+                      plugin_page);
+
     LEAVE("widget = %p", priv->budget_view);
     return GTK_WIDGET(priv->budget_view);
 }
diff --git a/gnucash/gnome/gnc-plugin-page-invoice.c b/gnucash/gnome/gnc-plugin-page-invoice.c
index cbc08c9b7..f4fa4c4a7 100644
--- a/gnucash/gnome/gnc-plugin-page-invoice.c
+++ b/gnucash/gnome/gnc-plugin-page-invoice.c
@@ -605,22 +605,17 @@ gnc_plugin_page_invoice_focus (InvoiceWindow *iw)
  */
 static void
 gnc_plugin_page_invoice_main_window_page_changed (GncMainWindow *window,
-        GncPluginPage *plugin_page, gpointer user_data)
+                                                  GncPluginPage *current_plugin_page,
+                                                  GncPluginPage *invoice_plugin_page)
 {
     // We continue only if the plugin_page is a valid
-    if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
+    if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_INVOICE(current_plugin_page) ||
+        !invoice_plugin_page || !GNC_IS_PLUGIN_PAGE_INVOICE(invoice_plugin_page))
         return;
 
-    if (gnc_main_window_get_current_page (window) == plugin_page)
+    if (current_plugin_page == invoice_plugin_page)
     {
-        GncPluginPageInvoice *page;
-        GncPluginPageInvoicePrivate *priv;
-
-        if (!GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page))
-            return;
-
-        page = GNC_PLUGIN_PAGE_INVOICE(plugin_page);
-        priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(page);
+        GncPluginPageInvoicePrivate *priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(invoice_plugin_page);
 
         // The page changed signal is emitted multiple times so we need
         // to use an idle_add to change the focus to the sheet
diff --git a/gnucash/gnome/gnc-plugin-page-owner-tree.c b/gnucash/gnome/gnc-plugin-page-owner-tree.c
index 5022e7907..1b54a06f6 100644
--- a/gnucash/gnome/gnc-plugin-page-owner-tree.c
+++ b/gnucash/gnome/gnc-plugin-page-owner-tree.c
@@ -384,22 +384,17 @@ gnc_plugin_page_owner_focus (GtkTreeView *tree_view)
  */
 static void
 gnc_plugin_page_owner_main_window_page_changed (GncMainWindow *window,
-        GncPluginPage *plugin_page, gpointer user_data)
+                                                GncPluginPage *current_plugin_page,
+                                                GncPluginPage *owner_plugin_page)
 {
     // We continue only if the plugin_page is a valid
-    if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
+    if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_OWNER_TREE(current_plugin_page) ||
+        !owner_plugin_page || !GNC_IS_PLUGIN_PAGE_OWNER_TREE(owner_plugin_page))
         return;
 
-    if (gnc_main_window_get_current_page (window) == plugin_page)
+    if (current_plugin_page == owner_plugin_page)
     {
-        GncPluginPageOwnerTree *page;
-        GncPluginPageOwnerTreePrivate *priv;
-
-        if (!GNC_IS_PLUGIN_PAGE_OWNER_TREE(plugin_page))
-            return;
-
-        page = GNC_PLUGIN_PAGE_OWNER_TREE(plugin_page);
-        priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(page);
+        GncPluginPageOwnerTreePrivate *priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(owner_plugin_page);
 
         // The page changed signal is emitted multiple times so we need
         // to use an idle_add to change the focus to the tree view
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index af60b32a7..ace2c379d 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -1144,11 +1144,36 @@ get_filter_default_num_of_days (GNCLedgerDisplayType ledger_type)
         return "0";
 }
 
+static void
+gnc_plugin_register_main_window_page_changed (GncMainWindow *window,
+                                              GncPluginPage *current_plugin_page,
+                                              GncPluginPage *register_plugin_page)
+{
+    GncPluginPageRegisterPrivate *priv;
+
+    // We continue only if the plugin_page is a valid
+    if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_REGISTER(current_plugin_page) ||
+        !register_plugin_page || !GNC_IS_PLUGIN_PAGE_REGISTER(register_plugin_page))
+        return;
+
+    priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(register_plugin_page);
+
+    if (current_plugin_page == register_plugin_page)
+    {
+        // The page changed signal is emitted multiple times so we need
+        // to use an idle_add to change the focus to the register
+        g_idle_remove_by_data (GNC_PLUGIN_PAGE_REGISTER (register_plugin_page));
+        g_idle_add ((GSourceFunc)gnc_plugin_page_register_focus,
+                      GNC_PLUGIN_PAGE_REGISTER (register_plugin_page));
+    }
+}
+
 static GtkWidget *
 gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
 {
     GncPluginPageRegister *page;
     GncPluginPageRegisterPrivate *priv;
+    GncMainWindow *window;
     GNCLedgerDisplayType ledger_type;
     GncWindow *gnc_window;
     guint numRows;
@@ -1361,6 +1386,11 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
     gnc_split_reg_set_moved_cb
     (priv->gsr, (GFunc)gnc_plugin_page_register_ui_update, page);
 
+    window = GNC_MAIN_WINDOW(GNC_PLUGIN_PAGE(plugin_page)->window);
+    g_signal_connect (window, "page_changed",
+                      G_CALLBACK(gnc_plugin_register_main_window_page_changed),
+                      plugin_page);
+
     /* DRH - Probably lots of other stuff from regWindowLedger should end up here. */
     LEAVE(" ");
     return priv->widget;
diff --git a/gnucash/gnome/gnc-plugin-page-sx-list.c b/gnucash/gnome/gnc-plugin-page-sx-list.c
index 6cbabc586..2f6ab431f 100644
--- a/gnucash/gnome/gnc-plugin-page-sx-list.c
+++ b/gnucash/gnome/gnc-plugin-page-sx-list.c
@@ -205,22 +205,17 @@ gnc_plugin_page_sx_list_focus (GtkTreeView *tree_view)
  */
 static void
 gnc_plugin_page_sx_list_main_window_page_changed (GncMainWindow *window,
-        GncPluginPage *plugin_page, gpointer user_data)
+                                                  GncPluginPage *current_plugin_page,
+                                                  GncPluginPage *sx_plugin_page)
 {
     // We continue only if the plugin_page is a valid
-    if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
+    if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_SX_LIST(current_plugin_page) ||
+        !sx_plugin_page || !GNC_IS_PLUGIN_PAGE_SX_LIST(sx_plugin_page))
         return;
 
-    if (gnc_main_window_get_current_page (window) == plugin_page)
+    if (current_plugin_page == sx_plugin_page)
     {
-        GncPluginPageSxList *page;
-        GncPluginPageSxListPrivate *priv;
-
-        if (!GNC_IS_PLUGIN_PAGE_SX_LIST(plugin_page))
-            return;
-
-        page = GNC_PLUGIN_PAGE_SX_LIST(plugin_page);
-        priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
+        GncPluginPageSxListPrivate *priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(sx_plugin_page);
 
         // The page changed signal is emitted multiple times so we need
         // to use an idle_add to change the focus to the tree view
diff --git a/gnucash/gnome/gnc-plugin-register.c b/gnucash/gnome/gnc-plugin-register.c
index 181a7f883..31ea43be0 100644
--- a/gnucash/gnome/gnc-plugin-register.c
+++ b/gnucash/gnome/gnc-plugin-register.c
@@ -120,27 +120,6 @@ gnc_plugin_register_new (void)
     return GNC_PLUGIN (plugin);
 }
 
-static void
-gnc_plugin_register_main_window_page_changed(GncMainWindow *window,
-        GncPluginPage *plugin_page, gpointer user_data)
-{
-    // We continue only if the plugin_page is a valid
-    if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
-        return;
-
-    if (gnc_main_window_get_current_page (window) == plugin_page)
-    {
-        if (!GNC_IS_PLUGIN_PAGE_REGISTER(plugin_page))
-            return;
-
-        // The page changed signal is emitted multiple times so we need
-        // to use an idle_add to change the focus to the register
-        g_idle_remove_by_data (GNC_PLUGIN_PAGE_REGISTER (plugin_page));
-        g_idle_add ((GSourceFunc)gnc_plugin_page_register_focus,
-                      GNC_PLUGIN_PAGE_REGISTER (plugin_page));
-    }
-}
-
 static void
 gnc_plugin_register_class_init (GncPluginRegisterClass *klass)
 {
@@ -204,10 +183,6 @@ gnc_plugin_register_add_to_window (GncPlugin *plugin,
 {
     gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
                            gnc_plugin_register_pref_changed, window);
-
-    g_signal_connect(window, "page_changed",
-                     G_CALLBACK(gnc_plugin_register_main_window_page_changed),
-                     plugin);
 }
 
 
diff --git a/gnucash/report/report-gnome/gnc-plugin-page-report.c b/gnucash/report/report-gnome/gnc-plugin-page-report.c
index f3bcdaf1d..19272f77e 100644
--- a/gnucash/report/report-gnome/gnc-plugin-page-report.c
+++ b/gnucash/report/report-gnome/gnc-plugin-page-report.c
@@ -250,24 +250,18 @@ gnc_plugin_page_report_focus (GtkWidget *widget)
  */
 static void
 gnc_plugin_page_report_main_window_page_changed (GncMainWindow *window,
-        GncPluginPage *plugin_page, gpointer user_data)
+                                                 GncPluginPage *current_plugin_page,
+                                                 GncPluginPage *report_plugin_page)
 {
     // We continue only if the plugin_page is a valid
-    if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
+    if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_REPORT(current_plugin_page) ||
+        !report_plugin_page || !GNC_IS_PLUGIN_PAGE_REPORT(report_plugin_page))
         return;
 
-    if (gnc_main_window_get_current_page (window) == plugin_page)
+    if (current_plugin_page == report_plugin_page)
     {
-        GncPluginPageReport *report;
-        GncPluginPageReportPrivate *priv;
-        GtkWidget *widget;
-
-        if (!GNC_IS_PLUGIN_PAGE_REPORT(plugin_page))
-            return;
-
-        report = GNC_PLUGIN_PAGE_REPORT(plugin_page);
-        priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
-        widget = gnc_html_get_widget(priv->html);
+        GncPluginPageReportPrivate *priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report_plugin_page);
+        GtkWidget *widget = gnc_html_get_widget (priv->html);
 
         // The page changed signal is emitted multiple times so we need
         // to use an idle_add to change the focus to the webkit widget

commit 7ee3f43037bef40e78b0d792bfbafd4d9cfd42f8
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sat Jan 11 13:54:56 2020 +0000

    Bug 797566 - Crash on use of context menu in importer
    
    If the context menu key is used on the "Assign transfer account page"
    the application will crash. This was down to the call back function
    gnc_gen_trans_onPopupMenu_cb being defined with a second parameter of
    GdkEvent but it should not have, removing this fixes the bug.

diff --git a/gnucash/import-export/import-main-matcher.c b/gnucash/import-export/import-main-matcher.c
index 34320bc8f..dcc228ed7 100644
--- a/gnucash/import-export/import-main-matcher.c
+++ b/gnucash/import-export/import-main-matcher.c
@@ -124,7 +124,6 @@ static gboolean gnc_gen_trans_onButtonPressed_cb (
                     GNCImportMainMatcher *info);
 static gboolean gnc_gen_trans_onPopupMenu_cb (
                     GtkTreeView *treeview,
-                    GdkEvent *event,
                     GNCImportMainMatcher *info);
 static void refresh_model_row (
                     GNCImportMainMatcher *gui,
@@ -651,7 +650,6 @@ gnc_gen_trans_onButtonPressed_cb (GtkTreeView *treeview,
 
 static gboolean
 gnc_gen_trans_onPopupMenu_cb (GtkTreeView *treeview,
-                              GdkEvent *event,
                               GNCImportMainMatcher *info)
 {
     GtkTreeSelection *selection;



Summary of changes:
 gnucash/gnome/gnc-plugin-account-tree.c            | 39 --------------------
 gnucash/gnome/gnc-plugin-budget.c                  | 39 --------------------
 gnucash/gnome/gnc-plugin-page-account-tree.c       | 26 ++++++++++++++
 gnucash/gnome/gnc-plugin-page-budget.c             | 27 ++++++++++++++
 gnucash/gnome/gnc-plugin-page-invoice.c            | 17 ++++-----
 gnucash/gnome/gnc-plugin-page-owner-tree.c         | 17 ++++-----
 gnucash/gnome/gnc-plugin-page-register.c           | 42 ++++++++++++++++++++++
 gnucash/gnome/gnc-plugin-page-sx-list.c            | 17 ++++-----
 gnucash/gnome/gnc-plugin-register.c                | 25 -------------
 gnucash/gnome/gnc-split-reg.c                      |  8 +++++
 gnucash/gnome/gnc-split-reg.h                      |  1 +
 gnucash/import-export/import-main-matcher.c        |  2 --
 gnucash/register/register-gnome/gnucash-sheet.c    | 15 ++++++--
 gnucash/register/register-gnome/gnucash-sheet.h    |  2 ++
 gnucash/register/register-gnome/gnucash-sheetP.h   |  2 ++
 .../report/report-gnome/gnc-plugin-page-report.c   | 20 ++++-------
 16 files changed, 146 insertions(+), 153 deletions(-)



More information about the gnucash-changes mailing list