From 854152b3957485212f8d817f2d74e63186d9555a Mon Sep 17 00:00:00 2001 From: Vyn Date: Tue, 24 Jun 2025 08:35:38 +0200 Subject: [PATCH 1/4] Replace 'edit source window' with popup --- CMakeLists.txt | 1 - src/components/editSourceModal.slint | 63 +++++++++++++++++++ src/ui.slint | 3 +- src/windows/AppWindow/Actions.slint | 2 +- src/windows/AppWindow/AppWindow.cpp | 25 +++++--- src/windows/AppWindow/AppWindow.h | 2 - src/windows/AppWindow/AppWindow.slint | 8 ++- src/windows/AppWindow/Models.slint | 1 + .../AppWindow/views/CalendarView.slint | 4 -- src/windows/AppWindow/views/SideBar.slint | 12 +++- .../EditSourceWindow/EditSourceWindow.cpp | 61 ------------------ .../EditSourceWindow/EditSourceWindow.h | 29 --------- .../EditSourceWindow/EditSourceWindow.slint | 53 ---------------- 13 files changed, 101 insertions(+), 163 deletions(-) create mode 100644 src/components/editSourceModal.slint delete mode 100644 src/windows/EditSourceWindow/EditSourceWindow.cpp delete mode 100644 src/windows/EditSourceWindow/EditSourceWindow.h delete mode 100644 src/windows/EditSourceWindow/EditSourceWindow.slint diff --git a/CMakeLists.txt b/CMakeLists.txt index a73a08e..754d63c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,6 @@ add_executable(mirai src/windows/AppWindow/AppWindow.cpp src/windows/AddSourceWindow/AddSourceWindow.cpp src/windows/SettingsWindow/SettingsWindow.cpp - src/windows/EditSourceWindow/EditSourceWindow.cpp src/windows/EditEventWindow/EditEventWindow.cpp src/SeleniteSetup.cpp src/shared/Utils.cpp diff --git a/src/components/editSourceModal.slint b/src/components/editSourceModal.slint new file mode 100644 index 0000000..0ec956d --- /dev/null +++ b/src/components/editSourceModal.slint @@ -0,0 +1,63 @@ +import { VTextInput } from "../../external/selenite/components/TextInput.slint"; +import { VButton } from "../../external/selenite/components/index.slint"; +import { AppWindowActions } from "../windows/AppWindow/Actions.slint"; +import { Palette } from "@selenite"; +import { AppWindowModels } from "../windows/AppWindow/Models.slint"; + +export component EditSourceModal inherits Rectangle { + private property source-id-to-edit: -1; + private property name: ""; + private property path: ""; + + init() => { + if (self.absolute-position.x < 500px) { + self.x += 500px - self.absolute-position.x; + } + } + + public function edit(source-id: int) { + source-id-to-edit = source-id; + self.name = AppWindowModels.get-source-name-from-id(source-id); + self.path = AppWindowModels.get-source-path-from-id(source-id); + popup.show(); + } + + popup := PopupWindow { + close-policy: close-on-click-outside; + background := Rectangle { + height: 100%; + width: 100%; + background: Palette.background1; + border-color: Palette.popup-border; + border-width: 1px; + border-radius: 4px; + } + + VerticalLayout { + padding: 16px; + spacing: 8px; + nameInput := VTextInput { + label: "Name"; + text <=> root.name; + } + pathInput := VTextInput { + label: "Path"; + text <=> root.path; + } + VButton { + text: "Save"; + clicked => { + AppWindowActions.edit-source(source-id-to-edit, name, path); + popup.close(); + } + } + VButton { + text: "Delete"; + background-color: Palette.red; + double-clicked => { + //root.delete-source(root.id) + } + } + } + } +} diff --git a/src/ui.slint b/src/ui.slint index 3e9ca63..67f7759 100644 --- a/src/ui.slint +++ b/src/ui.slint @@ -3,9 +3,8 @@ import { AppWindowActions } from "windows/AppWindow/Actions.slint"; import { AppWindow } from "windows/AppWindow/AppWindow.slint"; import { SettingsWindow } from "windows/SettingsWindow/SettingsWindow.slint"; import { AddSourceWindow } from "windows/AddSourceWindow//AddSourceWindow.slint"; -import { EditSourceWindow } from "windows/EditSourceWindow/EditSourceWindow.slint"; import { EditEventWindow } from "windows/EditEventWindow/EditEventWindow.slint"; import { Utils } from "shared/Utils.slint"; import { Palette } from "@selenite"; -export { Utils, Palette, AppWindow, AppWindowModels, AppWindowActions, SettingsWindow, AddSourceWindow, EditSourceWindow, EditEventWindow } +export { Utils, Palette, AppWindow, AppWindowModels, AppWindowActions, SettingsWindow, AddSourceWindow, EditEventWindow } diff --git a/src/windows/AppWindow/Actions.slint b/src/windows/AppWindow/Actions.slint index cbcb399..ad64868 100644 --- a/src/windows/AppWindow/Actions.slint +++ b/src/windows/AppWindow/Actions.slint @@ -50,7 +50,7 @@ export global AppWindowActions { callback source-clicked(int); callback open-settings-window(); callback open-add-source-window(); - callback open-edit-source-window(int); + callback edit-source(sourceId: int, name: string, path: string); callback open-new-task-form(OpenNewTaskFormParams); callback open-edit-task-form(int, int); diff --git a/src/windows/AppWindow/AppWindow.cpp b/src/windows/AppWindow/AppWindow.cpp index d2d91ec..a1340f9 100644 --- a/src/windows/AppWindow/AppWindow.cpp +++ b/src/windows/AppWindow/AppWindow.cpp @@ -34,8 +34,7 @@ AppWindow::AppWindow(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance), addSourceWindow_(miraiInstance), - editSourceWindow_(miraiInstance), settingsWindow_(miraiInstance), - editEventWindow_(miraiInstance), view_(miraiInstance) + settingsWindow_(miraiInstance), editEventWindow_(miraiInstance), view_(miraiInstance) { sources_ = std::make_shared>(); days_ = std::make_shared>(); @@ -105,6 +104,14 @@ void AppWindow::setupCallbacks() return slint::SharedString(source->name()); }); + models().on_get_source_path_from_id([&](int sourceId) { + auto source = miraiInstance_->getSourceById(sourceId); + assert(source); + mirai::MarkdownDataProvider *sourceProvider = + dynamic_cast(source->dataProvider()); + return slint::SharedString(sourceProvider->path()); + }); + miraiInstance_->onSourceAdded([&](mirai::Source *source) { refreshModels(); }); @@ -120,11 +127,11 @@ void AppWindow::setupCallbacks() actions().on_open_add_source_window([&]() { addSourceWindow_.open(); }); - actions().on_open_edit_source_window([&](int sourceId) { - auto source = miraiInstance_->getSourceById(sourceId); - assert(source); - editSourceWindow_.open(source); - }); + /*actions().on_open_edit_source_window([&](int sourceId) {*/ + /*auto source = miraiInstance_->getSourceById(sourceId);*/ + /*assert(source);*/ + /*editSourceWindow_.open(source);*/ + /*});*/ actions().on_open_add_event_window([&]() { editEventWindow_.open(); }); @@ -158,6 +165,10 @@ void AppWindow::setupCallbacks() reloadTasks(); }); + actions().on_edit_source([&](int sourceId, slint::SharedString name, slint::SharedString path) { + miraiInstance_->editSource(sourceId, std::string(name), std::string(path)); + }); + actions().on_delete_task_clicked([&](int sourceId, int taskId) { auto source = miraiInstance_->getSourceById(sourceId); assert(source); diff --git a/src/windows/AppWindow/AppWindow.h b/src/windows/AppWindow/AppWindow.h index cf496e1..b8ff3ab 100644 --- a/src/windows/AppWindow/AppWindow.h +++ b/src/windows/AppWindow/AppWindow.h @@ -8,7 +8,6 @@ #include "../AddSourceWindow/AddSourceWindow.h" #include "../EditEventWindow/EditEventWindow.h" -#include "../EditSourceWindow/EditSourceWindow.h" #include "../SettingsWindow/SettingsWindow.h" #include "mirai-core/Mirai.h" #include "mirai-core/View.h" @@ -40,7 +39,6 @@ class AppWindow slint::ComponentHandle mainWindow_ = ui::AppWindow::create(); SettingsWindow settingsWindow_; AddSourceWindow addSourceWindow_; - EditSourceWindow editSourceWindow_; EditEventWindow editEventWindow_; mirai::Mirai *miraiInstance_; diff --git a/src/windows/AppWindow/AppWindow.slint b/src/windows/AppWindow/AppWindow.slint index 49f7eef..c4b7de5 100644 --- a/src/windows/AppWindow/AppWindow.slint +++ b/src/windows/AppWindow/AppWindow.slint @@ -4,11 +4,13 @@ import { SideBar } from "views/SideBar.slint"; import { MainView } from "views/TasksView.slint"; import { SettingsWindow } from "../SettingsWindow/SettingsWindow.slint"; import { AddSourceWindow } from "../AddSourceWindow//AddSourceWindow.slint"; -import { EditSourceWindow } from "../EditSourceWindow/EditSourceWindow.slint"; import { Palette } from "@selenite"; import { CalendarView } from "views/CalendarView.slint"; import { VButton } from "../../../external/selenite/components/Button.slint"; import { ToggleButton } from "../../../external/selenite/components/index.slint"; +import { VTextInput } from "../../../external/selenite/components/TextInput.slint"; +import { AppWindowActions } from "Actions.slint"; +import { EditSourceModal } from "../../components/editSourceModal.slint"; export component AppWindow inherits Window { @@ -19,6 +21,8 @@ export component AppWindow inherits Window { private property show-tasks: false; + + HorizontalLayout { // padding: 16px; //spacing: 16px; @@ -70,4 +74,4 @@ export component AppWindow inherits Window { } } -export { AppWindowModels, Palette, SettingsWindow, AddSourceWindow, EditSourceWindow } // Export to make it visible to the C++ backend +export { AppWindowModels, Palette, SettingsWindow, AddSourceWindow } // Export to make it visible to the C++ backend diff --git a/src/windows/AppWindow/Models.slint b/src/windows/AppWindow/Models.slint index 4c1008a..75c1212 100644 --- a/src/windows/AppWindow/Models.slint +++ b/src/windows/AppWindow/Models.slint @@ -48,4 +48,5 @@ export global AppWindowModels { callback get-source-id-from-name(string) -> int; pure callback get-source-name-from-id(int) -> string; + pure callback get-source-path-from-id(int) -> string; } diff --git a/src/windows/AppWindow/views/CalendarView.slint b/src/windows/AppWindow/views/CalendarView.slint index 9ab3574..cd95e40 100644 --- a/src/windows/AppWindow/views/CalendarView.slint +++ b/src/windows/AppWindow/views/CalendarView.slint @@ -47,16 +47,12 @@ export component CalendarView inherits Rectangle { VButton { text: "Create"; clicked => { - debug("clicked OK"); - debug(createEventPopup.width); - debug(createEventPopup.height); AppWindowActions.create-event({ title: titleInput.text, date: dateInput.date, startsAt: startTimeInput.time, endsAt: endTimeInput.time }); - debug("Event sent"); createEventPopup.close(); } } diff --git a/src/windows/AppWindow/views/SideBar.slint b/src/windows/AppWindow/views/SideBar.slint index 5565853..f898c00 100644 --- a/src/windows/AppWindow/views/SideBar.slint +++ b/src/windows/AppWindow/views/SideBar.slint @@ -1,9 +1,19 @@ import { AppWindowModels, TaskData } from "../Models.slint"; import { AppWindowActions } from "../Actions.slint"; import { VButton, ToggleButton, VActionButton, VText, Svg, Palette } from "@selenite"; +import { EditSourceModal } from "../../../components/editSourceModal.slint"; export component SideBar inherits Rectangle { + function open-edit-source-window(source-id: int) { + editSourcePopup.edit(source-id) + } + + editSourcePopup := EditSourceModal { + //x: parent.width / 2 - 200px; + //y: parent.height / 2 - 300px; + } + VerticalLayout { height: parent.height; padding: 16px; @@ -51,7 +61,7 @@ export component SideBar inherits Rectangle { visible: parent.active; icon-svg: Svg.cog; background: transparent; - clicked => { AppWindowActions.open-edit-source-window(item.id) } + clicked => { editSourcePopup.edit(item.id) } } } } diff --git a/src/windows/EditSourceWindow/EditSourceWindow.cpp b/src/windows/EditSourceWindow/EditSourceWindow.cpp deleted file mode 100644 index 8408429..0000000 --- a/src/windows/EditSourceWindow/EditSourceWindow.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Mirai. Copyright (C) 2024 Vyn - * This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only) - * The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt - */ - -#include "EditSourceWindow.h" -#include "../../SeleniteSetup.h" -#include "mirai-core/MarkdownDataProvider.h" -#include "mirai-core/Mirai.h" -#include "slint.h" -#include "slint_string.h" -#include "ui.h" -#include -#include -#include -#include -#include -#include -#include -#include - -EditSourceWindow::EditSourceWindow(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance) -{ - - const auto palettePath = std::string(getenv("HOME")) + "/.config/evalyte/theme.json"; - const auto palette = selenite::parseJson(palettePath); - - if (palette.has_value()) { - setSelenitePalette(window_->global(), palette.value()); - } - - setupCallbacks(); -} - -void EditSourceWindow::setupCallbacks() -{ - window_->on_modify_source([&](ui::ModifySourceParam params) { - miraiInstance_->editSource(params.id, std::string(params.name), std::string(params.path)); - close(); - }); - window_->on_delete_source([&](int sourceId) { - miraiInstance_->deleteSource(sourceId); - close(); - }); -} - -void EditSourceWindow::open(mirai::Source *source) -{ - assert(source != nullptr); - auto markdownSource = dynamic_cast(source->dataProvider()); - window_->set_id(source->id); - window_->set_name(slint::SharedString(source->name())); - window_->set_path(slint::SharedString(markdownSource->path())); - window_->show(); -} - -void EditSourceWindow::close() -{ - window_->hide(); -} diff --git a/src/windows/EditSourceWindow/EditSourceWindow.h b/src/windows/EditSourceWindow/EditSourceWindow.h deleted file mode 100644 index 59e5164..0000000 --- a/src/windows/EditSourceWindow/EditSourceWindow.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Mirai. Copyright (C) 2024 Vyn - * This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only) - * The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt - */ - -#pragma once - -#include "mirai-core/Mirai.h" -#include "mirai-core/Source.h" -#include "slint.h" -#include "ui.h" - -class EditSourceWindow -{ - - public: - EditSourceWindow(mirai::Mirai *mirai); - - void open(mirai::Source *source); - void close(); - - private: - void setupCallbacks(); - - std::shared_ptr> sources_; - slint::ComponentHandle window_ = ui::EditSourceWindow::create(); - mirai::Mirai *miraiInstance_; -}; diff --git a/src/windows/EditSourceWindow/EditSourceWindow.slint b/src/windows/EditSourceWindow/EditSourceWindow.slint deleted file mode 100644 index 9ddab3f..0000000 --- a/src/windows/EditSourceWindow/EditSourceWindow.slint +++ /dev/null @@ -1,53 +0,0 @@ -import { VerticalBox, CheckBox } from "std-widgets.slint"; -import { VButton, VText, VTextInput, Palette } from "@selenite"; - -export struct ModifySourceParam { - id: int, - name: string, - path: string -} - -export component EditSourceWindow inherits Window { - in-out property id; - in-out property name <=> nameInput.text; - in-out property path <=> pathInput.text; - - title: "Mirai - Edit source"; - min-height: 100px; - max-height: 4000px; // needed, otherwise the window wants to fit the content (on Swaywm) - min-width: 400px; - background: Palette.background; - - callback modify-source(ModifySourceParam); - callback delete-source(int); - - VerticalLayout { - padding: 16px; - spacing: 8px; - nameInput := VTextInput { - label: "Name"; - } - pathInput := VTextInput { - label: "Path"; - } - VButton { - text: "Save"; - clicked => { - root.modify-source({ - id: root.id, - name: nameInput.text, - path: pathInput.text - }) - } - } - VButton { - text: "Delete"; - background-color: Palette.red; - double-clicked => { - root.delete-source(root.id) - } - } - } -} - -export { Palette } // Export to make it visible to the C++ backend From fcdeec19eda321ce58ca85714ed4d3a4b5bf2185 Mon Sep 17 00:00:00 2001 From: Vyn Date: Tue, 24 Jun 2025 09:31:34 +0200 Subject: [PATCH 2/4] Replace 'add source window' with popup --- external/selenite | 2 +- src/components/editSourceModal.slint | 63 ----------------------- src/modals/AddSourceModal.slint | 36 +++++++++++++ src/modals/EditSourceModal.slint | 46 +++++++++++++++++ src/windows/AppWindow/Actions.slint | 1 + src/windows/AppWindow/AppWindow.cpp | 6 +++ src/windows/AppWindow/AppWindow.slint | 9 ++-- src/windows/AppWindow/views/SideBar.slint | 11 ++-- 8 files changed, 98 insertions(+), 76 deletions(-) delete mode 100644 src/components/editSourceModal.slint create mode 100644 src/modals/AddSourceModal.slint create mode 100644 src/modals/EditSourceModal.slint diff --git a/external/selenite b/external/selenite index acbd562..fa86c85 160000 --- a/external/selenite +++ b/external/selenite @@ -1 +1 @@ -Subproject commit acbd56205d758bf74d7f121ce8085898acbacc9f +Subproject commit fa86c85483725f269ee06001dba8c4c2a438194d diff --git a/src/components/editSourceModal.slint b/src/components/editSourceModal.slint deleted file mode 100644 index 0ec956d..0000000 --- a/src/components/editSourceModal.slint +++ /dev/null @@ -1,63 +0,0 @@ -import { VTextInput } from "../../external/selenite/components/TextInput.slint"; -import { VButton } from "../../external/selenite/components/index.slint"; -import { AppWindowActions } from "../windows/AppWindow/Actions.slint"; -import { Palette } from "@selenite"; -import { AppWindowModels } from "../windows/AppWindow/Models.slint"; - -export component EditSourceModal inherits Rectangle { - private property source-id-to-edit: -1; - private property name: ""; - private property path: ""; - - init() => { - if (self.absolute-position.x < 500px) { - self.x += 500px - self.absolute-position.x; - } - } - - public function edit(source-id: int) { - source-id-to-edit = source-id; - self.name = AppWindowModels.get-source-name-from-id(source-id); - self.path = AppWindowModels.get-source-path-from-id(source-id); - popup.show(); - } - - popup := PopupWindow { - close-policy: close-on-click-outside; - background := Rectangle { - height: 100%; - width: 100%; - background: Palette.background1; - border-color: Palette.popup-border; - border-width: 1px; - border-radius: 4px; - } - - VerticalLayout { - padding: 16px; - spacing: 8px; - nameInput := VTextInput { - label: "Name"; - text <=> root.name; - } - pathInput := VTextInput { - label: "Path"; - text <=> root.path; - } - VButton { - text: "Save"; - clicked => { - AppWindowActions.edit-source(source-id-to-edit, name, path); - popup.close(); - } - } - VButton { - text: "Delete"; - background-color: Palette.red; - double-clicked => { - //root.delete-source(root.id) - } - } - } - } -} diff --git a/src/modals/AddSourceModal.slint b/src/modals/AddSourceModal.slint new file mode 100644 index 0000000..e74e9c3 --- /dev/null +++ b/src/modals/AddSourceModal.slint @@ -0,0 +1,36 @@ +import { Palette } from "@selenite"; +import { VTextInput } from "../../external/selenite/components/TextInput.slint"; +import { VButton } from "../../external/selenite/components/index.slint"; +import { AppWindowModels } from "../windows/AppWindow/Models.slint"; +import { AppWindowActions } from "../windows/AppWindow/Actions.slint"; +import { Modal } from "../../external/selenite/components/Modal.slint"; + +export component AddSourceModal inherits Modal { + private property source-id-to-edit: -1; + private property name: ""; + private property path: ""; + + public function open() { + root.show(); + } + + VerticalLayout { + padding: 16px; + spacing: 8px; + nameInput := VTextInput { + label: "Name"; + text <=> root.name; + } + pathInput := VTextInput { + label: "Path"; + text <=> root.path; + } + VButton { + text: "Add"; + clicked => { + AppWindowActions.add-source(name, path); + root.close(); + } + } + } +} diff --git a/src/modals/EditSourceModal.slint b/src/modals/EditSourceModal.slint new file mode 100644 index 0000000..f196afe --- /dev/null +++ b/src/modals/EditSourceModal.slint @@ -0,0 +1,46 @@ +import { Palette } from "@selenite"; +import { VTextInput } from "../../external/selenite/components/TextInput.slint"; +import { VButton } from "../../external/selenite/components/index.slint"; +import { AppWindowModels } from "../windows/AppWindow/Models.slint"; +import { AppWindowActions } from "../windows/AppWindow/Actions.slint"; +import { Modal } from "../../external/selenite/components/Modal.slint"; + +export component EditSourceModal inherits Modal { + private property source-id-to-edit: -1; + private property name: ""; + private property path: ""; + + public function edit(source-id: int) { + source-id-to-edit = source-id; + root.name = AppWindowModels.get-source-name-from-id(source-id); + root.path = AppWindowModels.get-source-path-from-id(source-id); + root.show(); + } + + VerticalLayout { + padding: 16px; + spacing: 8px; + nameInput := VTextInput { + label: "Name"; + text <=> root.name; + } + pathInput := VTextInput { + label: "Path"; + text <=> root.path; + } + VButton { + text: "Save"; + clicked => { + AppWindowActions.edit-source(source-id-to-edit, name, path); + root.close(); + } + } + VButton { + text: "Delete"; + background-color: Palette.red; + double-clicked => { + //root.delete-source(root.id) + } + } + } +} diff --git a/src/windows/AppWindow/Actions.slint b/src/windows/AppWindow/Actions.slint index ad64868..f74753d 100644 --- a/src/windows/AppWindow/Actions.slint +++ b/src/windows/AppWindow/Actions.slint @@ -50,6 +50,7 @@ export global AppWindowActions { callback source-clicked(int); callback open-settings-window(); callback open-add-source-window(); + callback add-source(name: string, path: string); callback edit-source(sourceId: int, name: string, path: string); callback open-new-task-form(OpenNewTaskFormParams); diff --git a/src/windows/AppWindow/AppWindow.cpp b/src/windows/AppWindow/AppWindow.cpp index a1340f9..19dfaf6 100644 --- a/src/windows/AppWindow/AppWindow.cpp +++ b/src/windows/AppWindow/AppWindow.cpp @@ -165,6 +165,12 @@ void AppWindow::setupCallbacks() reloadTasks(); }); + actions().on_add_source([&](slint::SharedString name, slint::SharedString path) { + std::unique_ptr file = + std::make_unique(std::string(path)); + miraiInstance_->addSource(std::string(name), "FileSystemMarkdown", std::move(file)); + }); + actions().on_edit_source([&](int sourceId, slint::SharedString name, slint::SharedString path) { miraiInstance_->editSource(sourceId, std::string(name), std::string(path)); }); diff --git a/src/windows/AppWindow/AppWindow.slint b/src/windows/AppWindow/AppWindow.slint index c4b7de5..4d5123b 100644 --- a/src/windows/AppWindow/AppWindow.slint +++ b/src/windows/AppWindow/AppWindow.slint @@ -1,6 +1,5 @@ import { AppWindowModels } from "Models.slint"; import { Button, VerticalBox, CheckBox } from "std-widgets.slint"; -import { SideBar } from "views/SideBar.slint"; import { MainView } from "views/TasksView.slint"; import { SettingsWindow } from "../SettingsWindow/SettingsWindow.slint"; import { AddSourceWindow } from "../AddSourceWindow//AddSourceWindow.slint"; @@ -10,8 +9,8 @@ import { VButton } from "../../../external/selenite/components/Button.slint"; import { ToggleButton } from "../../../external/selenite/components/index.slint"; import { VTextInput } from "../../../external/selenite/components/TextInput.slint"; import { AppWindowActions } from "Actions.slint"; -import { EditSourceModal } from "../../components/editSourceModal.slint"; - +import { SideBar } from "views/SideBar.slint"; + export component AppWindow inherits Window { title: "Mirai"; @@ -21,8 +20,6 @@ export component AppWindow inherits Window { private property show-tasks: false; - - HorizontalLayout { // padding: 16px; //spacing: 16px; @@ -47,7 +44,7 @@ export component AppWindow inherits Window { active: show-tasks; clicked => { show-tasks = true } } - } + } SideBar { min-width: 256px; } diff --git a/src/windows/AppWindow/views/SideBar.slint b/src/windows/AppWindow/views/SideBar.slint index f898c00..680d00b 100644 --- a/src/windows/AppWindow/views/SideBar.slint +++ b/src/windows/AppWindow/views/SideBar.slint @@ -1,7 +1,8 @@ import { AppWindowModels, TaskData } from "../Models.slint"; import { AppWindowActions } from "../Actions.slint"; import { VButton, ToggleButton, VActionButton, VText, Svg, Palette } from "@selenite"; -import { EditSourceModal } from "../../../components/editSourceModal.slint"; +import { EditSourceModal } from "../../../modals/EditSourceModal.slint"; +import { AddSourceModal } from "../../../modals/AddSourceModal.slint"; export component SideBar inherits Rectangle { @@ -9,10 +10,8 @@ export component SideBar inherits Rectangle { editSourcePopup.edit(source-id) } - editSourcePopup := EditSourceModal { - //x: parent.width / 2 - 200px; - //y: parent.height / 2 - 300px; - } + addSourcePopup := AddSourceModal{} + editSourcePopup := EditSourceModal {} VerticalLayout { height: parent.height; @@ -35,7 +34,7 @@ export component SideBar inherits Rectangle { icon-svg: Svg.plus; icon-colorize: Palette.green; background: transparent; - clicked => { AppWindowActions.open-add-source-window() } + clicked => { addSourcePopup.open() } } } VerticalLayout { From c804ce1c7bcbfab01ec93ce7a4ff48cdbdbb74b4 Mon Sep 17 00:00:00 2001 From: Vyn Date: Tue, 24 Jun 2025 09:34:05 +0200 Subject: [PATCH 3/4] Remove old 'add source window' --- CMakeLists.txt | 1 - src/ui.slint | 3 +- .../AddSourceWindow/AddSourceWindow.cpp | 59 ------------------- src/windows/AddSourceWindow/AddSourceWindow.h | 28 --------- .../AddSourceWindow/AddSourceWindow.slint | 45 -------------- src/windows/AppWindow/AppWindow.cpp | 6 +- src/windows/AppWindow/AppWindow.h | 2 - src/windows/AppWindow/AppWindow.slint | 3 +- 8 files changed, 5 insertions(+), 142 deletions(-) delete mode 100644 src/windows/AddSourceWindow/AddSourceWindow.cpp delete mode 100644 src/windows/AddSourceWindow/AddSourceWindow.h delete mode 100644 src/windows/AddSourceWindow/AddSourceWindow.slint diff --git a/CMakeLists.txt b/CMakeLists.txt index 754d63c..d90a0a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,6 @@ add_subdirectory(external/evalyte-cpp-common) add_executable(mirai src/main.cpp src/windows/AppWindow/AppWindow.cpp - src/windows/AddSourceWindow/AddSourceWindow.cpp src/windows/SettingsWindow/SettingsWindow.cpp src/windows/EditEventWindow/EditEventWindow.cpp src/SeleniteSetup.cpp diff --git a/src/ui.slint b/src/ui.slint index 67f7759..9f10028 100644 --- a/src/ui.slint +++ b/src/ui.slint @@ -2,9 +2,8 @@ import { AppWindowModels } from "windows/AppWindow/Models.slint"; import { AppWindowActions } from "windows/AppWindow/Actions.slint"; import { AppWindow } from "windows/AppWindow/AppWindow.slint"; import { SettingsWindow } from "windows/SettingsWindow/SettingsWindow.slint"; -import { AddSourceWindow } from "windows/AddSourceWindow//AddSourceWindow.slint"; import { EditEventWindow } from "windows/EditEventWindow/EditEventWindow.slint"; import { Utils } from "shared/Utils.slint"; import { Palette } from "@selenite"; -export { Utils, Palette, AppWindow, AppWindowModels, AppWindowActions, SettingsWindow, AddSourceWindow, EditEventWindow } +export { Utils, Palette, AppWindow, AppWindowModels, AppWindowActions, SettingsWindow, EditEventWindow } diff --git a/src/windows/AddSourceWindow/AddSourceWindow.cpp b/src/windows/AddSourceWindow/AddSourceWindow.cpp deleted file mode 100644 index ecb958b..0000000 --- a/src/windows/AddSourceWindow/AddSourceWindow.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Mirai. Copyright (C) 2024 Vyn - * This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only) - * The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt - */ - -#include "AddSourceWindow.h" -#include "../../SeleniteSetup.h" -#include "evalyte-cpp-common/evalyte.h" -#include "mirai-core/MarkdownDataProvider.h" -#include "mirai-core/Mirai.h" -#include "slint.h" -#include "slint_string.h" -#include "ui.h" -#include -#include -#include -#include -#include -#include -#include -#include - -AddSourceWindow::AddSourceWindow(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance) -{ - window_->set_default_source_path(slint::SharedString(evalyte::dataDirectoryPath("mirai") + "/") - ); - - const auto palettePath = std::string(getenv("HOME")) + "/.config/evalyte/theme.json"; - const auto palette = selenite::parseJson(palettePath); - - if (palette.has_value()) { - setSelenitePalette(window_->global(), palette.value()); - } - - setupCallbacks(); -} - -void AddSourceWindow::setupCallbacks() -{ - window_->on_add_source([&](ui::AddSourceParam params) { - std::unique_ptr file = - std::make_unique(std::string(params.path)); - miraiInstance_->addSource( - std::string(params.name), std::string(params.type), std::move(file) - ); - window_->hide(); - }); -} - -void AddSourceWindow::open() -{ - window_->show(); -} - -void AddSourceWindow::close() -{ - window_->hide(); -} diff --git a/src/windows/AddSourceWindow/AddSourceWindow.h b/src/windows/AddSourceWindow/AddSourceWindow.h deleted file mode 100644 index cfbcd4e..0000000 --- a/src/windows/AddSourceWindow/AddSourceWindow.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Mirai. Copyright (C) 2024 Vyn - * This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only) - * The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt - */ - -#pragma once - -#include "mirai-core/Mirai.h" -#include "slint.h" -#include "ui.h" - -class AddSourceWindow -{ - - public: - AddSourceWindow(mirai::Mirai *mirai); - - void open(); - void close(); - - private: - void setupCallbacks(); - - std::shared_ptr> sources_; - slint::ComponentHandle window_ = ui::AddSourceWindow::create(); - mirai::Mirai *miraiInstance_; -}; diff --git a/src/windows/AddSourceWindow/AddSourceWindow.slint b/src/windows/AddSourceWindow/AddSourceWindow.slint deleted file mode 100644 index 468a021..0000000 --- a/src/windows/AddSourceWindow/AddSourceWindow.slint +++ /dev/null @@ -1,45 +0,0 @@ -import { VerticalBox, CheckBox } from "std-widgets.slint"; -import { VButton, VText, VTextInput, Palette } from "@selenite"; - -export struct AddSourceParam { - name: string, - type: string, - path: string -} - -export component AddSourceWindow inherits Window { - - title: "Mirai - Add source"; - min-height: 100px; - max-height: 4000px; // needed, otherwise the window wants to fit the content (on Swaywm) - min-width: 400px; - background: Palette.background; - - in-out property default-source-path; - callback add-source(AddSourceParam); - - VerticalLayout { - padding: 16px; - spacing: 8px; - nameInput := VTextInput { - label: "Name"; - text: "todo"; - } - pathInput := VTextInput { - label: "Path"; - text: root.default-source-path + nameInput.text + ".md"; - } - VButton { - text: "Create"; - clicked => { - root.add-source({ - name: nameInput.text, - type: "FileSystemMarkdown", - path: pathInput.text - }) - } - } - } -} - -export { Palette } // Export to make it visible to the C++ backend diff --git a/src/windows/AppWindow/AppWindow.cpp b/src/windows/AppWindow/AppWindow.cpp index 19dfaf6..75f7fdb 100644 --- a/src/windows/AppWindow/AppWindow.cpp +++ b/src/windows/AppWindow/AppWindow.cpp @@ -33,8 +33,8 @@ #include AppWindow::AppWindow(mirai::Mirai *miraiInstance) - : miraiInstance_(miraiInstance), addSourceWindow_(miraiInstance), - settingsWindow_(miraiInstance), editEventWindow_(miraiInstance), view_(miraiInstance) + : miraiInstance_(miraiInstance), settingsWindow_(miraiInstance), + editEventWindow_(miraiInstance), view_(miraiInstance) { sources_ = std::make_shared>(); days_ = std::make_shared>(); @@ -125,7 +125,7 @@ void AppWindow::setupCallbacks() settingsWindow_.open(); }); actions().on_open_add_source_window([&]() { - addSourceWindow_.open(); + // addSourceWindow_.open(); }); /*actions().on_open_edit_source_window([&](int sourceId) {*/ /*auto source = miraiInstance_->getSourceById(sourceId);*/ diff --git a/src/windows/AppWindow/AppWindow.h b/src/windows/AppWindow/AppWindow.h index b8ff3ab..177683e 100644 --- a/src/windows/AppWindow/AppWindow.h +++ b/src/windows/AppWindow/AppWindow.h @@ -6,7 +6,6 @@ #pragma once -#include "../AddSourceWindow/AddSourceWindow.h" #include "../EditEventWindow/EditEventWindow.h" #include "../SettingsWindow/SettingsWindow.h" #include "mirai-core/Mirai.h" @@ -38,7 +37,6 @@ class AppWindow slint::ComponentHandle mainWindow_ = ui::AppWindow::create(); SettingsWindow settingsWindow_; - AddSourceWindow addSourceWindow_; EditEventWindow editEventWindow_; mirai::Mirai *miraiInstance_; diff --git a/src/windows/AppWindow/AppWindow.slint b/src/windows/AppWindow/AppWindow.slint index 4d5123b..625d51c 100644 --- a/src/windows/AppWindow/AppWindow.slint +++ b/src/windows/AppWindow/AppWindow.slint @@ -2,7 +2,6 @@ import { AppWindowModels } from "Models.slint"; import { Button, VerticalBox, CheckBox } from "std-widgets.slint"; import { MainView } from "views/TasksView.slint"; import { SettingsWindow } from "../SettingsWindow/SettingsWindow.slint"; -import { AddSourceWindow } from "../AddSourceWindow//AddSourceWindow.slint"; import { Palette } from "@selenite"; import { CalendarView } from "views/CalendarView.slint"; import { VButton } from "../../../external/selenite/components/Button.slint"; @@ -71,4 +70,4 @@ export component AppWindow inherits Window { } } -export { AppWindowModels, Palette, SettingsWindow, AddSourceWindow } // Export to make it visible to the C++ backend +export { AppWindowModels, Palette, SettingsWindow } // Export to make it visible to the C++ backend From 2e1e5db5eaff2ef69266f3d565fd338bcb48031b Mon Sep 17 00:00:00 2001 From: Vyn Date: Tue, 24 Jun 2025 10:03:50 +0200 Subject: [PATCH 4/4] Replace 'add event window' with popup --- CMakeLists.txt | 1 - external/selenite | 2 +- src/modals/AddEventModal.slint | 43 ++++++++++++ src/ui.slint | 3 +- src/windows/AppWindow/AppWindow.cpp | 5 +- src/windows/AppWindow/AppWindow.h | 2 - .../AppWindow/views/CalendarView.slint | 47 +------------ .../EditEventWindow/EditEventWindow.cpp | 50 -------------- src/windows/EditEventWindow/EditEventWindow.h | 33 --------- .../EditEventWindow/EditEventWindow.slint | 68 ------------------- 10 files changed, 50 insertions(+), 204 deletions(-) create mode 100644 src/modals/AddEventModal.slint delete mode 100644 src/windows/EditEventWindow/EditEventWindow.cpp delete mode 100644 src/windows/EditEventWindow/EditEventWindow.h delete mode 100644 src/windows/EditEventWindow/EditEventWindow.slint diff --git a/CMakeLists.txt b/CMakeLists.txt index d90a0a6..f10b6a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,6 @@ add_executable(mirai src/main.cpp src/windows/AppWindow/AppWindow.cpp src/windows/SettingsWindow/SettingsWindow.cpp - src/windows/EditEventWindow/EditEventWindow.cpp src/SeleniteSetup.cpp src/shared/Utils.cpp ) diff --git a/external/selenite b/external/selenite index fa86c85..810607c 160000 --- a/external/selenite +++ b/external/selenite @@ -1 +1 @@ -Subproject commit fa86c85483725f269ee06001dba8c4c2a438194d +Subproject commit 810607c01fa659f31bd11bd41a9ee5611e5db8ea diff --git a/src/modals/AddEventModal.slint b/src/modals/AddEventModal.slint new file mode 100644 index 0000000..4e6a00c --- /dev/null +++ b/src/modals/AddEventModal.slint @@ -0,0 +1,43 @@ +import { Palette } from "@selenite"; +import { VTextInput } from "../../external/selenite/components/TextInput.slint"; +import { VButton, VText, VDatePicker } from "../../external/selenite/components/index.slint"; +import { AppWindowActions } from "../windows/AppWindow/Actions.slint"; +import { Modal } from "../../external/selenite/components/Modal.slint"; +import { VTimePicker } from "../../external/selenite/components/TimePicker.slint"; + +export component AddEventModal inherits Modal { + public function open() { + root.show(); + } + + VerticalLayout { + padding: 16px; + spacing: 8px; + titleInput := VTextInput { + label: "title"; + } + VText { text: "on"; vertical-alignment: bottom;} + dateInput := VDatePicker { + enabled: true; + } + HorizontalLayout { + spacing: 4px; + VText { text: "between"; vertical-alignment: bottom; } + startTimeInput := VTimePicker { } + VText { text: "and"; vertical-alignment: bottom; } + endTimeInput := VTimePicker { } + } + VButton { + text: "Create"; + clicked => { + AppWindowActions.create-event({ + title: titleInput.text, + date: dateInput.date, + startsAt: startTimeInput.time, + endsAt: endTimeInput.time + }); + root.close(); + } + } + } +} diff --git a/src/ui.slint b/src/ui.slint index 9f10028..2a72c3f 100644 --- a/src/ui.slint +++ b/src/ui.slint @@ -2,8 +2,7 @@ import { AppWindowModels } from "windows/AppWindow/Models.slint"; import { AppWindowActions } from "windows/AppWindow/Actions.slint"; import { AppWindow } from "windows/AppWindow/AppWindow.slint"; import { SettingsWindow } from "windows/SettingsWindow/SettingsWindow.slint"; -import { EditEventWindow } from "windows/EditEventWindow/EditEventWindow.slint"; import { Utils } from "shared/Utils.slint"; import { Palette } from "@selenite"; -export { Utils, Palette, AppWindow, AppWindowModels, AppWindowActions, SettingsWindow, EditEventWindow } +export { Utils, Palette, AppWindow, AppWindowModels, AppWindowActions, SettingsWindow } diff --git a/src/windows/AppWindow/AppWindow.cpp b/src/windows/AppWindow/AppWindow.cpp index 75f7fdb..8a632d0 100644 --- a/src/windows/AppWindow/AppWindow.cpp +++ b/src/windows/AppWindow/AppWindow.cpp @@ -33,8 +33,7 @@ #include AppWindow::AppWindow(mirai::Mirai *miraiInstance) - : miraiInstance_(miraiInstance), settingsWindow_(miraiInstance), - editEventWindow_(miraiInstance), view_(miraiInstance) + : miraiInstance_(miraiInstance), settingsWindow_(miraiInstance), view_(miraiInstance) { sources_ = std::make_shared>(); days_ = std::make_shared>(); @@ -133,7 +132,7 @@ void AppWindow::setupCallbacks() /*editSourceWindow_.open(source);*/ /*});*/ actions().on_open_add_event_window([&]() { - editEventWindow_.open(); + // editEventWindow_.open(); }); actions().on_task_clicked([&](int sourceId, int taskId) { diff --git a/src/windows/AppWindow/AppWindow.h b/src/windows/AppWindow/AppWindow.h index 177683e..0d25941 100644 --- a/src/windows/AppWindow/AppWindow.h +++ b/src/windows/AppWindow/AppWindow.h @@ -6,7 +6,6 @@ #pragma once -#include "../EditEventWindow/EditEventWindow.h" #include "../SettingsWindow/SettingsWindow.h" #include "mirai-core/Mirai.h" #include "mirai-core/View.h" @@ -37,7 +36,6 @@ class AppWindow slint::ComponentHandle mainWindow_ = ui::AppWindow::create(); SettingsWindow settingsWindow_; - EditEventWindow editEventWindow_; mirai::Mirai *miraiInstance_; mirai::View view_; diff --git a/src/windows/AppWindow/views/CalendarView.slint b/src/windows/AppWindow/views/CalendarView.slint index cd95e40..507590d 100644 --- a/src/windows/AppWindow/views/CalendarView.slint +++ b/src/windows/AppWindow/views/CalendarView.slint @@ -4,10 +4,11 @@ import { Button, VerticalBox, CheckBox, ScrollView, ComboBox } from "std-widgets import { TaskLine } from "../../../components/TaskLine.slint"; import { EventGroup } from "../../../components/EventGroup.slint"; import { Calendar } from "../../../components/Calendar.slint"; -import { VPopupIconMenu, VDatePicker, VTimePicker, VCheckBox, VButton, VTag, VText, VTextInput, Svg, Palette } from "@selenite"; +import { VDatePicker, VTimePicker, VCheckBox, VButton, VTag, VText, VTextInput, Svg, Palette } from "@selenite"; import { CreateTaskOrEvent } from "../../../components/CreateTaskOrEvent.slint"; import { Utils } from "../../../shared/Utils.slint"; import { VActionButton } from "../../../../external/selenite/components/index.slint"; +import { AddEventModal } from "../../../modals/AddEventModal.slint"; export component CalendarView inherits Rectangle { @@ -15,49 +16,7 @@ export component CalendarView inherits Rectangle { private property icon-not-visible: Svg.not-visible; private property completed-tasks-visible: false; - createEventPopup := PopupWindow { - x: parent.width / 2 - 200px; - y: parent.height / 2 - 300px; - close-policy: close-on-click-outside; - background := Rectangle { - height: 100%; - width: 100%; - background: Palette.background1; - border-color: Palette.popup-border; - border-width: 1px; - border-radius: 4px; - } - VerticalLayout { - padding: 16px; - spacing: 8px; - titleInput := VTextInput { - label: "title"; - } - VText { text: "on"; vertical-alignment: bottom;} - dateInput := VDatePicker { - enabled: true; - } - HorizontalLayout { - spacing: 4px; - VText { text: "between"; vertical-alignment: bottom; } - startTimeInput := VTimePicker { } - VText { text: "and"; vertical-alignment: bottom; } - endTimeInput := VTimePicker { } - } - VButton { - text: "Create"; - clicked => { - AppWindowActions.create-event({ - title: titleInput.text, - date: dateInput.date, - startsAt: startTimeInput.time, - endsAt: endTimeInput.time - }); - createEventPopup.close(); - } - } - } - } + createEventPopup := AddEventModal {} VerticalLayout { padding: 16px; diff --git a/src/windows/EditEventWindow/EditEventWindow.cpp b/src/windows/EditEventWindow/EditEventWindow.cpp deleted file mode 100644 index 276ad05..0000000 --- a/src/windows/EditEventWindow/EditEventWindow.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Mirai. Copyright (C) 2024 Vyn - * This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only) - * The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt - */ - -#include "EditEventWindow.h" -#include "../../SeleniteSetup.h" -#include "evalyte-cpp-common/evalyte.h" -#include "mirai-core/DataProvider.h" -#include "mirai-core/MarkdownDataProvider.h" -#include "mirai-core/Mirai.h" -#include "slint.h" -#include "slint_string.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -EditEventWindow::EditEventWindow(mirai::Mirai *miraiInstance) : miraiInstance_(miraiInstance) -{ - - const auto palettePath = std::string(getenv("HOME")) + "/.config/evalyte/theme.json"; - const auto palette = selenite::parseJson(palettePath); - - if (palette.has_value()) { - setSelenitePalette(window_->global(), palette.value()); - } - - setupCallbacks(); -} - -void EditEventWindow::setupCallbacks() -{ -} - -void EditEventWindow::open() -{ - window_->show(); -} - -void EditEventWindow::close() -{ - window_->hide(); -} diff --git a/src/windows/EditEventWindow/EditEventWindow.h b/src/windows/EditEventWindow/EditEventWindow.h deleted file mode 100644 index 4914c01..0000000 --- a/src/windows/EditEventWindow/EditEventWindow.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Mirai. Copyright (C) 2024 Vyn - * This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only) - * The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt - */ - -#pragma once - -#include "mirai-core/Mirai.h" -#include "slint.h" -#include "ui.h" - -class EditEventWindow -{ - - public: - EditEventWindow(mirai::Mirai *mirai); - - void open(); - void close(); - - auto getHandle() - { - return this->window_; - } - - private: - void setupCallbacks(); - - std::shared_ptr> sources_; - slint::ComponentHandle window_ = ui::EditEventWindow::create(); - mirai::Mirai *miraiInstance_; -}; diff --git a/src/windows/EditEventWindow/EditEventWindow.slint b/src/windows/EditEventWindow/EditEventWindow.slint deleted file mode 100644 index 8f1297d..0000000 --- a/src/windows/EditEventWindow/EditEventWindow.slint +++ /dev/null @@ -1,68 +0,0 @@ -import { AppWindowModels } from "../AppWindow/Models.slint"; -import { Button, VerticalBox, CheckBox } from "std-widgets.slint"; -import { VText, VTextInput, Palette } from "@selenite"; -import { VButton } from "../../../external/selenite/components/index.slint"; -import { Date, Time, Button, VerticalBox, CheckBox, ScrollView, ComboBox } from "std-widgets.slint"; -import { VDatePicker } from "../../../external/selenite/components/DatePicker.slint"; -import { VTimePicker } from "../../../external/selenite/components/TimePicker.slint"; - -export struct CreateEventParams { - title: string, - date: Date, - startsAt: Time, - endsAt: Time -} - -export component EditEventWindow inherits Window { - - title: "Mirai - Event"; - min-height: 100px; - max-height: 500px; // needed, otherwise the window wants to fit the content (on Swaywm) - max-width: 500px; // needed, otherwise the window wants to fit the content (on Swaywm) - background: Palette.background; - in-out property sourceId; - - callback create-event(CreateEventParams); - callback delete-event(int); - - VerticalLayout { - padding: 16px; - spacing: 8px; - titleInput := VTextInput { - label: "title"; - } - VText { text: "on"; vertical-alignment: bottom;} - dateInput := VDatePicker { - enabled: true; - } - HorizontalLayout { - spacing: 4px; - VText { text: "between"; vertical-alignment: bottom; } - startTimeInput := VTimePicker { } - VText { text: "and"; vertical-alignment: bottom; } - endTimeInput := VTimePicker { } - } - VButton { - text: "Create"; - clicked => { - debug("clicked"); - root.create-event({ - title: titleInput.text, - date: dateInput.date, - startsAt: startTimeInput.time, - endsAt: endTimeInput.time - }) - } - } - VButton { - text: "Delete"; - background-color: Palette.red; - double-clicked => { - //root.delete-event(root.id) - } - } - } - -} - -export { AppWindowModels, Palette } // Export to make it visible to the C++ backend