Add Window to edit/delete list
This commit is contained in:
parent
fa5fb4edad
commit
c41e0ee641
7 changed files with 95 additions and 4 deletions
|
@ -34,6 +34,10 @@ add_subdirectory(external/evalyte-cpp-common)
|
|||
target_include_directories(lali PRIVATE "external/evalyte-cpp-common/include")
|
||||
target_link_libraries(lali PRIVATE evalyte-cpp-common)
|
||||
|
||||
add_subdirectory(external/selenite/cpp)
|
||||
target_include_directories(lali PRIVATE "external/selenite/cpp/include")
|
||||
target_link_libraries(lali PRIVATE selenite)
|
||||
|
||||
add_subdirectory(external/rei-json)
|
||||
target_include_directories(lali PRIVATE "external/rei-json/include")
|
||||
target_link_libraries(lali PRIVATE rei-json)
|
||||
|
|
2
external/selenite
vendored
2
external/selenite
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 3fb5f620fdc3e422d468642263858ffce72cdbb9
|
||||
Subproject commit 482980b29aca92dd3282bd3c81e78c520f30a233
|
|
@ -6,6 +6,8 @@
|
|||
#include "evalyte-cpp-common/evalyte.h"
|
||||
#include "rei-json/Field.h"
|
||||
#include "rei-json/Object.h"
|
||||
#include "selenite/palette.h"
|
||||
#include "selenite/selenite.h"
|
||||
#include "ui.h"
|
||||
#include "rei-json/Array.h"
|
||||
#include "rei-json/json.h"
|
||||
|
@ -31,6 +33,15 @@ public:
|
|||
listsSlint = std::make_shared<slint::VectorModel<ui::List>>();
|
||||
animesSlint = std::make_shared<slint::VectorModel<ui::Anime>>();
|
||||
|
||||
const auto palettePath = std::string(getenv("HOME")) + "/.config/evalyte/theme.json";
|
||||
const auto palette = selenite::parseJson(palettePath);
|
||||
if (palette.has_value()) {
|
||||
std::println(std::cerr, "Warning, no {} found", palettePath);
|
||||
setSelenitePalette<slint::Color, selenite::Color>(ui->global<ui::Palette>(), palette.value());
|
||||
setSelenitePalette<slint::Color, selenite::Color>(addAnimeWindow->global<ui::Palette>(), palette.value());
|
||||
setSelenitePalette<slint::Color, selenite::Color>(editListWindow->global<ui::Palette>(), palette.value());
|
||||
}
|
||||
|
||||
for (int i = 0; i < THREAD_COUNT; ++i) {
|
||||
startThread(i);
|
||||
}
|
||||
|
@ -105,6 +116,7 @@ public:
|
|||
|
||||
void initModels() {
|
||||
|
||||
listsSlint->clear();
|
||||
listsSlint = std::make_shared<slint::VectorModel<ui::List>>();
|
||||
ui->global<ui::State>().set_lists(listsSlint);
|
||||
|
||||
|
@ -146,6 +158,28 @@ public:
|
|||
removeAnimeFromList(currentListIndex, animeIndex);
|
||||
});
|
||||
|
||||
ui->global<ui::State>().on_open_edit_list_window([&](int index) {
|
||||
auto& listJson = json.getArray("lists").getObject(index);
|
||||
editListWindow->set_index(index);
|
||||
editListWindow->set_name(slint::SharedString(listJson["name"].asString()));
|
||||
editListWindow->show();
|
||||
});
|
||||
|
||||
editListWindow->on_edit_list([&](int index, slint::SharedString name) {
|
||||
auto& listJson = json.getArray("lists").getObject(index);
|
||||
listJson["name"].asString() = std::string(name);
|
||||
editListWindow->hide();
|
||||
initModels();
|
||||
save();
|
||||
});
|
||||
|
||||
editListWindow->on_delete_list([&](int index) {
|
||||
json.getArray("lists").remove(index);
|
||||
editListWindow->hide();
|
||||
initModels();
|
||||
save();
|
||||
});
|
||||
|
||||
addAnimeWindow->on_import_anilist_anime([&] (slint::SharedString animeIdStr) {
|
||||
int animeId = stoi(std::string(animeIdStr));
|
||||
int currentListIndex = ui->global<ui::State>().get_current_list().index;
|
||||
|
@ -351,6 +385,7 @@ private:
|
|||
rei::json::JsonObject json;
|
||||
slint::ComponentHandle<ui::AppWindow> ui;
|
||||
slint::ComponentHandle<ui::AddAnimeWindow> addAnimeWindow = ui::AddAnimeWindow::create();
|
||||
slint::ComponentHandle<ui::EditListWindow> editListWindow = ui::EditListWindow::create();
|
||||
std::shared_ptr<slint::VectorModel<ui::Anime>> animesSlint;
|
||||
std::shared_ptr<slint::VectorModel<ui::List>> listsSlint;
|
||||
std::mutex animeListLock;
|
||||
|
|
|
@ -120,17 +120,24 @@ export component AppWindow inherits Window {
|
|||
|
||||
HorizontalLayout {
|
||||
alignment: start;
|
||||
spacing: 8px;
|
||||
if State.current-list.source == ListSource.Local : VButton {
|
||||
icon-svg: Svg.plus;
|
||||
text: "Add";
|
||||
clicked => { State.open-add-anime-window() }
|
||||
}
|
||||
if State.current-list.source == ListSource.Anilist : VButton {
|
||||
icon-svg: Svg.refresh;
|
||||
text: "Sync";
|
||||
clicked => { State.sync-list() }
|
||||
}
|
||||
VButton {
|
||||
text: "Settings";
|
||||
icon-svg: Svg.cog;
|
||||
clicked => { State.open-edit-list-window(State.current-list.index) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
animes-grid-background := Rectangle {
|
||||
//background: #111111;
|
||||
|
@ -172,7 +179,7 @@ export component AppWindow inherits Window {
|
|||
popup := VPopupIconMenu {
|
||||
VActionButton {
|
||||
icon-svg: Svg.trash;
|
||||
icon-colorize: Colors.red;
|
||||
icon-colorize: Palette.red;
|
||||
icon-size: 1.5rem;
|
||||
border-radius: 0;
|
||||
clicked => {
|
||||
|
|
41
src/EditListWindow.slint
Normal file
41
src/EditListWindow.slint
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { State } from "./state.slint";
|
||||
import { VText, VTextInput , VButton, ToggleButton, VActionButton, Svg, Palette } from "@selenite";
|
||||
import { ComboBox } from "std-widgets.slint";
|
||||
|
||||
export component EditListWindow inherits Window {
|
||||
title: "Lali - Edit List";
|
||||
|
||||
in property <int> index;
|
||||
in-out property <string> name;
|
||||
|
||||
background: Palette.background;
|
||||
default-font-size: 16px;
|
||||
padding: 0px;
|
||||
|
||||
width: 200px;
|
||||
|
||||
callback edit-list(int, string);
|
||||
callback delete-list(int);
|
||||
|
||||
VerticalLayout {
|
||||
alignment: start;
|
||||
padding: 16px;
|
||||
spacing: 16px;
|
||||
|
||||
VTextInput {
|
||||
label: "Name";
|
||||
text <=> name;
|
||||
}
|
||||
|
||||
VButton {
|
||||
text: "Save";
|
||||
clicked => { edit-list(index, name) }
|
||||
}
|
||||
|
||||
VButton {
|
||||
text: "Delete";
|
||||
background: Palette.red;
|
||||
double-clicked => { delete-list(index) }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,5 +46,7 @@ export global State {
|
|||
callback open-add-anime-window();
|
||||
callback remove-anime(int);
|
||||
|
||||
callback open-edit-list-window(int);
|
||||
|
||||
callback config-changed();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { AppWindow } from "./AppWindow.slint";
|
||||
import { AddAnimeWindow } from "./AddAnimeWindow.slint";
|
||||
import { EditListWindow } from "./EditListWindow.slint";
|
||||
import { Palette } from "@selenite";
|
||||
import { State } from "./state.slint";
|
||||
|
||||
export { State, AppWindow, AddAnimeWindow }
|
||||
export { State, Palette, AppWindow, AddAnimeWindow, EditListWindow }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue