ake sure the Account tree view has focus when budgets open

This commit is contained in:
Robert Fewell 2017-12-29 10:38:45 +00:00
parent 45a52a5d5e
commit 437a375692
5 changed files with 77 additions and 0 deletions

View File

@ -290,6 +290,17 @@ gnc_budget_view_get_account_from_path(GncBudgetView* view, GtkTreePath* path)
return gnc_tree_view_account_get_account_from_path(GNC_TREE_VIEW_ACCOUNT(priv->tree_view), path);
}
GtkWidget*
gnc_budget_view_get_account_tree_view (GncBudgetView* view)
{
GncBudgetViewPrivate *priv;
g_return_val_if_fail(GNC_IS_BUDGET_VIEW(view), NULL);
priv = GNC_BUDGET_VIEW_GET_PRIVATE(view);
return GTK_WIDGET(priv->fd->tree_view);
}
GList*
gnc_budget_view_get_selected_accounts(GncBudgetView* view)
{

View File

@ -68,6 +68,7 @@ gboolean gnc_budget_view_restore(GncBudgetView* view, GKeyFile *key_file, const
GtkTreeSelection* gnc_budget_view_get_selection(GncBudgetView* view);
Account* gnc_budget_view_get_account_from_path(GncBudgetView* view, GtkTreePath* path);
GList* gnc_budget_view_get_selected_accounts(GncBudgetView* view);
GtkWidget *gnc_budget_view_get_account_tree_view (GncBudgetView* view);
G_END_DECLS

View File

@ -44,6 +44,8 @@ static QofLogModule log_module = GNC_MOD_GUI;
static void gnc_plugin_budget_class_init (GncPluginBudgetClass *klass);
static void gnc_plugin_budget_init (GncPluginBudget *plugin);
static void gnc_plugin_budget_finalize (GObject *object);
static void gnc_plugin_budget_add_to_window (GncPlugin *plugin,
GncMainWindow *window, GQuark type);
/* Command Callbacks */
static void gnc_plugin_budget_cmd_new_budget (GtkAction *action,
@ -126,6 +128,26 @@ GncPlugin * gnc_plugin_budget_new (void)
return GNC_PLUGIN (plugin);
}
static void
gnc_plugin_budget_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_BUDGET(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_budget_focus,
GNC_PLUGIN_PAGE_BUDGET (plugin_page));
}
}
static void
gnc_plugin_budget_class_init (GncPluginBudgetClass *klass)
{
@ -136,6 +158,9 @@ gnc_plugin_budget_class_init (GncPluginBudgetClass *klass)
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gnc_plugin_budget_finalize;
/* function overrides */
plugin_class->add_to_window = gnc_plugin_budget_add_to_window;
plugin_class->plugin_name = GNC_PLUGIN_BUDGET_NAME;
plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
plugin_class->actions = gnc_plugin_actions;
@ -162,6 +187,20 @@ gnc_plugin_budget_finalize(GObject *object)
}
/**
* Called when this plugin is added to a main window. Connect a few callbacks
* here to track page changes.
*
*/
static void gnc_plugin_budget_add_to_window (GncPlugin *plugin,
GncMainWindow *mainwindow,
GQuark type)
{
g_signal_connect(mainwindow, "page_changed",
G_CALLBACK(gnc_plugin_budget_main_window_page_changed),
plugin);
}
/************************************************************
* Command Callbacks *
************************************************************/

View File

@ -368,6 +368,22 @@ gnc_plugin_page_budget_close_cb (gpointer user_data)
}
gboolean
gnc_plugin_page_budget_focus (GncPluginPageBudget *page)
{
if (GNC_IS_PLUGIN_PAGE_BUDGET(page))
{
GncPluginPageBudgetPrivate *priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(page);
GncBudgetView *budget_view = priv->budget_view;
GtkWidget *account_view = gnc_budget_view_get_account_tree_view (budget_view);
if (!gtk_widget_is_focus (GTK_WIDGET(account_view)))
gtk_widget_grab_focus (GTK_WIDGET(account_view));
}
return FALSE;
}
static void
gnc_plugin_page_budget_refresh_cb(GHashTable *changes, gpointer user_data)
{

View File

@ -70,6 +70,16 @@ GncPluginPage *gnc_plugin_page_budget_new (GncBudget *budget);
void gnc_budget_gui_delete_budget(GncBudget *budget);
/** Given a pointer to a budget plugin page, set the focus to
* the Account GtkTreeView. This is used in a g_idle_add so
* return FALSE.
*
* @param page The "budget" page.
*
* @return FALSE
*/
gboolean gnc_plugin_page_budget_focus (GncPluginPageBudget *page);
G_END_DECLS
#endif /* __GNC_PLUGIN_PAGE_BUDGET_H */