optimization
This commit is contained in:
parent
fbe63367d2
commit
72c366a54a
|
@ -1,6 +1,7 @@
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
|
use std::ops::Deref;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
@ -110,6 +111,7 @@ impl MemoryCardsEditScene {
|
||||||
});
|
});
|
||||||
let self_binding = self.obj();
|
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| {
|
factory.connect_closure("bind", false, closure_local!(@strong self_binding => move |_f: &SignalListItemFactory, list_item: &Object| {
|
||||||
let card_object = &list_item
|
let card_object = &list_item
|
||||||
.downcast_ref::<ListItem>()
|
.downcast_ref::<ListItem>()
|
||||||
|
@ -137,13 +139,13 @@ impl MemoryCardsEditScene {
|
||||||
b.set_visible(false);
|
b.set_visible(false);
|
||||||
gtk::glib::MainContext::default().spawn_local(new_card_setup(Rc::clone(&new_win)));
|
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 conn = Connection::open(get_db_path()).unwrap();
|
||||||
|
|
||||||
let hieroglyph = w.get_hieroglyph_input();
|
let hieroglyph = w.get_hieroglyph_input();
|
||||||
let reading = w.get_reading_input();
|
let reading = w.get_reading_input();
|
||||||
let translation = w.get_translation_input();
|
let translation = w.get_translation_input();
|
||||||
|
|
||||||
conn.execute("INSERT OR REPLACE INTO cards ( id,
|
conn.execute("INSERT OR REPLACE INTO cards ( id,
|
||||||
hieroglyph,
|
hieroglyph,
|
||||||
reading,
|
reading,
|
||||||
|
@ -159,7 +161,11 @@ impl MemoryCardsEditScene {
|
||||||
(SELECT imagename FROM cards WHERE hieroglyph = ?1)
|
(SELECT imagename FROM cards WHERE hieroglyph = ?1)
|
||||||
)", (&hieroglyph, &reading, &translation)).unwrap();
|
)", (&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();
|
binding.imp().update_state();
|
||||||
w.close();
|
w.close();
|
||||||
}));
|
}));
|
||||||
|
@ -176,9 +182,13 @@ impl MemoryCardsEditScene {
|
||||||
let connection = Connection::open(get_db_path()).unwrap();
|
let connection = Connection::open(get_db_path()).unwrap();
|
||||||
let imagepath = &card.imagepath();
|
let imagepath = &card.imagepath();
|
||||||
let imagename = &Path::new(&imagepath).file_name().unwrap().to_str().unwrap();
|
let imagename = &Path::new(&imagepath).file_name().unwrap().to_str().unwrap();
|
||||||
fs::remove_file(get_images_store_path() + "/" + &imagename).expect("Could not remove file!");
|
match fs::remove_file(get_images_store_path() + "/" + &imagename) {
|
||||||
connection.execute("DELETE FROM cards WHERE imagename = ?1", [&imagename]).unwrap();
|
Ok(()) => (),
|
||||||
self_binding.imp().query_cards(None);
|
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();
|
self_binding.imp().update_state();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
mod imp;
|
mod imp;
|
||||||
use glib::Object;
|
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! {
|
glib::wrapper! {
|
||||||
pub struct MemoryCardsEditScene(ObjectSubclass<imp::MemoryCardsEditScene>)
|
pub struct MemoryCardsEditScene(ObjectSubclass<imp::MemoryCardsEditScene>)
|
||||||
|
|
Loading…
Reference in New Issue