Skip to content

Commit

Permalink
Merge branch 'maint'
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Feb 15, 2020
2 parents 907bff3 + 555a467 commit efed709
Show file tree
Hide file tree
Showing 19 changed files with 413 additions and 382 deletions.
8 changes: 7 additions & 1 deletion gnucash/gnome-utils/gnc-main-window.c
Expand Up @@ -2859,6 +2859,9 @@ gnc_main_window_disconnect (GncMainWindow *window,
g_signal_handlers_disconnect_by_func(G_OBJECT(page->notebook_page),
G_CALLBACK(gnc_main_window_button_press_cb), page);

// Remove the page_changed signal callback
gnc_plugin_page_disconnect_page_changed (GNC_PLUGIN_PAGE(page));

/* Disconnect the page and summarybar from the window */
priv = GNC_MAIN_WINDOW_GET_PRIVATE(window);
if (priv->current_page == page)
Expand Down Expand Up @@ -3780,7 +3783,7 @@ gnc_quartz_shutdown (GtkosxApplication *theApp, gpointer data)
/* Do Nothing. It's too late. */
}
/* Should quit responds to NSApplicationBlockTermination; returning
* TRUE means "don't terminate", FALSE means "do terminate".
* TRUE means "don't terminate", FALSE means "do terminate".
*/
static gboolean
gnc_quartz_should_quit (GtkosxApplication *theApp, GncMainWindow *window)
Expand Down Expand Up @@ -4431,6 +4434,9 @@ gnc_main_window_cmd_window_move_page (GtkAction *action, GncMainWindow *window)
tab_widget = gtk_notebook_get_tab_label (notebook, page->notebook_page);
menu_widget = gtk_notebook_get_menu_label (notebook, page->notebook_page);

// Remove the page_changed signal callback
gnc_plugin_page_disconnect_page_changed (GNC_PLUGIN_PAGE(page));

/* Ref the page components, then remove it from its old window */
g_object_ref(page);
g_object_ref(tab_widget);
Expand Down
102 changes: 100 additions & 2 deletions gnucash/gnome-utils/gnc-plugin-page.c
Expand Up @@ -58,6 +58,9 @@ static void gnc_plugin_page_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);

static void gnc_plugin_page_default_focus (GncPluginPage *plugin_page,
gboolean on_current_page);

enum
{
INSERTED,
Expand Down Expand Up @@ -102,6 +105,9 @@ typedef struct _GncPluginPagePrivate
gchar *page_color;
gchar *uri;
gchar *statusbar_text;

gulong page_changed_id;

} GncPluginPagePrivate;

GNC_DEFINE_TYPE_WITH_CODE(GncPluginPage, gnc_plugin_page, G_TYPE_OBJECT,
Expand Down Expand Up @@ -371,6 +377,7 @@ gnc_plugin_page_class_init (GncPluginPageClass *klass)

klass->tab_icon = NULL;
klass->plugin_name = NULL;
klass->focus_page = gnc_plugin_page_default_focus;

g_object_class_install_property
(gobject_class,
Expand Down Expand Up @@ -506,18 +513,19 @@ static void
gnc_plugin_page_init (GncPluginPage *page, void *data)
{
GncPluginPagePrivate *priv;

GncPluginPageClass *klass = (GncPluginPageClass*)data;

priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);
priv->page_name = NULL;
priv->page_color = NULL;
priv->uri = NULL;
priv->page_changed_id = 0;

page->window = NULL;
page->summarybar = NULL;

gnc_gobject_tracking_remember(G_OBJECT(page),
gnc_gobject_tracking_remember(G_OBJECT(page),
G_OBJECT_CLASS(klass));
}

Expand Down Expand Up @@ -848,6 +856,96 @@ gnc_plugin_page_set_page_color (GncPluginPage *page, const gchar *color)
}


static void
gnc_plugin_page_default_focus (GncPluginPage *plugin_page,
gboolean on_current_page)
{
GncPluginPagePrivate *priv;

if (!on_current_page)
return;

g_return_if_fail (GNC_IS_PLUGIN_PAGE(plugin_page));

priv = GNC_PLUGIN_PAGE_GET_PRIVATE(plugin_page);

if (G_LIKELY(GNC_PLUGIN_PAGE_GET_CLASS(plugin_page)->focus_page_function))
{
// The page changed signal is emitted multiple times so we need
// to use an idle_add to change the focus
g_idle_remove_by_data (GNC_PLUGIN_PAGE(plugin_page));
g_idle_add ((GSourceFunc)(GNC_PLUGIN_PAGE_GET_CLASS(plugin_page)->focus_page_function),
GNC_PLUGIN_PAGE(plugin_page));
}
}


/* this is the callback for the plugin "page_changed" signal */
static void
gnc_plugin_page_main_window_changed (GtkWindow *window,
GObject *object,
gpointer user_data)
{
GncPluginPage *current_plugin_page = GNC_PLUGIN_PAGE(object);
GncPluginPage *plugin_page = GNC_PLUGIN_PAGE(user_data);
GncPluginPagePrivate *priv;
gboolean on_current_page = FALSE;

// Continue if current_plugin_page is valid
if (!current_plugin_page || !GNC_IS_PLUGIN_PAGE(current_plugin_page))
return;

// Continue only if the plugin_page is valid
if (!plugin_page || !GNC_IS_PLUGIN_PAGE(plugin_page))
return;

priv = GNC_PLUGIN_PAGE_GET_PRIVATE(plugin_page);

if (current_plugin_page == plugin_page)
on_current_page = TRUE;

(GNC_PLUGIN_PAGE_GET_CLASS(plugin_page)->focus_page)(plugin_page, on_current_page);
}

/* this is the callback for the plugin "inserted" signal which will setup
* the callback for the "page_changed" signal and save a pointer to the
* page focus function. */
void
gnc_plugin_page_inserted_cb (GncPluginPage *page, gpointer user_data)
{
GncPluginPagePrivate *priv;

g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));

priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);

priv->page_changed_id = g_signal_connect (G_OBJECT(page->window), "page_changed",
G_CALLBACK(gnc_plugin_page_main_window_changed),
page);

// on initial load try and set the page focus
(GNC_PLUGIN_PAGE_GET_CLASS(page)->focus_page)(page, TRUE);
}


/* disconnect the page_changed callback */
void
gnc_plugin_page_disconnect_page_changed (GncPluginPage *page)
{
GncPluginPagePrivate *priv;

g_return_if_fail (GNC_IS_PLUGIN_PAGE(page));

priv = GNC_PLUGIN_PAGE_GET_PRIVATE(page);

if (priv->page_changed_id > 0)
{
g_signal_handler_disconnect (G_OBJECT(page->window), priv->page_changed_id);
priv->page_changed_id = 0;
}
}


/* Retrieve the Uniform Resource Identifier for this page. */
const gchar *
gnc_plugin_page_get_uri (GncPluginPage *page)
Expand Down
35 changes: 34 additions & 1 deletion gnucash/gnome-utils/gnc-plugin-page.h
Expand Up @@ -156,6 +156,21 @@ typedef struct
* @param window The window where the page was added. */
void (* window_changed) (GncPluginPage *plugin_page, GtkWidget *window);

/** Perform plugin specific actions to set the focus.
*
* @param page The page that was added to a window.
*
* @param on_current_pgae Whether this page is the currentone. */
void (* focus_page) (GncPluginPage *plugin_page, gboolean on_current_page);

/** This function performs specific actions to set the focus on a specific
* widget.
*
* @param page The page that was added to a window.
*
* @param on_current_pgae Whether this page is the currentone. */
gboolean (* focus_page_function) (GncPluginPage *plugin_page);

/** This function vector allows page specific actions to occur
* when the page name is changed.
*
Expand Down Expand Up @@ -393,12 +408,30 @@ const gchar *gnc_plugin_page_get_page_color (GncPluginPage *page);
*
* @param page The page whose name should be retrieved.
*
* @return The color for this page. This string is owned by the page and
* @param The color for this page. This string is owned by the page and
* should not be freed by the caller.
*/
void gnc_plugin_page_set_page_color (GncPluginPage *page, const char *color);


/** Set up the page_changed callback for when the current page is changed.
* This will store a pointer to the page focus funtion passed as a parameter
* so that it can be used in setting up the g_idle_add
*
* @param page The page the callback is setup for.
*
* @param user_data The page focus function
*/
void gnc_plugin_page_inserted_cb (GncPluginPage *page, gpointer user_data);


/** Disconnect the page_changed_id signal callback.
*
* @param page The page whose name should be retrieved.
*/
void gnc_plugin_page_disconnect_page_changed (GncPluginPage *page);


/** Retrieve the Uniform Resource Identifier for this page.
*
* @param page The page whose URI should be retrieved.
Expand Down
8 changes: 8 additions & 0 deletions gnucash/gnome/gnc-plugin-budget.c
Expand Up @@ -149,11 +149,19 @@ gnc_plugin_budget_cmd_new_budget (GtkAction *action,
{
GncBudget *budget;
GncPluginPage *page;
gchar *description, *date;

g_return_if_fail (user_data != NULL);

budget = gnc_budget_new (gnc_get_current_book());
page = gnc_plugin_page_budget_new (budget);

date = qof_print_date (gnc_time (NULL));
description = g_strdup_printf ("%s: %s", _("Created"), date);
gnc_budget_set_description (budget, description);
g_free (description);
g_free (date);

gnc_main_window_open_page (user_data->window, page);
}

Expand Down
47 changes: 17 additions & 30 deletions gnucash/gnome/gnc-plugin-page-account-tree.c
Expand Up @@ -114,6 +114,7 @@ static void gnc_plugin_page_account_tree_init (GncPluginPageAccountTree *plugin_
static void gnc_plugin_page_account_tree_finalize (GObject *object);
static void gnc_plugin_page_account_tree_selected (GObject *object, gpointer user_data);

static gboolean gnc_plugin_page_account_tree_focus_widget (GncPluginPage *plugin_page);
static GtkWidget *gnc_plugin_page_account_tree_create_widget (GncPluginPage *plugin_page);
static void gnc_plugin_page_account_tree_destroy_widget (GncPluginPage *plugin_page);
static void gnc_plugin_page_account_tree_save_page (GncPluginPage *plugin_page, GKeyFile *file, const gchar *group);
Expand Down Expand Up @@ -405,6 +406,7 @@ gnc_plugin_page_account_tree_class_init (GncPluginPageAccountTreeClass *klass)
gnc_plugin_class->destroy_widget = gnc_plugin_page_account_tree_destroy_widget;
gnc_plugin_class->save_page = gnc_plugin_page_account_tree_save_page;
gnc_plugin_class->recreate_page = gnc_plugin_page_account_tree_recreate_page;
gnc_plugin_class->focus_page_function = gnc_plugin_page_account_tree_focus_widget;

plugin_page_signals[ACCOUNT_SELECTED] =
g_signal_new ("account_selected",
Expand Down Expand Up @@ -573,12 +575,16 @@ gnc_plugin_page_account_tree_get_current_account (GncPluginPageAccountTree *page
return account;
}

gboolean
gnc_plugin_page_account_tree_focus (GncPluginPageAccountTree *page)
/**
* Whenever the current page is changed, if an account page is
* the current page, set focus on the tree view.
*/
static gboolean
gnc_plugin_page_account_tree_focus_widget (GncPluginPage *account_plugin_page)
{
if (GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(page))
if (GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(account_plugin_page))
{
GncPluginPageAccountTreePrivate *priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page);
GncPluginPageAccountTreePrivate *priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(account_plugin_page);
GtkTreeView *view = GTK_TREE_VIEW(priv->tree_view);

if (!gtk_widget_is_focus (GTK_WIDGET(view)))
Expand Down Expand Up @@ -636,32 +642,11 @@ 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;
Expand Down Expand Up @@ -759,10 +744,9 @@ 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);
g_signal_connect (G_OBJECT(plugin_page), "inserted",
G_CALLBACK(gnc_plugin_page_inserted_cb),
NULL);

// Read account filter state information from account section
gnc_tree_view_account_restore_filter (GNC_TREE_VIEW_ACCOUNT(priv->tree_view), &priv->fd,
Expand Down Expand Up @@ -798,8 +782,11 @@ gnc_plugin_page_account_tree_destroy_widget (GncPluginPage *plugin_page)
// Destroy the filter override hash table
g_hash_table_destroy(priv->fd.filter_override);

// Remove the page_changed signal callback
gnc_plugin_page_disconnect_page_changed (GNC_PLUGIN_PAGE(plugin_page));

// Remove the page focus idle function if present
g_idle_remove_by_data (GNC_PLUGIN_PAGE_ACCOUNT_TREE (plugin_page));
g_idle_remove_by_data (plugin_page);

if (priv->widget)
{
Expand Down
9 changes: 0 additions & 9 deletions gnucash/gnome/gnc-plugin-page-account-tree.h
Expand Up @@ -95,15 +95,6 @@ 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).
*
Expand Down

0 comments on commit efed709

Please sign in to comment.