diff --git a/src/app/editor/master_editor.cc b/src/app/editor/master_editor.cc index 97c8fbcc..1f24dbae 100644 --- a/src/app/editor/master_editor.cc +++ b/src/app/editor/master_editor.cc @@ -22,6 +22,7 @@ #include "app/editor/music/music_editor.h" #include "app/editor/overworld_editor.h" #include "app/editor/sprite/sprite_editor.h" +#include "app/editor/utils/recent_files.h" #include "app/emu/emulator.h" #include "app/gfx/snes_palette.h" #include "app/gfx/snes_tile.h" @@ -78,53 +79,6 @@ bool BeginCentered(const char* name) { return ImGui::Begin(name, nullptr, flags); } -class RecentFilesManager { - public: - RecentFilesManager(const std::string& filename) : filename_(filename) {} - - void AddFile(const std::string& filePath) { - // Add a file to the list, avoiding duplicates - auto it = std::find(recentFiles_.begin(), recentFiles_.end(), filePath); - if (it == recentFiles_.end()) { - recentFiles_.push_back(filePath); - } - } - - void Save() { - std::ofstream file(filename_); - if (!file.is_open()) { - return; // Handle the error appropriately - } - - for (const auto& filePath : recentFiles_) { - file << filePath << std::endl; - } - } - - void Load() { - std::ifstream file(filename_); - if (!file.is_open()) { - return; // Handle the error appropriately - } - - recentFiles_.clear(); - std::string line; - while (std::getline(file, line)) { - if (!line.empty()) { - recentFiles_.push_back(line); - } - } - } - - const std::vector& GetRecentFiles() const { - return recentFiles_; - } - - private: - std::string filename_; - std::vector recentFiles_; -}; - // Function to switch the active tab in a tab bar void SetTabBarTab(ImGuiTabBar* tab_bar, ImGuiID tab_id) { if (tab_bar == NULL) return; diff --git a/src/app/editor/master_editor.h b/src/app/editor/master_editor.h index c56385ff..d48d5073 100644 --- a/src/app/editor/master_editor.h +++ b/src/app/editor/master_editor.h @@ -18,9 +18,9 @@ #include "app/editor/dungeon_editor.h" #include "app/editor/graphics/graphics_editor.h" #include "app/editor/graphics/palette_editor.h" +#include "app/editor/graphics/screen_editor.h" #include "app/editor/music/music_editor.h" #include "app/editor/overworld_editor.h" -#include "app/editor/graphics/screen_editor.h" #include "app/editor/sprite/sprite_editor.h" #include "app/emu/emulator.h" #include "app/gfx/snes_palette.h" diff --git a/src/app/editor/utils/recent_files.h b/src/app/editor/utils/recent_files.h new file mode 100644 index 00000000..2b0c7f6c --- /dev/null +++ b/src/app/editor/utils/recent_files.h @@ -0,0 +1,64 @@ +#ifndef YAZE_APP_EDITOR_UTILS_RECENT_FILES_H +#define YAZE_APP_EDITOR_UTILS_RECENT_FILES_H + +#include +#include +#include +#include + +namespace yaze { +namespace app { +namespace editor { + +class RecentFilesManager { + public: + RecentFilesManager(const std::string& filename) : filename_(filename) {} + + void AddFile(const std::string& filePath) { + // Add a file to the list, avoiding duplicates + auto it = std::find(recentFiles_.begin(), recentFiles_.end(), filePath); + if (it == recentFiles_.end()) { + recentFiles_.push_back(filePath); + } + } + + void Save() { + std::ofstream file(filename_); + if (!file.is_open()) { + return; // Handle the error appropriately + } + + for (const auto& filePath : recentFiles_) { + file << filePath << std::endl; + } + } + + void Load() { + std::ifstream file(filename_); + if (!file.is_open()) { + return; // Handle the error appropriately + } + + recentFiles_.clear(); + std::string line; + while (std::getline(file, line)) { + if (!line.empty()) { + recentFiles_.push_back(line); + } + } + } + + const std::vector& GetRecentFiles() const { + return recentFiles_; + } + + private: + std::string filename_; + std::vector recentFiles_; +}; + +} // namespace editor +} // namespace app +} // namespace yaze + +#endif // YAZE_APP_EDITOR_UTILS_RECENT_FILES_H \ No newline at end of file