From fcdeec19eda321ce58ca85714ed4d3a4b5bf2185 Mon Sep 17 00:00:00 2001 From: Vyn Date: Tue, 24 Jun 2025 09:31:34 +0200 Subject: [PATCH] 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 {