summaryrefslogtreecommitdiff
path: root/gtk/gtkrecentaction.c
blob: 449eaad3c79318c921882ead32fece58d557c440 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
/* GTK - The GIMP Toolkit
 * Recent chooser action for GtkUIManager
 *
 * Copyright (C) 2007, Emmanuele Bassi
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * 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.
 */

#include "config.h"

#include "gtkintl.h"
#include "gtkrecentaction.h"
#include "gtkimagemenuitem.h"
#include "gtkmenutoolbutton.h"
#include "gtkrecentchooser.h"
#include "gtkrecentchoosermenu.h"
#include "gtkrecentchooserutils.h"
#include "gtkrecentchooserprivate.h"
#include "gtkprivate.h"
#include "gtkalias.h"

#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;

  /* RecentChooser properties */
  guint show_private   : 1;
  guint show_not_found : 1;
  guint show_tips      : 1;
  guint show_icons     : 1;
  guint local_only     : 1;

  gint limit;

  GtkRecentSortType sort_type;
  GtkRecentSortFunc sort_func;
  gpointer sort_data;
  GDestroyNotify data_destroy;

  GtkRecentFilter *current_filter;

  GSList *choosers;
  GtkRecentChooser *current_chooser;
};

enum
{
  PROP_0,

  PROP_SHOW_NUMBERS
};

static void gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface);

G_DEFINE_TYPE_WITH_CODE (GtkRecentAction,
                         gtk_recent_action,
                         GTK_TYPE_ACTION,
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
                                                gtk_recent_chooser_iface_init));

static gboolean
gtk_recent_action_set_current_uri (GtkRecentChooser  *chooser,
                                   const gchar       *uri,
                                   GError           **error)
{
  GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
  GtkRecentActionPrivate *priv = action->priv;
  GSList *l;

  for (l = priv->choosers; l; l = l->next)
    {
      GtkRecentChooser *recent_chooser = l->data;

      if (!gtk_recent_chooser_set_current_uri (recent_chooser, uri, error))
        return FALSE;
    }

  return TRUE;
}

static gchar *
gtk_recent_action_get_current_uri (GtkRecentChooser *chooser)
{
  GtkRecentAction *recent_action = GTK_RECENT_ACTION (chooser);
  GtkRecentActionPrivate *priv = recent_action->priv;

  if (priv->current_chooser)
    return gtk_recent_chooser_get_current_uri (priv->current_chooser);

  return NULL;
}

static gboolean
gtk_recent_action_select_uri (GtkRecentChooser  *chooser,
                              const gchar       *uri,
                              GError           **error)
{
  GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
  GtkRecentActionPrivate *priv = action->priv;
  GSList *l;

  for (l = priv->choosers; l; l = l->next)
    {
      GtkRecentChooser *recent_chooser = l->data;

      if (!gtk_recent_chooser_select_uri (recent_chooser, uri, error))
        return FALSE;
    }

  return TRUE;
}

static void
gtk_recent_action_unselect_uri (GtkRecentChooser *chooser,
                                const gchar      *uri)
{
  GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
  GtkRecentActionPrivate *priv = action->priv;
  GSList *l;

  for (l = priv->choosers; l; l = l->next)
    {
      GtkRecentChooser *chooser = l->data;
      
      gtk_recent_chooser_unselect_uri (chooser, uri);
    }
}

static void
gtk_recent_action_select_all (GtkRecentChooser *chooser)
{
  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_type_name (G_OBJECT_TYPE (chooser)));
}


static GList *
gtk_recent_action_get_items (GtkRecentChooser *chooser)
{
  GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
  GtkRecentActionPrivate *priv = action->priv;

  return _gtk_recent_chooser_get_items (chooser,
                                        priv->current_filter,
                                        priv->sort_func,
                                        priv->sort_data);
}

static GtkRecentManager *
gtk_recent_action_get_recent_manager (GtkRecentChooser *chooser)
{
  return GTK_RECENT_ACTION_GET_PRIVATE (chooser)->manager;
}

static void
gtk_recent_action_set_sort_func (GtkRecentChooser  *chooser,
                                 GtkRecentSortFunc  sort_func,
                                 gpointer           sort_data,
                                 GDestroyNotify     data_destroy)
{
  GtkRecentAction *action = GTK_RECENT_ACTION (chooser);
  GtkRecentActionPrivate *priv = action->priv;
  GSList *l;
  
  if (priv->data_destroy)
    {
      priv->data_destroy (priv->sort_data);
      priv->data_destroy = NULL;
    }
      
  priv->sort_func = NULL;
  priv->sort_data = NULL;
  
  if (sort_func)
    {
      priv->sort_func = sort_func;
      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 void
set_current_filter (GtkRecentAction *action,
                    GtkRecentFilter *filter)
{
  GtkRecentActionPrivate *priv = action->priv;
  GSList *l;

  g_object_ref (action);

  if (priv->current_filter)
    g_object_unref (priv->current_filter);

  priv->current_filter = filter;

  if (priv->current_filter)
    g_object_ref_sink (priv->current_filter);

  for (l = priv->choosers; l; l = l->next)
    {
      GtkRecentChooser *chooser = l->data;

      gtk_recent_chooser_set_filter (chooser, priv->current_filter);
    }

  g_object_notify (G_OBJECT (action), "filter");

  g_object_unref (action);
}

static void
gtk_recent_action_add_filter (GtkRecentChooser *chooser,
                              GtkRecentFilter  *filter)
{
  GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (chooser);

  if (priv->current_filter != filter)
    set_current_filter (GTK_RECENT_ACTION (chooser), filter);
}

static void
gtk_recent_action_remove_filter (GtkRecentChooser *chooser,
                                 GtkRecentFilter  *filter)
{
  GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (chooser);

  if (priv->current_filter == filter)
    set_current_filter (GTK_RECENT_ACTION (chooser), NULL);
}

static GSList *
gtk_recent_action_list_filters (GtkRecentChooser *chooser)
{
  GSList *retval = NULL;
  GtkRecentFilter *current_filter;

  current_filter = GTK_RECENT_ACTION_GET_PRIVATE (chooser)->current_filter;
  retval = g_slist_prepend (retval, current_filter);

  return retval;
}


static void
gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface)
{
  iface->set_current_uri = gtk_recent_action_set_current_uri;
  iface->get_current_uri = gtk_recent_action_get_current_uri;
  iface->select_uri = gtk_recent_action_select_uri;
  iface->unselect_uri = gtk_recent_action_unselect_uri;
  iface->select_all = gtk_recent_action_select_all;
  iface->unselect_all = gtk_recent_action_unselect_all;
  iface->get_items = gtk_recent_action_get_items;
  iface->get_recent_manager = gtk_recent_action_get_recent_manager;
  iface->set_sort_func = gtk_recent_action_set_sort_func;
  iface->add_filter = gtk_recent_action_add_filter;
  iface->remove_filter = gtk_recent_action_remove_filter;
  iface->list_filters = gtk_recent_action_list_filters;
}

static void
gtk_recent_action_activate (GtkAction *action)
{
  /* 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;
}

static void
delegate_selection_changed (GtkRecentAction  *action,
                            GtkRecentChooser *chooser)
{
  GtkRecentActionPrivate *priv = action->priv;

  priv->current_chooser = chooser;

  g_signal_emit_by_name (action, "selection-changed");
}

static void
delegate_item_activated (GtkRecentAction  *action,
                         GtkRecentChooser *chooser)
{
  GtkRecentActionPrivate *priv = action->priv;

  priv->current_chooser = chooser;

  g_signal_emit_by_name (action, "item-activated");
}

static void
gtk_recent_action_connect_proxy (GtkAction *action,
                                 GtkWidget *widget)
{
  GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
  GtkRecentActionPrivate *priv = recent_action->priv;

  if (GTK_IS_RECENT_CHOOSER (widget) &&
      !g_slist_find (priv->choosers, widget))
    {
      g_object_set (G_OBJECT (widget),
                    "show-private", priv->show_private,
                    "show-not-found", priv->show_not_found,
                    "show-tips", priv->show_tips,
                    "show-icons", priv->show_icons,
                    "show-numbers", priv->show_numbers,
                    "limit", priv->limit,
                    "sort-type", priv->sort_type,
                    "filter", priv->current_filter,
                    "local-only", priv->local_only,
                    NULL);
  
      if (priv->sort_func)
        {
          gtk_recent_chooser_set_sort_func (GTK_RECENT_CHOOSER (widget),
                                            priv->sort_func,
                                            priv->sort_data,
                                            priv->data_destroy);
        }

      g_signal_connect_swapped (widget, "selection_changed",
                                G_CALLBACK (delegate_selection_changed),
                                action);
      g_signal_connect_swapped (widget, "item-activated",
                                G_CALLBACK (delegate_item_activated),
                                action);
    }

  GTK_ACTION_CLASS (gtk_recent_action_parent_class)->connect_proxy (action, widget);
}

static void
gtk_recent_action_disconnect_proxy (GtkAction *action,
                                    GtkWidget *widget)
{
  GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
  GtkRecentActionPrivate *priv = recent_action->priv;

  /* if it was one of the recent choosers we created, remove it
   * from the list
   */
  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);
}

static GtkWidget *
gtk_recent_action_create_menu (GtkAction *action)
{
  GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
  GtkRecentActionPrivate *priv = recent_action->priv;
  GtkWidget *widget;

  widget = g_object_new (GTK_TYPE_RECENT_CHOOSER_MENU,
                         "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,
                         "recent-manager", priv->manager,
                         "filter", priv->current_filter,
                         "local-only", priv->local_only,
                         NULL);
  
  if (priv->sort_func)
    {
      gtk_recent_chooser_set_sort_func (GTK_RECENT_CHOOSER (widget),
                                        priv->sort_func,
                                        priv->sort_data,
                                        priv->data_destroy);
    }

  g_signal_connect_swapped (widget, "selection_changed",
                            G_CALLBACK (delegate_selection_changed),
                            recent_action);
  g_signal_connect_swapped (widget, "item-activated",
                            G_CALLBACK (delegate_item_activated),
                            recent_action);

  /* keep track of the choosers we create */
  priv->choosers = g_slist_prepend (priv->choosers, widget);

  return widget;
}

static GtkWidget *
gtk_recent_action_create_menu_item (GtkAction *action)
{
  GtkWidget *menu;
  GtkWidget *menuitem;

  menu = gtk_recent_action_create_menu (action);
  menuitem = g_object_new (GTK_TYPE_IMAGE_MENU_ITEM, NULL);
  gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
  gtk_widget_show (menu);

  return menuitem;
}

static GtkWidget *
gtk_recent_action_create_tool_item (GtkAction *action)
{
  GtkWidget *menu;
  GtkWidget *toolitem;

  menu = gtk_recent_action_create_menu (action);
  toolitem = g_object_new (GTK_TYPE_MENU_TOOL_BUTTON, NULL);
  gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (toolitem), menu);
  gtk_widget_show (menu);

  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
gtk_recent_action_finalize (GObject *gobject)
{
  GtkRecentAction *action = GTK_RECENT_ACTION (gobject);
  GtkRecentActionPrivate *priv = action->priv;

  priv->manager = NULL;
  
  if (priv->data_destroy)
    {
      priv->data_destroy (priv->sort_data);
      priv->data_destroy = NULL;
    }

  priv->sort_data = NULL;
  priv->sort_func = NULL;

  g_slist_free (priv->choosers);

  G_OBJECT_CLASS (gtk_recent_action_parent_class)->finalize (gobject);
}

static void
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);
      priv->current_filter = NULL;
    }

  G_OBJECT_CLASS (gtk_recent_action_parent_class)->dispose (gobject);
}

static void
gtk_recent_action_set_property (GObject      *gobject,
                                guint         prop_id,
                                const GValue *value,
                                GParamSpec   *pspec)
{
  GtkRecentAction *action = GTK_RECENT_ACTION (gobject);
  GtkRecentActionPrivate *priv = action->priv;
  GSList *l;

  switch (prop_id)
    {
    case PROP_SHOW_NUMBERS:
      priv->show_numbers = g_value_get_boolean (value);
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
      priv->show_private = g_value_get_boolean (value);
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
      priv->show_not_found = g_value_get_boolean (value);
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
      priv->show_tips = g_value_get_boolean (value);
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
      priv->show_icons = g_value_get_boolean (value);
      break;
    case GTK_RECENT_CHOOSER_PROP_LIMIT:
      priv->limit = g_value_get_int (value);
      break;
    case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
      priv->local_only = g_value_get_boolean (value);
      break;
    case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
      priv->sort_type = g_value_get_enum (value);
      break;
    case GTK_RECENT_CHOOSER_PROP_FILTER:
      /* this already iterates over the choosers list */
      set_current_filter (action, g_value_get_object (value));
      return;
    case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
      g_warning ("%s: Choosers of type `%s' do not support selecting multiple items.",
                 G_STRFUNC,
                 G_OBJECT_TYPE_NAME (gobject));
      return;
    case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
      /* this is a construct-only property; we set the recent-manager
       * of the choosers with this value when we create them, so there's
       * no need to iterate later.
       */
      set_recent_manager (action, g_value_get_object (value));
      return;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
      return;
    }

  /* propagate the properties to the proxies we have created */
  for (l = priv->choosers; l != NULL; l = l->next)
    {
      GObject *proxy = l->data;

      g_object_set_property (proxy, pspec->name, value);
    }
}

static void
gtk_recent_action_get_property (GObject    *gobject,
                                guint       prop_id,
                                GValue     *value,
                                GParamSpec *pspec)
{
  GtkRecentActionPrivate *priv = GTK_RECENT_ACTION_GET_PRIVATE (gobject);

  switch (prop_id)
    {
    case PROP_SHOW_NUMBERS:
      g_value_set_boolean (value, priv->show_numbers);
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
      g_value_set_boolean (value, priv->show_private);
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
      g_value_set_boolean (value, priv->show_not_found);
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
      g_value_set_boolean (value, priv->show_tips);
      break;
    case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
      g_value_set_boolean (value, priv->show_icons);
      break;
    case GTK_RECENT_CHOOSER_PROP_LIMIT:
      g_value_set_int (value, priv->limit);
      break;
    case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
      g_value_set_boolean (value, priv->local_only);
      break;
    case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
      g_value_set_enum (value, priv->sort_type);
      break;
    case GTK_RECENT_CHOOSER_PROP_FILTER:
      g_value_set_object (value, priv->current_filter);
      break;
    case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
      g_value_set_boolean (value, FALSE);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
      break;
    }
}

static void
gtk_recent_action_class_init (GtkRecentActionClass *klass)
{
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  GtkActionClass *action_class = GTK_ACTION_CLASS (klass);

  g_type_class_add_private (klass, sizeof (GtkRecentActionPrivate));

  gobject_class->finalize = gtk_recent_action_finalize;
  gobject_class->dispose = gtk_recent_action_dispose;
  gobject_class->set_property = gtk_recent_action_set_property;
  gobject_class->get_property = gtk_recent_action_get_property;

  action_class->activate = gtk_recent_action_activate;
  action_class->connect_proxy = gtk_recent_action_connect_proxy;
  action_class->disconnect_proxy = gtk_recent_action_disconnect_proxy;
  action_class->create_menu_item = gtk_recent_action_create_menu_item;
  action_class->create_tool_item = gtk_recent_action_create_tool_item;
  action_class->create_menu = gtk_recent_action_create_menu;
  action_class->menu_item_type = GTK_TYPE_IMAGE_MENU_ITEM;
  action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;

  _gtk_recent_chooser_install_properties (gobject_class);

  g_object_class_install_property (gobject_class,
                                   PROP_SHOW_NUMBERS,
                                   g_param_spec_boolean ("show-numbers",
                                                         P_("Show Numbers"),
                                                         P_("Whether the items should be displayed with a number"),
                                                         FALSE,
                                                         G_PARAM_READWRITE));

}

static void
gtk_recent_action_init (GtkRecentAction *action)
{
  GtkRecentActionPrivate *priv;

  action->priv = priv = GTK_RECENT_ACTION_GET_PRIVATE (action);

  priv->show_numbers = FALSE;
  priv->show_icons = TRUE;
  priv->show_tips = FALSE;
  priv->show_not_found = TRUE;
  priv->show_private = FALSE;
  priv->local_only = TRUE;

  priv->limit = FALLBACK_ITEM_LIMIT;

  priv->sort_type = GTK_RECENT_SORT_NONE;
  priv->sort_func = NULL;
  priv->sort_data = NULL;
  priv->data_destroy = NULL;

  priv->current_filter = NULL;

  priv->manager = NULL;
  priv->manager_changed_id = 0;
}

/**
 * gtk_recent_action_new:
 * @name: a unique name for the action
 * @label: the label displayed in menu items and on buttons, or %NULL
 * @tooltip: a tooltip for the action, or %NULL
 * @stock_id: the stock icon to display in widgets representing the
 *   action, or %NULL
 *
 * Creates a new #GtkRecentAction object. To add the action to
 * a #GtkActionGroup and set the accelerator for the action,
 * call gtk_action_group_add_action_with_accel().
 *
 * Return value: the newly created #GtkRecentAction.
 *
 * Since: 2.12
 */
GtkAction *
gtk_recent_action_new (const gchar *name,
                       const gchar *label,
                       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,
                       "tooltip", tooltip,
                       "stock-id", stock_id,
                       NULL);
}

/**
 * gtk_recent_action_new_for_manager:
 * @name: a unique name for the action
 * @label: the label displayed in menu items and on buttons, or %NULL
 * @tooltip: a tooltip for the action, or %NULL
 * @stock_id: the stock icon to display in widgets representing the
 *   action, or %NULL
 * @manager: a #GtkRecentManager, or %NULL for using the default
 *   #GtkRecentManager
 *
 * Creates a new #GtkRecentAction object. To add the action to
 * a #GtkActionGroup and set the accelerator for the action,
 * call gtk_action_group_add_action_with_accel().
 *
 * Return value: the newly created #GtkRecentAction
 * 
 * Since: 2.12
 */
GtkAction *
gtk_recent_action_new_for_manager (const gchar      *name,
                                   const gchar      *label,
                                   const gchar      *tooltip,
                                   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,
                       "tooltip", tooltip,
                       "stock-id", stock_id,
                       "recent-manager", manager,
                       NULL);
}

/**
 * gtk_recent_action_get_show_numbers:
 * @action: a #GtkRecentAction
 *
 * Returns the value set by gtk_recent_chooser_menu_set_show_numbers().
 *
 * Return value: %TRUE if numbers should be shown.
 *
 * Since: 2.12
 */
gboolean
gtk_recent_action_get_show_numbers (GtkRecentAction *action)
{
  g_return_val_if_fail (GTK_IS_RECENT_ACTION (action), FALSE);

  return action->priv->show_numbers;
}

/**
 * gtk_recent_action_set_show_numbers:
 * @action: a #GtkRecentAction
 * @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
 * 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.
 *
 * Since: 2.12
 */
void
gtk_recent_action_set_show_numbers (GtkRecentAction *action,
                                    gboolean         show_numbers)
{
  GtkRecentActionPrivate *priv;

  g_return_if_fail (GTK_IS_RECENT_ACTION (action));

  priv = action->priv;

  if (priv->show_numbers != show_numbers)
    {
      g_object_ref (action);

      priv->show_numbers = show_numbers;

      g_object_notify (G_OBJECT (action), "show-numbers");
      g_object_unref (action);
    }
}

#define __GTK_RECENT_ACTION_C__
#include "gtkaliasdef.c"