]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkrecentchoosermenu.c
Fix possible recursion by resetting the idle source id. (#507605, William
[~andy/gtk] / gtk / gtkrecentchoosermenu.c
index 8720bcd82b84c96d7267686f7a03d5d5d4162c88..f72909b5a9ea11d19e2564b902e2fb0d1139fb63 100644 (file)
@@ -44,7 +44,7 @@
 #include "gtkimage.h"
 #include "gtklabel.h"
 #include "gtkobject.h"
-#include "gtktooltips.h"
+#include "gtktooltip.h"
 #include "gtktypebuiltins.h"
 #include "gtkprivate.h"
 #include "gtkalias.h"
@@ -85,9 +85,6 @@ struct _GtkRecentChooserMenuPrivate
   gulong manager_changed_id;
 
   gulong populate_id;
-
-  /* tooltips for our bookmark items*/
-  GtkTooltips *tooltips;
 };
 
 enum {
@@ -234,20 +231,14 @@ gtk_recent_chooser_menu_init (GtkRecentChooserMenu *menu)
   priv->local_only = TRUE;
   
   priv->limit = FALLBACK_ITEM_LIMIT;
-
   priv->sort_type = GTK_RECENT_SORT_NONE;
-  
   priv->icon_size = FALLBACK_ICON_SIZE;
-  
   priv->label_width = DEFAULT_LABEL_WIDTH;
   
   priv->first_recent_item_pos = -1;
   priv->placeholder = NULL;
 
   priv->current_filter = NULL;
-    
-  priv->tooltips = gtk_tooltips_new ();
-  g_object_ref_sink (priv->tooltips);
 }
 
 static void
@@ -290,12 +281,6 @@ gtk_recent_chooser_menu_dispose (GObject *object)
       priv->populate_id = 0;
     }
 
-  if (priv->tooltips)
-    {
-      g_object_unref (priv->tooltips);
-      priv->tooltips = NULL;
-    }
   if (priv->current_filter)
     {
       g_object_unref (priv->current_filter);
@@ -435,9 +420,7 @@ gtk_recent_chooser_menu_get_property (GObject    *object,
       g_value_set_boolean (value, priv->show_icons);
       break;
     case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
-      g_warning ("%s: Choosers of type `%s' do not support selecting multiple items.",
-                 G_STRFUNC,
-                 G_OBJECT_TYPE_NAME (object));
+      g_value_set_boolean (value, FALSE);
       break;
     case GTK_RECENT_CHOOSER_PROP_FILTER:
       g_value_set_object (value, priv->current_filter);
@@ -744,25 +727,20 @@ gtk_recent_chooser_menu_add_tip (GtkRecentChooserMenu *menu,
                                 GtkWidget            *item)
 {
   GtkRecentChooserMenuPrivate *priv;
-  gchar *path, *tip_text;
+  gchar *path;
 
   g_assert (info != NULL);
   g_assert (item != NULL);
 
   priv = menu->priv;
   
-  if (!priv->tooltips)
-    return;
-  
   path = gtk_recent_info_get_uri_display (info);
   if (path)
     {
-      tip_text = g_strdup_printf (_("Open '%s'"), path);
+      gchar *tip_text = g_strdup_printf (_("Open '%s'"), path);
 
-      gtk_tooltips_set_tip (priv->tooltips,
-                            item,
-                            tip_text,
-                            NULL);
+      gtk_widget_set_tooltip_text (item, tip_text);
+      gtk_widget_set_has_tooltip (item, priv->show_tips);
 
       g_free (path);
       g_free (tip_text);
@@ -795,9 +773,21 @@ gtk_recent_chooser_menu_create_item (GtkRecentChooserMenu *menu,
       
       /* avoid clashing mnemonics */
       if (count <= 10)
-        text = g_strdup_printf ("_%d. %s", count, escaped);
+        /* This is the label format that is used for the first 10 items 
+         * in a recent files menu. The %d is the number of the item,
+         * the %s is the name of the item. Please keep the _ in front
+         * of the number to give these menu items a mnemonic.
+         *
+         * Don't include the prefix "recent menu label|" in the translation.
+         */
+        text = g_strdup_printf (Q_("recent menu label|_%d. %s"), count, escaped);
       else
-        text = g_strdup_printf ("%d. %s", count, escaped);
+        /* This is the format that is used for items in a recent files menu. 
+         * The %d is the number of the item, the %s is the name of the item. 
+         *
+         * Don't include the prefix "recent menu label|" in the translation.
+         */
+        text = g_strdup_printf (Q_("recent menu label|%d. %s"), count, escaped);
       
       item = gtk_image_menu_item_new_with_mnemonic (text);
       
@@ -936,8 +926,6 @@ idle_populate_func (gpointer data)
   pdata = (MenuPopulateData *) data;
   priv = pdata->menu->priv;
 
-  priv->populate_id = 0;
-
   if (!pdata->items)
     {
       pdata->items = gtk_recent_chooser_get_items (GTK_RECENT_CHOOSER (pdata->menu));
@@ -946,6 +934,7 @@ idle_populate_func (gpointer data)
           /* show the placeholder here */
           gtk_widget_show (pdata->placeholder);
           pdata->displayed_items = 1;
+          priv->populate_id = 0;
 
          return FALSE;
        }
@@ -988,6 +977,8 @@ check_and_return:
       g_list_foreach (pdata->items, (GFunc) gtk_recent_info_unref, NULL);
       g_list_free (pdata->items);
 
+      priv->populate_id = 0;
+
       retval = FALSE;
     }
   else
@@ -1001,14 +992,17 @@ idle_populate_clean_up (gpointer data)
 {
   MenuPopulateData *pdata = data;
 
-  /* show the placeholder in case no item survived
-   * the filtering process in the idle loop
-   */
-  if (!pdata->displayed_items)
-    gtk_widget_show (pdata->placeholder);
-  g_object_unref (pdata->placeholder);
-
-  g_slice_free (MenuPopulateData, data);
+  if (pdata->menu->priv->populate_id == 0)
+    {
+      /* show the placeholder in case no item survived
+       * the filtering process in the idle loop
+       */
+      if (!pdata->displayed_items)
+        gtk_widget_show (pdata->placeholder);
+      g_object_unref (pdata->placeholder);
+
+      g_slice_free (MenuPopulateData, data);
+    }
 }
 
 static void
@@ -1114,21 +1108,33 @@ get_icon_size_for_widget (GtkWidget *widget)
   return FALLBACK_ICON_SIZE;
 }
 
+static void
+foreach_set_shot_tips (GtkWidget *widget,
+                       gpointer   user_data)
+{
+  GtkRecentChooserMenu *menu = user_data;
+  GtkRecentChooserMenuPrivate *priv = menu->priv;
+  gboolean has_mark;
+
+  /* toggle the tooltip only on the items we create */
+  has_mark =
+    GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "gtk-recent-menu-mark"));
+
+  if (has_mark)
+    gtk_widget_set_has_tooltip (widget, priv->show_tips);
+}
+
 static void
 gtk_recent_chooser_menu_set_show_tips (GtkRecentChooserMenu *menu,
                                       gboolean              show_tips)
 {
-  if (menu->priv->show_tips == show_tips)
+  GtkRecentChooserMenuPrivate *priv = menu->priv;
+
+  if (priv->show_tips == show_tips)
     return;
   
-  g_assert (menu->priv->tooltips != NULL);
-  
-  if (show_tips)
-    gtk_tooltips_enable (menu->priv->tooltips);
-  else
-    gtk_tooltips_disable (menu->priv->tooltips);
-  
-  menu->priv->show_tips = show_tips;
+  priv->show_tips = show_tips;
+  gtk_container_foreach (GTK_CONTAINER (menu), foreach_set_shot_tips, menu);
 }
 
 /*