Change the way the focus is added to plugin_pages

This change corrects a previous commit and makes all the plugin_pages
follow the same format. In the previous commit a test was made for the
plugin_page to be equal to one returned from get_current_page which
would always be the case. With this change the respective plugin_page
is passed as a parameter to the 'page_changed' call back and it is this
that is tested against the current plugin_page.
This commit is contained in:
Robert Fewell 2020-01-11 14:06:13 +00:00
parent 7ee3f43037
commit 94cb96501e
10 changed files with 108 additions and 149 deletions

View File

@ -44,8 +44,6 @@
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);
@ -97,26 +95,6 @@ gnc_plugin_account_tree_new (void)
return GNC_PLUGIN (plugin);
}
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_remove_by_data (GNC_PLUGIN_PAGE_ACCOUNT_TREE (plugin_page));
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
@ -138,9 +116,6 @@ 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;
@ -176,20 +151,6 @@ 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

@ -101,28 +101,6 @@ 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_remove_by_data (GNC_PLUGIN_PAGE_BUDGET(plugin_page));
g_idle_add ((GSourceFunc)gnc_plugin_page_budget_focus,
GNC_PLUGIN_PAGE_BUDGET(plugin_page));
}
}
G_DEFINE_TYPE_WITH_PRIVATE(GncPluginBudget, gnc_plugin_budget, GNC_TYPE_PLUGIN)
static void
@ -135,9 +113,6 @@ 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;
@ -163,20 +138,6 @@ 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

@ -636,11 +636,32 @@ gnc_plugin_page_account_editing_finished_cb (gpointer various, GncPluginPageRegi
gtk_action_set_sensitive (action, TRUE);
}
static void
gnc_plugin_account_tree_main_window_page_changed (GncMainWindow *window,
GncPluginPage *current_plugin_page,
GncPluginPage *account_plugin_page)
{
// We continue only if the plugin_page is a valid
if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(current_plugin_page)||
!account_plugin_page || !GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(account_plugin_page))
return;
if (current_plugin_page == account_plugin_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_remove_by_data (GNC_PLUGIN_PAGE_ACCOUNT_TREE (account_plugin_page));
g_idle_add ((GSourceFunc)gnc_plugin_page_account_tree_focus,
GNC_PLUGIN_PAGE_ACCOUNT_TREE (account_plugin_page));
}
}
static GtkWidget *
gnc_plugin_page_account_tree_create_widget (GncPluginPage *plugin_page)
{
GncPluginPageAccountTree *page;
GncPluginPageAccountTreePrivate *priv;
GncMainWindow *window;
GtkTreeSelection *selection;
GtkTreeView *tree_view;
GtkWidget *scrolled_window;
@ -738,6 +759,11 @@ gnc_plugin_page_account_tree_create_widget (GncPluginPage *plugin_page)
gnc_plugin_page_account_tree_summarybar_position_changed,
page);
window = GNC_MAIN_WINDOW(GNC_PLUGIN_PAGE(page)->window);
g_signal_connect (window, "page_changed",
G_CALLBACK(gnc_plugin_account_tree_main_window_page_changed),
plugin_page);
// Read account filter state information from account section
gnc_tree_view_account_restore_filter (GNC_TREE_VIEW_ACCOUNT(priv->tree_view), &priv->fd,
gnc_state_get_current(), gnc_tree_view_get_state_section (GNC_TREE_VIEW(priv->tree_view)));

View File

@ -423,6 +423,27 @@ gnc_plugin_page_budget_refresh_cb (GHashTable *changes, gpointer user_data)
}
static void
gnc_plugin_budget_main_window_page_changed (GncMainWindow *window,
GncPluginPage *current_plugin_page,
GncPluginPage *budget_plugin_page)
{
// We continue only if the plugin_page is a valid
if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_BUDGET(current_plugin_page) ||
!budget_plugin_page || !GNC_IS_PLUGIN_PAGE_BUDGET(budget_plugin_page))
return;
if (current_plugin_page == budget_plugin_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_remove_by_data (GNC_PLUGIN_PAGE_BUDGET(budget_plugin_page));
g_idle_add ((GSourceFunc)gnc_plugin_page_budget_focus,
GNC_PLUGIN_PAGE_BUDGET(budget_plugin_page));
}
}
/****************************
* GncPluginPage Functions *
***************************/
@ -431,6 +452,7 @@ gnc_plugin_page_budget_create_widget (GncPluginPage *plugin_page)
{
GncPluginPageBudget *page;
GncPluginPageBudgetPrivate *priv;
GncMainWindow *window;
ENTER("page %p", plugin_page);
page = GNC_PLUGIN_PAGE_BUDGET(plugin_page);
@ -465,6 +487,11 @@ gnc_plugin_page_budget_create_widget (GncPluginPage *plugin_page)
gnc_budget_get_guid (priv->budget),
QOF_EVENT_DESTROY | QOF_EVENT_MODIFY);
window = GNC_MAIN_WINDOW(GNC_PLUGIN_PAGE(page)->window);
g_signal_connect (window, "page_changed",
G_CALLBACK(gnc_plugin_budget_main_window_page_changed),
plugin_page);
LEAVE("widget = %p", priv->budget_view);
return GTK_WIDGET(priv->budget_view);
}

View File

@ -605,22 +605,17 @@ gnc_plugin_page_invoice_focus (InvoiceWindow *iw)
*/
static void
gnc_plugin_page_invoice_main_window_page_changed (GncMainWindow *window,
GncPluginPage *plugin_page, gpointer user_data)
GncPluginPage *current_plugin_page,
GncPluginPage *invoice_plugin_page)
{
// We continue only if the plugin_page is a valid
if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_INVOICE(current_plugin_page) ||
!invoice_plugin_page || !GNC_IS_PLUGIN_PAGE_INVOICE(invoice_plugin_page))
return;
if (gnc_main_window_get_current_page (window) == plugin_page)
if (current_plugin_page == invoice_plugin_page)
{
GncPluginPageInvoice *page;
GncPluginPageInvoicePrivate *priv;
if (!GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page))
return;
page = GNC_PLUGIN_PAGE_INVOICE(plugin_page);
priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(page);
GncPluginPageInvoicePrivate *priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(invoice_plugin_page);
// The page changed signal is emitted multiple times so we need
// to use an idle_add to change the focus to the sheet

View File

@ -384,22 +384,17 @@ gnc_plugin_page_owner_focus (GtkTreeView *tree_view)
*/
static void
gnc_plugin_page_owner_main_window_page_changed (GncMainWindow *window,
GncPluginPage *plugin_page, gpointer user_data)
GncPluginPage *current_plugin_page,
GncPluginPage *owner_plugin_page)
{
// We continue only if the plugin_page is a valid
if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_OWNER_TREE(current_plugin_page) ||
!owner_plugin_page || !GNC_IS_PLUGIN_PAGE_OWNER_TREE(owner_plugin_page))
return;
if (gnc_main_window_get_current_page (window) == plugin_page)
if (current_plugin_page == owner_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);
GncPluginPageOwnerTreePrivate *priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(owner_plugin_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

View File

@ -1144,11 +1144,36 @@ get_filter_default_num_of_days (GNCLedgerDisplayType ledger_type)
return "0";
}
static void
gnc_plugin_register_main_window_page_changed (GncMainWindow *window,
GncPluginPage *current_plugin_page,
GncPluginPage *register_plugin_page)
{
GncPluginPageRegisterPrivate *priv;
// We continue only if the plugin_page is a valid
if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_REGISTER(current_plugin_page) ||
!register_plugin_page || !GNC_IS_PLUGIN_PAGE_REGISTER(register_plugin_page))
return;
priv = GNC_PLUGIN_PAGE_REGISTER_GET_PRIVATE(register_plugin_page);
if (current_plugin_page == register_plugin_page)
{
// The page changed signal is emitted multiple times so we need
// to use an idle_add to change the focus to the register
g_idle_remove_by_data (GNC_PLUGIN_PAGE_REGISTER (register_plugin_page));
g_idle_add ((GSourceFunc)gnc_plugin_page_register_focus,
GNC_PLUGIN_PAGE_REGISTER (register_plugin_page));
}
}
static GtkWidget *
gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
{
GncPluginPageRegister *page;
GncPluginPageRegisterPrivate *priv;
GncMainWindow *window;
GNCLedgerDisplayType ledger_type;
GncWindow *gnc_window;
guint numRows;
@ -1361,6 +1386,11 @@ gnc_plugin_page_register_create_widget (GncPluginPage *plugin_page)
gnc_split_reg_set_moved_cb
(priv->gsr, (GFunc)gnc_plugin_page_register_ui_update, page);
window = GNC_MAIN_WINDOW(GNC_PLUGIN_PAGE(plugin_page)->window);
g_signal_connect (window, "page_changed",
G_CALLBACK(gnc_plugin_register_main_window_page_changed),
plugin_page);
/* DRH - Probably lots of other stuff from regWindowLedger should end up here. */
LEAVE(" ");
return priv->widget;

View File

@ -205,22 +205,17 @@ gnc_plugin_page_sx_list_focus (GtkTreeView *tree_view)
*/
static void
gnc_plugin_page_sx_list_main_window_page_changed (GncMainWindow *window,
GncPluginPage *plugin_page, gpointer user_data)
GncPluginPage *current_plugin_page,
GncPluginPage *sx_plugin_page)
{
// We continue only if the plugin_page is a valid
if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_SX_LIST(current_plugin_page) ||
!sx_plugin_page || !GNC_IS_PLUGIN_PAGE_SX_LIST(sx_plugin_page))
return;
if (gnc_main_window_get_current_page (window) == plugin_page)
if (current_plugin_page == sx_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);
GncPluginPageSxListPrivate *priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(sx_plugin_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

View File

@ -120,27 +120,6 @@ gnc_plugin_register_new (void)
return GNC_PLUGIN (plugin);
}
static void
gnc_plugin_register_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_REGISTER(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 register
g_idle_remove_by_data (GNC_PLUGIN_PAGE_REGISTER (plugin_page));
g_idle_add ((GSourceFunc)gnc_plugin_page_register_focus,
GNC_PLUGIN_PAGE_REGISTER (plugin_page));
}
}
static void
gnc_plugin_register_class_init (GncPluginRegisterClass *klass)
{
@ -204,10 +183,6 @@ gnc_plugin_register_add_to_window (GncPlugin *plugin,
{
gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL_REGISTER, NULL,
gnc_plugin_register_pref_changed, window);
g_signal_connect(window, "page_changed",
G_CALLBACK(gnc_plugin_register_main_window_page_changed),
plugin);
}

View File

@ -250,24 +250,18 @@ gnc_plugin_page_report_focus (GtkWidget *widget)
*/
static void
gnc_plugin_page_report_main_window_page_changed (GncMainWindow *window,
GncPluginPage *plugin_page, gpointer user_data)
GncPluginPage *current_plugin_page,
GncPluginPage *report_plugin_page)
{
// We continue only if the plugin_page is a valid
if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE_REPORT(current_plugin_page) ||
!report_plugin_page || !GNC_IS_PLUGIN_PAGE_REPORT(report_plugin_page))
return;
if (gnc_main_window_get_current_page (window) == plugin_page)
if (current_plugin_page == report_plugin_page)
{
GncPluginPageReport *report;
GncPluginPageReportPrivate *priv;
GtkWidget *widget;
if (!GNC_IS_PLUGIN_PAGE_REPORT(plugin_page))
return;
report = GNC_PLUGIN_PAGE_REPORT(plugin_page);
priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
widget = gnc_html_get_widget(priv->html);
GncPluginPageReportPrivate *priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report_plugin_page);
GtkWidget *widget = gnc_html_get_widget (priv->html);
// The page changed signal is emitted multiple times so we need
// to use an idle_add to change the focus to the webkit widget