Support multiple files

This commit is contained in:
Vyn 2024-04-14 14:11:41 +02:00
parent f8f49233dc
commit 689eea07a7
22 changed files with 528 additions and 131 deletions

View file

@ -12,7 +12,10 @@
#include "TasksView.h"
#include "TodoMd.h"
#include <algorithm>
#include <functional>
#include <memory>
#include <optional>
#include <string>
namespace mirai
{
@ -23,10 +26,13 @@ class Mirai
public:
void loadFile(const std::string &path);
void save();
void addTask(TaskItem taskItem);
void addTask(TaskItemData taskItem);
void addTask(std::string text, std::string date);
void removeTask(const TaskItem *taskItem);
void addFile(TasksFileConfig config);
std::optional<std::reference_wrapper<TasksFile>> getFileByPath(const std::string &path);
std::vector<std::unique_ptr<TasksFile>> &getFiles();
std::weak_ptr<TasksView> getTasks();
const std::vector<std::string> &getTags();
@ -34,7 +40,8 @@ class Mirai
// The `TasksFile`s are shared to the views, their lifetime can outlive
// this (Mirai) object
// because we can't control if the caller will keep the main object alive.
std::shared_ptr<std::vector<TasksFile>> files = std::make_shared<std::vector<TasksFile>>();
std::shared_ptr<std::vector<std::unique_ptr<TasksFile>>> files =
std::make_shared<std::vector<std::unique_ptr<TasksFile>>>();
// We keep a vector of shared_ptr because we need the ref counting mechanism to know
// if we have to remove the view (not used) or tell the view to update() on