yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
recent_files.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_UTILS_RECENT_FILES_H
2#define YAZE_APP_EDITOR_UTILS_RECENT_FILES_H
3
4#include <algorithm>
5#include <fstream>
6#include <string>
7#include <vector>
8
9namespace yaze {
10namespace app {
11namespace editor {
12
14 public:
15 RecentFilesManager(const std::string& filename) : filename_(filename) {}
16
17 void AddFile(const std::string& filePath) {
18 // Add a file to the list, avoiding duplicates
19 auto it = std::find(recentFiles_.begin(), recentFiles_.end(), filePath);
20 if (it == recentFiles_.end()) {
21 recentFiles_.push_back(filePath);
22 }
23 }
24
25 void Save() {
26 std::ofstream file(filename_);
27 if (!file.is_open()) {
28 return; // Handle the error appropriately
29 }
30
31 for (const auto& filePath : recentFiles_) {
32 file << filePath << std::endl;
33 }
34 }
35
36 void Load() {
37 std::ifstream file(filename_);
38 if (!file.is_open()) {
39 return; // Handle the error appropriately
40 }
41
42 recentFiles_.clear();
43 std::string line;
44 while (std::getline(file, line)) {
45 if (!line.empty()) {
46 recentFiles_.push_back(line);
47 }
48 }
49 }
50
51 const std::vector<std::string>& GetRecentFiles() const {
52 return recentFiles_;
53 }
54
55 private:
56 std::string filename_;
57 std::vector<std::string> recentFiles_;
58};
59
60} // namespace editor
61} // namespace app
62} // namespace yaze
63
64#endif // YAZE_APP_EDITOR_UTILS_RECENT_FILES_H
const std::vector< std::string > & GetRecentFiles() const
std::vector< std::string > recentFiles_
void AddFile(const std::string &filePath)
RecentFilesManager(const std::string &filename)
Definition common.cc:21