fix images
This commit is contained in:
parent
67ce4e9b36
commit
3d0543931d
|
@ -11,8 +11,8 @@ use crate::widgets::card_entry::CardEntry;
|
|||
use glib::subclass::InitializingObject;
|
||||
use gtk::gio::ListStore;
|
||||
// use gtk::glib::ffi::GString;
|
||||
use gtk::glib::GString;
|
||||
use gtk::glib::object::ObjectExt;
|
||||
use gtk::glib::GString;
|
||||
use gtk::glib::{clone, closure_local};
|
||||
use gtk::prelude::WidgetExt;
|
||||
use gtk::subclass::prelude::*;
|
||||
|
@ -61,9 +61,6 @@ impl ObjectImpl for MemoryCardsEditScene {
|
|||
fn constructed(&self) {
|
||||
self.parent_constructed();
|
||||
|
||||
// self.query_cards(None);
|
||||
// self.update_card_list();
|
||||
|
||||
let binding = self.obj();
|
||||
|
||||
self.add_button.connect_closure("clicked",
|
||||
|
@ -76,12 +73,11 @@ impl ObjectImpl for MemoryCardsEditScene {
|
|||
}));
|
||||
new_win.get_done_button().connect_closure("clicked", true, closure_local!(@strong binding => move |_w: &Button| {
|
||||
binding.imp().query_cards(None);
|
||||
// binding.imp().update_card_list();
|
||||
}));
|
||||
new_win.present();
|
||||
}));
|
||||
|
||||
self.search_entry.connect_closure("changed", false, closure_local!(@strong binding => move |e: &SearchEntry| {
|
||||
self.search_entry.connect_closure("activate", false, closure_local!(@strong binding => move |e: &SearchEntry| {
|
||||
binding.imp().query_cards(
|
||||
match e.text().as_str() {
|
||||
"" => None,
|
||||
|
@ -92,22 +88,12 @@ impl ObjectImpl for MemoryCardsEditScene {
|
|||
}
|
||||
}
|
||||
);
|
||||
// binding.imp().update_card_list();
|
||||
}));
|
||||
self.query_cards(None);
|
||||
// self.update_card_list();
|
||||
}
|
||||
}
|
||||
|
||||
impl MemoryCardsEditScene {
|
||||
// pub fn clear_displaying_card(&self) {
|
||||
// let c: &ListBox = self.cards_container.as_ref();
|
||||
|
||||
// while c.first_child() != None {
|
||||
// c.remove(&c.first_child().unwrap());
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn query_cards(&self, options: Option<String>) {
|
||||
let conn = Connection::open(get_db_path()).unwrap();
|
||||
|
||||
|
@ -141,10 +127,11 @@ impl MemoryCardsEditScene {
|
|||
})
|
||||
.unwrap();
|
||||
self.displaying_cards.borrow_mut().clear();
|
||||
|
||||
println!("pos1");
|
||||
for c in cards_iter {
|
||||
self.displaying_cards.borrow_mut().push(c.unwrap());
|
||||
}
|
||||
println!("pos2");
|
||||
|
||||
let model = ListStore::new::<CardEntry>();
|
||||
model.extend_from_slice(&*self.displaying_cards.borrow());
|
||||
|
@ -172,69 +159,31 @@ impl MemoryCardsEditScene {
|
|||
.child()
|
||||
.and_downcast::<CardEntry>()
|
||||
.unwrap();
|
||||
// card_object_to_display.get_image_widget().set_file(Some(
|
||||
// // &card_object.get_image_widget().file().unwrap()
|
||||
// match card_object.get_image_widget().file() {
|
||||
// None => "",
|
||||
// Some(t) => {
|
||||
// t.to_string().to_owned().as_str()
|
||||
// }
|
||||
// }
|
||||
// ));
|
||||
|
||||
// let path =
|
||||
// // card_object_to_display.get_image_widget().set_file(Some(
|
||||
// // // &card_object.get_image_widget().file().unwrap()
|
||||
// // match card_object.get_image_widget().file() {
|
||||
// // None => "",
|
||||
// // Some(t) => {
|
||||
// // t.to_string().to_owned().as_str()
|
||||
// // }
|
||||
// // }
|
||||
// // ));
|
||||
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());
|
||||
});
|
||||
|
||||
println!("test");
|
||||
println!("pos3");
|
||||
|
||||
let no_selection_model = NoSelection::new(Some(model));
|
||||
let list_view = ListView::new(Some(no_selection_model), Some(factory));
|
||||
self.cards_scrolled_window.set_child(Some(&list_view));
|
||||
println!("pos4");
|
||||
}
|
||||
|
||||
// pub fn update_card_list(&self) {
|
||||
// let c: &ListBox = self.cards_container.as_ref();
|
||||
|
||||
// self.clear_displaying_card();
|
||||
|
||||
// for card in self.displaying_cards.borrow().iter() {
|
||||
// let self_binding = self.obj();
|
||||
// c.append(card);
|
||||
|
||||
// card.get_delete_button_widget().connect_closure("clicked", false, closure_local!(@strong 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_card_list();
|
||||
// }));
|
||||
|
||||
// card.get_edit_button_widget().connect_closure("clicked", false, closure_local!(@strong self_binding as binding, @strong card => move |_b: &Button| {
|
||||
// let new_win = Rc::new(MemoryCardsNewScene::new(&binding.application().unwrap()));
|
||||
|
||||
// //setting corresponding properties
|
||||
// new_win.get_picture_widget().set_file(Some(&gio::File::for_path(card.imagepath())));
|
||||
// new_win.get_hieroglyph_entry().set_text(&card.hieroglyph());
|
||||
// new_win.get_reading_entry().set_text(&card.reading());
|
||||
// new_win.get_translation_entry().set_text(&card.translation());
|
||||
|
||||
// new_win.get_file_choose_button().connect_clicked(clone!(@strong new_win, @strong card => move |b: &Button| {
|
||||
// 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 => move |_w: &Button| {
|
||||
// binding.imp().query_cards(None);
|
||||
// binding.imp().update_card_list();
|
||||
// }));
|
||||
// new_win.present();
|
||||
// }));
|
||||
// card.update_file_for_image();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
async fn new_card_setup<W: IsA<gtk::Window>>(window: Rc<W>) {
|
||||
|
@ -287,8 +236,7 @@ async fn new_card_setup<W: IsA<gtk::Window>>(window: Rc<W>) {
|
|||
reading,
|
||||
translation,
|
||||
is_learning
|
||||
) VALUES
|
||||
(
|
||||
) VALUES (
|
||||
(SELECT id FROM cards WHERE hieroglyph = ?2),
|
||||
?1,
|
||||
?2,
|
||||
|
|
|
@ -41,6 +41,10 @@ impl CardEntry {
|
|||
self.imp().image.as_ref()
|
||||
}
|
||||
|
||||
pub fn get_image_file_path(&self) -> String {
|
||||
self.imp().imagepath.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn get_delete_button_widget(&self) -> &Button {
|
||||
self.imp().delete_button.as_ref()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue