Validate list of filenames

This commit is contained in:
Bruno
2021-04-27 23:20:18 +02:00
parent d2f0f42c2d
commit f46ffc004a
2 changed files with 36 additions and 20 deletions

View File

@@ -455,6 +455,39 @@ void Settings::Load()
} }
void Settings::History::push(const string &filename)
{
if (filename.empty()) {
front_is_valid = false;
return;
}
filenames.remove(filename);
filenames.push_front(filename);
if (filenames.size() > MAX_RECENT_HISTORY)
filenames.pop_back();
front_is_valid = true;
changed = true;
}
void Settings::History::remove(const std::string &filename)
{
if (filename.empty())
return;
if (filenames.front() == filename)
front_is_valid = false;
filenames.remove(filename);
changed = true;
}
void Settings::History::validate()
{
for (auto fit = filenames.begin(); fit != filenames.end();) {
if ( SystemToolkit::file_exists( *fit ))
++fit;
else
fit = filenames.erase(fit);
}
}
void Settings::Lock() void Settings::Lock()
{ {

View File

@@ -93,26 +93,9 @@ struct History
save_on_exit = false; save_on_exit = false;
changed = false; changed = false;
} }
void push(const std::string &filename) { void push(const std::string &filename);
if (filename.empty()) { void remove(const std::string &filename);
front_is_valid = false; void validate();
return;
}
filenames.remove(filename);
filenames.push_front(filename);
if (filenames.size() > MAX_RECENT_HISTORY)
filenames.pop_back();
front_is_valid = true;
changed = true;
}
void remove(const std::string &filename) {
if (filename.empty())
return;
if (filenames.front() == filename)
front_is_valid = false;
filenames.remove(filename);
changed = true;
}
}; };
struct TransitionConfig struct TransitionConfig