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