- Use sytem wide recent used files.


git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@561 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
bgk 2008-06-05 11:32:49 +00:00
parent b439e0dbe5
commit 017db09af7
5 changed files with 32 additions and 151 deletions

View File

@ -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');

View File

@ -292,29 +292,6 @@
<property name="visible">True</property>
<property name="label" translatable="yes">Rece_nt</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>
</child>
<child>

View File

@ -127,7 +127,6 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
}
vCreateFileOpenDialog();
vLoadHistoryFromConfig();
vLoadJoypadsFromConfig();
Gtk::MenuItem * poMI;
@ -233,18 +232,22 @@ Window::Window(GtkWindow * _pstWindow, const Glib::RefPtr<Xml> & _poXml) :
// Recent menu
//
m_poRecentMenu = dynamic_cast<Gtk::Menu *>(_poXml->get_widget("RecentMenu_menu"));
vUpdateHistoryMenu();
m_poRecentManager = Gtk::RecentManager::get_default();
m_poRecentResetItem = dynamic_cast<Gtk::MenuItem *>(_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<Gtk::CheckMenuItem *>(_poXml->get_widget("RecentFreeze"));
poCMI->set_active(m_poHistoryConfig->oGetKey<bool>("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<Gtk::MenuItem *>(_poXml->get_widget("RecentMenu"));
m_poRecentMenu->set_submenu(static_cast<Gtk::Menu &>(*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<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)
{
if (m_poHistoryConfig->oGetKey<bool>("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<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);
}
m_poRecentManager->add_item(sURL);
}
void Window::vLoadJoypadsFromConfig()

View File

@ -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<std::string> m_listHistory;
Glib::RefPtr<Gtk::RecentManager> m_poRecentManager;
Gtk::MenuItem * m_poRecentMenu;
Gtk::RecentChooserMenu * m_poRecentChooserMenu;
std::list<Gtk::Widget *> 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();

View File

@ -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()