]> Pileus Git - ~andy/gtk/blob - gtk/gtkrecentaction.c
Remove useless inlined function and propagate the properties to the
[~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   
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
213 static void
214 set_current_filter (GtkRecentAction *action,
215                     GtkRecentFilter *filter)
216 {
217   GtkRecentActionPrivate *priv = action->priv;
218
219   g_object_ref (action);
220
221   if (priv->current_filter)
222     g_object_unref (priv->current_filter);
223
224   priv->current_filter = filter;
225
226   if (priv->current_filter)
227     g_object_ref_sink (priv->current_filter);
228
229   g_object_notify (G_OBJECT (action), "filter");
230
231   g_object_unref (action);
232 }
233
234 static void
235 gtk_recent_action_add_filter (GtkRecentChooser *chooser,
236                               GtkRecentFilter  *filter)
237 {
238   GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (chooser);
239
240   if (priv->current_filter != filter)
241     set_current_filter (GTK_RECENT_ACTION (chooser), filter);
242 }
243
244 static void
245 gtk_recent_action_remove_filter (GtkRecentChooser *chooser,
246                                  GtkRecentFilter  *filter)
247 {
248   GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (chooser);
249
250   if (priv->current_filter == filter)
251     set_current_filter (GTK_RECENT_ACTION (chooser), NULL);
252 }
253
254 static GSList *
255 gtk_recent_action_list_filters (GtkRecentChooser *chooser)
256 {
257   GSList *retval = NULL;
258   GtkRecentFilter *current_filter;
259
260   current_filter = GTK_RECENT_ACTION_GET_PRIVATE (chooser)->current_filter;
261   retval = g_slist_prepend (retval, current_filter);
262
263   return retval;
264 }
265
266
267 static void
268 gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface)
269 {
270   iface->set_current_uri = gtk_recent_action_set_current_uri;
271   iface->get_current_uri = gtk_recent_action_get_current_uri;
272   iface->select_uri = gtk_recent_action_select_uri;
273   iface->unselect_uri = gtk_recent_action_unselect_uri;
274   iface->select_all = gtk_recent_action_select_all;
275   iface->unselect_all = gtk_recent_action_unselect_all;
276   iface->get_items = gtk_recent_action_get_items;
277   iface->get_recent_manager = gtk_recent_action_get_recent_manager;
278   iface->set_sort_func = gtk_recent_action_set_sort_func;
279   iface->add_filter = gtk_recent_action_add_filter;
280   iface->remove_filter = gtk_recent_action_remove_filter;
281   iface->list_filters = gtk_recent_action_list_filters;
282 }
283
284 static void
285 gtk_recent_action_activate (GtkAction *action)
286 {
287   /* we have probably been invoked by a menu tool button or by a
288    * direct call of gtk_action_activate(); since no item has been
289    * selected, we must unset the current recent chooser pointer
290    */
291   GTK_RECENT_ACTION_GET_PRIVATE (action)->current_chooser = NULL;
292 }
293
294 static void
295 delegate_selection_changed (GtkRecentAction  *action,
296                             GtkRecentChooser *chooser)
297 {
298   GtkRecentActionPrivate *priv = action->priv;
299
300   priv->current_chooser = chooser;
301
302   g_signal_emit_by_name (action, "selection-changed");
303 }
304
305 static void
306 delegate_item_activated (GtkRecentAction  *action,
307                          GtkRecentChooser *chooser)
308 {
309   GtkRecentActionPrivate *priv = action->priv;
310
311   priv->current_chooser = chooser;
312
313   g_signal_emit_by_name (action, "item-activated");
314 }
315
316 static void
317 gtk_recent_action_connect_proxy (GtkAction *action,
318                                  GtkWidget *widget)
319 {
320   GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
321   GtkRecentActionPrivate *priv = recent_action->priv;
322
323   if (GTK_IS_RECENT_CHOOSER (widget) &&
324       !g_slist_find (priv->choosers, widget))
325     {
326       g_object_set (G_OBJECT (widget),
327                     "show-private", priv->show_private,
328                     "show-not-found", priv->show_not_found,
329                     "show-tips", priv->show_tips,
330                     "show-icons", priv->show_icons,
331                     "show-numbers", priv->show_numbers,
332                     "limit", priv->limit,
333                     "sort-type", priv->sort_type,
334                     NULL);
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   GTK_ACTION_CLASS (gtk_recent_action_parent_class)->connect_proxy (action, widget);
353 }
354
355 static void
356 gtk_recent_action_disconnect_proxy (GtkAction *action,
357                                     GtkWidget *widget)
358 {
359   GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
360   GtkRecentActionPrivate *priv = recent_action->priv;
361
362   /* if it was one of the recent choosers we created, remove it
363    * from the list
364    */
365   if (g_slist_find (priv->choosers, widget))
366     priv->choosers = g_slist_remove (priv->choosers, widget);
367
368   GTK_ACTION_CLASS (gtk_recent_action_parent_class)->disconnect_proxy (action, widget);
369 }
370
371 static GtkWidget *
372 gtk_recent_action_create_menu (GtkAction *action)
373 {
374   GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
375   GtkRecentActionPrivate *priv = recent_action->priv;
376   GtkWidget *widget;
377
378   widget = g_object_new (GTK_TYPE_RECENT_CHOOSER_MENU,
379                          "show-private", priv->show_private,
380                          "show-not-found", priv->show_not_found,
381                          "show-tips", priv->show_tips,
382                          "show-icons", priv->show_icons,
383                          "show-numbers", priv->show_numbers,
384                          "limit", priv->limit,
385                          "sort-type", priv->sort_type,
386                          "recent-manager", priv->manager,
387                          NULL);
388   
389   if (priv->sort_func)
390     {
391       gtk_recent_chooser_set_sort_func (GTK_RECENT_CHOOSER (widget),
392                                         priv->sort_func,
393                                         priv->sort_data,
394                                         priv->data_destroy);
395     }
396
397   g_signal_connect_swapped (widget, "selection_changed",
398                             G_CALLBACK (delegate_selection_changed),
399                             recent_action);
400   g_signal_connect_swapped (widget, "item-activated",
401                             G_CALLBACK (delegate_item_activated),
402                             recent_action);
403
404   /* keep track of the choosers we create */
405   priv->choosers = g_slist_prepend (priv->choosers, widget);
406
407   return widget;
408 }
409
410 static GtkWidget *
411 gtk_recent_action_create_menu_item (GtkAction *action)
412 {
413   GtkWidget *menu;
414   GtkWidget *menuitem;
415
416   menu = gtk_recent_action_create_menu (action);
417   menuitem = g_object_new (GTK_TYPE_IMAGE_MENU_ITEM, NULL);
418   gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
419   gtk_widget_show (menu);
420
421   return menuitem;
422 }
423
424 static GtkWidget *
425 gtk_recent_action_create_tool_item (GtkAction *action)
426 {
427   GtkWidget *menu;
428   GtkWidget *toolitem;
429
430   menu = gtk_recent_action_create_menu (action);
431   toolitem = g_object_new (GTK_TYPE_MENU_TOOL_BUTTON, NULL);
432   gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (toolitem), menu);
433   gtk_widget_show (menu);
434
435   return toolitem;
436 }
437
438 static void
439 manager_changed_cb (GtkRecentManager *manager,
440                     gpointer          user_data)
441 {
442   /* do we need to propagate the signal to all the proxies? guess not */
443 }
444
445 static void
446 set_recent_manager (GtkRecentAction  *action,
447                     GtkRecentManager *manager)
448 {
449   GtkRecentActionPrivate *priv = action->priv;
450
451   if (priv->manager)
452     {
453       if (priv->manager_changed_id)
454         {
455           g_signal_handler_disconnect (priv->manager, priv->manager_changed_id);
456           priv->manager_changed_id = 0;
457         }
458
459       priv->manager = NULL;
460     }
461
462   if (manager)
463     priv->manager = NULL;
464   else
465     priv->manager = gtk_recent_manager_get_default ();
466
467   if (priv->manager)
468     priv->manager_changed_id = g_signal_connect (priv->manager, "changed",
469                                                  G_CALLBACK (manager_changed_cb),
470                                                  action);
471 }
472
473 static void
474 gtk_recent_action_finalize (GObject *gobject)
475 {
476   GtkRecentAction *action = GTK_RECENT_ACTION (gobject);
477   GtkRecentActionPrivate *priv = action->priv;
478
479   priv->manager = NULL;
480   
481   if (priv->data_destroy)
482     {
483       priv->data_destroy (priv->sort_data);
484       priv->data_destroy = NULL;
485     }
486
487   priv->sort_data = NULL;
488   priv->sort_func = NULL;
489
490   g_slist_free (priv->choosers);
491
492   G_OBJECT_CLASS (gtk_recent_action_parent_class)->finalize (gobject);
493 }
494
495 static void
496 gtk_recent_action_dispose (GObject *gobject)
497 {
498   GtkRecentAction *action = GTK_RECENT_ACTION (gobject);
499   GtkRecentActionPrivate *priv = action->priv;
500
501   if (priv->manager_changed_id)
502     {
503       if (priv->manager)
504         g_signal_handler_disconnect (priv->manager, priv->manager_changed_id);
505
506       priv->manager_changed_id = 0;
507     }
508
509   if (priv->current_filter)
510     {
511       g_object_unref (priv->current_filter);
512       priv->current_filter = NULL;
513     }
514
515   G_OBJECT_CLASS (gtk_recent_action_parent_class)->dispose (gobject);
516 }
517
518 static void
519 gtk_recent_action_set_property (GObject      *gobject,
520                                 guint         prop_id,
521                                 const GValue *value,
522                                 GParamSpec   *pspec)
523 {
524   GtkRecentAction *action = GTK_RECENT_ACTION (gobject);
525   GtkRecentActionPrivate *priv = action->priv;
526   GSList *l;
527
528   switch (prop_id)
529     {
530     case PROP_SHOW_NUMBERS:
531       priv->show_numbers = g_value_get_boolean (value);
532       break;
533     case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
534       priv->show_private = g_value_get_boolean (value);
535       break;
536     case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
537       priv->show_not_found = g_value_get_boolean (value);
538       break;
539     case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
540       priv->show_tips = g_value_get_boolean (value);
541       break;
542     case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
543       priv->show_icons = g_value_get_boolean (value);
544       break;
545     case GTK_RECENT_CHOOSER_PROP_LIMIT:
546       priv->limit = g_value_get_int (value);
547       break;
548     case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
549       priv->local_only = g_value_get_boolean (value);
550       break;
551     case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
552       priv->sort_type = g_value_get_enum (value);
553       break;
554     case GTK_RECENT_CHOOSER_PROP_FILTER:
555       set_current_filter (action, g_value_get_object (value));
556       break;
557     case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
558       g_warning ("%s: Choosers of type `%s' do not support selecting multiple items.",
559                  G_STRFUNC,
560                  G_OBJECT_TYPE_NAME (gobject));
561       break;
562     case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
563       set_recent_manager (action, g_value_get_object (value));
564       break;
565     default:
566       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
567       return;
568     }
569
570   /* propagate the properties to the proxies we have created */
571   for (l = priv->choosers; l != NULL; l = l->next)
572     {
573       GObject *proxy = l->data;
574
575       g_object_set_property (proxy, pspec->name, value);
576     }
577 }
578
579 static void
580 gtk_recent_action_get_property (GObject    *gobject,
581                                 guint       prop_id,
582                                 GValue     *value,
583                                 GParamSpec *pspec)
584 {
585   GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (gobject);
586
587   switch (prop_id)
588     {
589     case PROP_SHOW_NUMBERS:
590       g_value_set_boolean (value, priv->show_numbers);
591       break;
592     case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
593       g_value_set_boolean (value, priv->show_private);
594       break;
595     case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
596       g_value_set_boolean (value, priv->show_not_found);
597       break;
598     case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
599       g_value_set_boolean (value, priv->show_tips);
600       break;
601     case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
602       g_value_set_boolean (value, priv->show_icons);
603       break;
604     case GTK_RECENT_CHOOSER_PROP_LIMIT:
605       g_value_set_int (value, priv->limit);
606       break;
607     case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
608       g_value_set_boolean (value, priv->local_only);
609       break;
610     case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
611       g_value_set_enum (value, priv->sort_type);
612       break;
613     case GTK_RECENT_CHOOSER_PROP_FILTER:
614       g_value_set_object (value, priv->current_filter);
615       break;
616     case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
617       g_warning ("%s: Choosers of type `%s' do not support selecting multiple items.",
618                  G_STRFUNC,
619                  G_OBJECT_TYPE_NAME (gobject));
620       break;
621     default:
622       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
623       break;
624     }
625 }
626
627 static void
628 gtk_recent_action_class_init (GtkRecentActionClass *klass)
629 {
630   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
631   GtkActionClass *action_class = GTK_ACTION_CLASS (klass);
632
633   g_type_class_add_private (klass, sizeof (GtkRecentActionPrivate));
634
635   gobject_class->finalize = gtk_recent_action_finalize;
636   gobject_class->dispose = gtk_recent_action_dispose;
637   gobject_class->set_property = gtk_recent_action_set_property;
638   gobject_class->get_property = gtk_recent_action_get_property;
639
640   action_class->activate = gtk_recent_action_activate;
641   action_class->connect_proxy = gtk_recent_action_connect_proxy;
642   action_class->disconnect_proxy = gtk_recent_action_disconnect_proxy;
643   action_class->create_menu_item = gtk_recent_action_create_menu_item;
644   action_class->create_tool_item = gtk_recent_action_create_tool_item;
645   action_class->create_menu = gtk_recent_action_create_menu;
646   action_class->menu_item_type = GTK_TYPE_IMAGE_MENU_ITEM;
647   action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;
648
649   _gtk_recent_chooser_install_properties (gobject_class);
650
651   g_object_class_install_property (gobject_class,
652                                    PROP_SHOW_NUMBERS,
653                                    g_param_spec_boolean ("show-numbers",
654                                                          P_("Show Numbers"),
655                                                          P_("Whether the items should be displayed with a number"),
656                                                          FALSE,
657                                                          G_PARAM_READWRITE));
658
659 }
660
661 static void
662 gtk_recent_action_init (GtkRecentAction *action)
663 {
664   GtkRecentActionPrivate *priv;
665
666   action->priv = priv = GTK_RECENT_ACTION_GET_PRIVATE (action);
667
668   priv->show_numbers = FALSE;
669   priv->show_icons = TRUE;
670   priv->show_tips = FALSE;
671   priv->show_not_found = TRUE;
672   priv->show_private = FALSE;
673   priv->local_only = TRUE;
674
675   priv->limit = FALLBACK_ITEM_LIMIT;
676
677   priv->sort_type = GTK_RECENT_SORT_NONE;
678   priv->sort_func = NULL;
679   priv->sort_data = NULL;
680   priv->data_destroy = NULL;
681
682   priv->current_filter = NULL;
683
684   priv->manager = NULL;
685   priv->manager_changed_id = 0;
686 }
687
688 /**
689  * gtk_recent_action_new:
690  * @name: a unique name for the action
691  * @label: the label displayed in menu items and on buttons
692  * @tooltip: a tooltip for the action
693  * @stock_id: the stock icon to display in widgets representing the action
694  *
695  * Creates a new #GtkRecentAction object. To add the action to
696  * a #GtkActionGroup and set the accelerator for the action,
697  * call gtk_action_group_add_action_with_accel().
698  *
699  * Return value: the newly created #GtkRecentAction.
700  *
701  * Since: 2.12
702  */
703 GtkAction *
704 gtk_recent_action_new (const gchar *name,
705                        const gchar *label,
706                        const gchar *tooltip,
707                        const gchar *stock_id)
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                        NULL);
715 }
716
717 /**
718  * gtk_recent_action_new_for_manager:
719  * @name: a unique name for the action
720  * @label: the label displayed in menu items and on buttons
721  * @tooltip: a tooltip for the action
722  * @stock_id: the stock icon to display in widgets representing the action
723  * @manager: a #GtkRecentManager or %NULL
724  *
725  * Creates a new #GtkRecentAction object. To add the action to
726  * a #GtkActionGroup and set the accelerator for the action,
727  * call gtk_action_group_add_action_with_accel().
728  *
729  * Return value: the newly created #GtkRecentAction
730  * 
731  * Since: 2.12
732  */
733 GtkAction *
734 gtk_recent_action_new_for_manager (const gchar      *name,
735                                    const gchar      *label,
736                                    const gchar      *tooltip,
737                                    const gchar      *stock_id,
738                                    GtkRecentManager *manager)
739 {
740   return g_object_new (GTK_TYPE_RECENT_ACTION,
741                        "name", name,
742                        "label", label,
743                        "tooltip", tooltip,
744                        "stock-id", stock_id,
745                        "recent-manager", manager,
746                        NULL);
747 }
748
749 /**
750  * gtk_recent_action_get_show_numbers:
751  * @action: a #GtkRecentAction
752  *
753  * Returns the value set by gtk_recent_chooser_menu_set_show_numbers().
754  *
755  * Return value: %TRUE if numbers should be shown.
756  *
757  * Since: 2.12
758  */
759 gboolean
760 gtk_recent_action_get_show_numbers (GtkRecentAction *action)
761 {
762   g_return_val_if_fail (GTK_IS_RECENT_ACTION (action), FALSE);
763
764   return action->priv->show_numbers;
765 }
766
767 /**
768  * gtk_recent_action_set_show_numbers:
769  * @action: a #GtkRecentAction
770  * @show_numbers
771  *
772  * Sets whether a number should be added to the items shown by the
773  * widgets representing @action. The  numbers are shown to provide
774  * a unique character for a mnemonic to be used inside the menu item's
775  * label. Only the first ten items get a number to avoid clashes.
776  *
777  * Since: 2.12
778  */
779 void
780 gtk_recent_action_set_show_numbers (GtkRecentAction *action,
781                                     gboolean         show_numbers)
782 {
783   GtkRecentActionPrivate *priv;
784
785   g_return_if_fail (GTK_IS_RECENT_ACTION (action));
786
787   priv = action->priv;
788
789   if (priv->show_numbers != show_numbers)
790     {
791       g_object_ref (action);
792
793       priv->show_numbers = show_numbers;
794
795       g_object_notify (G_OBJECT (action), "show-numbers");
796       g_object_unref (action);
797     }
798 }
799
800 #define __GTK_RECENT_ACTION_C__
801 #include "gtkaliasdef.c"