1 /*! 2 @file 3 @author Albert Semenov 4 @date 08/2010 5 */ 6 7 #include "Precompiled.h" 8 #include "RecentFilesManager.h" 9 #include "SettingsManager.h" 10 #include "FileSystemInfo/FileSystemInfo.h" 11 12 template <> tools::RecentFilesManager* MyGUI::Singleton<tools::RecentFilesManager>::msInstance = nullptr; 13 template <> const char* MyGUI::Singleton<tools::RecentFilesManager>::mClassTypeName = "RecentFilesManager"; 14 15 namespace tools 16 { 17 RecentFilesManager()18 RecentFilesManager::RecentFilesManager() : 19 mMaxRecentFolders(0), 20 mMaxRecentFiles(0), 21 mMaxRecentProjects(0) 22 { 23 } 24 initialise()25 void RecentFilesManager::initialise() 26 { 27 if (!SettingsManager::getInstance().tryGetValue<size_t>("Files/MaxRecentFolders", mMaxRecentFolders)) 28 mMaxRecentFolders = 8; 29 30 if (!SettingsManager::getInstance().tryGetValue<size_t>("Files/MaxRecentFiles", mMaxRecentFiles)) 31 mMaxRecentFiles = 8; 32 33 if (!SettingsManager::getInstance().tryGetValue<size_t>("Files/MaxRecentProjects", mMaxRecentProjects)) 34 mMaxRecentProjects = 8; 35 36 mRecentFolder = SettingsManager::getInstance().getValue("Files/RecentFolder"); 37 mRecentFolders = SettingsManager::getInstance().getValueList<MyGUI::UString>("Files/RecentFolder.List"); 38 mRecentFiles = SettingsManager::getInstance().getValueList<MyGUI::UString>("Files/RecentFile.List"); 39 mRecentProjects = SettingsManager::getInstance().getValueList<MyGUI::UString>("Files/RecentProject.List"); 40 41 checkArray(mRecentFolders, mMaxRecentFolders); 42 checkArray(mRecentFiles, mMaxRecentFiles); 43 checkArray(mRecentProjects, mMaxRecentProjects); 44 } 45 shutdown()46 void RecentFilesManager::shutdown() 47 { 48 SettingsManager::getInstance().setValue("Files/RecentFolder", mRecentFolder); 49 SettingsManager::getInstance().setValueList<MyGUI::UString>("Files/RecentFolder.List", mRecentFolders); 50 SettingsManager::getInstance().setValueList<MyGUI::UString>("Files/RecentFile.List", mRecentFiles); 51 SettingsManager::getInstance().setValueList<MyGUI::UString>("Files/RecentProject.List", mRecentProjects); 52 } 53 addRecentFolder(const MyGUI::UString & _folder)54 void RecentFilesManager::addRecentFolder(const MyGUI::UString& _folder) 55 { 56 MyGUI::UString folder(_folder); 57 if (_folder.empty()) 58 folder = MyGUI::UString(common::getSystemCurrentFolder()); 59 60 mRecentFolders.insert(mRecentFolders.begin(), folder); 61 62 checkArray(mRecentFolders, mMaxRecentFolders); 63 } 64 getRecentFolders() const65 const RecentFilesManager::VectorUString& RecentFilesManager::getRecentFolders() const 66 { 67 return mRecentFolders; 68 } 69 getRecentFolder() const70 const MyGUI::UString& RecentFilesManager::getRecentFolder() const 71 { 72 return mRecentFolder; 73 } 74 setRecentFolder(const MyGUI::UString & _value)75 void RecentFilesManager::setRecentFolder(const MyGUI::UString& _value) 76 { 77 mRecentFolder = _value; 78 79 addRecentFolder(mRecentFolder); 80 } 81 checkArray(VectorUString & _array,size_t _maxElements)82 void RecentFilesManager::checkArray(VectorUString& _array, size_t _maxElements) 83 { 84 for (size_t index = 0; index < _array.size(); ++ index) 85 _array.erase(std::remove(_array.begin() + index + 1, _array.end(), _array[index]), _array.end()); 86 87 while (_array.size() > _maxElements) 88 _array.pop_back(); 89 } 90 addRecentFile(const MyGUI::UString & _fileName)91 void RecentFilesManager::addRecentFile(const MyGUI::UString& _fileName) 92 { 93 mRecentFiles.insert(mRecentFiles.begin(), _fileName); 94 95 checkArray(mRecentFiles, mMaxRecentFiles); 96 97 SettingsManager::getInstance().setValueList<MyGUI::UString>("Files/RecentFile.List", mRecentFiles); 98 } 99 getRecentFiles() const100 const RecentFilesManager::VectorUString& RecentFilesManager::getRecentFiles() const 101 { 102 return mRecentFiles; 103 } 104 addRecentProject(const MyGUI::UString & _fileName)105 void RecentFilesManager::addRecentProject(const MyGUI::UString& _fileName) 106 { 107 mRecentProjects.insert(mRecentProjects.begin(), _fileName); 108 109 checkArray(mRecentProjects, mMaxRecentProjects); 110 111 SettingsManager::getInstance().setValueList<MyGUI::UString>("Files/RecentProject.List", mRecentProjects); 112 } 113 getRecentProjects() const114 const RecentFilesManager::VectorUString& RecentFilesManager::getRecentProjects() const 115 { 116 return mRecentProjects; 117 } 118 119 } 120