Add Source creation/edition + Add missing edit forms for tasks and events

This commit is contained in:
Vyn 2024-11-01 13:43:45 +01:00
parent f1ac8a42d1
commit a15c23bb21
24 changed files with 358 additions and 205 deletions

View file

@ -53,6 +53,7 @@ AppWindowBackend::AppWindowBackend(mirai::Mirai *miraiInstance)
std::cerr << "Warning, no " << palettePath << " found" << std::endl;
setSelenitePalette(mainWindow_->global<ui::Palette>(), palette.value());
setSelenitePalette(settingsWindow_->global<ui::Palette>(), palette.value());
setSelenitePalette(addSourceWindow_->global<ui::Palette>(), palette.value());
}
mainWindow_->global<ui::Backend>().set_sources(sourcesNames);
@ -116,6 +117,40 @@ void AppWindowBackend::setupCallbacks()
mainWindow_->global<ui::Backend>().on_settings_clicked([&]() {
settingsWindow_->show();
});
mainWindow_->global<ui::Backend>().on_add_source_clicked([&]() {
addSourceWindow_->show();
});
mainWindow_->global<ui::Backend>().on_edit_source_clicked([&](int sourceId) {
auto source = miraiInstance_->getSourceById(sourceId);
assert(source);
auto markdownSource = dynamic_cast<mirai::MarkdownDataProvider *>(source->dataProvider());
editSourceWindow_->set_id(source->id);
editSourceWindow_->set_name(slint::SharedString(source->name()));
editSourceWindow_->set_path(slint::SharedString(markdownSource->path()));
editSourceWindow_->show();
});
addSourceWindow_->global<ui::Backend>().on_add_source([&](ui::AddSourceParam params) {
std::unique_ptr<mirai::DataProvider> file =
std::make_unique<mirai::MarkdownDataProvider>(std::string(params.path));
miraiInstance_->addSource(
std::string(params.name), std::string(params.type), std::move(file)
);
addSourceWindow_->hide();
reloadSources();
reloadTasks();
});
editSourceWindow_->global<ui::Backend>().on_modify_source([&](ui::ModifySourceParam params) {
miraiInstance_->editSource(params.id, std::string(params.name), std::string(params.path));
editSourceWindow_->hide();
reloadSources();
reloadTasks();
});
editSourceWindow_->global<ui::Backend>().on_delete_source([&](int sourceId) {
miraiInstance_->deleteSource(sourceId);
editSourceWindow_->hide();
reloadSources();
reloadTasks();
});
mainWindow_->global<ui::Backend>().on_task_clicked([&](int sourceId, int taskId) {
auto source = miraiInstance_->getSourceById(sourceId);
assert(source);
@ -296,6 +331,7 @@ void AppWindowBackend::reloadTasks()
auto &task = tasksForDate.at(taskIndex);
slintDayTasks->push_back({
.sourceId = task.sourceId(),
.eventId = -1,
.id = task.id(),
.title = slint::SharedString(task.title()),
.checked = task.checked(),
@ -320,6 +356,7 @@ void AppWindowBackend::reloadTasks()
auto &task = eventTasks.at(taskIndex);
slintTasks->push_back({
.sourceId = task.sourceId(),
.eventId = currentEvent.id(),
.id = task.id(),
.title = slint::SharedString(task.title()),
.checked = task.checked(),
@ -336,6 +373,7 @@ void AppWindowBackend::reloadTasks()
auto &task = unscheduledTasksView.at(taskIndex);
unscheduledTasks_->push_back({
.sourceId = task.sourceId(),
.eventId = -1,
.id = task.id(),
.title = slint::SharedString(task.title()),
.checked = task.checked(),
@ -389,7 +427,8 @@ void AppWindowBackend::reloadSources()
mirai::MarkdownDataProvider *sourceProvider =
dynamic_cast<mirai::MarkdownDataProvider *>(source->dataProvider());
sources_->push_back(
{.name = slint::SharedString(source->name()),
{.id = source->id,
.name = slint::SharedString(source->name()),
.selected = isSourceSelected && !noSourceSelected,
.path = slint::SharedString(sourceProvider->path())}
);