diff --git a/Editor/ProjectManager.cpp b/Editor/ProjectManager.cpp index 197806b44..bbf33342e 100644 --- a/Editor/ProjectManager.cpp +++ b/Editor/ProjectManager.cpp @@ -99,6 +99,9 @@ bool ProjectManager::openProject(const HECL::SystemString& path) m_vm.m_mainWindow->setTitle(m_proj->getProjectRootPath().getLastComponent()); m_vm.DismissSplash(); m_vm.FadeInEditors(); + + m_vm.pushRecentProject(m_proj->getProjectRootPath().getAbsolutePath()); + return true; makeDefault: @@ -164,6 +167,8 @@ bool ProjectManager::saveProject() HECL::Rename(oldSpacesPath.getAbsolutePath().c_str(), newSpacesPath.getAbsolutePath().c_str()); + m_vm.pushRecentProject(m_proj->getProjectRootPath().getAbsolutePath()); + return true; } diff --git a/Editor/SplashScreen.hpp b/Editor/SplashScreen.hpp index 52b6ddd7d..a93c12297 100644 --- a/Editor/SplashScreen.hpp +++ b/Editor/SplashScreen.hpp @@ -93,7 +93,11 @@ class SplashScreen : public Specter::ModalWindow std::string m_text; const std::string* text() const {return &m_text;} - void activated() {m_parent.m_openProjBind.m_deferPath = m_path;} + void activated(const boo::SWindowCoord& coord) + { + m_parent.m_openProjBind.m_deferPath = m_path; + m_parent.m_openProjBind.m_splash.m_openButt.m_view->closeMenu(coord); + } OpenRecentMenuItem(OpenRecentMenuRoot& parent, const HECL::SystemString& path) : m_parent(parent), m_path(path) diff --git a/Editor/ViewManager.cpp b/Editor/ViewManager.cpp index e3a90daa7..c83fa04f1 100644 --- a/Editor/ViewManager.cpp +++ b/Editor/ViewManager.cpp @@ -4,6 +4,7 @@ #include "SplashScreen.hpp" #include "locale/locale.hpp" #include "ResourceBrowser.hpp" +#include using YAMLNode = Athena::io::YAMLNode; @@ -75,20 +76,76 @@ void ViewManager::DismissSplash() ViewManager::ViewManager(HECL::Runtime::FileStoreManager& fileMgr, HECL::CVarManager& cvarMgr) : m_fileStoreManager(fileMgr), m_cvarManager(cvarMgr), m_projManager(*this), - m_fontCache(fileMgr), m_translator(URDE::SystemLocaleOrEnglish()) -{} + m_fontCache(fileMgr), m_translator(URDE::SystemLocaleOrEnglish()), + m_recentProjectsPath(HECL::SysFormat(_S("%s/recent_projects.txt"), fileMgr.getStoreRoot().c_str())), + m_recentFilesPath(HECL::SysFormat(_S("%s/recent_files.txt"), fileMgr.getStoreRoot().c_str())) +{ + char path[2048]; + HECL::Sstat theStat; + + FILE* fp = HECL::Fopen(m_recentProjectsPath.c_str(), _S("r"), HECL::FileLockType::Read); + if (fp) + { + while (fgets(path, 2048, fp)) + { + std::string pathStr(path); + pathStr.pop_back(); + HECL::SystemStringView pathStrView(pathStr); + if (!HECL::Stat(pathStrView.c_str(), &theStat) && S_ISDIR(theStat.st_mode)) + m_recentProjects.push_back(pathStrView); + } + fclose(fp); + } + + fp = HECL::Fopen(m_recentFilesPath.c_str(), _S("r"), HECL::FileLockType::Read); + if (fp) + { + while (fgets(path, 2048, fp)) + { + std::string pathStr(path); + pathStr.pop_back(); + HECL::SystemStringView pathStrView(pathStr); + if (!HECL::Stat(pathStrView.c_str(), &theStat) && S_ISDIR(theStat.st_mode)) + m_recentFiles.push_back(pathStrView); + } + fclose(fp); + } +} ViewManager::~ViewManager() {} void ViewManager::pushRecentProject(const HECL::SystemString& path) { + for (HECL::SystemString& testPath : m_recentProjects) + { + if (path == testPath) + return; + } m_recentProjects.push_back(path); + FILE* fp = HECL::Fopen(m_recentProjectsPath.c_str(), _S("w"), HECL::FileLockType::Write); + if (fp) + { + for (HECL::SystemString& pPath : m_recentProjects) + fprintf(fp, "%s\n", HECL::SystemUTF8View(pPath).c_str()); + fclose(fp); + } } void ViewManager::pushRecentFile(const HECL::SystemString& path) { + for (HECL::SystemString& testPath : m_recentFiles) + { + if (path == testPath) + return; + } m_recentFiles.push_back(path); -} + FILE* fp = HECL::Fopen(m_recentFilesPath.c_str(), _S("w"), HECL::FileLockType::Write); + if (fp) + { + for (HECL::SystemString& pPath : m_recentFiles) + fprintf(fp, "%s\n", HECL::SystemUTF8View(pPath).c_str()); + fclose(fp); + }} void ViewManager::init(boo::IApplication* app) { diff --git a/Editor/ViewManager.hpp b/Editor/ViewManager.hpp index 608916719..073820a36 100644 --- a/Editor/ViewManager.hpp +++ b/Editor/ViewManager.hpp @@ -29,7 +29,9 @@ class ViewManager : public Specter::IViewManager std::unique_ptr m_rootSpace; Specter::View* m_rootSpaceView = nullptr; - std::vector m_recentProjects = {"Test", "One", "Two", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}; + HECL::SystemString m_recentProjectsPath; + std::vector m_recentProjects; + HECL::SystemString m_recentFilesPath; std::vector m_recentFiles; bool m_updatePf = false; diff --git a/hecl b/hecl index 02236f044..691e6180c 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 02236f04488aee598ee268a6aefbdfb9e56bb98c +Subproject commit 691e6180c4ab6eae12ee236f4d35b8c2ff74a6b2 diff --git a/libSpecter b/libSpecter index c0cc30bca..a7644ff04 160000 --- a/libSpecter +++ b/libSpecter @@ -1 +1 @@ -Subproject commit c0cc30bca09e92b0c8e566016334c162c459f9dc +Subproject commit a7644ff04e5a21ffbd18721f4f53cc3d6fa531c4