'GTK. Update programmatically recent-files submenu with GtkRecentChooserMenu

I'm using GTK+3 and I would like to do a recent-files submenu which it could update programmatically, not just by the GUI user interaction (that is working). I've used GtkRecentChooserMenu.

I've made this for setting the submenu:

GtkWidget * recentChooser = gtk_recent_chooser_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (win->menuItemRecent), recentChooser); //win->menuItemRecent is a GtkMenuItem
gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (recentChooser), TRUE);
GtkRecentFilter *filter = gtk_recent_filter_new ();
gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (recentChooser), GTK_RECENT_SORT_MRU);
gtk_recent_filter_add_pattern (filter, "*.tnt");
gtk_recent_filter_add_pattern (filter, "*.run");
gtk_recent_filter_add_pattern (filter, "*.tre");
gtk_recent_filter_add_pattern (filter, "*.dat");
gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (recentChooser), filter);
g_signal_connect (G_OBJECT (recentChooser), "item-activated", G_CALLBACK (on_recentFile_activated), NULL);
gtk_recent_chooser_set_show_icons(GTK_RECENT_CHOOSER (recentChooser), FALSE);

As I said, all this is working. Now, for the programmatic submenu update, I've tried this:

submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM(win->menuItemRecent));
GtkRecentChooser * chooser = GTK_RECENT_CHOOSER(submenu);
GtkRecentManager * manager = GTK_RECENT_CHOOSER_GET_IFACE(chooser)->get_recent_manager (chooser);
gtk_recent_manager_add_item(manager, file); //file is a file name to add into submenu

But this isn't working. The gtk_recent_manager_add_item() seems add (because it returns TRUE) but the submenu doesn't update.

Thanks in advance.

Martín



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source