From f00f7335b7986ea2c7d14e17cbd4e3b48313d7e1 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Fri, 29 Dec 2017 10:22:50 +0000 Subject: [PATCH] Make sure the sx tree view has focus on page load --- gnucash/gnome/gnc-plugin-page-sx-list.c | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/gnucash/gnome/gnc-plugin-page-sx-list.c b/gnucash/gnome/gnc-plugin-page-sx-list.c index e2334594ff..b70b1f31a7 100644 --- a/gnucash/gnome/gnc-plugin-page-sx-list.c +++ b/gnucash/gnome/gnc-plugin-page-sx-list.c @@ -209,6 +209,49 @@ gnc_plugin_page_sx_list_new (void) } +static gboolean +gnc_plugin_page_sx_list_focus (GtkTreeView *tree_view) +{ + if (GTK_IS_TREE_VIEW(tree_view)) + { + if (!gtk_widget_is_focus (GTK_WIDGET(tree_view))) + gtk_widget_grab_focus (GTK_WIDGET(tree_view)); + } + return FALSE; +} + + +/** + * Whenever the current page is changed, if a schedule editor page is + * the current page, set focus on the treeview. + */ +static void +gnc_plugin_page_sx_list_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) + { + 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); + + // 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_add ((GSourceFunc)gnc_plugin_page_sx_list_focus, + GTK_TREE_VIEW (priv->tree_view)); + } +} + + static void gnc_plugin_page_sx_list_class_init (GncPluginPageSxListClass *klass) { @@ -355,6 +398,7 @@ gnc_plugin_page_sx_list_create_widget (GncPluginPage *plugin_page) { GncPluginPageSxList *page; GncPluginPageSxListPrivate *priv; + GncMainWindow *window; GtkWidget *widget; GtkWidget *vbox; GtkWidget *label; @@ -481,6 +525,11 @@ gnc_plugin_page_sx_list_create_widget (GncPluginPage *plugin_page) gnc_gui_component_set_session (priv->gnc_component_id, gnc_get_current_session()); + window = GNC_MAIN_WINDOW(GNC_PLUGIN_PAGE(plugin_page)->window); + g_signal_connect(window, "page_changed", + G_CALLBACK(gnc_plugin_page_sx_list_main_window_page_changed), + plugin_page); + return priv->widget; }