Make sure the tree view has focus on Account tree page load

This commit is contained in:
Robert Fewell 2017-12-29 10:20:28 +00:00
parent 26b82b56e0
commit 2314a322d4
3 changed files with 62 additions and 0 deletions

View File

@ -44,6 +44,8 @@
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);
@ -125,6 +127,27 @@ gnc_plugin_account_tree_new (void)
}
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_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
* class, and also configure the private data storage for this
@ -145,6 +168,9 @@ 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;
@ -182,6 +208,20 @@ 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 *
************************************************************/

View File

@ -587,6 +587,19 @@ gnc_plugin_page_account_tree_get_current_account (GncPluginPageAccountTree *page
return account;
}
gboolean
gnc_plugin_page_account_tree_focus (GncPluginPageAccountTree *page)
{
if (GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(page))
{
GncPluginPageAccountTreePrivate *priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
GtkTreeView *view = GTK_TREE_VIEW(priv->tree_view);
if (!gtk_widget_is_focus (GTK_WIDGET(view)))
gtk_widget_grab_focus (GTK_WIDGET(view));
}
return FALSE;
}
/* Virtual Functions */

View File

@ -95,6 +95,15 @@ GncPluginPage *gnc_plugin_page_account_tree_new (void);
Account * gnc_plugin_page_account_tree_get_current_account (GncPluginPageAccountTree *page);
/** Given a pointer to an account tree plugin page, set the focus to
* the GtkTreeView. This is used in a g_idle_add so return FALSE.
*
* @param page The "account tree" page.
*
* @return FALSE;
*/
gboolean gnc_plugin_page_account_tree_focus (GncPluginPageAccountTree *page);
/** Given a pointer to an account, the account tree will open
* and the account will be selected (if any).
*