Delete button
This commit is contained in:
parent
f30bc31d46
commit
6a6ecd79d4
|
@ -11,7 +11,7 @@ use crate::widgets::card_entry::CardEntry;
|
|||
use glib::subclass::InitializingObject;
|
||||
use gtk::gio::ListStore;
|
||||
use gtk::glib::object::ObjectExt;
|
||||
use gtk::glib::{clone, closure_local};
|
||||
use gtk::glib::{clone, closure_local, Object};
|
||||
use gtk::prelude::WidgetExt;
|
||||
use gtk::subclass::prelude::*;
|
||||
use gtk::{
|
||||
|
@ -91,14 +91,12 @@ impl ObjectImpl for MemoryCardsEditScene {
|
|||
}));
|
||||
// self.query_cards(None);
|
||||
self.update_state();
|
||||
println!("Constructed");
|
||||
}
|
||||
}
|
||||
|
||||
impl MemoryCardsEditScene {
|
||||
|
||||
pub fn update_state(&self) {
|
||||
println!("Updating state");
|
||||
let model = ListStore::new::<CardEntry>();
|
||||
model.extend_from_slice(&*self.displaying_cards.borrow());
|
||||
|
||||
|
@ -110,8 +108,9 @@ impl MemoryCardsEditScene {
|
|||
.unwrap()
|
||||
.set_child(Some(&card_entry));
|
||||
});
|
||||
let self_binding = self.obj();
|
||||
|
||||
factory.connect_bind(move |_, list_item| {
|
||||
factory.connect_closure("bind", false, closure_local!(@strong self_binding => move |_f: &SignalListItemFactory, list_item: &Object| {
|
||||
let card_object = &list_item
|
||||
.downcast_ref::<ListItem>()
|
||||
.unwrap()
|
||||
|
@ -126,12 +125,24 @@ impl MemoryCardsEditScene {
|
|||
.and_downcast::<CardEntry>()
|
||||
.unwrap();
|
||||
|
||||
card_object_to_display.get_delete_button_widget().connect_closure("clicked", false, closure_local!(@strong card_object as card, @strong self_binding => move |_b: &Button| {
|
||||
let connection = Connection::open(get_db_path()).unwrap();
|
||||
let imagepath = &card.imagepath();
|
||||
let imagename = &Path::new(&imagepath).file_name().unwrap().to_str().unwrap();
|
||||
fs::remove_file(get_images_store_path() + "/" + &imagename).expect("Could not remove file!");
|
||||
connection.execute("DELETE FROM cards WHERE imagename = ?1", [&imagename]).unwrap();
|
||||
self_binding.imp().query_cards(None);
|
||||
self_binding.imp().update_state();
|
||||
}));
|
||||
|
||||
card_object_to_display.get_image_widget().set_file(Some(card_object.get_image_file_path().as_str()));
|
||||
card_object_to_display.set_hieroglyph(card_object.hieroglyph());
|
||||
card_object_to_display.set_reading(card_object.reading());
|
||||
card_object_to_display.set_translation(card_object.translation());
|
||||
card_object_to_display.set_islearning(card_object.islearning());
|
||||
});
|
||||
}));
|
||||
|
||||
// factory.connect_bind();
|
||||
|
||||
let no_selection_model = NoSelection::new(Some(model));
|
||||
let list_view = ListView::new(Some(no_selection_model), Some(factory));
|
||||
|
@ -163,9 +174,6 @@ impl MemoryCardsEditScene {
|
|||
Some(row.get(3).unwrap()),
|
||||
Some(row.get(4).unwrap()),
|
||||
);
|
||||
if c.is_learning().unwrap() {
|
||||
println!("{c:?}");
|
||||
}
|
||||
let entry = CardEntry::new(Some(&c));
|
||||
entry.update_state();
|
||||
Ok(entry)
|
||||
|
|
|
@ -20,14 +20,13 @@ glib::wrapper! {
|
|||
impl CardEntry {
|
||||
pub fn new(card: Option<&Card>) -> Self {
|
||||
match card {
|
||||
Some(card) =>
|
||||
Object::builder()
|
||||
.property("imagepath", card.image_path().unwrap())
|
||||
.property("hieroglyph", card.hieroglyph().unwrap())
|
||||
.property("reading", card.reading().unwrap())
|
||||
.property("translation", card.translation().unwrap())
|
||||
.property("islearning", card.is_learning().unwrap())
|
||||
.build(),
|
||||
Some(card) => Object::builder()
|
||||
.property("imagepath", card.image_path().unwrap())
|
||||
.property("hieroglyph", card.hieroglyph().unwrap())
|
||||
.property("reading", card.reading().unwrap())
|
||||
.property("translation", card.translation().unwrap())
|
||||
.property("islearning", card.is_learning().unwrap())
|
||||
.build(),
|
||||
None => Object::builder()
|
||||
.property("imagepath", "")
|
||||
.property("hieroglyph", "")
|
||||
|
@ -60,30 +59,6 @@ impl CardEntry {
|
|||
image_binding.set_file(Some(&path));
|
||||
}
|
||||
|
||||
// pub fn get_hieroglyph(&self) -> String {
|
||||
// self.imp().hieroglyph.borrow().clone()
|
||||
// }
|
||||
|
||||
// pub fn set_hieroglyph(&self, h: &String) {
|
||||
// self.imp().hieroglyph.borrow_mut() = h;
|
||||
// }
|
||||
|
||||
// pub fn get_reading(&self) -> String {
|
||||
// self.imp().reading.borrow().clone()
|
||||
// }
|
||||
|
||||
// pub fn set_reading(&self, r: &String) {
|
||||
// self.imp().reading.borrow_mut() = r;
|
||||
// }
|
||||
|
||||
// pub fn get_translation(&self) -> String {
|
||||
// self.imp().translation.borrow().clone()
|
||||
// }
|
||||
|
||||
// pub fn set_translation(&self, t: &String) {
|
||||
// self.imp().translation.borrow_mut() = t;
|
||||
// }
|
||||
|
||||
pub fn update_state(&self) {
|
||||
let conn = Connection::open(get_db_path()).unwrap();
|
||||
let is_learning_switch_binding: &Switch = self.imp().is_learning_switch.as_ref();
|
||||
|
|
Loading…
Reference in New Issue