Replace 'add source window' with popup

This commit is contained in:
Vyn 2025-06-24 09:31:34 +02:00
parent 854152b395
commit fcdeec19ed
Signed by: vyn
GPG key ID: E1B2BE34E7A971E7
8 changed files with 98 additions and 76 deletions

2
external/selenite vendored

@ -1 +1 @@
Subproject commit acbd56205d758bf74d7f121ce8085898acbacc9f
Subproject commit fa86c85483725f269ee06001dba8c4c2a438194d

View file

@ -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 <int> source-id-to-edit: -1;
private property <string> name: "";
private property <string> 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)
}
}
}
}
}

View file

@ -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 <int> source-id-to-edit: -1;
private property <string> name: "";
private property <string> 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();
}
}
}
}

View file

@ -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 <int> source-id-to-edit: -1;
private property <string> name: "";
private property <string> 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)
}
}
}
}

View file

@ -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);

View file

@ -165,6 +165,12 @@ void AppWindow::setupCallbacks()
reloadTasks();
});
actions().on_add_source([&](slint::SharedString name, slint::SharedString path) {
std::unique_ptr<mirai::DataProvider> file =
std::make_unique<mirai::MarkdownDataProvider>(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));
});

View file

@ -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,7 +9,7 @@ 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 {
@ -21,8 +20,6 @@ export component AppWindow inherits Window {
private property<bool> show-tasks: false;
HorizontalLayout {
// padding: 16px;
//spacing: 16px;

View file

@ -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 {