implemented delete card entry
This commit is contained in:
@@ -60,7 +60,6 @@ impl ObjectImpl for MemoryCardsEditScene {
|
||||
}));
|
||||
self.update_card_list();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl MemoryCardsEditScene {
|
||||
@@ -70,33 +69,44 @@ impl MemoryCardsEditScene {
|
||||
while c.first_child() != None {
|
||||
c.remove(&c.first_child().unwrap());
|
||||
}
|
||||
|
||||
|
||||
let conn = Connection::open(get_db_path()).unwrap();
|
||||
let mut stmt = conn
|
||||
.prepare("SELECT imagename, hieroglyph, reading FROM cards")
|
||||
.unwrap();
|
||||
let cards_iter = stmt
|
||||
.query_map([], |row| {
|
||||
let a: String = row.get(0).unwrap();
|
||||
let b: String = row.get(1).unwrap();
|
||||
let c: String = row.get(2).unwrap();
|
||||
let entry = CardEntry::new(&a, &b, &c);
|
||||
let image_path: String = row.get(0).unwrap();
|
||||
let image_path = get_images_store_path() + &image_path;
|
||||
let hieroglyph: String = row.get(1).unwrap();
|
||||
let reading: String = row.get(2).unwrap();
|
||||
let entry = CardEntry::new(&image_path, &hieroglyph, &reading);
|
||||
Ok(entry)
|
||||
})
|
||||
.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 path = get_images_store_path() + &card_binding.imagepath();
|
||||
card_binding.set_imagepath(&*path);
|
||||
card_binding.get_picture_widget().set_file(Some(&gio::File::for_path(&path)));
|
||||
let self_binding = self.obj();
|
||||
c.append(&card_binding);
|
||||
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();
|
||||
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().update_card_list();
|
||||
}));
|
||||
card_binding.update_file_for_picture();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async fn file_choose_dialog<W: IsA<gtk::Window>>(window: Rc<W>) {
|
||||
let dialog: FileDialog = gtk::FileDialog::builder().build();
|
||||
let answer = dialog.open_future(Some(&*window)).await;
|
||||
|
||||
Reference in New Issue
Block a user