- Use sytem wide recent used files.
This commit is contained in:
bgk 2008-06-05 11:32:49 +00:00
parent 8535979111
commit 123570a068
5 changed files with 32 additions and 151 deletions

View File

@ -45,6 +45,8 @@ int main(int argc, char * argv[])
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
#endif // ENABLE_NLS #endif // ENABLE_NLS
Glib::set_application_name(_("VBA-M"));
Gtk::Main oKit(argc, argv); Gtk::Main oKit(argc, argv);
#ifdef USE_OPENGL #ifdef USE_OPENGL

View File

@ -292,29 +292,6 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Rece_nt</property> <property name="label" translatable="yes">Rece_nt</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<child>
<widget class="GtkMenu" id="RecentMenu_menu">
<child>
<widget class="GtkMenuItem" id="RecentReset">
<property name="visible">True</property>
<property name="label" translatable="yes">_Reset</property>
<property name="use_underline">True</property>
</widget>
</child>
<child>
<widget class="GtkCheckMenuItem" id="RecentFreeze">
<property name="visible">True</property>
<property name="label" translatable="yes">_Freeze</property>
<property name="use_underline">True</property>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="separator29">
<property name="visible">True</property>
</widget>
</child>
</widget>
</child>
</widget> </widget>
</child> </child>
<child> <child>

View File

@ -127,7 +127,6 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
} }
vCreateFileOpenDialog(); vCreateFileOpenDialog();
vLoadHistoryFromConfig();
vLoadJoypadsFromConfig(); vLoadJoypadsFromConfig();
Gtk::MenuItem * poMI; Gtk::MenuItem * poMI;
@ -233,18 +232,22 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
// Recent menu // Recent menu
// //
m_poRecentMenu = dynamic_cast<Gtk::Menu *>(_poXml->get_widget("RecentMenu_menu")); m_poRecentManager = Gtk::RecentManager::get_default();
vUpdateHistoryMenu();
m_poRecentResetItem = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("RecentReset")); Gtk::RecentFilter oRecentFilter;
m_poRecentResetItem->signal_activate().connect(sigc::mem_fun(*this, &Window::vOnRecentReset)); oRecentFilter.add_application( Glib::get_application_name() );
poCMI = dynamic_cast<Gtk::CheckMenuItem *>(_poXml->get_widget("RecentFreeze")); m_poRecentChooserMenu = Gtk::manage( new Gtk::RecentChooserMenu(m_poRecentManager) );
poCMI->set_active(m_poHistoryConfig->oGetKey<bool>("freeze")); m_poRecentChooserMenu->set_show_numbers();
vOnRecentFreezeToggled(poCMI); m_poRecentChooserMenu->set_show_tips();
poCMI->signal_toggled().connect(sigc::bind( m_poRecentChooserMenu->set_local_only();
sigc::mem_fun(*this, &Window::vOnRecentFreezeToggled), m_poRecentChooserMenu->add_filter(oRecentFilter);
poCMI)); m_poRecentChooserMenu->signal_item_activated().connect(
sigc::mem_fun(*this, &Window::vOnRecentFile));
m_poRecentMenu = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("RecentMenu"));
m_poRecentMenu->set_submenu(static_cast<Gtk::Menu &>(*m_poRecentChooserMenu));
// Import menu // Import menu
// //
@ -853,7 +856,6 @@ Window::~Window()
{ {
vOnFileClose(); vOnFileClose();
vUnInitSystem(); vUnInitSystem();
vSaveHistoryToConfig();
vSaveJoypadsToConfig(); vSaveJoypadsToConfig();
vSaveConfig(m_sConfigFile); vSaveConfig(m_sConfigFile);
@ -963,21 +965,6 @@ void Window::vInitConfig()
{ {
m_oConfig.vClear(); 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 // Directories section
// //
m_poDirConfig = m_oConfig.poAddSection("Directories"); 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<std::string>::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) void Window::vHistoryAdd(const std::string & _rsFile)
{ {
if (m_poHistoryConfig->oGetKey<bool>("freeze")) std::string sURL = "file://" + _rsFile;
{
return;
}
m_listHistory.remove(_rsFile); m_poRecentManager->add_item(sURL);
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<Gtk::AccelGroup> poAccelGroup = get_accel_group();
guint uiAccelKey = GDK_F1;
for (std::list<std::string>::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);
}
} }
void Window::vLoadJoypadsFromConfig() void Window::vLoadJoypadsFromConfig()

View File

@ -148,9 +148,7 @@ protected:
void vOnSaveGame(int _iSlot); void vOnSaveGame(int _iSlot);
virtual void vOnFilePauseToggled(Gtk::CheckMenuItem * _poCMI); virtual void vOnFilePauseToggled(Gtk::CheckMenuItem * _poCMI);
virtual void vOnFileReset(); virtual void vOnFileReset();
virtual void vOnRecentReset(); virtual void vOnRecentFile();
virtual void vOnRecentFreezeToggled(Gtk::CheckMenuItem * _poCMI);
virtual void vOnRecentFile(std::string _sFile);
virtual void vOnImportBatteryFile(); virtual void vOnImportBatteryFile();
virtual void vOnExportBatteryFile(); virtual void vOnExportBatteryFile();
virtual void vOnFileScreenCapture(); virtual void vOnFileScreenCapture();
@ -234,7 +232,6 @@ private:
std::string m_sUserDataDir; std::string m_sUserDataDir;
std::string m_sConfigFile; std::string m_sConfigFile;
Config::File m_oConfig; Config::File m_oConfig;
Config::Section * m_poHistoryConfig;
Config::Section * m_poDirConfig; Config::Section * m_poDirConfig;
Config::Section * m_poCoreConfig; Config::Section * m_poCoreConfig;
Config::Section * m_poDisplayConfig; Config::Section * m_poDisplayConfig;
@ -244,8 +241,6 @@ private:
Gtk::FileChooserDialog * m_poFileOpenDialog; Gtk::FileChooserDialog * m_poFileOpenDialog;
ScreenArea * m_poScreenArea; ScreenArea * m_poScreenArea;
Gtk::Menu * m_poRecentMenu;
Gtk::MenuItem * m_poRecentResetItem;
Gtk::CheckMenuItem * m_poFilePauseItem; Gtk::CheckMenuItem * m_poFilePauseItem;
Gtk::CheckMenuItem * m_poUseBiosItem; Gtk::CheckMenuItem * m_poUseBiosItem;
Gtk::CheckMenuItem * m_poSoundOffItem; Gtk::CheckMenuItem * m_poSoundOffItem;
@ -262,7 +257,9 @@ private:
Gtk::MenuItem * m_apoSaveGameItem[10]; Gtk::MenuItem * m_apoSaveGameItem[10];
SGameSlot m_astGameSlot[10]; SGameSlot m_astGameSlot[10];
std::list<std::string> m_listHistory; Glib::RefPtr<Gtk::RecentManager> m_poRecentManager;
Gtk::MenuItem * m_poRecentMenu;
Gtk::RecentChooserMenu * m_poRecentChooserMenu;
std::list<Gtk::Widget *> m_listSensitiveWhenPlaying; std::list<Gtk::Widget *> m_listSensitiveWhenPlaying;
@ -296,11 +293,7 @@ private:
void vInitScreenArea(EVideoOutput _eVideoOutput); void vInitScreenArea(EVideoOutput _eVideoOutput);
void vLoadConfig(const std::string & _rsFile); void vLoadConfig(const std::string & _rsFile);
void vSaveConfig(const std::string & _rsFile); void vSaveConfig(const std::string & _rsFile);
void vLoadHistoryFromConfig();
void vSaveHistoryToConfig();
void vHistoryAdd(const std::string & _rsFile); void vHistoryAdd(const std::string & _rsFile);
void vClearHistoryMenu();
void vUpdateHistoryMenu();
void vLoadJoypadsFromConfig(); void vLoadJoypadsFromConfig();
void vSaveJoypadsToConfig(); void vSaveJoypadsToConfig();
void vUpdateScreen(); void vUpdateScreen();

View File

@ -246,21 +246,15 @@ void Window::vOnFileReset()
} }
} }
void Window::vOnRecentReset() void Window::vOnRecentFile()
{ {
m_listHistory.clear(); Glib::ustring sURI = m_poRecentChooserMenu->get_current_uri();
vClearHistoryMenu();
}
void Window::vOnRecentFreezeToggled(Gtk::CheckMenuItem * _poCMI) if (!sURI.empty())
{ {
m_poRecentResetItem->set_sensitive(! _poCMI->get_active()); std::string sFileName = Glib::filename_from_uri(sURI);
m_poHistoryConfig->vSetKey("freeze", _poCMI->get_active()); bLoadROM(sFileName);
} }
void Window::vOnRecentFile(std::string _sFile)
{
bLoadROM(_sFile);
} }
void Window::vOnImportBatteryFile() void Window::vOnImportBatteryFile()