mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-01 17:03:19 +00:00
Replace 'edit source window' with popup
This commit is contained in:
parent
129b30b9e7
commit
854152b395
13 changed files with 101 additions and 163 deletions
|
@ -33,7 +33,6 @@ add_executable(mirai
|
||||||
src/windows/AppWindow/AppWindow.cpp
|
src/windows/AppWindow/AppWindow.cpp
|
||||||
src/windows/AddSourceWindow/AddSourceWindow.cpp
|
src/windows/AddSourceWindow/AddSourceWindow.cpp
|
||||||
src/windows/SettingsWindow/SettingsWindow.cpp
|
src/windows/SettingsWindow/SettingsWindow.cpp
|
||||||
src/windows/EditSourceWindow/EditSourceWindow.cpp
|
|
||||||
src/windows/EditEventWindow/EditEventWindow.cpp
|
src/windows/EditEventWindow/EditEventWindow.cpp
|
||||||
src/SeleniteSetup.cpp
|
src/SeleniteSetup.cpp
|
||||||
src/shared/Utils.cpp
|
src/shared/Utils.cpp
|
||||||
|
|
63
src/components/editSourceModal.slint
Normal file
63
src/components/editSourceModal.slint
Normal file
|
@ -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 <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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,9 +3,8 @@ import { AppWindowActions } from "windows/AppWindow/Actions.slint";
|
||||||
import { AppWindow } from "windows/AppWindow/AppWindow.slint";
|
import { AppWindow } from "windows/AppWindow/AppWindow.slint";
|
||||||
import { SettingsWindow } from "windows/SettingsWindow/SettingsWindow.slint";
|
import { SettingsWindow } from "windows/SettingsWindow/SettingsWindow.slint";
|
||||||
import { AddSourceWindow } from "windows/AddSourceWindow//AddSourceWindow.slint";
|
import { AddSourceWindow } from "windows/AddSourceWindow//AddSourceWindow.slint";
|
||||||
import { EditSourceWindow } from "windows/EditSourceWindow/EditSourceWindow.slint";
|
|
||||||
import { EditEventWindow } from "windows/EditEventWindow/EditEventWindow.slint";
|
import { EditEventWindow } from "windows/EditEventWindow/EditEventWindow.slint";
|
||||||
import { Utils } from "shared/Utils.slint";
|
import { Utils } from "shared/Utils.slint";
|
||||||
import { Palette } from "@selenite";
|
import { Palette } from "@selenite";
|
||||||
|
|
||||||
export { Utils, Palette, AppWindow, AppWindowModels, AppWindowActions, SettingsWindow, AddSourceWindow, EditSourceWindow, EditEventWindow }
|
export { Utils, Palette, AppWindow, AppWindowModels, AppWindowActions, SettingsWindow, AddSourceWindow, EditEventWindow }
|
||||||
|
|
|
@ -50,7 +50,7 @@ export global AppWindowActions {
|
||||||
callback source-clicked(int);
|
callback source-clicked(int);
|
||||||
callback open-settings-window();
|
callback open-settings-window();
|
||||||
callback open-add-source-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-new-task-form(OpenNewTaskFormParams);
|
||||||
callback open-edit-task-form(int, int);
|
callback open-edit-task-form(int, int);
|
||||||
|
|
|
@ -34,8 +34,7 @@
|
||||||
|
|
||||||
AppWindow::AppWindow(mirai::Mirai *miraiInstance)
|
AppWindow::AppWindow(mirai::Mirai *miraiInstance)
|
||||||
: miraiInstance_(miraiInstance), addSourceWindow_(miraiInstance),
|
: miraiInstance_(miraiInstance), addSourceWindow_(miraiInstance),
|
||||||
editSourceWindow_(miraiInstance), settingsWindow_(miraiInstance),
|
settingsWindow_(miraiInstance), editEventWindow_(miraiInstance), view_(miraiInstance)
|
||||||
editEventWindow_(miraiInstance), view_(miraiInstance)
|
|
||||||
{
|
{
|
||||||
sources_ = std::make_shared<slint::VectorModel<ui::Source>>();
|
sources_ = std::make_shared<slint::VectorModel<ui::Source>>();
|
||||||
days_ = std::make_shared<slint::VectorModel<ui::Day>>();
|
days_ = std::make_shared<slint::VectorModel<ui::Day>>();
|
||||||
|
@ -105,6 +104,14 @@ void AppWindow::setupCallbacks()
|
||||||
return slint::SharedString(source->name());
|
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<mirai::MarkdownDataProvider *>(source->dataProvider());
|
||||||
|
return slint::SharedString(sourceProvider->path());
|
||||||
|
});
|
||||||
|
|
||||||
miraiInstance_->onSourceAdded([&](mirai::Source *source) {
|
miraiInstance_->onSourceAdded([&](mirai::Source *source) {
|
||||||
refreshModels();
|
refreshModels();
|
||||||
});
|
});
|
||||||
|
@ -120,11 +127,11 @@ void AppWindow::setupCallbacks()
|
||||||
actions().on_open_add_source_window([&]() {
|
actions().on_open_add_source_window([&]() {
|
||||||
addSourceWindow_.open();
|
addSourceWindow_.open();
|
||||||
});
|
});
|
||||||
actions().on_open_edit_source_window([&](int sourceId) {
|
/*actions().on_open_edit_source_window([&](int sourceId) {*/
|
||||||
auto source = miraiInstance_->getSourceById(sourceId);
|
/*auto source = miraiInstance_->getSourceById(sourceId);*/
|
||||||
assert(source);
|
/*assert(source);*/
|
||||||
editSourceWindow_.open(source);
|
/*editSourceWindow_.open(source);*/
|
||||||
});
|
/*});*/
|
||||||
actions().on_open_add_event_window([&]() {
|
actions().on_open_add_event_window([&]() {
|
||||||
editEventWindow_.open();
|
editEventWindow_.open();
|
||||||
});
|
});
|
||||||
|
@ -158,6 +165,10 @@ void AppWindow::setupCallbacks()
|
||||||
reloadTasks();
|
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) {
|
actions().on_delete_task_clicked([&](int sourceId, int taskId) {
|
||||||
auto source = miraiInstance_->getSourceById(sourceId);
|
auto source = miraiInstance_->getSourceById(sourceId);
|
||||||
assert(source);
|
assert(source);
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#include "../AddSourceWindow/AddSourceWindow.h"
|
#include "../AddSourceWindow/AddSourceWindow.h"
|
||||||
#include "../EditEventWindow/EditEventWindow.h"
|
#include "../EditEventWindow/EditEventWindow.h"
|
||||||
#include "../EditSourceWindow/EditSourceWindow.h"
|
|
||||||
#include "../SettingsWindow/SettingsWindow.h"
|
#include "../SettingsWindow/SettingsWindow.h"
|
||||||
#include "mirai-core/Mirai.h"
|
#include "mirai-core/Mirai.h"
|
||||||
#include "mirai-core/View.h"
|
#include "mirai-core/View.h"
|
||||||
|
@ -40,7 +39,6 @@ class AppWindow
|
||||||
slint::ComponentHandle<ui::AppWindow> mainWindow_ = ui::AppWindow::create();
|
slint::ComponentHandle<ui::AppWindow> mainWindow_ = ui::AppWindow::create();
|
||||||
SettingsWindow settingsWindow_;
|
SettingsWindow settingsWindow_;
|
||||||
AddSourceWindow addSourceWindow_;
|
AddSourceWindow addSourceWindow_;
|
||||||
EditSourceWindow editSourceWindow_;
|
|
||||||
EditEventWindow editEventWindow_;
|
EditEventWindow editEventWindow_;
|
||||||
|
|
||||||
mirai::Mirai *miraiInstance_;
|
mirai::Mirai *miraiInstance_;
|
||||||
|
|
|
@ -4,11 +4,13 @@ import { SideBar } from "views/SideBar.slint";
|
||||||
import { MainView } from "views/TasksView.slint";
|
import { MainView } from "views/TasksView.slint";
|
||||||
import { SettingsWindow } from "../SettingsWindow/SettingsWindow.slint";
|
import { SettingsWindow } from "../SettingsWindow/SettingsWindow.slint";
|
||||||
import { AddSourceWindow } from "../AddSourceWindow//AddSourceWindow.slint";
|
import { AddSourceWindow } from "../AddSourceWindow//AddSourceWindow.slint";
|
||||||
import { EditSourceWindow } from "../EditSourceWindow/EditSourceWindow.slint";
|
|
||||||
import { Palette } from "@selenite";
|
import { Palette } from "@selenite";
|
||||||
import { CalendarView } from "views/CalendarView.slint";
|
import { CalendarView } from "views/CalendarView.slint";
|
||||||
import { VButton } from "../../../external/selenite/components/Button.slint";
|
import { VButton } from "../../../external/selenite/components/Button.slint";
|
||||||
import { ToggleButton } from "../../../external/selenite/components/index.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 {
|
export component AppWindow inherits Window {
|
||||||
|
|
||||||
|
@ -19,6 +21,8 @@ export component AppWindow inherits Window {
|
||||||
|
|
||||||
private property<bool> show-tasks: false;
|
private property<bool> show-tasks: false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HorizontalLayout {
|
HorizontalLayout {
|
||||||
// padding: 16px;
|
// padding: 16px;
|
||||||
//spacing: 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
|
||||||
|
|
|
@ -48,4 +48,5 @@ export global AppWindowModels {
|
||||||
|
|
||||||
callback get-source-id-from-name(string) -> int;
|
callback get-source-id-from-name(string) -> int;
|
||||||
pure callback get-source-name-from-id(int) -> string;
|
pure callback get-source-name-from-id(int) -> string;
|
||||||
|
pure callback get-source-path-from-id(int) -> string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,16 +47,12 @@ export component CalendarView inherits Rectangle {
|
||||||
VButton {
|
VButton {
|
||||||
text: "Create";
|
text: "Create";
|
||||||
clicked => {
|
clicked => {
|
||||||
debug("clicked OK");
|
|
||||||
debug(createEventPopup.width);
|
|
||||||
debug(createEventPopup.height);
|
|
||||||
AppWindowActions.create-event({
|
AppWindowActions.create-event({
|
||||||
title: titleInput.text,
|
title: titleInput.text,
|
||||||
date: dateInput.date,
|
date: dateInput.date,
|
||||||
startsAt: startTimeInput.time,
|
startsAt: startTimeInput.time,
|
||||||
endsAt: endTimeInput.time
|
endsAt: endTimeInput.time
|
||||||
});
|
});
|
||||||
debug("Event sent");
|
|
||||||
createEventPopup.close();
|
createEventPopup.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
import { AppWindowModels, TaskData } from "../Models.slint";
|
import { AppWindowModels, TaskData } from "../Models.slint";
|
||||||
import { AppWindowActions } from "../Actions.slint";
|
import { AppWindowActions } from "../Actions.slint";
|
||||||
import { VButton, ToggleButton, VActionButton, VText, Svg, Palette } from "@selenite";
|
import { VButton, ToggleButton, VActionButton, VText, Svg, Palette } from "@selenite";
|
||||||
|
import { EditSourceModal } from "../../../components/editSourceModal.slint";
|
||||||
|
|
||||||
export component SideBar inherits Rectangle {
|
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 {
|
VerticalLayout {
|
||||||
height: parent.height;
|
height: parent.height;
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
|
@ -51,7 +61,7 @@ export component SideBar inherits Rectangle {
|
||||||
visible: parent.active;
|
visible: parent.active;
|
||||||
icon-svg: Svg.cog;
|
icon-svg: Svg.cog;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
clicked => { AppWindowActions.open-edit-source-window(item.id) }
|
clicked => { editSourcePopup.edit(item.id) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 <bits/chrono.h>
|
|
||||||
#include <cassert>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <ctime>
|
|
||||||
#include <optional>
|
|
||||||
#include <print>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
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<ui::Palette>(), 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<mirai::MarkdownDataProvider *>(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();
|
|
||||||
}
|
|
|
@ -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<slint::VectorModel<ui::Source>> sources_;
|
|
||||||
slint::ComponentHandle<ui::EditSourceWindow> window_ = ui::EditSourceWindow::create();
|
|
||||||
mirai::Mirai *miraiInstance_;
|
|
||||||
};
|
|
|
@ -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 <int> 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
|
|
Loading…
Add table
Add a link
Reference in a new issue