diff --git a/src/gtk/main.cpp b/src/gtk/main.cpp index 22e4531a..05f28394 100644 --- a/src/gtk/main.cpp +++ b/src/gtk/main.cpp @@ -45,15 +45,17 @@ int main(int argc, char * argv[]) bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); #endif // ENABLE_NLS + Glib::set_application_name(_("VBA-M")); + Gtk::Main oKit(argc, argv); - + #ifdef USE_OPENGL Gtk::GL::init(argc, argv); #endif // USE_OPENGL - + Glib::OptionContext oContext; Glib::OptionGroup oGroup("main_group", _("Main VBA-M options")); - + Glib::OptionEntry oVersion; oVersion.set_long_name("version"); oVersion.set_short_name('v'); diff --git a/src/gtk/vba.glade b/src/gtk/vba.glade index 41e91175..19a94047 100644 --- a/src/gtk/vba.glade +++ b/src/gtk/vba.glade @@ -292,29 +292,6 @@ True Rece_nt True - - - - - True - _Reset - True - - - - - True - _Freeze - True - - - - - True - - - - diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index cc54ec89..0be27483 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -127,7 +127,6 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml) : } vCreateFileOpenDialog(); - vLoadHistoryFromConfig(); vLoadJoypadsFromConfig(); Gtk::MenuItem * poMI; @@ -233,18 +232,22 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr & _poXml) : // Recent menu // - m_poRecentMenu = dynamic_cast(_poXml->get_widget("RecentMenu_menu")); - vUpdateHistoryMenu(); + m_poRecentManager = Gtk::RecentManager::get_default(); - m_poRecentResetItem = dynamic_cast(_poXml->get_widget("RecentReset")); - m_poRecentResetItem->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnRecentReset)); + Gtk::RecentFilter oRecentFilter; + oRecentFilter.add_application( Glib::get_application_name() ); - poCMI = dynamic_cast(_poXml->get_widget("RecentFreeze")); - poCMI->set_active(m_poHistoryConfig->oGetKey("freeze")); - vOnRecentFreezeToggled(poCMI); - poCMI->signal_toggled().connect(sigc::bind( - sigc::mem_fun(*this, &Window::vOnRecentFreezeToggled), - poCMI)); + m_poRecentChooserMenu = Gtk::manage( new Gtk::RecentChooserMenu(m_poRecentManager) ); + m_poRecentChooserMenu->set_show_numbers(); + m_poRecentChooserMenu->set_show_tips(); + m_poRecentChooserMenu->set_local_only(); + m_poRecentChooserMenu->add_filter(oRecentFilter); + m_poRecentChooserMenu->signal_item_activated().connect( + sigc::mem_fun(*this, &Window::vOnRecentFile)); + + + m_poRecentMenu = dynamic_cast(_poXml->get_widget("RecentMenu")); + m_poRecentMenu->set_submenu(static_cast(*m_poRecentChooserMenu)); // Import menu // @@ -853,7 +856,6 @@ Window::~Window() { vOnFileClose(); vUnInitSystem(); - vSaveHistoryToConfig(); vSaveJoypadsToConfig(); vSaveConfig(m_sConfigFile); @@ -963,21 +965,6 @@ void Window::vInitConfig() { m_oConfig.vClear(); - // History section - // - m_poHistoryConfig = m_oConfig.poAddSection("History"); - m_poHistoryConfig->vSetKey("freeze", false ); - m_poHistoryConfig->vSetKey("0", "" ); - m_poHistoryConfig->vSetKey("1", "" ); - m_poHistoryConfig->vSetKey("2", "" ); - m_poHistoryConfig->vSetKey("3", "" ); - m_poHistoryConfig->vSetKey("4", "" ); - m_poHistoryConfig->vSetKey("5", "" ); - m_poHistoryConfig->vSetKey("6", "" ); - m_poHistoryConfig->vSetKey("7", "" ); - m_poHistoryConfig->vSetKey("8", "" ); - m_poHistoryConfig->vSetKey("9", "" ); - // Directories section // m_poDirConfig = m_oConfig.poAddSection("Directories"); @@ -1252,83 +1239,11 @@ void Window::vSaveConfig(const std::string & _rsFile) } } -void Window::vLoadHistoryFromConfig() -{ - char csKey[] = "0"; - for (int i = 0; i < 10; i++, csKey[0]++) - { - std::string sFile = m_poHistoryConfig->sGetKey(csKey); - if (sFile == "") - { - break; - } - m_listHistory.push_back(sFile); - } -} - -void Window::vSaveHistoryToConfig() -{ - char csKey[] = "0"; - for (std::list::const_iterator it = m_listHistory.begin(); - it != m_listHistory.end(); - it++, csKey[0]++) - { - m_poHistoryConfig->vSetKey(csKey, *it); - } -} - void Window::vHistoryAdd(const std::string & _rsFile) { - if (m_poHistoryConfig->oGetKey("freeze")) - { - return; - } + std::string sURL = "file://" + _rsFile; - m_listHistory.remove(_rsFile); - m_listHistory.push_front(_rsFile); - if (m_listHistory.size() > 10) - { - m_listHistory.pop_back(); - } - - vUpdateHistoryMenu(); -} - -void Window::vClearHistoryMenu() -{ - Gtk::Menu_Helpers::MenuList::iterator it = m_poRecentMenu->items().begin(); - for (int i = 0; i < 3; i++, it++) - ; - - m_poRecentMenu->items().erase(it, m_poRecentMenu->items().end()); -} - -void Window::vUpdateHistoryMenu() -{ - vClearHistoryMenu(); - - Glib::RefPtr poAccelGroup = get_accel_group(); - - guint uiAccelKey = GDK_F1; - for (std::list::const_iterator it = m_listHistory.begin(); - it != m_listHistory.end(); - it++, uiAccelKey++) - { - Gtk::Image * poImage = Gtk::manage(new Gtk::Image(Gtk::Stock::OPEN, Gtk::ICON_SIZE_MENU)); - Glib::ustring sLabel = Glib::path_get_basename(*it); - Gtk::ImageMenuItem * poIMI = Gtk::manage(new Gtk::ImageMenuItem(*poImage, sLabel)); - - poIMI->set_tooltip_text(*it); - - poIMI->signal_activate().connect(sigc::bind( - sigc::mem_fun(*this, &Window::vOnRecentFile), - *it)); - - poIMI->add_accelerator("activate", poAccelGroup, uiAccelKey, Gdk::CONTROL_MASK, Gtk::ACCEL_VISIBLE); - - poIMI->show(); - m_poRecentMenu->items().push_back(*poIMI); - } + m_poRecentManager->add_item(sURL); } void Window::vLoadJoypadsFromConfig() diff --git a/src/gtk/window.h b/src/gtk/window.h index 22088d04..41172fd9 100644 --- a/src/gtk/window.h +++ b/src/gtk/window.h @@ -148,9 +148,7 @@ protected: void vOnSaveGame(int _iSlot); virtual void vOnFilePauseToggled(Gtk::CheckMenuItem * _poCMI); virtual void vOnFileReset(); - virtual void vOnRecentReset(); - virtual void vOnRecentFreezeToggled(Gtk::CheckMenuItem * _poCMI); - virtual void vOnRecentFile(std::string _sFile); + virtual void vOnRecentFile(); virtual void vOnImportBatteryFile(); virtual void vOnExportBatteryFile(); virtual void vOnFileScreenCapture(); @@ -234,7 +232,6 @@ private: std::string m_sUserDataDir; std::string m_sConfigFile; Config::File m_oConfig; - Config::Section * m_poHistoryConfig; Config::Section * m_poDirConfig; Config::Section * m_poCoreConfig; Config::Section * m_poDisplayConfig; @@ -244,8 +241,6 @@ private: Gtk::FileChooserDialog * m_poFileOpenDialog; ScreenArea * m_poScreenArea; - Gtk::Menu * m_poRecentMenu; - Gtk::MenuItem * m_poRecentResetItem; Gtk::CheckMenuItem * m_poFilePauseItem; Gtk::CheckMenuItem * m_poUseBiosItem; Gtk::CheckMenuItem * m_poSoundOffItem; @@ -262,7 +257,9 @@ private: Gtk::MenuItem * m_apoSaveGameItem[10]; SGameSlot m_astGameSlot[10]; - std::list m_listHistory; + Glib::RefPtr m_poRecentManager; + Gtk::MenuItem * m_poRecentMenu; + Gtk::RecentChooserMenu * m_poRecentChooserMenu; std::list m_listSensitiveWhenPlaying; @@ -296,11 +293,7 @@ private: void vInitScreenArea(EVideoOutput _eVideoOutput); void vLoadConfig(const std::string & _rsFile); void vSaveConfig(const std::string & _rsFile); - void vLoadHistoryFromConfig(); - void vSaveHistoryToConfig(); void vHistoryAdd(const std::string & _rsFile); - void vClearHistoryMenu(); - void vUpdateHistoryMenu(); void vLoadJoypadsFromConfig(); void vSaveJoypadsToConfig(); void vUpdateScreen(); diff --git a/src/gtk/windowcallbacks.cpp b/src/gtk/windowcallbacks.cpp index 9e05505c..7e9af1e3 100644 --- a/src/gtk/windowcallbacks.cpp +++ b/src/gtk/windowcallbacks.cpp @@ -246,21 +246,15 @@ void Window::vOnFileReset() } } -void Window::vOnRecentReset() +void Window::vOnRecentFile() { - m_listHistory.clear(); - vClearHistoryMenu(); -} + Glib::ustring sURI = m_poRecentChooserMenu->get_current_uri(); -void Window::vOnRecentFreezeToggled(Gtk::CheckMenuItem * _poCMI) -{ - m_poRecentResetItem->set_sensitive(! _poCMI->get_active()); - m_poHistoryConfig->vSetKey("freeze", _poCMI->get_active()); -} - -void Window::vOnRecentFile(std::string _sFile) -{ - bLoadROM(_sFile); + if (!sURI.empty()) + { + std::string sFileName = Glib::filename_from_uri(sURI); + bLoadROM(sFileName); + } } void Window::vOnImportBatteryFile()