]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkrecentaction.c
entry: Use GtkSelectionWindow for touch text selection
[~andy/gtk] / gtk / gtkrecentaction.c
index c55c68ab356ad2354bebcb45255756e5d8b4b29f..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;
 
@@ -81,23 +89,6 @@ G_DEFINE_TYPE_WITH_CODE (GtkRecentAction,
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
                                                 gtk_recent_chooser_iface_init));
 
-static inline void
-recent_chooser_set_property (GtkRecentAction *action,
-                             const gchar     *property_name,
-                             const GValue    *value)
-{
-  GSList *proxies, *l;
-
-  proxies = gtk_action_get_proxies (GTK_ACTION (action));
-  for (l = proxies; l != NULL; l = l->next)
-    {
-      GObject *proxy = l->data;
-
-      g_object_set_property (proxy, property_name, value);
-    }
-  g_slist_free (proxies);
-}
-
 static gboolean
 gtk_recent_action_set_current_uri (GtkRecentChooser  *chooser,
                                    const gchar       *uri,
@@ -169,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)));
 }
 
@@ -198,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
@@ -209,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)
     {
@@ -225,9 +217,18 @@ 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 inline void
+static void
 set_current_filter (GtkRecentAction *action,
                     GtkRecentFilter *filter)
 {
@@ -252,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);
@@ -262,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);
@@ -271,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;
@@ -301,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
@@ -337,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),
@@ -366,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
@@ -382,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 *
@@ -401,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)
@@ -452,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
@@ -515,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);
@@ -574,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;
@@ -582,8 +554,6 @@ gtk_recent_action_set_property (GObject      *gobject,
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
       return;
     }
-
-  recent_chooser_set_property (action, pspec->name, value);
 }
 
 static void
@@ -592,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)
     {
@@ -624,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);
@@ -673,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;
@@ -692,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,
@@ -716,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,
@@ -727,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,
@@ -747,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,
@@ -777,10 +757,10 @@ gtk_recent_action_get_show_numbers (GtkRecentAction *action)
 /**
  * gtk_recent_action_set_show_numbers:
  * @action: a #GtkRecentAction
- * @show_numbers
+ * @show_numbers: %TRUE if the shown items should be numbered
  *
  * Sets whether a number should be added to the items shown by the
- * widgets representing @action. The  numbers are shown to provide
+ * widgets representing @action. The numbers are shown to provide
  * a unique character for a mnemonic to be used inside the menu item's
  * label. Only the first ten items get a number to avoid clashes.
  *
@@ -806,6 +786,3 @@ gtk_recent_action_set_show_numbers (GtkRecentAction *action,
       g_object_unref (action);
     }
 }
-
-#define __GTK_RECENT_ACTION_C__
-#include "gtkaliasdef.c"