mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 10:13:42 +00:00
Fix tags list not up to date after adding or removing a tag
This commit is contained in:
parent
dc4f0795c7
commit
9ced5c422d
3 changed files with 27 additions and 10 deletions
|
@ -22,16 +22,7 @@ void Mirai::loadFile(const std::string &path)
|
||||||
{
|
{
|
||||||
auto tasksFile = TodoMdFormat::readFile(path);
|
auto tasksFile = TodoMdFormat::readFile(path);
|
||||||
files->push_back(std::move(tasksFile));
|
files->push_back(std::move(tasksFile));
|
||||||
tags.clear();
|
reloadTags();
|
||||||
for (auto &file : *files) {
|
|
||||||
for (auto &task : file->getTasks()) {
|
|
||||||
for (auto &tag : task->getTags()) {
|
|
||||||
if (!vectorUtils::contains(tags, tag)) {
|
|
||||||
tags.push_back(tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mirai::save()
|
void Mirai::save()
|
||||||
|
@ -42,6 +33,7 @@ void Mirai::save()
|
||||||
file->setDirty(false);
|
file->setDirty(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
reloadTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mirai::addTask(TaskItemData taskItem)
|
void Mirai::addTask(TaskItemData taskItem)
|
||||||
|
@ -103,4 +95,18 @@ const std::vector<std::string> &Mirai::getTags()
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mirai::reloadTags()
|
||||||
|
{
|
||||||
|
tags.clear();
|
||||||
|
for (auto &file : *files) {
|
||||||
|
for (auto &task : file->getTasks()) {
|
||||||
|
for (auto &tag : task->getTags()) {
|
||||||
|
if (!vectorUtils::contains(tags, tag)) {
|
||||||
|
tags.push_back(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mirai
|
} // namespace mirai
|
||||||
|
|
|
@ -36,6 +36,8 @@ class Mirai
|
||||||
std::weak_ptr<TasksView> getTasks();
|
std::weak_ptr<TasksView> getTasks();
|
||||||
const std::vector<std::string> &getTags();
|
const std::vector<std::string> &getTags();
|
||||||
|
|
||||||
|
void reloadTags();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// The `TasksFile`s are shared to the views, their lifetime can outlive
|
// The `TasksFile`s are shared to the views, their lifetime can outlive
|
||||||
// this (Mirai) object
|
// this (Mirai) object
|
||||||
|
|
|
@ -45,6 +45,15 @@ void TasksView::update()
|
||||||
tasksToShow.push_back(task.get());
|
tasksToShow.push_back(task.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ranges::sort(tasksToShow, [](const TaskItem *t1, const TaskItem *t2) {
|
||||||
|
if (t1->hasDate() && !t2->hasDate()) {
|
||||||
|
return true;
|
||||||
|
} else if (!t1->hasDate() && t2->hasDate()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return t1->getDate() < t2->getDate();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void TasksView::addTagFilter(const std::string &tag)
|
void TasksView::addTagFilter(const std::string &tag)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue