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.
This commit is contained in:
Robert Fewell 2020-06-08 17:16:23 +01:00
parent 4fba473570
commit cb69b806e7
4 changed files with 113 additions and 92 deletions

View File

@ -338,6 +338,10 @@ gnc_embedded_window_setup_window (GncEmbeddedWindow *window)
g_signal_connect (G_OBJECT (window->ui_merge), "add_widget", g_signal_connect (G_OBJECT (window->ui_merge), "add_widget",
G_CALLBACK (gnc_embedded_window_add_widget), window); 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; priv->action_group = NULL;
LEAVE(" "); LEAVE(" ");
} }

View File

@ -3490,95 +3490,6 @@ gnc_main_window_init_menu_updaters (GncMainWindow *window)
G_CALLBACK (gnc_main_window_edit_menu_hide_cb), 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 static void
gnc_main_window_window_menu (GncMainWindow *window) 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_signal_connect (G_OBJECT (window->ui_merge), "add_widget",
G_CALLBACK (gnc_main_window_add_widget), window); 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_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"); filename = gnc_filepath_locate_ui_file("gnc-main-window-ui.xml");

View File

@ -210,3 +210,93 @@ gnc_window_show_progress (const char *message, double percentage)
while (gtk_events_pending ()) while (gtk_events_pending ())
gtk_main_iteration (); 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 */

View File

@ -79,6 +79,22 @@ GncWindow *gnc_window_get_progressbar_window (void);
GtkWidget *gnc_window_get_progressbar (GncWindow *window); GtkWidget *gnc_window_get_progressbar (GncWindow *window);
void gnc_window_show_progress (const char *message, double percentage); 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 G_END_DECLS
#endif /* __GNC_WINDOW_H */ #endif /* __GNC_WINDOW_H */