void SubMainFrame::UpdateHistory() { ConfigFile *clientConfig = Globals::Instance()->GetConfig(); int iHistorySize = clientConfig->getInteger("FileHistorySize", 4); std::vector<std::string> listFileHistory = clientConfig->getArray("FileHistory"); if(iHistorySize != 0 && listFileHistory.size() != 0) { //Clear the Recent Files menu wxMenuItemList menuItems = m_menuRecentImages->GetMenuItems(); for ( wxMenuItemList::compatibility_iterator node = menuItems.GetFirst(); node; node = node->GetNext() ) { wxMenuItem *item = node->GetData(); m_menuRecentImages->Delete(item); } //Add the recent history to the menu for(int i = 0; i < iHistorySize && i < listFileHistory.size(); i++) { //Add the previous files to the menu for opening wxMenuItem* menuItemTest = new wxMenuItem( m_menuRecentImages, IDX_MENU_HISTORYOPEN + i, wxString( listFileHistory.at(i).c_str(), wxConvLocal ), wxT("Open this file."), wxITEM_NORMAL ); m_menuRecentImages->Insert(0,menuItemTest); } } }
void SubMainFrame::HistoryOpen( wxCommandEvent& event ) { ConfigFile *clientConfig = Globals::Instance()->GetConfig(); std::vector<std::string> listFileHistory = clientConfig->getArray("FileHistory"); int iHistoryIndex = event.GetId() - IDX_MENU_HISTORYOPEN; if(iHistoryIndex >= 0 && iHistoryIndex < listFileHistory.size()) { wxString filename = wxString(listFileHistory.at(iHistoryIndex).c_str(), wxConvLocal); OpenFile(filename); } }
void SubMainFrame::OpenLastFiles() { ConfigFile *clientConfig = Globals::Instance()->GetConfig(); //Open the last file in the history if(clientConfig->getBool("AutoOpenLastSession", true)) { std::vector<std::string> listFileSession = clientConfig->getArray("RecentFileSession"); for(std::vector<std::string>::iterator iter = listFileSession.begin(); iter != listFileSession.end(); iter++) { OpenFile(wxString((*iter).c_str(), wxConvLocal)); wxLogDebug(wxT("Auto Opened: %s"), wxString(*iter)); } } }
//Add the file to the File History void SubMainFrame::AddFileToHistory(wxString strFilename) { ConfigFile *clientConfig = Globals::Instance()->GetConfig(); std::vector<std::string> listFileHistory = clientConfig->getArray("FileHistory"); for(std::vector<std::string>::iterator iter = listFileHistory.begin(); iter != listFileHistory.end(); iter++) { if(strFilename == wxString((*iter).c_str(), wxConvLocal)) { listFileHistory.erase(iter); break; } } listFileHistory.push_back(std::string(strFilename.mb_str())); while(listFileHistory.size() > clientConfig->getInteger("FileHistorySize",4)) { listFileHistory.erase(listFileHistory.begin()); } clientConfig->setArray("FileHistory", listFileHistory); UpdateHistory(); }