Added "recent files" support:

- when loading a rom, the filename is saved in recent files
  with "application/x-nds-binary" mime type
- a new "open recent" submenu let you choose a recent file
  with the "application/x-nds-binary" mime type
This commit is contained in:
yabause 2009-07-11 16:08:38 +00:00
parent fbc2d8e296
commit d0200bdbcd
1 changed files with 31 additions and 0 deletions

View File

@ -126,6 +126,7 @@ static const char *ui_description =
" <menubar name='MainMenu'>"
" <menu action='FileMenu'>"
" <menuitem action='open'/>"
" <menu action='RecentMenu'/>"
" <separator/>"
" <menuitem action='savestateto'/>"
" <menuitem action='loadstatefrom'/>"
@ -247,6 +248,7 @@ static const char *ui_description =
static const GtkActionEntry action_entries[] = {
{ "FileMenu", NULL, "_File" },
{ "open", "gtk-open", "_Open", "<Ctrl>o", NULL, OpenNdsDialog },
{ "RecentMenu", NULL, "Open _recent" },
{ "savestateto", NULL, "Save state _to ...", NULL, NULL, SaveStateDialog },
{ "loadstatefrom", NULL, "Load state _from ...", NULL, NULL, LoadStateDialog },
{ "recordmovie", NULL, "Record movie _to ...", NULL, NULL, RecordMovieDialog },
@ -903,6 +905,18 @@ static void OpenNdsDialog()
gtk_dialog_run(GTK_DIALOG(pDialog));
gtk_widget_destroy(pDialog);
} else {
GtkRecentData recentData;
memset(&recentData, 0, sizeof(GtkRecentData));
recentData.mime_type = "application/x-nds-binary";
recentData.app_name = (gchar *) g_get_application_name ();
recentData.app_exec = g_strjoin (" ", g_get_prgname (), "%f", NULL);
GtkRecentManager *manager;
manager = gtk_recent_manager_get_default ();
gtk_recent_manager_add_full (manager, g_filename_to_uri(sPath, NULL, NULL), &recentData);
g_free(recentData.app_exec);
gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), TRUE);
}
@ -916,6 +930,13 @@ static void OpenNdsDialog()
gtk_widget_destroy(pFileSelection);
}
static void OpenRecent(GtkRecentChooser *chooser, gpointer user_data)
{
Open(g_filename_from_uri(gtk_recent_chooser_get_current_uri(chooser), NULL, NULL));
gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), TRUE);
}
static void Reset()
{
NDS_Reset();
@ -1871,6 +1892,16 @@ common_gtk_main( struct configured_features *my_config)
pToolBar = gtk_ui_manager_get_widget (ui_manager, "/ToolBar");
gtk_box_pack_start (GTK_BOX(pVBox), pToolBar, FALSE, FALSE, 0);
{
GtkWidget * recentMenu = gtk_ui_manager_get_widget (ui_manager, "/MainMenu/FileMenu/RecentMenu");
GtkWidget * recentFiles = gtk_recent_chooser_menu_new();
GtkRecentFilter * recentFilter = gtk_recent_filter_new();
gtk_recent_filter_add_mime_type(recentFilter, "application/x-nds-binary");
gtk_recent_chooser_set_filter(GTK_RECENT_CHOOSER(recentFiles), recentFilter);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(recentMenu), recentFiles);
g_signal_connect(G_OBJECT(recentFiles), "item-activated", G_CALLBACK(OpenRecent), NULL);
}
/* Creating the place for showing DS screens */
pDrawingArea = gtk_drawing_area_new();
gtk_container_add (GTK_CONTAINER (pVBox), pDrawingArea);