autoupdate on card_entry add

This commit is contained in:
leca 2024-04-06 15:58:20 +03:00
parent 193db81657
commit 24acb4ecd1
2 changed files with 21 additions and 8 deletions

View File

@ -14,6 +14,7 @@ use gtk::{gio, glib, Box, Button, CompositeTemplate, ScrolledWindow, SearchEntry
use gtk::{prelude::*, FileDialog};
use rusqlite::Connection;
use sha256::try_digest;
use gtk::prelude::WidgetExt;
#[derive(CompositeTemplate, Default)]
#[template(resource = "/org/foxarmy/learn-hieroglyph/cards/edit/ui.xml")]
@ -56,7 +57,11 @@ impl ObjectImpl for MemoryCardsEditScene {
new_win.get_file_choose_button().connect_clicked(clone!(@strong new_win => move |_| {
gtk::glib::MainContext::default().spawn_local(file_choose_dialog(Rc::clone(&new_win)));
}));
new_win.get_done_button().connect_closure("clicked", true, closure_local!(@strong binding => move |_w: &Button| {
binding.imp().update_card_list();
}));
new_win.present();
}));
self.update_card_list();
}
@ -86,14 +91,13 @@ impl MemoryCardsEditScene {
.unwrap();
for card in cards_iter {
// let card_binding = card.unwrap();
// let path = &card_binding.imagepath();
// println!("path: {}", path);
// card_binding.set_imagepath(&*path);
// card_binding.get_picture_widget().set_file(Some(&gio::File::for_path(&path)));
let card_binding = card.unwrap();
let self_binding = self.obj();
c.append(&card_binding);
card_binding.connect_closure("created", false, closure_local!(move | | {
println!("New card created");
}));
card_binding.get_delete_button_widget().connect_closure("clicked", false, closure_local!(@strong card_binding, @strong self_binding => move |_b: &Button| {
let connection = Connection::open(get_db_path()).unwrap();
let imagepath = card_binding.imagepath();
@ -144,9 +148,8 @@ async fn file_choose_dialog<W: IsA<gtk::Window>>(window: Rc<W>) {
let conn = Connection::open(get_db_path()).unwrap();
let query = "INSERT INTO cards (imagename, hieroglyph, reading) VALUES(?1, ?2, ?3)";
conn.execute(query, (&new_filename, &hieroglyph, &reading)).unwrap();
conn.execute(query, (&new_filename, &hieroglyph, &reading)).unwrap();
w.close();
}),
);
}

View File

@ -1,7 +1,9 @@
use std::cell::RefCell;
use std::sync::OnceLock;
use glib::subclass::InitializingObject;
use glib::Properties;
use gtk::glib::subclass::Signal;
use gtk::subclass::prelude::*;
use gtk::{glib, prelude::*, Button, CompositeTemplate, Label, Picture};
@ -42,6 +44,15 @@ impl ObjectSubclass for CardEntry {
}
#[glib::derived_properties]
impl ObjectImpl for CardEntry {
fn signals() -> &'static [Signal] {
static SIGNALS: OnceLock<Vec<Signal>> = OnceLock::new();
SIGNALS.get_or_init(|| {
vec![Signal::builder("created")
.build()]
})
}
fn constructed(&self) {
self.parent_constructed();
@ -57,7 +68,6 @@ impl ObjectImpl for CardEntry {
.bind_property("reading", reading_label_binding, "label")
.sync_create()
.build();
}
fn dispose(&self) {