Make sure the sx tree view has focus on page load

This commit is contained in:
Robert Fewell 2017-12-29 10:22:50 +00:00
parent 13d5570b47
commit f00f7335b7

View File

@ -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;
}