[easytag] Show menu item tooltips in the status bar



commit f048c43dc435392c4f703642eb75aa160f994c0e
Author: David King <amigadave amigadave com>
Date:   Wed May 15 22:26:49 2013 +0100

    Show menu item tooltips in the status bar
    
    Refactor the existing status bar code to add a separate context for
    permanent messages, temporary messages and tooltip messages. Add proxy
    handlers to the application-wide GtkUIManager to push and pop status
    messages when menu items are selected and deselected.

 src/bar.c |  169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 156 insertions(+), 13 deletions(-)
---
diff --git a/src/bar.c b/src/bar.c
index 7b1a3c8..923ccf9 100644
--- a/src/bar.c
+++ b/src/bar.c
@@ -41,6 +41,8 @@
  ***************/
 static GtkWidget *StatusBar = NULL;
 static guint StatusBarContext;
+static guint timer_cid;
+static guint tooltip_cid;
 static guint StatusbarTimerId = 0;
 static GList *ActionPairsList = NULL;
 
@@ -53,6 +55,18 @@ static void Check_Menu_Item_Toggled_Browse_Subdir (GtkWidget *checkmenuitem);
 static void Init_Menu_Bar (void);
 static void Statusbar_Remove_Timer (void);
 
+static void et_statusbar_push_tooltip (const gchar *message);
+static void et_statusbar_pop_tooltip (void);
+static void et_ui_manager_on_connect_proxy (GtkUIManager *manager,
+                                            GtkAction *action,
+                                            GtkWidget *proxy,
+                                            gpointer user_data);
+static void et_ui_manager_on_disconnect_proxy (GtkUIManager *manager,
+                                               GtkAction *action,
+                                               GtkWidget *proxy,
+                                               gpointer user_data);
+static void on_menu_item_select (GtkMenuItem *item, gpointer user_data);
+static void on_menu_item_deselect (GtkMenuItem *item, gpointer user_data);
 
 /*************
  * Functions o
@@ -376,6 +390,12 @@ void Create_UI (GtkWidget **ppmenubar, GtkWidget **pptoolbar)
                                         NULL);
 
     UIManager = gtk_ui_manager_new();
+
+    g_signal_connect (UIManager, "connect-proxy",
+                      G_CALLBACK (et_ui_manager_on_connect_proxy), NULL);
+    g_signal_connect (UIManager, "disconnect-proxy",
+                      G_CALLBACK (et_ui_manager_on_disconnect_proxy), NULL);
+
     if (!gtk_ui_manager_add_ui_from_string(UIManager, ui_xml, -1, &error))
     {
         g_error(_("Could not merge UI, error was: %s\n"), error->message);
@@ -478,6 +498,10 @@ GtkWidget *Create_Status_Bar (void)
     gtk_widget_set_size_request(StatusBar, 200, -1);
     /* Create serie */
     StatusBarContext = gtk_statusbar_get_context_id(GTK_STATUSBAR(StatusBar),"Messages");
+    timer_cid = gtk_statusbar_get_context_id (GTK_STATUSBAR (StatusBar),
+                                              "timer");
+    tooltip_cid = gtk_statusbar_get_context_id (GTK_STATUSBAR (StatusBar),
+                                                "tooltip");
 
     Statusbar_Message (_("Ready to start"), TRUE);
 
@@ -488,7 +512,7 @@ GtkWidget *Create_Status_Bar (void)
 static gboolean
 Statusbar_Stop_Timer (void)
 {
-    gtk_statusbar_pop(GTK_STATUSBAR(StatusBar),StatusBarContext);
+    gtk_statusbar_pop (GTK_STATUSBAR (StatusBar), timer_cid);
     return G_SOURCE_REMOVE;
 }
 
@@ -506,6 +530,7 @@ Statusbar_Remove_Timer (void)
 {
     if (StatusbarTimerId)
     {
+        Statusbar_Stop_Timer ();
         g_source_remove(StatusbarTimerId);
         StatusbarTimerId = 0;
     }
@@ -525,26 +550,50 @@ Statusbar_Message (const gchar *message, gboolean with_timer)
 
     msg_temp = Try_To_Validate_Utf8_String(message);
     
-    /* Remove a running timer */
-    Statusbar_Remove_Timer();
-
-    /* Pop last message */
-    gtk_statusbar_pop(GTK_STATUSBAR(StatusBar),StatusBarContext);
-
     /* Push the given message */
-    gtk_statusbar_push(GTK_STATUSBAR(StatusBar),StatusBarContext,msg_temp);
+    if (with_timer)
+    {
+        Statusbar_Start_Timer ();
+        gtk_statusbar_push (GTK_STATUSBAR (StatusBar), timer_cid, msg_temp);
+    }
+    else
+    {
+        gtk_statusbar_pop (GTK_STATUSBAR (StatusBar), StatusBarContext);
+        gtk_statusbar_push (GTK_STATUSBAR (StatusBar), StatusBarContext,
+                            msg_temp);
+    }
 
     g_free(msg_temp);
+}
 
-    while (gtk_events_pending())
-        gtk_main_iteration();
+/*
+ * et_statusbar_push_tooltip:
+ * @message: a tooltip to display in the status bar
+ *
+ * Display a tooltip in the status bar of the main window. Call
+ * et_statusbar_pop_tooltip() to stop displaying the tooltip message.
+ */
+static void
+et_statusbar_push_tooltip (const gchar *message)
+{
+    g_return_if_fail (StatusBar != NULL && message != NULL);
 
-    if (with_timer)
-        Statusbar_Start_Timer();
+    gtk_statusbar_push (GTK_STATUSBAR (StatusBar), tooltip_cid, message);
 }
 
+/*
+ * et_statusbar_pop_tooltip:
+ *
+ * Pop a tooltip message from the status bar. et_statusbar_push_tooltip() must
+ * have been called first.
+ */
+static void
+et_statusbar_pop_tooltip (void)
+{
+    g_return_if_fail (StatusBar != NULL);
 
-
+    gtk_statusbar_pop (GTK_STATUSBAR (StatusBar), tooltip_cid);
+}
 
 
 
@@ -559,3 +608,97 @@ GtkWidget *Create_Progress_Bar (void)
     gtk_widget_show(ProgressBar);
     return ProgressBar;
 }
+
+/*
+ * et_ui_manager_on_connect_proxy:
+ * @manager: the UI manager which generated the signal
+ * @action: the action which was connected to @proxy
+ * @proxy: the widget which was connected to @action
+ * @user_data: user data set when the signal was connected
+ *
+ * Connect handlers for selection and deselection of menu items, in order to
+ * set tooltips for the menu items as status bar messages.
+ */
+static void
+et_ui_manager_on_connect_proxy (GtkUIManager *manager, GtkAction *action,
+                                GtkWidget *proxy, gpointer user_data)
+{
+    if (GTK_IS_MENU_ITEM (proxy))
+    {
+        guint id;
+
+        id = g_signal_connect (proxy, "select",
+                               G_CALLBACK (on_menu_item_select), action);
+        g_object_set_data (G_OBJECT (proxy), "select-id",
+                           GUINT_TO_POINTER (id));
+        id = g_signal_connect (proxy, "deselect",
+                               G_CALLBACK (on_menu_item_deselect), NULL);
+        g_object_set_data (G_OBJECT (proxy), "deselect-id",
+                           GUINT_TO_POINTER (id));
+    }
+}
+
+/*
+ * et_ui_manager_on_disconnect_proxy:
+ * @manager: the UI manager which generated the signal
+ * @action: the action which was connected to @proxy
+ * @proxy: the widget which was connected to @action
+ * @user_data: user data set when the signal was connected
+ *
+ * Disconnect handlers for selecting and deselecting menu items.
+ */
+static void
+et_ui_manager_on_disconnect_proxy (GtkUIManager *manager, GtkAction *action,
+                                   GtkWidget *proxy, gpointer user_data)
+{
+    if (GTK_IS_MENU_ITEM (proxy))
+    {
+        guint id;
+
+        id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (proxy),
+                                                  "select-id"));
+        g_signal_handler_disconnect (proxy, id);
+        id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (proxy),
+                                                  "deselect-id"));
+        g_signal_handler_disconnect (proxy, id);
+    }
+}
+
+/*
+ * on_menu_item_select:
+ * @item: the menu item which was selected
+ * @user_data: the #GtkAction corresponding to @item
+ *
+ * Set the current status bar message to the tooltip of the menu @item which
+ * was selected.
+ */
+static void
+on_menu_item_select (GtkMenuItem *item, gpointer user_data)
+{
+    GtkAction *action;
+    const gchar *message;
+
+    g_return_if_fail (user_data != NULL);
+
+    action = GTK_ACTION (user_data);
+    message = gtk_action_get_tooltip (action);
+
+    if (message)
+    {
+        et_statusbar_push_tooltip (message);
+    }
+}
+
+/*
+ * on_menu_item_deselect:
+ * @item: the menu item which was deselected
+ * @user_data: user data set when the signal was connected
+ *
+ * Clear the current tooltip status bar message when the menu item is
+ * deselected.
+ */
+static void
+on_menu_item_deselect (GtkMenuItem *item, gpointer user_data)
+{
+    et_statusbar_pop_tooltip ();
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]