mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 01:33:19 +00:00
Add Source creation/edition + Add missing edit forms for tasks and events
This commit is contained in:
parent
f1ac8a42d1
commit
a15c23bb21
24 changed files with 358 additions and 205 deletions
|
@ -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())}
|
||||
);
|
||||
|
|
|
@ -34,6 +34,8 @@ class AppWindowBackend
|
|||
|
||||
slint::ComponentHandle<ui::AppWindow> mainWindow_ = ui::AppWindow::create();
|
||||
slint::ComponentHandle<ui::SettingsWindow> settingsWindow_ = ui::SettingsWindow::create();
|
||||
slint::ComponentHandle<ui::AddSourceWindow> addSourceWindow_ = ui::AddSourceWindow::create();
|
||||
slint::ComponentHandle<ui::EditSourceWindow> editSourceWindow_ = ui::EditSourceWindow::create();
|
||||
|
||||
mirai::Mirai *miraiInstance_;
|
||||
mirai::View view_;
|
||||
|
|
15
src/main.cpp
15
src/main.cpp
|
@ -6,28 +6,15 @@
|
|||
|
||||
#include "AppWindowBackend.h"
|
||||
#include "evalyte-cpp-common/config.h"
|
||||
#include "mirai-core/Config.h"
|
||||
#include "mirai-core/DataProvider.h"
|
||||
#include "mirai-core/MarkdownDataProvider.h"
|
||||
#include "mirai-core/Mirai.h"
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
mirai::Mirai mirai;
|
||||
|
||||
const auto configFilePath = evalyte::createConfigDirectoryPath("mirai") + "/config.json";
|
||||
mirai::Config config(configFilePath);
|
||||
for (const auto &sourceFilePath : config.sources()) {
|
||||
std::unique_ptr<mirai::DataProvider> file =
|
||||
std::make_unique<mirai::MarkdownDataProvider>(sourceFilePath);
|
||||
mirai.loadSource(std::move(file));
|
||||
}
|
||||
|
||||
mirai::Mirai mirai{configFilePath};
|
||||
AppWindowBackend appWindow{&mirai};
|
||||
appWindow.run();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue