From: S?bastien G. <kx...@us...> - 2004-05-03 17:01:13
|
Update of /cvsroot/vba/VisualBoyAdvance/src/gtk In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6897 Modified Files: Makefile.am Makefile.in configfile.cpp configfile.h vba.glade window.cpp window.h windowcallbacks.cpp Log Message: Added recent files menu. Index: Makefile.am =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/Makefile.am,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Makefile.am 1 May 2004 14:03:58 -0000 1.4 --- Makefile.am 3 May 2004 17:00:26 -0000 1.5 *************** *** 12,15 **** --- 12,16 ---- intl.h \ main.cpp \ + menuitem.h \ screenarea.cpp \ screenarea.h \ Index: window.h =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/window.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** window.h 1 May 2004 14:04:02 -0000 1.12 --- window.h 3 May 2004 17:00:27 -0000 1.13 *************** *** 23,33 **** #include <sys/types.h> #ifndef GTKMM20 # include "sigccompat.h" #endif // ! GTKMM20 - #include <libglademm.h> - #include <gtkmm.h> - #include <string> #include <list> --- 23,33 ---- #include <sys/types.h> + #include <libglademm.h> + #include <gtkmm.h> + #ifndef GTKMM20 # include "sigccompat.h" #endif // ! GTKMM20 #include <string> #include <list> *************** *** 135,138 **** --- 135,141 ---- virtual void vOnFilePauseToggled(Gtk::CheckMenuItem * _poCMI); virtual void vOnFileReset(); + virtual void vOnRecentReset(); + virtual void vOnRecentFreezeToggled(Gtk::CheckMenuItem * _poCMI); + virtual void vOnRecent(std::string _sFile); virtual void vOnFileClose(); virtual void vOnFileExit(); *************** *** 207,210 **** --- 210,214 ---- std::string m_sConfigFile; Config::File m_oConfig; + Config::Section * m_poHistoryConfig; Config::Section * m_poDirConfig; Config::Section * m_poCoreConfig; *************** *** 214,217 **** --- 218,222 ---- Gtk::FileSelection * m_poFileOpenDialog; ScreenArea * m_poScreenArea; + Gtk::Menu * m_poRecentMenu; Gtk::CheckMenuItem * m_poFilePauseItem; Gtk::CheckMenuItem * m_poUseBiosItem; *************** *** 229,234 **** --- 234,243 ---- SGameSlot m_astGameSlot[10]; + std::list<std::string> m_listHistory; + std::list<Gtk::Widget *> m_listSensitiveWhenPlaying; + Gtk::Tooltips m_oTooltips; + SigC::Connection m_oEmuSig; *************** *** 254,264 **** void vInitConfig(); void vCheckConfig(); ! void vLoadConfig(const std::string & _sFilename); ! void vSaveConfig(const std::string & _sFilename); void vLoadKeymap(); void vUpdateScreen(); void vDrawDefaultScreen(); void vSetDefaultTitle(); ! bool bLoadROM(const std::string & _rsFilename); void vLoadBattery(); void vSaveBattery(); --- 263,278 ---- void vInitConfig(); void vCheckConfig(); ! 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 vLoadKeymap(); void vUpdateScreen(); void vDrawDefaultScreen(); void vSetDefaultTitle(); ! bool bLoadROM(const std::string & _rsFile); void vLoadBattery(); void vSaveBattery(); Index: configfile.h =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/configfile.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** configfile.h 15 Apr 2004 03:58:45 -0000 1.2 --- configfile.h 3 May 2004 17:00:27 -0000 1.3 *************** *** 128,132 **** public: File(); ! File(const std::string & _rsFilename); virtual ~File(); --- 128,132 ---- public: File(); ! File(const std::string & _rsFile); virtual ~File(); *************** *** 135,142 **** Section * poGetSection(const std::string & _rsName); void vRemoveSection(const std::string & _rsName); ! void vLoad(const std::string & _rsFilename, bool _bAddSection = true, bool _bAddKey = true); ! void vSave(const std::string & _rsFilename); void vClear(); --- 135,142 ---- Section * poGetSection(const std::string & _rsName); void vRemoveSection(const std::string & _rsName); ! void vLoad(const std::string & _rsFile, bool _bAddSection = true, bool _bAddKey = true); ! void vSave(const std::string & _rsFile); void vClear(); Index: configfile.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/configfile.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** configfile.cpp 15 Apr 2004 03:58:45 -0000 1.2 --- configfile.cpp 3 May 2004 17:00:27 -0000 1.3 *************** *** 98,104 **** } ! File::File(const string & _rsFilename) { ! vLoad(_rsFilename); } --- 98,104 ---- } ! File::File(const string & _rsFile) { ! vLoad(_rsFile); } *************** *** 161,169 **** } ! void File::vLoad(const string & _rsFilename, bool _bAddSection, bool _bAddKey) { ! string sBuffer = Glib::file_get_contents(_rsFilename); Section * poSection = NULL; char ** lines = g_strsplit(sBuffer.c_str(), "\n", 0); --- 161,169 ---- } ! void File::vLoad(const string & _rsFile, bool _bAddSection, bool _bAddKey) { ! string sBuffer = Glib::file_get_contents(_rsFile); Section * poSection = NULL; char ** lines = g_strsplit(sBuffer.c_str(), "\n", 0); *************** *** 211,217 **** } ! void File::vSave(const string & _rsFilename) { ! Glib::RefPtr<IOChannel> poFile = IOChannel::create_from_file(_rsFilename, "w"); poFile->set_encoding(""); --- 211,217 ---- } ! void File::vSave(const string & _rsFile) { ! Glib::RefPtr<IOChannel> poFile = IOChannel::create_from_file(_rsFile, "w"); poFile->set_encoding(""); Index: Makefile.in =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/Makefile.in,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Makefile.in 1 May 2004 14:03:58 -0000 1.4 --- Makefile.in 3 May 2004 17:00:26 -0000 1.5 *************** *** 165,168 **** --- 165,169 ---- intl.h \ main.cpp \ + menuitem.h \ screenarea.cpp \ screenarea.h \ Index: window.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/window.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** window.cpp 1 May 2004 14:03:59 -0000 1.12 --- window.cpp 3 May 2004 17:00:27 -0000 1.13 *************** *** 33,36 **** --- 33,37 ---- #include "../Util.h" + #include "menuitem.h" #include "tools.h" #include "intl.h" *************** *** 119,122 **** --- 120,124 ---- } + vLoadHistoryFromConfig(); vLoadKeymap(); *************** *** 180,183 **** --- 182,200 ---- poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnFileExit)); + // Recent menu + // + m_poRecentMenu = dynamic_cast<Gtk::Menu *>(_poXml->get_widget("RecentMenu_menu")); + vUpdateHistoryMenu(); + + poMI = dynamic_cast<Gtk::MenuItem *>(_poXml->get_widget("RecentReset")); + poMI->signal_activate().connect(SigC::slot(*this, &Window::vOnRecentReset)); + + 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<Gtk::CheckMenuItem *>( + SigC::slot(*this, &Window::vOnRecentFreezeToggled), + poCMI)); + // Frameskip menu // *************** *** 709,712 **** --- 726,730 ---- { vOnFileClose(); + vSaveHistoryToConfig(); vSaveConfig(m_sConfigFile); *************** *** 797,800 **** --- 815,833 ---- 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 // *************** *** 999,1007 **** } ! void Window::vLoadConfig(const std::string & _sFilename) { try { ! m_oConfig.vLoad(_sFilename, false, false); } catch (const Glib::Error & e) --- 1032,1040 ---- } ! void Window::vLoadConfig(const std::string & _rsFile) { try { ! m_oConfig.vLoad(_rsFile, false, false); } catch (const Glib::Error & e) *************** *** 1018,1026 **** } ! void Window::vSaveConfig(const std::string & _sFilename) { try { ! m_oConfig.vSave(_sFilename); } catch (const Glib::Error & e) --- 1051,1059 ---- } ! void Window::vSaveConfig(const std::string & _rsFile) { try { ! m_oConfig.vSave(_rsFile); } catch (const Glib::Error & e) *************** *** 1037,1040 **** --- 1070,1151 ---- } + 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; + } + + 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(); + + 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); + VBA::ImageMenuItem * poIMI = Gtk::manage(new VBA::ImageMenuItem(*poImage, sLabel)); + + m_oTooltips.set_tip(*poIMI, *it); + + poIMI->signal_activate().connect(SigC::bind<std::string>( + SigC::slot(*this, &Window::vOnRecent), + *it)); + + poIMI->set_accel_key(Gtk::AccelKey(uiAccelKey, Gdk::CONTROL_MASK)); + poIMI->accelerate(*this); + + poIMI->show(); + m_poRecentMenu->items().push_back(*poIMI); + } + } + void Window::vLoadKeymap() { *************** *** 1214,1228 **** } ! bool Window::bLoadROM(const std::string & _rsFilename) { vOnFileClose(); ! m_sRomFile = _rsFilename; ! const char * csFilename = _rsFilename.c_str(); ! IMAGE_TYPE eType = utilFindType(csFilename); if (eType == IMAGE_UNKNOWN) { ! systemMessage(0, _("Unknown file type %s"), csFilename); return false; } --- 1325,1339 ---- } ! bool Window::bLoadROM(const std::string & _rsFile) { vOnFileClose(); ! m_sRomFile = _rsFile; ! const char * csFile = _rsFile.c_str(); ! IMAGE_TYPE eType = utilFindType(csFile); if (eType == IMAGE_UNKNOWN) { ! systemMessage(0, _("Unknown file type %s"), csFile); return false; } *************** *** 1231,1235 **** if (eType == IMAGE_GB) { ! bLoaded = gbLoadRom(csFilename); if (bLoaded) { --- 1342,1346 ---- if (eType == IMAGE_GB) { ! bLoaded = gbLoadRom(csFile); if (bLoaded) { *************** *** 1240,1244 **** else if (eType == IMAGE_GBA) { ! int iSize = CPULoadRom(csFilename); bLoaded = (iSize > 0); if (bLoaded) --- 1351,1355 ---- else if (eType == IMAGE_GBA) { ! int iSize = CPULoadRom(csFile); bLoaded = (iSize > 0); if (bLoaded) *************** *** 1263,1267 **** if (! bLoaded) { ! systemMessage(0, _("Failed to load file %s"), csFilename); return false; } --- 1374,1378 ---- if (! bLoaded) { ! systemMessage(0, _("Failed to load file %s"), csFile); return false; } *************** *** 1284,1287 **** --- 1395,1399 ---- vUpdateGameSlots(); + vHistoryAdd(_rsFile); for (std::list<Gtk::Widget *>::iterator it = m_listSensitiveWhenPlaying.begin(); Index: vba.glade =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/vba.glade,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** vba.glade 29 Apr 2004 01:44:36 -0000 1.8 --- vba.glade 3 May 2004 17:00:27 -0000 1.9 *************** *** 51,55 **** <child internal-child="image"> ! <widget class="GtkImage" id="image106"> <property name="visible">True</property> <property name="stock">gtk-open</property> --- 51,55 ---- <child internal-child="image"> ! <widget class="GtkImage" id="image108"> <property name="visible">True</property> <property name="stock">gtk-open</property> *************** *** 367,370 **** --- 367,398 ---- <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> + <property name="active">False</property> + </widget> + </child> + + <child> + <widget class="GtkSeparatorMenuItem" id="separator29"> + <property name="visible">True</property> + </widget> + </child> + </widget> + </child> </widget> </child> *************** *** 427,431 **** <child internal-child="image"> ! <widget class="GtkImage" id="image107"> <property name="visible">True</property> <property name="stock">gtk-close</property> --- 455,459 ---- <child internal-child="image"> ! <widget class="GtkImage" id="image109"> <property name="visible">True</property> <property name="stock">gtk-close</property> *************** *** 448,452 **** <child internal-child="image"> ! <widget class="GtkImage" id="image108"> <property name="visible">True</property> <property name="stock">gtk-quit</property> --- 476,480 ---- <child internal-child="image"> ! <widget class="GtkImage" id="image110"> <property name="visible">True</property> <property name="stock">gtk-quit</property> Index: windowcallbacks.cpp =================================================================== RCS file: /cvsroot/vba/VisualBoyAdvance/src/gtk/windowcallbacks.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** windowcallbacks.cpp 29 Apr 2004 01:44:36 -0000 1.1 --- windowcallbacks.cpp 3 May 2004 17:00:27 -0000 1.2 *************** *** 169,172 **** --- 169,188 ---- } + void Window::vOnRecentReset() + { + m_listHistory.clear(); + vClearHistoryMenu(); + } + + void Window::vOnRecentFreezeToggled(Gtk::CheckMenuItem * _poCMI) + { + m_poHistoryConfig->vSetKey("freeze", _poCMI->get_active()); + } + + void Window::vOnRecent(std::string _sFile) + { + bLoadROM(_sFile); + } + void Window::vOnFileClose() { |