]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkrecentaction.c
texthandles: Keep state internally to avoid X overhead
[~andy/gtk] / gtk / gtkrecentaction.c
index 1a8f99e754e0dcb9995a3fcb89fb34752a09dab4..211ab97ed01f1d4cc7fc7ea2115a7358856af55f 100644 (file)
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <config.h>
+#include "config.h"
 
 #include "gtkintl.h"
 #include "gtkrecentaction.h"
 #include "gtkrecentchooserutils.h"
 #include "gtkrecentchooserprivate.h"
 #include "gtkprivate.h"
-#include "gtkalias.h"
+
+/**
+ * SECTION:gtkrecentaction
+ * @Short_description: An action of which represents a list of recently used files
+ * @Title: GtkRecentAction
+ *
+ * A #GtkRecentAction represents a list of recently used files, which
+ * can be shown by widgets such as #GtkRecentChooserDialog or
+ * #GtkRecentChooserMenu.
+ *
+ * To construct a submenu showing recently used files, use a #GtkRecentAction
+ * as the action for a &lt;menuitem&gt;. To construct a menu toolbutton showing
+ * the recently used files in the popup menu, use a #GtkRecentAction as the
+ * action for a &lt;toolitem&gt; element.
+ */
+
 
 #define FALLBACK_ITEM_LIMIT     10
 
-#define GTK_RECENT_ACTION_GET_PRIVATE(obj)      \
-        (G_TYPE_INSTANCE_GET_PRIVATE ((obj),    \
-         GTK_TYPE_RECENT_ACTION,                \
-         GtkRecentActionPrivate))
 
 struct _GtkRecentActionPrivate
 {
   GtkRecentManager *manager;
-  guint manager_changed_id;
 
   guint show_numbers   : 1;
 
@@ -57,8 +65,8 @@ struct _GtkRecentActionPrivate
 
   GtkRecentSortType sort_type;
   GtkRecentSortFunc sort_func;
-  gpointer sort_data;
-  GDestroyNotify data_destroy;
+  gpointer          sort_data;
+  GDestroyNotify    data_destroy;
 
   GtkRecentFilter *current_filter;
 
@@ -152,16 +160,16 @@ gtk_recent_action_unselect_uri (GtkRecentChooser *chooser,
 static void
 gtk_recent_action_select_all (GtkRecentChooser *chooser)
 {
-  g_warning (_("This function is not implemented for "
-               "widgets of class '%s'"),
+  g_warning ("This function is not implemented for "
+            "widgets of class '%s'",
              g_type_name (G_OBJECT_TYPE (chooser)));
 }
 
 static void
 gtk_recent_action_unselect_all (GtkRecentChooser *chooser)
 {
-  g_warning (_("This function is not implemented for "
-               "widgets of class '%s'"),
+  g_warning ("This function is not implemented for "
+            "widgets of class '%s'",
              g_type_name (G_OBJECT_TYPE (chooser)));
 }
 
@@ -181,7 +189,7 @@ gtk_recent_action_get_items (GtkRecentChooser *chooser)
 static GtkRecentManager *
 gtk_recent_action_get_recent_manager (GtkRecentChooser *chooser)
 {
-  return GTK_RECENT_ACTION_GET_PRIVATE (chooser)->manager;
+  return GTK_RECENT_ACTION (chooser)->priv->manager;
 }
 
 static void
@@ -192,6 +200,7 @@ gtk_recent_action_set_sort_func (GtkRecentChooser  *chooser,
 {
   GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
   GtkRecentActionPrivate *priv = action->priv;
+  GSList *l;
   
   if (priv->data_destroy)
     {
@@ -208,6 +217,15 @@ gtk_recent_action_set_sort_func (GtkRecentChooser  *chooser,
       priv->sort_data = sort_data;
       priv->data_destroy = data_destroy;
     }
+
+  for (l = priv->choosers; l; l = l->next)
+    {
+      GtkRecentChooser *chooser_menu = l->data;
+      
+      gtk_recent_chooser_set_sort_func (chooser_menu, priv->sort_func,
+                                        priv->sort_data,
+                                        priv->data_destroy);
+    }
 }
 
 static void
@@ -235,7 +253,8 @@ static void
 gtk_recent_action_add_filter (GtkRecentChooser *chooser,
                               GtkRecentFilter  *filter)
 {
-  GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (chooser);
+  GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
+  GtkRecentActionPrivate *priv = action->priv;
 
   if (priv->current_filter != filter)
     set_current_filter (GTK_RECENT_ACTION (chooser), filter);
@@ -245,7 +264,8 @@ static void
 gtk_recent_action_remove_filter (GtkRecentChooser *chooser,
                                  GtkRecentFilter  *filter)
 {
-  GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (chooser);
+  GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
+  GtkRecentActionPrivate *priv = action->priv;
 
   if (priv->current_filter == filter)
     set_current_filter (GTK_RECENT_ACTION (chooser), NULL);
@@ -254,10 +274,12 @@ gtk_recent_action_remove_filter (GtkRecentChooser *chooser,
 static GSList *
 gtk_recent_action_list_filters (GtkRecentChooser *chooser)
 {
+  GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
+  GtkRecentActionPrivate *priv = action->priv;
   GSList *retval = NULL;
   GtkRecentFilter *current_filter;
 
-  current_filter = GTK_RECENT_ACTION_GET_PRIVATE (chooser)->current_filter;
+  current_filter = priv->current_filter;
   retval = g_slist_prepend (retval, current_filter);
 
   return retval;
@@ -284,11 +306,14 @@ gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface)
 static void
 gtk_recent_action_activate (GtkAction *action)
 {
+  GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
+  GtkRecentActionPrivate *priv = recent_action->priv;
+
   /* we have probably been invoked by a menu tool button or by a
    * direct call of gtk_action_activate(); since no item has been
    * selected, we must unset the current recent chooser pointer
    */
-  GTK_RECENT_ACTION_GET_PRIVATE (action)->current_chooser = NULL;
+  priv->current_chooser = NULL;
 }
 
 static void
@@ -320,19 +345,10 @@ gtk_recent_action_connect_proxy (GtkAction *action,
   GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
   GtkRecentActionPrivate *priv = recent_action->priv;
 
+  /* it can only be a recent chooser implementor anyway... */
   if (GTK_IS_RECENT_CHOOSER (widget) &&
       !g_slist_find (priv->choosers, widget))
     {
-      g_object_set (G_OBJECT (widget),
-                    "show-private", priv->show_private,
-                    "show-not-found", priv->show_not_found,
-                    "show-tips", priv->show_tips,
-                    "show-icons", priv->show_icons,
-                    "show-numbers", priv->show_numbers,
-                    "limit", priv->limit,
-                    "sort-type", priv->sort_type,
-                    NULL);
-  
       if (priv->sort_func)
         {
           gtk_recent_chooser_set_sort_func (GTK_RECENT_CHOOSER (widget),
@@ -349,7 +365,8 @@ gtk_recent_action_connect_proxy (GtkAction *action,
                                 action);
     }
 
-  GTK_ACTION_CLASS (gtk_recent_action_parent_class)->connect_proxy (action, widget);
+  if (GTK_ACTION_CLASS (gtk_recent_action_parent_class)->connect_proxy)
+    GTK_ACTION_CLASS (gtk_recent_action_parent_class)->connect_proxy (action, widget);
 }
 
 static void
@@ -365,7 +382,8 @@ gtk_recent_action_disconnect_proxy (GtkAction *action,
   if (g_slist_find (priv->choosers, widget))
     priv->choosers = g_slist_remove (priv->choosers, widget);
 
-  GTK_ACTION_CLASS (gtk_recent_action_parent_class)->disconnect_proxy (action, widget);
+  if (GTK_ACTION_CLASS (gtk_recent_action_parent_class)->disconnect_proxy)
+    GTK_ACTION_CLASS (gtk_recent_action_parent_class)->disconnect_proxy (action, widget);
 }
 
 static GtkWidget *
@@ -384,6 +402,8 @@ gtk_recent_action_create_menu (GtkAction *action)
                          "limit", priv->limit,
                          "sort-type", priv->sort_type,
                          "recent-manager", priv->manager,
+                         "filter", priv->current_filter,
+                         "local-only", priv->local_only,
                          NULL);
   
   if (priv->sort_func)
@@ -435,39 +455,16 @@ gtk_recent_action_create_tool_item (GtkAction *action)
   return toolitem;
 }
 
-static void
-manager_changed_cb (GtkRecentManager *manager,
-                    gpointer          user_data)
-{
-  /* do we need to propagate the signal to all the proxies? guess not */
-}
-
 static void
 set_recent_manager (GtkRecentAction  *action,
                     GtkRecentManager *manager)
 {
   GtkRecentActionPrivate *priv = action->priv;
 
-  if (priv->manager)
-    {
-      if (priv->manager_changed_id)
-        {
-          g_signal_handler_disconnect (priv->manager, priv->manager_changed_id);
-          priv->manager_changed_id = 0;
-        }
-
-      priv->manager = NULL;
-    }
-
   if (manager)
     priv->manager = NULL;
   else
     priv->manager = gtk_recent_manager_get_default ();
-
-  if (priv->manager)
-    priv->manager_changed_id = g_signal_connect (priv->manager, "changed",
-                                                 G_CALLBACK (manager_changed_cb),
-                                                 action);
 }
 
 static void
@@ -498,14 +495,6 @@ gtk_recent_action_dispose (GObject *gobject)
   GtkRecentAction *action = GTK_RECENT_ACTION (gobject);
   GtkRecentActionPrivate *priv = action->priv;
 
-  if (priv->manager_changed_id)
-    {
-      if (priv->manager)
-        g_signal_handler_disconnect (priv->manager, priv->manager_changed_id);
-
-      priv->manager_changed_id = 0;
-    }
-
   if (priv->current_filter)
     {
       g_object_unref (priv->current_filter);
@@ -523,7 +512,6 @@ gtk_recent_action_set_property (GObject      *gobject,
 {
   GtkRecentAction *action = GTK_RECENT_ACTION (gobject);
   GtkRecentActionPrivate *priv = action->priv;
-  GSList *l;
 
   switch (prop_id)
     {
@@ -558,7 +546,7 @@ gtk_recent_action_set_property (GObject      *gobject,
       g_warning ("%s: Choosers of type `%s' do not support selecting multiple items.",
                  G_STRFUNC,
                  G_OBJECT_TYPE_NAME (gobject));
-      break;
+      return;
     case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
       set_recent_manager (action, g_value_get_object (value));
       break;
@@ -566,14 +554,6 @@ gtk_recent_action_set_property (GObject      *gobject,
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
       return;
     }
-
-  /* propagate the properties to the proxies we have created */
-  for (l = priv->choosers; l != NULL; l = l->next)
-    {
-      GObject *proxy = l->data;
-
-      g_object_set_property (proxy, pspec->name, value);
-    }
 }
 
 static void
@@ -582,7 +562,8 @@ gtk_recent_action_get_property (GObject    *gobject,
                                 GValue     *value,
                                 GParamSpec *pspec)
 {
-  GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (gobject);
+  GtkRecentAction *action = GTK_RECENT_ACTION (gobject);
+  GtkRecentActionPrivate *priv = action->priv;
 
   switch (prop_id)
     {
@@ -614,9 +595,7 @@ gtk_recent_action_get_property (GObject    *gobject,
       g_value_set_object (value, priv->current_filter);
       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 (gobject));
+      g_value_set_boolean (value, FALSE);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
@@ -663,7 +642,9 @@ gtk_recent_action_init (GtkRecentAction *action)
 {
   GtkRecentActionPrivate *priv;
 
-  action->priv = priv = GTK_RECENT_ACTION_GET_PRIVATE (action);
+  action->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (action,
+                                                     GTK_TYPE_RECENT_ACTION,
+                                                     GtkRecentActionPrivate);
 
   priv->show_numbers = FALSE;
   priv->show_icons = TRUE;
@@ -682,15 +663,16 @@ gtk_recent_action_init (GtkRecentAction *action)
   priv->current_filter = NULL;
 
   priv->manager = NULL;
-  priv->manager_changed_id = 0;
 }
 
 /**
  * gtk_recent_action_new:
  * @name: a unique name for the action
- * @label: the label displayed in menu items and on buttons
- * @tooltip: a tooltip for the action
- * @stock_id: the stock icon to display in widgets representing the action
+ * @label: (allow-none): the label displayed in menu items and on buttons,
+ *   or %NULL
+ * @tooltip: (allow-none): a tooltip for the action, or %NULL
+ * @stock_id: (allow-none): the stock icon to display in widgets representing
+ *   the action, or %NULL
  *
  * Creates a new #GtkRecentAction object. To add the action to
  * a #GtkActionGroup and set the accelerator for the action,
@@ -706,6 +688,8 @@ gtk_recent_action_new (const gchar *name,
                        const gchar *tooltip,
                        const gchar *stock_id)
 {
+  g_return_val_if_fail (name != NULL, NULL);
+
   return g_object_new (GTK_TYPE_RECENT_ACTION,
                        "name", name,
                        "label", label,
@@ -717,10 +701,13 @@ gtk_recent_action_new (const gchar *name,
 /**
  * gtk_recent_action_new_for_manager:
  * @name: a unique name for the action
- * @label: the label displayed in menu items and on buttons
- * @tooltip: a tooltip for the action
- * @stock_id: the stock icon to display in widgets representing the action
- * @manager: a #GtkRecentManager or %NULL
+ * @label: (allow-none): the label displayed in menu items and on buttons,
+ *   or %NULL
+ * @tooltip: (allow-none): a tooltip for the action, or %NULL
+ * @stock_id: (allow-none): the stock icon to display in widgets representing
+ *   the action, or %NULL
+ * @manager: (allow-none): a #GtkRecentManager, or %NULL for using the default
+ *   #GtkRecentManager
  *
  * Creates a new #GtkRecentAction object. To add the action to
  * a #GtkActionGroup and set the accelerator for the action,
@@ -737,6 +724,9 @@ gtk_recent_action_new_for_manager (const gchar      *name,
                                    const gchar      *stock_id,
                                    GtkRecentManager *manager)
 {
+  g_return_val_if_fail (name != NULL, NULL);
+  g_return_val_if_fail (manager == NULL || GTK_IS_RECENT_MANAGER (manager), NULL);
+
   return g_object_new (GTK_TYPE_RECENT_ACTION,
                        "name", name,
                        "label", label,
@@ -796,6 +786,3 @@ gtk_recent_action_set_show_numbers (GtkRecentAction *action,
       g_object_unref (action);
     }
 }
-
-#define __GTK_RECENT_ACTION_C__
-#include "gtkaliasdef.c"