]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkrecentaction.c
appchooserdialog: remove redundant checks
[~andy/gtk] / gtk / gtkrecentaction.c
index 5beec74a477429e7ca3e7c9d37c1d25082f01239..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
@@ -213,7 +221,7 @@ gtk_recent_action_set_sort_func (GtkRecentChooser  *chooser,
   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);
@@ -225,7 +233,6 @@ set_current_filter (GtkRecentAction *action,
                     GtkRecentFilter *filter)
 {
   GtkRecentActionPrivate *priv = action->priv;
-  GSList *l;
 
   g_object_ref (action);
 
@@ -237,13 +244,6 @@ set_current_filter (GtkRecentAction *action,
   if (priv->current_filter)
     g_object_ref_sink (priv->current_filter);
 
-  for (l = priv->choosers; l; l = l->next)
-    {
-      GtkRecentChooser *chooser = l->data;
-
-      gtk_recent_chooser_set_filter (chooser, priv->current_filter);
-    }
-
   g_object_notify (G_OBJECT (action), "filter");
 
   g_object_unref (action);
@@ -253,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);
@@ -263,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);
@@ -272,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;
@@ -302,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
@@ -338,20 +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,
-                    "filter", priv->current_filter,
-                    NULL);
-  
       if (priv->sort_func)
         {
           gtk_recent_chooser_set_sort_func (GTK_RECENT_CHOOSER (widget),
@@ -368,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
@@ -384,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 *
@@ -404,6 +403,7 @@ gtk_recent_action_create_menu (GtkAction *action)
                          "sort-type", priv->sort_type,
                          "recent-manager", priv->manager,
                          "filter", priv->current_filter,
+                         "local-only", priv->local_only,
                          NULL);
   
   if (priv->sort_func)
@@ -455,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
@@ -518,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);
@@ -543,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)
     {
@@ -572,33 +540,20 @@ gtk_recent_action_set_property (GObject      *gobject,
       priv->sort_type = g_value_get_enum (value);
       break;
     case GTK_RECENT_CHOOSER_PROP_FILTER:
-      /* this already iterates over the choosers list */
       set_current_filter (action, g_value_get_object (value));
-      return;
+      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));
       return;
     case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
-      /* this is a construct-only property; we set the recent-manager
-       * of the choosers with this value when we create them, so there's
-       * no need to iterate later.
-       */
       set_recent_manager (action, g_value_get_object (value));
-      return;
+      break;
     default:
       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
@@ -607,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)
     {
@@ -686,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;
@@ -705,16 +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, or %NULL
- * @tooltip: a tooltip for the action, or %NULL
- * @stock_id: the stock icon to display in widgets representing the
- *   action, 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
  *
  * Creates a new #GtkRecentAction object. To add the action to
  * a #GtkActionGroup and set the accelerator for the action,
@@ -743,11 +701,12 @@ 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, or %NULL
- * @tooltip: a tooltip for the action, or %NULL
- * @stock_id: the stock icon to display in widgets representing the
- *   action, or %NULL
- * @manager: a #GtkRecentManager, or %NULL for using the default
+ * @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
@@ -827,6 +786,3 @@ gtk_recent_action_set_show_numbers (GtkRecentAction *action,
       g_object_unref (action);
     }
 }
-
-#define __GTK_RECENT_ACTION_C__
-#include "gtkaliasdef.c"