optimization
This commit is contained in:
parent
fbe63367d2
commit
72c366a54a
|
@ -1,6 +1,7 @@
|
|||
use std::cell::RefCell;
|
||||
use std::fs;
|
||||
use std::io::ErrorKind;
|
||||
use std::ops::Deref;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
|
||||
|
@ -110,6 +111,7 @@ impl MemoryCardsEditScene {
|
|||
});
|
||||
let self_binding = self.obj();
|
||||
|
||||
//setting up every card's buttons behavior: editing, switch flipping and deleting.
|
||||
factory.connect_closure("bind", false, closure_local!(@strong self_binding => move |_f: &SignalListItemFactory, list_item: &Object| {
|
||||
let card_object = &list_item
|
||||
.downcast_ref::<ListItem>()
|
||||
|
@ -137,13 +139,13 @@ impl MemoryCardsEditScene {
|
|||
b.set_visible(false);
|
||||
gtk::glib::MainContext::default().spawn_local(new_card_setup(Rc::clone(&new_win)));
|
||||
}));
|
||||
new_win.get_done_button().connect_closure("clicked", true, closure_local!(@strong binding, @strong new_win as w => move |_w: &Button| {
|
||||
new_win.get_done_button().connect_closure("clicked", true, closure_local!(@strong binding, @strong new_win as w, @strong card => move |_w: &Button| {
|
||||
let conn = Connection::open(get_db_path()).unwrap();
|
||||
|
||||
let hieroglyph = w.get_hieroglyph_input();
|
||||
let reading = w.get_reading_input();
|
||||
let translation = w.get_translation_input();
|
||||
|
||||
|
||||
conn.execute("INSERT OR REPLACE INTO cards ( id,
|
||||
hieroglyph,
|
||||
reading,
|
||||
|
@ -159,7 +161,11 @@ impl MemoryCardsEditScene {
|
|||
(SELECT imagename FROM cards WHERE hieroglyph = ?1)
|
||||
)", (&hieroglyph, &reading, &translation)).unwrap();
|
||||
|
||||
binding.imp().query_cards(None);
|
||||
card.set_hieroglyph(hieroglyph);
|
||||
card.set_reading(reading);
|
||||
card.set_translation(translation);
|
||||
|
||||
// binding.imp().query_cards(None);
|
||||
binding.imp().update_state();
|
||||
w.close();
|
||||
}));
|
||||
|
@ -176,9 +182,13 @@ impl MemoryCardsEditScene {
|
|||
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);
|
||||
match fs::remove_file(get_images_store_path() + "/" + &imagename) {
|
||||
Ok(()) => (),
|
||||
Err(_) => ()
|
||||
};
|
||||
connection.execute("DELETE FROM cards WHERE hieroglyph = ?1", [&card.hieroglyph()]).unwrap();
|
||||
let position = self_binding.imp().displaying_cards.borrow().iter().position(|c| *c == card).unwrap();
|
||||
self_binding.imp().displaying_cards.borrow_mut().remove(position);
|
||||
self_binding.imp().update_state();
|
||||
}));
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
mod imp;
|
||||
use glib::Object;
|
||||
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Application, Button};
|
||||
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Application, Button, ListBox};
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct MemoryCardsEditScene(ObjectSubclass<imp::MemoryCardsEditScene>)
|
||||
|
|
Loading…
Reference in New Issue