diff options
Diffstat (limited to 'source/file.cpp')
-rw-r--r-- | source/file.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/source/file.cpp b/source/file.cpp index 0f0015c..dfd9148 100644 --- a/source/file.cpp +++ b/source/file.cpp @@ -17,6 +17,7 @@ #include "stmdsp_code.hpp" +#include <algorithm> #include <cstdlib> #include <filesystem> #include <fstream> @@ -34,6 +35,7 @@ enum class FileAction { Save, SaveAs }; + static FileAction fileAction = FileAction::None; static std::string fileCurrentPath; static std::vector<std::filesystem::path> fileTemplateList; @@ -56,17 +58,31 @@ static void openCurrentFile() } } -void openNewFile() +static void openNewFile() { fileCurrentPath.clear(); editor.SetText(stmdsp::file_content); } -void fileScanTemplates() +static std::vector<std::filesystem::path> fileScanTemplates() +{ + const auto path = std::filesystem::current_path() / "templates"; + const std::filesystem::recursive_directory_iterator rdi (path); + + std::vector<std::filesystem::path> list; + std::transform( + std::filesystem::begin(rdi), + std::filesystem::end(rdi), + std::back_inserter(list), + [](const auto& file) { return file.path(); }); + std::sort(list.begin(), list.end()); + return list; +} + +void fileInit() { - auto path = std::filesystem::current_path() / "templates"; - for (const auto& file : std::filesystem::recursive_directory_iterator{path}) - fileTemplateList.push_back(file.path()); + fileTemplateList = fileScanTemplates(); + openNewFile(); } void fileRenderMenu() |