Make sure the tree view is the focus on an owner page

This commit is contained in:
Robert Fewell
2017-12-29 10:40:21 +00:00
parent 18fff9635f
commit 34c9ba0549

View File

@@ -387,6 +387,50 @@ gnc_plugin_page_owner_tree_new (GncOwnerType owner_type)
return GNC_PLUGIN_PAGE(plugin_page);
}
static gboolean
gnc_plugin_page_owner_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 an owner page is
* the current page, set focus on the treeview.
*/
static void
gnc_plugin_page_owner_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)
{
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);
// 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_owner_focus,
GTK_TREE_VIEW (priv->tree_view));
}
}
static void
gnc_plugin_page_owner_tree_class_init (GncPluginPageOwnerTreeClass *klass)
{
@@ -554,6 +598,7 @@ gnc_plugin_page_owner_tree_create_widget (GncPluginPage *plugin_page)
{
GncPluginPageOwnerTree *page;
GncPluginPageOwnerTreePrivate *priv;
GncMainWindow *window;
GtkTreeSelection *selection;
GtkTreeView *tree_view;
GtkWidget *scrolled_window;
@@ -668,6 +713,11 @@ gnc_plugin_page_owner_tree_create_widget (GncPluginPage *plugin_page)
gnc_gui_component_set_session (priv->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_owner_main_window_page_changed),
plugin_page);
LEAVE("widget = %p", priv->widget);
return priv->widget;
}