]> Pileus Git - ~andy/gtk/blob - gtk/gtkrecentaction.c
Propagate local-only. (#511987, Jonh Wendell)
[~andy/gtk] / gtk / gtkrecentaction.c
1 /* GTK - The GIMP Toolkit
2  * Recent chooser action for GtkUIManager
3  *
4  * Copyright (C) 2007, Emmanuele Bassi
5  * 
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #include <config.h>
23
24 #include "gtkintl.h"
25 #include "gtkrecentaction.h"
26 #include "gtkimagemenuitem.h"
27 #include "gtkmenutoolbutton.h"
28 #include "gtkrecentchooser.h"
29 #include "gtkrecentchoosermenu.h"
30 #include "gtkrecentchooserutils.h"
31 #include "gtkrecentchooserprivate.h"
32 #include "gtkprivate.h"
33 #include "gtkalias.h"
34
35 #define FALLBACK_ITEM_LIMIT     10
36
37 #define GTK_RECENT_ACTION_GET_PRIVATE(obj)      \
38         (G_TYPE_INSTANCE_GET_PRIVATE ((obj),    \
39          GTK_TYPE_RECENT_ACTION,                \
40          GtkRecentActionPrivate))
41
42 struct _GtkRecentActionPrivate
43 {
44   GtkRecentManager *manager;
45   guint manager_changed_id;
46
47   guint show_numbers   : 1;
48
49   /* RecentChooser properties */
50   guint show_private   : 1;
51   guint show_not_found : 1;
52   guint show_tips      : 1;
53   guint show_icons     : 1;
54   guint local_only     : 1;
55
56   gint limit;
57
58   GtkRecentSortType sort_type;
59   GtkRecentSortFunc sort_func;
60   gpointer sort_data;
61   GDestroyNotify data_destroy;
62
63   GtkRecentFilter *current_filter;
64
65   GSList *choosers;
66   GtkRecentChooser *current_chooser;
67 };
68
69 enum
70 {
71   PROP_0,
72
73   PROP_SHOW_NUMBERS
74 };
75
76 static void gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface);
77
78 G_DEFINE_TYPE_WITH_CODE (GtkRecentAction,
79                          gtk_recent_action,
80                          GTK_TYPE_ACTION,
81                          G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
82                                                 gtk_recent_chooser_iface_init));
83
84 static gboolean
85 gtk_recent_action_set_current_uri (GtkRecentChooser  *chooser,
86                                    const gchar       *uri,
87                                    GError           **error)
88 {
89   GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
90   GtkRecentActionPrivate *priv = action->priv;
91   GSList *l;
92
93   for (l = priv->choosers; l; l = l->next)
94     {
95       GtkRecentChooser *recent_chooser = l->data;
96
97       if (!gtk_recent_chooser_set_current_uri (recent_chooser, uri, error))
98         return FALSE;
99     }
100
101   return TRUE;
102 }
103
104 static gchar *
105 gtk_recent_action_get_current_uri (GtkRecentChooser *chooser)
106 {
107   GtkRecentAction *recent_action = GTK_RECENT_ACTION (chooser);
108   GtkRecentActionPrivate *priv = recent_action->priv;
109
110   if (priv->current_chooser)
111     return gtk_recent_chooser_get_current_uri (priv->current_chooser);
112
113   return NULL;
114 }
115
116 static gboolean
117 gtk_recent_action_select_uri (GtkRecentChooser  *chooser,
118                               const gchar       *uri,
119                               GError           **error)
120 {
121   GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
122   GtkRecentActionPrivate *priv = action->priv;
123   GSList *l;
124
125   for (l = priv->choosers; l; l = l->next)
126     {
127       GtkRecentChooser *recent_chooser = l->data;
128
129       if (!gtk_recent_chooser_select_uri (recent_chooser, uri, error))
130         return FALSE;
131     }
132
133   return TRUE;
134 }
135
136 static void
137 gtk_recent_action_unselect_uri (GtkRecentChooser *chooser,
138                                 const gchar      *uri)
139 {
140   GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
141   GtkRecentActionPrivate *priv = action->priv;
142   GSList *l;
143
144   for (l = priv->choosers; l; l = l->next)
145     {
146       GtkRecentChooser *chooser = l->data;
147       
148       gtk_recent_chooser_unselect_uri (chooser, uri);
149     }
150 }
151
152 static void
153 gtk_recent_action_select_all (GtkRecentChooser *chooser)
154 {
155   g_warning (_("This function is not implemented for "
156                "widgets of class '%s'"),
157              g_type_name (G_OBJECT_TYPE (chooser)));
158 }
159
160 static void
161 gtk_recent_action_unselect_all (GtkRecentChooser *chooser)
162 {
163   g_warning (_("This function is not implemented for "
164                "widgets of class '%s'"),
165              g_type_name (G_OBJECT_TYPE (chooser)));
166 }
167
168
169 static GList *
170 gtk_recent_action_get_items (GtkRecentChooser *chooser)
171 {
172   GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
173   GtkRecentActionPrivate *priv = action->priv;
174
175   return _gtk_recent_chooser_get_items (chooser,
176                                         priv->current_filter,
177                                         priv->sort_func,
178                                         priv->sort_data);
179 }
180
181 static GtkRecentManager *
182 gtk_recent_action_get_recent_manager (GtkRecentChooser *chooser)
183 {
184   return GTK_RECENT_ACTION_GET_PRIVATE (chooser)->manager;
185 }
186
187 static void
188 gtk_recent_action_set_sort_func (GtkRecentChooser  *chooser,
189                                  GtkRecentSortFunc  sort_func,
190                                  gpointer           sort_data,
191                                  GDestroyNotify     data_destroy)
192 {
193   GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
194   GtkRecentActionPrivate *priv = action->priv;
195   GSList *l;
196   
197   if (priv->data_destroy)
198     {
199       priv->data_destroy (priv->sort_data);
200       priv->data_destroy = NULL;
201     }
202       
203   priv->sort_func = NULL;
204   priv->sort_data = NULL;
205   
206   if (sort_func)
207     {
208       priv->sort_func = sort_func;
209       priv->sort_data = sort_data;
210       priv->data_destroy = data_destroy;
211     }
212
213   for (l = priv->choosers; l; l = l->next)
214     {
215       GtkRecentChooser *chooser_menu = l->data;
216
217       gtk_recent_chooser_set_sort_func (chooser_menu, priv->sort_func,
218                                         priv->sort_data,
219                                         priv->data_destroy);
220     }
221 }
222
223 static void
224 set_current_filter (GtkRecentAction *action,
225                     GtkRecentFilter *filter)
226 {
227   GtkRecentActionPrivate *priv = action->priv;
228   GSList *l;
229
230   g_object_ref (action);
231
232   if (priv->current_filter)
233     g_object_unref (priv->current_filter);
234
235   priv->current_filter = filter;
236
237   if (priv->current_filter)
238     g_object_ref_sink (priv->current_filter);
239
240   for (l = priv->choosers; l; l = l->next)
241     {
242       GtkRecentChooser *chooser = l->data;
243
244       gtk_recent_chooser_set_filter (chooser, priv->current_filter);
245     }
246
247   g_object_notify (G_OBJECT (action), "filter");
248
249   g_object_unref (action);
250 }
251
252 static void
253 gtk_recent_action_add_filter (GtkRecentChooser *chooser,
254                               GtkRecentFilter  *filter)
255 {
256   GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (chooser);
257
258   if (priv->current_filter != filter)
259     set_current_filter (GTK_RECENT_ACTION (chooser), filter);
260 }
261
262 static void
263 gtk_recent_action_remove_filter (GtkRecentChooser *chooser,
264                                  GtkRecentFilter  *filter)
265 {
266   GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (chooser);
267
268   if (priv->current_filter == filter)
269     set_current_filter (GTK_RECENT_ACTION (chooser), NULL);
270 }
271
272 static GSList *
273 gtk_recent_action_list_filters (GtkRecentChooser *chooser)
274 {
275   GSList *retval = NULL;
276   GtkRecentFilter *current_filter;
277
278   current_filter = GTK_RECENT_ACTION_GET_PRIVATE (chooser)->current_filter;
279   retval = g_slist_prepend (retval, current_filter);
280
281   return retval;
282 }
283
284
285 static void
286 gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface)
287 {
288   iface->set_current_uri = gtk_recent_action_set_current_uri;
289   iface->get_current_uri = gtk_recent_action_get_current_uri;
290   iface->select_uri = gtk_recent_action_select_uri;
291   iface->unselect_uri = gtk_recent_action_unselect_uri;
292   iface->select_all = gtk_recent_action_select_all;
293   iface->unselect_all = gtk_recent_action_unselect_all;
294   iface->get_items = gtk_recent_action_get_items;
295   iface->get_recent_manager = gtk_recent_action_get_recent_manager;
296   iface->set_sort_func = gtk_recent_action_set_sort_func;
297   iface->add_filter = gtk_recent_action_add_filter;
298   iface->remove_filter = gtk_recent_action_remove_filter;
299   iface->list_filters = gtk_recent_action_list_filters;
300 }
301
302 static void
303 gtk_recent_action_activate (GtkAction *action)
304 {
305   /* we have probably been invoked by a menu tool button or by a
306    * direct call of gtk_action_activate(); since no item has been
307    * selected, we must unset the current recent chooser pointer
308    */
309   GTK_RECENT_ACTION_GET_PRIVATE (action)->current_chooser = NULL;
310 }
311
312 static void
313 delegate_selection_changed (GtkRecentAction  *action,
314                             GtkRecentChooser *chooser)
315 {
316   GtkRecentActionPrivate *priv = action->priv;
317
318   priv->current_chooser = chooser;
319
320   g_signal_emit_by_name (action, "selection-changed");
321 }
322
323 static void
324 delegate_item_activated (GtkRecentAction  *action,
325                          GtkRecentChooser *chooser)
326 {
327   GtkRecentActionPrivate *priv = action->priv;
328
329   priv->current_chooser = chooser;
330
331   g_signal_emit_by_name (action, "item-activated");
332 }
333
334 static void
335 gtk_recent_action_connect_proxy (GtkAction *action,
336                                  GtkWidget *widget)
337 {
338   GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
339   GtkRecentActionPrivate *priv = recent_action->priv;
340
341   if (GTK_IS_RECENT_CHOOSER (widget) &&
342       !g_slist_find (priv->choosers, widget))
343     {
344       g_object_set (G_OBJECT (widget),
345                     "show-private", priv->show_private,
346                     "show-not-found", priv->show_not_found,
347                     "show-tips", priv->show_tips,
348                     "show-icons", priv->show_icons,
349                     "show-numbers", priv->show_numbers,
350                     "limit", priv->limit,
351                     "sort-type", priv->sort_type,
352                     "filter", priv->current_filter,
353                     "local-only", priv->local_only,
354                     NULL);
355   
356       if (priv->sort_func)
357         {
358           gtk_recent_chooser_set_sort_func (GTK_RECENT_CHOOSER (widget),
359                                             priv->sort_func,
360                                             priv->sort_data,
361                                             priv->data_destroy);
362         }
363
364       g_signal_connect_swapped (widget, "selection_changed",
365                                 G_CALLBACK (delegate_selection_changed),
366                                 action);
367       g_signal_connect_swapped (widget, "item-activated",
368                                 G_CALLBACK (delegate_item_activated),
369                                 action);
370     }
371
372   GTK_ACTION_CLASS (gtk_recent_action_parent_class)->connect_proxy (action, widget);
373 }
374
375 static void
376 gtk_recent_action_disconnect_proxy (GtkAction *action,
377                                     GtkWidget *widget)
378 {
379   GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
380   GtkRecentActionPrivate *priv = recent_action->priv;
381
382   /* if it was one of the recent choosers we created, remove it
383    * from the list
384    */
385   if (g_slist_find (priv->choosers, widget))
386     priv->choosers = g_slist_remove (priv->choosers, widget);
387
388   GTK_ACTION_CLASS (gtk_recent_action_parent_class)->disconnect_proxy (action, widget);
389 }
390
391 static GtkWidget *
392 gtk_recent_action_create_menu (GtkAction *action)
393 {
394   GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
395   GtkRecentActionPrivate *priv = recent_action->priv;
396   GtkWidget *widget;
397
398   widget = g_object_new (GTK_TYPE_RECENT_CHOOSER_MENU,
399                          "show-private", priv->show_private,
400                          "show-not-found", priv->show_not_found,
401                          "show-tips", priv->show_tips,
402                          "show-icons", priv->show_icons,
403                          "show-numbers", priv->show_numbers,
404                          "limit", priv->limit,
405                          "sort-type", priv->sort_type,
406                          "recent-manager", priv->manager,
407                          "filter", priv->current_filter,
408                          "local-only", priv->local_only,
409                          NULL);
410   
411   if (priv->sort_func)
412     {
413       gtk_recent_chooser_set_sort_func (GTK_RECENT_CHOOSER (widget),
414                                         priv->sort_func,
415                                         priv->sort_data,
416                                         priv->data_destroy);
417     }
418
419   g_signal_connect_swapped (widget, "selection_changed",
420                             G_CALLBACK (delegate_selection_changed),
421                             recent_action);
422   g_signal_connect_swapped (widget, "item-activated",
423                             G_CALLBACK (delegate_item_activated),
424                             recent_action);
425
426   /* keep track of the choosers we create */
427   priv->choosers = g_slist_prepend (priv->choosers, widget);
428
429   return widget;
430 }
431
432 static GtkWidget *
433 gtk_recent_action_create_menu_item (GtkAction *action)
434 {
435   GtkWidget *menu;
436   GtkWidget *menuitem;
437
438   menu = gtk_recent_action_create_menu (action);
439   menuitem = g_object_new (GTK_TYPE_IMAGE_MENU_ITEM, NULL);
440   gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
441   gtk_widget_show (menu);
442
443   return menuitem;
444 }
445
446 static GtkWidget *
447 gtk_recent_action_create_tool_item (GtkAction *action)
448 {
449   GtkWidget *menu;
450   GtkWidget *toolitem;
451
452   menu = gtk_recent_action_create_menu (action);
453   toolitem = g_object_new (GTK_TYPE_MENU_TOOL_BUTTON, NULL);
454   gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (toolitem), menu);
455   gtk_widget_show (menu);
456
457   return toolitem;
458 }
459
460 static void
461 manager_changed_cb (GtkRecentManager *manager,
462                     gpointer          user_data)
463 {
464   /* do we need to propagate the signal to all the proxies? guess not */
465 }
466
467 static void
468 set_recent_manager (GtkRecentAction  *action,
469                     GtkRecentManager *manager)
470 {
471   GtkRecentActionPrivate *priv = action->priv;
472
473   if (priv->manager)
474     {
475       if (priv->manager_changed_id)
476         {
477           g_signal_handler_disconnect (priv->manager, priv->manager_changed_id);
478           priv->manager_changed_id = 0;
479         }
480
481       priv->manager = NULL;
482     }
483
484   if (manager)
485     priv->manager = NULL;
486   else
487     priv->manager = gtk_recent_manager_get_default ();
488
489   if (priv->manager)
490     priv->manager_changed_id = g_signal_connect (priv->manager, "changed",
491                                                  G_CALLBACK (manager_changed_cb),
492                                                  action);
493 }
494
495 static void
496 gtk_recent_action_finalize (GObject *gobject)
497 {
498   GtkRecentAction *action = GTK_RECENT_ACTION (gobject);
499   GtkRecentActionPrivate *priv = action->priv;
500
501   priv->manager = NULL;
502   
503   if (priv->data_destroy)
504     {
505       priv->data_destroy (priv->sort_data);
506       priv->data_destroy = NULL;
507     }
508
509   priv->sort_data = NULL;
510   priv->sort_func = NULL;
511
512   g_slist_free (priv->choosers);
513
514   G_OBJECT_CLASS (gtk_recent_action_parent_class)->finalize (gobject);
515 }
516
517 static void
518 gtk_recent_action_dispose (GObject *gobject)
519 {
520   GtkRecentAction *action = GTK_RECENT_ACTION (gobject);
521   GtkRecentActionPrivate *priv = action->priv;
522
523   if (priv->manager_changed_id)
524     {
525       if (priv->manager)
526         g_signal_handler_disconnect (priv->manager, priv->manager_changed_id);
527
528       priv->manager_changed_id = 0;
529     }
530
531   if (priv->current_filter)
532     {
533       g_object_unref (priv->current_filter);
534       priv->current_filter = NULL;
535     }
536
537   G_OBJECT_CLASS (gtk_recent_action_parent_class)->dispose (gobject);
538 }
539
540 static void
541 gtk_recent_action_set_property (GObject      *gobject,
542                                 guint         prop_id,
543                                 const GValue *value,
544                                 GParamSpec   *pspec)
545 {
546   GtkRecentAction *action = GTK_RECENT_ACTION (gobject);
547   GtkRecentActionPrivate *priv = action->priv;
548   GSList *l;
549
550   switch (prop_id)
551     {
552     case PROP_SHOW_NUMBERS:
553       priv->show_numbers = g_value_get_boolean (value);
554       break;
555     case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
556       priv->show_private = g_value_get_boolean (value);
557       break;
558     case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
559       priv->show_not_found = g_value_get_boolean (value);
560       break;
561     case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
562       priv->show_tips = g_value_get_boolean (value);
563       break;
564     case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
565       priv->show_icons = g_value_get_boolean (value);
566       break;
567     case GTK_RECENT_CHOOSER_PROP_LIMIT:
568       priv->limit = g_value_get_int (value);
569       break;
570     case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
571       priv->local_only = g_value_get_boolean (value);
572       break;
573     case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
574       priv->sort_type = g_value_get_enum (value);
575       break;
576     case GTK_RECENT_CHOOSER_PROP_FILTER:
577       /* this already iterates over the choosers list */
578       set_current_filter (action, g_value_get_object (value));
579       return;
580     case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
581       g_warning ("%s: Choosers of type `%s' do not support selecting multiple items.",
582                  G_STRFUNC,
583                  G_OBJECT_TYPE_NAME (gobject));
584       return;
585     case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
586       /* this is a construct-only property; we set the recent-manager
587        * of the choosers with this value when we create them, so there's
588        * no need to iterate later.
589        */
590       set_recent_manager (action, g_value_get_object (value));
591       return;
592     default:
593       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
594       return;
595     }
596
597   /* propagate the properties to the proxies we have created */
598   for (l = priv->choosers; l != NULL; l = l->next)
599     {
600       GObject *proxy = l->data;
601
602       g_object_set_property (proxy, pspec->name, value);
603     }
604 }
605
606 static void
607 gtk_recent_action_get_property (GObject    *gobject,
608                                 guint       prop_id,
609                                 GValue     *value,
610                                 GParamSpec *pspec)
611 {
612   GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (gobject);
613
614   switch (prop_id)
615     {
616     case PROP_SHOW_NUMBERS:
617       g_value_set_boolean (value, priv->show_numbers);
618       break;
619     case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
620       g_value_set_boolean (value, priv->show_private);
621       break;
622     case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
623       g_value_set_boolean (value, priv->show_not_found);
624       break;
625     case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
626       g_value_set_boolean (value, priv->show_tips);
627       break;
628     case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
629       g_value_set_boolean (value, priv->show_icons);
630       break;
631     case GTK_RECENT_CHOOSER_PROP_LIMIT:
632       g_value_set_int (value, priv->limit);
633       break;
634     case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
635       g_value_set_boolean (value, priv->local_only);
636       break;
637     case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
638       g_value_set_enum (value, priv->sort_type);
639       break;
640     case GTK_RECENT_CHOOSER_PROP_FILTER:
641       g_value_set_object (value, priv->current_filter);
642       break;
643     case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
644       g_value_set_boolean (value, FALSE);
645       break;
646     default:
647       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
648       break;
649     }
650 }
651
652 static void
653 gtk_recent_action_class_init (GtkRecentActionClass *klass)
654 {
655   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
656   GtkActionClass *action_class = GTK_ACTION_CLASS (klass);
657
658   g_type_class_add_private (klass, sizeof (GtkRecentActionPrivate));
659
660   gobject_class->finalize = gtk_recent_action_finalize;
661   gobject_class->dispose = gtk_recent_action_dispose;
662   gobject_class->set_property = gtk_recent_action_set_property;
663   gobject_class->get_property = gtk_recent_action_get_property;
664
665   action_class->activate = gtk_recent_action_activate;
666   action_class->connect_proxy = gtk_recent_action_connect_proxy;
667   action_class->disconnect_proxy = gtk_recent_action_disconnect_proxy;
668   action_class->create_menu_item = gtk_recent_action_create_menu_item;
669   action_class->create_tool_item = gtk_recent_action_create_tool_item;
670   action_class->create_menu = gtk_recent_action_create_menu;
671   action_class->menu_item_type = GTK_TYPE_IMAGE_MENU_ITEM;
672   action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;
673
674   _gtk_recent_chooser_install_properties (gobject_class);
675
676   g_object_class_install_property (gobject_class,
677                                    PROP_SHOW_NUMBERS,
678                                    g_param_spec_boolean ("show-numbers",
679                                                          P_("Show Numbers"),
680                                                          P_("Whether the items should be displayed with a number"),
681                                                          FALSE,
682                                                          G_PARAM_READWRITE));
683
684 }
685
686 static void
687 gtk_recent_action_init (GtkRecentAction *action)
688 {
689   GtkRecentActionPrivate *priv;
690
691   action->priv = priv = GTK_RECENT_ACTION_GET_PRIVATE (action);
692
693   priv->show_numbers = FALSE;
694   priv->show_icons = TRUE;
695   priv->show_tips = FALSE;
696   priv->show_not_found = TRUE;
697   priv->show_private = FALSE;
698   priv->local_only = TRUE;
699
700   priv->limit = FALLBACK_ITEM_LIMIT;
701
702   priv->sort_type = GTK_RECENT_SORT_NONE;
703   priv->sort_func = NULL;
704   priv->sort_data = NULL;
705   priv->data_destroy = NULL;
706
707   priv->current_filter = NULL;
708
709   priv->manager = NULL;
710   priv->manager_changed_id = 0;
711 }
712
713 /**
714  * gtk_recent_action_new:
715  * @name: a unique name for the action
716  * @label: the label displayed in menu items and on buttons, or %NULL
717  * @tooltip: a tooltip for the action, or %NULL
718  * @stock_id: the stock icon to display in widgets representing the
719  *   action, or %NULL
720  *
721  * Creates a new #GtkRecentAction object. To add the action to
722  * a #GtkActionGroup and set the accelerator for the action,
723  * call gtk_action_group_add_action_with_accel().
724  *
725  * Return value: the newly created #GtkRecentAction.
726  *
727  * Since: 2.12
728  */
729 GtkAction *
730 gtk_recent_action_new (const gchar *name,
731                        const gchar *label,
732                        const gchar *tooltip,
733                        const gchar *stock_id)
734 {
735   g_return_val_if_fail (name != NULL, NULL);
736
737   return g_object_new (GTK_TYPE_RECENT_ACTION,
738                        "name", name,
739                        "label", label,
740                        "tooltip", tooltip,
741                        "stock-id", stock_id,
742                        NULL);
743 }
744
745 /**
746  * gtk_recent_action_new_for_manager:
747  * @name: a unique name for the action
748  * @label: the label displayed in menu items and on buttons, or %NULL
749  * @tooltip: a tooltip for the action, or %NULL
750  * @stock_id: the stock icon to display in widgets representing the
751  *   action, or %NULL
752  * @manager: a #GtkRecentManager, or %NULL for using the default
753  *   #GtkRecentManager
754  *
755  * Creates a new #GtkRecentAction object. To add the action to
756  * a #GtkActionGroup and set the accelerator for the action,
757  * call gtk_action_group_add_action_with_accel().
758  *
759  * Return value: the newly created #GtkRecentAction
760  * 
761  * Since: 2.12
762  */
763 GtkAction *
764 gtk_recent_action_new_for_manager (const gchar      *name,
765                                    const gchar      *label,
766                                    const gchar      *tooltip,
767                                    const gchar      *stock_id,
768                                    GtkRecentManager *manager)
769 {
770   g_return_val_if_fail (name != NULL, NULL);
771   g_return_val_if_fail (manager == NULL || GTK_IS_RECENT_MANAGER (manager), NULL);
772
773   return g_object_new (GTK_TYPE_RECENT_ACTION,
774                        "name", name,
775                        "label", label,
776                        "tooltip", tooltip,
777                        "stock-id", stock_id,
778                        "recent-manager", manager,
779                        NULL);
780 }
781
782 /**
783  * gtk_recent_action_get_show_numbers:
784  * @action: a #GtkRecentAction
785  *
786  * Returns the value set by gtk_recent_chooser_menu_set_show_numbers().
787  *
788  * Return value: %TRUE if numbers should be shown.
789  *
790  * Since: 2.12
791  */
792 gboolean
793 gtk_recent_action_get_show_numbers (GtkRecentAction *action)
794 {
795   g_return_val_if_fail (GTK_IS_RECENT_ACTION (action), FALSE);
796
797   return action->priv->show_numbers;
798 }
799
800 /**
801  * gtk_recent_action_set_show_numbers:
802  * @action: a #GtkRecentAction
803  * @show_numbers: %TRUE if the shown items should be numbered
804  *
805  * Sets whether a number should be added to the items shown by the
806  * widgets representing @action. The numbers are shown to provide
807  * a unique character for a mnemonic to be used inside the menu item's
808  * label. Only the first ten items get a number to avoid clashes.
809  *
810  * Since: 2.12
811  */
812 void
813 gtk_recent_action_set_show_numbers (GtkRecentAction *action,
814                                     gboolean         show_numbers)
815 {
816   GtkRecentActionPrivate *priv;
817
818   g_return_if_fail (GTK_IS_RECENT_ACTION (action));
819
820   priv = action->priv;
821
822   if (priv->show_numbers != show_numbers)
823     {
824       g_object_ref (action);
825
826       priv->show_numbers = show_numbers;
827
828       g_object_notify (G_OBJECT (action), "show-numbers");
829       g_object_unref (action);
830     }
831 }
832
833 #define __GTK_RECENT_ACTION_C__
834 #include "gtkaliasdef.c"