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
9
namespace
yaze
{
10
namespace
app {
11
namespace
editor {
12
13
class
RecentFilesManager
{
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
yaze::app::editor::RecentFilesManager
Definition
recent_files.h:13
yaze::app::editor::RecentFilesManager::GetRecentFiles
const std::vector< std::string > & GetRecentFiles() const
Definition
recent_files.h:51
yaze::app::editor::RecentFilesManager::recentFiles_
std::vector< std::string > recentFiles_
Definition
recent_files.h:57
yaze::app::editor::RecentFilesManager::AddFile
void AddFile(const std::string &filePath)
Definition
recent_files.h:17
yaze::app::editor::RecentFilesManager::Save
void Save()
Definition
recent_files.h:25
yaze::app::editor::RecentFilesManager::Load
void Load()
Definition
recent_files.h:36
yaze::app::editor::RecentFilesManager::filename_
std::string filename_
Definition
recent_files.h:56
yaze::app::editor::RecentFilesManager::RecentFilesManager
RecentFilesManager(const std::string &filename)
Definition
recent_files.h:15
yaze
Definition
common.cc:21
src
app
editor
utils
recent_files.h
Generated by
1.12.0