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 glib::subclass::InitializingObject;
|
||||||
use gtk::gio::ListStore;
|
use gtk::gio::ListStore;
|
||||||
// use gtk::glib::ffi::GString;
|
// use gtk::glib::ffi::GString;
|
||||||
use gtk::glib::GString;
|
|
||||||
use gtk::glib::object::ObjectExt;
|
use gtk::glib::object::ObjectExt;
|
||||||
|
use gtk::glib::GString;
|
||||||
use gtk::glib::{clone, closure_local};
|
use gtk::glib::{clone, closure_local};
|
||||||
use gtk::prelude::WidgetExt;
|
use gtk::prelude::WidgetExt;
|
||||||
use gtk::subclass::prelude::*;
|
use gtk::subclass::prelude::*;
|
||||||
|
@ -61,9 +61,6 @@ impl ObjectImpl for MemoryCardsEditScene {
|
||||||
fn constructed(&self) {
|
fn constructed(&self) {
|
||||||
self.parent_constructed();
|
self.parent_constructed();
|
||||||
|
|
||||||
// self.query_cards(None);
|
|
||||||
// self.update_card_list();
|
|
||||||
|
|
||||||
let binding = self.obj();
|
let binding = self.obj();
|
||||||
|
|
||||||
self.add_button.connect_closure("clicked",
|
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| {
|
new_win.get_done_button().connect_closure("clicked", true, closure_local!(@strong binding => move |_w: &Button| {
|
||||||
binding.imp().query_cards(None);
|
binding.imp().query_cards(None);
|
||||||
// binding.imp().update_card_list();
|
|
||||||
}));
|
}));
|
||||||
new_win.present();
|
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(
|
binding.imp().query_cards(
|
||||||
match e.text().as_str() {
|
match e.text().as_str() {
|
||||||
"" => None,
|
"" => None,
|
||||||
|
@ -92,22 +88,12 @@ impl ObjectImpl for MemoryCardsEditScene {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// binding.imp().update_card_list();
|
|
||||||
}));
|
}));
|
||||||
self.query_cards(None);
|
self.query_cards(None);
|
||||||
// self.update_card_list();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MemoryCardsEditScene {
|
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>) {
|
pub fn query_cards(&self, options: Option<String>) {
|
||||||
let conn = Connection::open(get_db_path()).unwrap();
|
let conn = Connection::open(get_db_path()).unwrap();
|
||||||
|
|
||||||
|
@ -141,10 +127,11 @@ impl MemoryCardsEditScene {
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
self.displaying_cards.borrow_mut().clear();
|
self.displaying_cards.borrow_mut().clear();
|
||||||
|
println!("pos1");
|
||||||
for c in cards_iter {
|
for c in cards_iter {
|
||||||
self.displaying_cards.borrow_mut().push(c.unwrap());
|
self.displaying_cards.borrow_mut().push(c.unwrap());
|
||||||
}
|
}
|
||||||
|
println!("pos2");
|
||||||
|
|
||||||
let model = ListStore::new::<CardEntry>();
|
let model = ListStore::new::<CardEntry>();
|
||||||
model.extend_from_slice(&*self.displaying_cards.borrow());
|
model.extend_from_slice(&*self.displaying_cards.borrow());
|
||||||
|
@ -172,69 +159,31 @@ impl MemoryCardsEditScene {
|
||||||
.child()
|
.child()
|
||||||
.and_downcast::<CardEntry>()
|
.and_downcast::<CardEntry>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// card_object_to_display.get_image_widget().set_file(Some(
|
|
||||||
// // &card_object.get_image_widget().file().unwrap()
|
// let path =
|
||||||
// match card_object.get_image_widget().file() {
|
// // card_object_to_display.get_image_widget().set_file(Some(
|
||||||
// None => "",
|
// // // &card_object.get_image_widget().file().unwrap()
|
||||||
// Some(t) => {
|
// // match card_object.get_image_widget().file() {
|
||||||
// t.to_string().to_owned().as_str()
|
// // 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_hieroglyph(card_object.hieroglyph());
|
||||||
card_object_to_display.set_reading(card_object.reading());
|
card_object_to_display.set_reading(card_object.reading());
|
||||||
card_object_to_display.set_translation(card_object.translation());
|
card_object_to_display.set_translation(card_object.translation());
|
||||||
card_object_to_display.set_islearning(card_object.islearning());
|
card_object_to_display.set_islearning(card_object.islearning());
|
||||||
});
|
});
|
||||||
|
|
||||||
println!("test");
|
println!("pos3");
|
||||||
|
|
||||||
let no_selection_model = NoSelection::new(Some(model));
|
let no_selection_model = NoSelection::new(Some(model));
|
||||||
let list_view = ListView::new(Some(no_selection_model), Some(factory));
|
let list_view = ListView::new(Some(no_selection_model), Some(factory));
|
||||||
self.cards_scrolled_window.set_child(Some(&list_view));
|
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>) {
|
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,
|
reading,
|
||||||
translation,
|
translation,
|
||||||
is_learning
|
is_learning
|
||||||
) VALUES
|
) VALUES (
|
||||||
(
|
|
||||||
(SELECT id FROM cards WHERE hieroglyph = ?2),
|
(SELECT id FROM cards WHERE hieroglyph = ?2),
|
||||||
?1,
|
?1,
|
||||||
?2,
|
?2,
|
||||||
|
|
|
@ -41,6 +41,10 @@ impl CardEntry {
|
||||||
self.imp().image.as_ref()
|
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 {
|
pub fn get_delete_button_widget(&self) -> &Button {
|
||||||
self.imp().delete_button.as_ref()
|
self.imp().delete_button.as_ref()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue