move RecentFilesManager to utils/recent_files.h
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#include "app/editor/music/music_editor.h"
|
#include "app/editor/music/music_editor.h"
|
||||||
#include "app/editor/overworld_editor.h"
|
#include "app/editor/overworld_editor.h"
|
||||||
#include "app/editor/sprite/sprite_editor.h"
|
#include "app/editor/sprite/sprite_editor.h"
|
||||||
|
#include "app/editor/utils/recent_files.h"
|
||||||
#include "app/emu/emulator.h"
|
#include "app/emu/emulator.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
#include "app/gfx/snes_tile.h"
|
#include "app/gfx/snes_tile.h"
|
||||||
@@ -78,53 +79,6 @@ bool BeginCentered(const char* name) {
|
|||||||
return ImGui::Begin(name, nullptr, flags);
|
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<std::string>& GetRecentFiles() const {
|
|
||||||
return recentFiles_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string filename_;
|
|
||||||
std::vector<std::string> recentFiles_;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Function to switch the active tab in a tab bar
|
// Function to switch the active tab in a tab bar
|
||||||
void SetTabBarTab(ImGuiTabBar* tab_bar, ImGuiID tab_id) {
|
void SetTabBarTab(ImGuiTabBar* tab_bar, ImGuiID tab_id) {
|
||||||
if (tab_bar == NULL) return;
|
if (tab_bar == NULL) return;
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
#include "app/editor/dungeon_editor.h"
|
#include "app/editor/dungeon_editor.h"
|
||||||
#include "app/editor/graphics/graphics_editor.h"
|
#include "app/editor/graphics/graphics_editor.h"
|
||||||
#include "app/editor/graphics/palette_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/music/music_editor.h"
|
||||||
#include "app/editor/overworld_editor.h"
|
#include "app/editor/overworld_editor.h"
|
||||||
#include "app/editor/graphics/screen_editor.h"
|
|
||||||
#include "app/editor/sprite/sprite_editor.h"
|
#include "app/editor/sprite/sprite_editor.h"
|
||||||
#include "app/emu/emulator.h"
|
#include "app/emu/emulator.h"
|
||||||
#include "app/gfx/snes_palette.h"
|
#include "app/gfx/snes_palette.h"
|
||||||
|
|||||||
64
src/app/editor/utils/recent_files.h
Normal file
64
src/app/editor/utils/recent_files.h
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#ifndef YAZE_APP_EDITOR_UTILS_RECENT_FILES_H
|
||||||
|
#define YAZE_APP_EDITOR_UTILS_RECENT_FILES_H
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<std::string>& GetRecentFiles() const {
|
||||||
|
return recentFiles_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string filename_;
|
||||||
|
std::vector<std::string> recentFiles_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace editor
|
||||||
|
} // namespace app
|
||||||
|
} // namespace yaze
|
||||||
|
|
||||||
|
#endif // YAZE_APP_EDITOR_UTILS_RECENT_FILES_H
|
||||||
Reference in New Issue
Block a user