Skip to content

Commit

Permalink
Make sure the tree view is the focus on an owner page
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob-IT committed Dec 29, 2017
1 parent 18fff96 commit 34c9ba0
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions gnucash/gnome/gnc-plugin-page-owner-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 34c9ba0

Please sign in to comment.