From cb69b806e7afc3e35adc3679f9ef580492484384 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Mon, 8 Jun 2020 17:16:23 +0100 Subject: [PATCH] Update Schedule Transaction Template dialog status bar Copy the functions from gnc_main_window that updates the status bar with the action tooltips to gnc_window so that both GncMainWindow and GncEmbeddedWindow can use without duplicating code. --- gnucash/gnome-utils/gnc-embedded-window.c | 4 + gnucash/gnome-utils/gnc-main-window.c | 95 +---------------------- gnucash/gnome-utils/gnc-window.c | 90 +++++++++++++++++++++ gnucash/gnome-utils/gnc-window.h | 16 ++++ 4 files changed, 113 insertions(+), 92 deletions(-) diff --git a/gnucash/gnome-utils/gnc-embedded-window.c b/gnucash/gnome-utils/gnc-embedded-window.c index 352eb368fd..1e57cbb2e8 100644 --- a/gnucash/gnome-utils/gnc-embedded-window.c +++ b/gnucash/gnome-utils/gnc-embedded-window.c @@ -338,6 +338,10 @@ gnc_embedded_window_setup_window (GncEmbeddedWindow *window) g_signal_connect (G_OBJECT (window->ui_merge), "add_widget", G_CALLBACK (gnc_embedded_window_add_widget), window); + /* Use the "connect-proxy" signal for tooltip display in the status bar */ + g_signal_connect (G_OBJECT (window->ui_merge), "connect-proxy", + G_CALLBACK (gnc_window_connect_proxy), priv->statusbar); + priv->action_group = NULL; LEAVE(" "); } diff --git a/gnucash/gnome-utils/gnc-main-window.c b/gnucash/gnome-utils/gnc-main-window.c index 4829f01542..36c5a85ba8 100644 --- a/gnucash/gnome-utils/gnc-main-window.c +++ b/gnucash/gnome-utils/gnc-main-window.c @@ -3490,95 +3490,6 @@ gnc_main_window_init_menu_updaters (GncMainWindow *window) G_CALLBACK (gnc_main_window_edit_menu_hide_cb), window); } -/* CS: This callback functions will set the statusbar text to the - * "tooltip" property of the currently selected GtkAction. - * - * This code is directly copied from gtk+/test/testmerge.c. - * Thanks to (L)GPL! */ -typedef struct _ActionStatus ActionStatus; -struct _ActionStatus -{ - GtkAction *action; - GtkWidget *statusbar; -}; - -static void -action_status_destroy (gpointer data) -{ - ActionStatus *action_status = data; - - g_object_unref (action_status->action); - g_object_unref (action_status->statusbar); - - g_free (action_status); -} - -static void -set_tip (GtkWidget *widget) -{ - ActionStatus *data; - gchar *tooltip; - - data = g_object_get_data (G_OBJECT (widget), "action-status"); - - if (data) - { - g_object_get (data->action, "tooltip", &tooltip, NULL); - - gtk_statusbar_push (GTK_STATUSBAR (data->statusbar), 0, - tooltip ? tooltip : " "); - - g_free (tooltip); - } -} - -static void -unset_tip (GtkWidget *widget) -{ - ActionStatus *data; - - data = g_object_get_data (G_OBJECT (widget), "action-status"); - - if (data) - gtk_statusbar_pop (GTK_STATUSBAR (data->statusbar), 0); -} - -static void -connect_proxy (GtkUIManager *merge, - GtkAction *action, - GtkWidget *proxy, - GtkWidget *statusbar) -{ - if (GTK_IS_MENU_ITEM (proxy)) - { - ActionStatus *data; - - data = g_object_get_data (G_OBJECT (proxy), "action-status"); - if (data) - { - g_object_unref (data->action); - g_object_unref (data->statusbar); - - data->action = g_object_ref (action); - data->statusbar = g_object_ref (statusbar); - } - else - { - data = g_new0 (ActionStatus, 1); - - data->action = g_object_ref (action); - data->statusbar = g_object_ref (statusbar); - - g_object_set_data_full (G_OBJECT (proxy), "action-status", - data, action_status_destroy); - - g_signal_connect (proxy, "select", G_CALLBACK (set_tip), NULL); - g_signal_connect (proxy, "deselect", G_CALLBACK (unset_tip), NULL); - } - } -} -/* CS: end copied code from gtk+/test/testmerge.c */ - static void gnc_main_window_window_menu (GncMainWindow *window) { @@ -3700,10 +3611,10 @@ gnc_main_window_setup_window (GncMainWindow *window) g_signal_connect (G_OBJECT (window->ui_merge), "add_widget", G_CALLBACK (gnc_main_window_add_widget), window); - /* Use the "connect-proxy" signal for tooltip display in the - status bar */ + + /* Use the "connect-proxy" signal for tooltip display in the status bar */ g_signal_connect (G_OBJECT (window->ui_merge), "connect-proxy", - G_CALLBACK (connect_proxy), priv->statusbar); + G_CALLBACK (gnc_window_connect_proxy), priv->statusbar); filename = gnc_filepath_locate_ui_file("gnc-main-window-ui.xml"); diff --git a/gnucash/gnome-utils/gnc-window.c b/gnucash/gnome-utils/gnc-window.c index c0de5658b8..d84d41a98e 100644 --- a/gnucash/gnome-utils/gnc-window.c +++ b/gnucash/gnome-utils/gnc-window.c @@ -210,3 +210,93 @@ gnc_window_show_progress (const char *message, double percentage) while (gtk_events_pending ()) gtk_main_iteration (); } + + +/* CS: This callback functions will set the statusbar text to the + * "tooltip" property of the currently selected GtkAction. + * + * This code is directly copied from gtk+/test/testmerge.c. + * Thanks to (L)GPL! */ +typedef struct _ActionStatus ActionStatus; +struct _ActionStatus +{ + GtkAction *action; + GtkWidget *statusbar; +}; + +static void +action_status_destroy (gpointer data) +{ + ActionStatus *action_status = data; + + g_object_unref (action_status->action); + g_object_unref (action_status->statusbar); + + g_free (action_status); +} + +static void +set_tip (GtkWidget *widget) +{ + ActionStatus *data; + gchar *tooltip; + + data = g_object_get_data (G_OBJECT (widget), "action-status"); + + if (data) + { + g_object_get (data->action, "tooltip", &tooltip, NULL); + + gtk_statusbar_push (GTK_STATUSBAR (data->statusbar), 0, + tooltip ? tooltip : " "); + + g_free (tooltip); + } +} + +static void +unset_tip (GtkWidget *widget) +{ + ActionStatus *data; + + data = g_object_get_data (G_OBJECT (widget), "action-status"); + + if (data) + gtk_statusbar_pop (GTK_STATUSBAR (data->statusbar), 0); +} + +void +gnc_window_connect_proxy (GtkUIManager *merge, + GtkAction *action, + GtkWidget *proxy, + GtkWidget *statusbar) +{ + if (GTK_IS_MENU_ITEM (proxy)) + { + ActionStatus *data; + + data = g_object_get_data (G_OBJECT (proxy), "action-status"); + if (data) + { + g_object_unref (data->action); + g_object_unref (data->statusbar); + + data->action = g_object_ref (action); + data->statusbar = g_object_ref (statusbar); + } + else + { + data = g_new0 (ActionStatus, 1); + + data->action = g_object_ref (action); + data->statusbar = g_object_ref (statusbar); + + g_object_set_data_full (G_OBJECT (proxy), "action-status", + data, action_status_destroy); + + g_signal_connect (proxy, "select", G_CALLBACK (set_tip), NULL); + g_signal_connect (proxy, "deselect", G_CALLBACK (unset_tip), NULL); + } + } +} +/* CS: end copied code from gtk+/test/testmerge.c */ diff --git a/gnucash/gnome-utils/gnc-window.h b/gnucash/gnome-utils/gnc-window.h index fa9b23a225..c8144dc16d 100644 --- a/gnucash/gnome-utils/gnc-window.h +++ b/gnucash/gnome-utils/gnc-window.h @@ -79,6 +79,22 @@ GncWindow *gnc_window_get_progressbar_window (void); GtkWidget *gnc_window_get_progressbar (GncWindow *window); void gnc_window_show_progress (const char *message, double percentage); +/** This callback functions will set the statusbar text to the + * "tooltip" property of the currently selected GtkAction + * + * @param merge A pointer to the ui manager + * + * @param action A pointer to the action + * + * @param proxy A pointer to the proxy + * + * @param statusbar A pointer to the statusbar widget + */ +void gnc_window_connect_proxy (GtkUIManager *merge, + GtkAction *action, + GtkWidget *proxy, + GtkWidget *statusbar); + G_END_DECLS #endif /* __GNC_WINDOW_H */