images are now updating instantly
This commit is contained in:
parent
72c366a54a
commit
f50b4cae8b
|
@ -1,7 +1,6 @@
|
||||||
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;
|
||||||
|
|
||||||
|
@ -79,6 +78,11 @@ impl ObjectImpl for MemoryCardsEditScene {
|
||||||
}));
|
}));
|
||||||
|
|
||||||
self.search_entry.connect_closure("activate", false, closure_local!(@strong binding => move |e: &SearchEntry| {
|
self.search_entry.connect_closure("activate", false, closure_local!(@strong binding => move |e: &SearchEntry| {
|
||||||
|
|
||||||
|
// Put query to the separate thread so that cards load on fly.
|
||||||
|
// gio::spawn_blocking(move || {
|
||||||
|
|
||||||
|
// });
|
||||||
binding.imp().query_cards(
|
binding.imp().query_cards(
|
||||||
match e.text().as_str() {
|
match e.text().as_str() {
|
||||||
"" => None,
|
"" => None,
|
||||||
|
@ -145,7 +149,7 @@ impl MemoryCardsEditScene {
|
||||||
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();
|
||||||
|
let imagepath = w.get_picture_widget().file();
|
||||||
conn.execute("INSERT OR REPLACE INTO cards ( id,
|
conn.execute("INSERT OR REPLACE INTO cards ( id,
|
||||||
hieroglyph,
|
hieroglyph,
|
||||||
reading,
|
reading,
|
||||||
|
@ -160,17 +164,23 @@ impl MemoryCardsEditScene {
|
||||||
(SELECT is_learning FROM cards WHERE hieroglyph = ?1),
|
(SELECT is_learning FROM cards WHERE hieroglyph = ?1),
|
||||||
(SELECT imagename FROM cards WHERE hieroglyph = ?1)
|
(SELECT imagename FROM cards WHERE hieroglyph = ?1)
|
||||||
)", (&hieroglyph, &reading, &translation)).unwrap();
|
)", (&hieroglyph, &reading, &translation)).unwrap();
|
||||||
|
let b = imagepath.unwrap().path().unwrap();
|
||||||
|
let a = b.to_str();
|
||||||
|
println!("a {}", a.unwrap());
|
||||||
|
card.set_imagepath(a.unwrap());
|
||||||
|
// card.get_image_widget().set_file(a);
|
||||||
card.set_hieroglyph(hieroglyph);
|
card.set_hieroglyph(hieroglyph);
|
||||||
card.set_reading(reading);
|
card.set_reading(reading);
|
||||||
card.set_translation(translation);
|
card.set_translation(translation);
|
||||||
|
// println!("{}", card.get_image_widget().file().unwrap().to_string());
|
||||||
|
card.update_file_for_image();
|
||||||
|
|
||||||
// binding.imp().query_cards(None);
|
binding.imp().update_state();
|
||||||
binding.imp().update_state();
|
|
||||||
w.close();
|
w.close();
|
||||||
}));
|
}));
|
||||||
new_win.present();
|
new_win.present();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
card_object_to_display.get_is_learning_switch_widget().connect_closure("state-set", false, closure_local!(@strong card_object as card => move |_s: &Switch, is_enabled: bool| {
|
card_object_to_display.get_is_learning_switch_widget().connect_closure("state-set", false, closure_local!(@strong card_object as card => move |_s: &Switch, is_enabled: bool| {
|
||||||
let connection = Connection::open(get_db_path()).unwrap();
|
let connection = Connection::open(get_db_path()).unwrap();
|
||||||
let is_learning = is_enabled;
|
let is_learning = is_enabled;
|
||||||
|
@ -178,6 +188,7 @@ impl MemoryCardsEditScene {
|
||||||
connection.execute("UPDATE cards SET is_learning = ?1 WHERE hieroglyph = ?2", (&is_learning, &hieroglyph)).unwrap();
|
connection.execute("UPDATE cards SET is_learning = ?1 WHERE hieroglyph = ?2", (&is_learning, &hieroglyph)).unwrap();
|
||||||
glib::Propagation::Proceed
|
glib::Propagation::Proceed
|
||||||
}));
|
}));
|
||||||
|
|
||||||
card_object_to_display.get_delete_button_widget().connect_closure("clicked", false, closure_local!(@strong card_object as card, @strong self_binding => move |_b: &Button| {
|
card_object_to_display.get_delete_button_widget().connect_closure("clicked", false, closure_local!(@strong card_object as card, @strong self_binding => move |_b: &Button| {
|
||||||
let connection = Connection::open(get_db_path()).unwrap();
|
let connection = Connection::open(get_db_path()).unwrap();
|
||||||
let imagepath = &card.imagepath();
|
let imagepath = &card.imagepath();
|
||||||
|
@ -199,8 +210,6 @@ impl MemoryCardsEditScene {
|
||||||
card_object_to_display.set_islearning(card_object.islearning());
|
card_object_to_display.set_islearning(card_object.islearning());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// factory.connect_bind();
|
|
||||||
|
|
||||||
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));
|
||||||
|
@ -305,7 +314,6 @@ async fn new_card_setup<W: IsA<gtk::Window>>(window: Rc<W>) {
|
||||||
// )
|
// )
|
||||||
// )", (&new_filename, &hieroglyph, &reading, &translation)).unwrap();
|
// )", (&new_filename, &hieroglyph, &reading, &translation)).unwrap();
|
||||||
// println!("")
|
// println!("")
|
||||||
|
|
||||||
conn.execute("UPDATE cards SET imagename = ?1 WHERE hieroglyph = ?2", (&new_filename, &hieroglyph)).unwrap();
|
conn.execute("UPDATE cards SET imagename = ?1 WHERE hieroglyph = ?2", (&new_filename, &hieroglyph)).unwrap();
|
||||||
// conn.execute("INSERT OR REPLACE INTO cards (id, imagename) VALUES ((SELECT id FROM cards WHERE hieroglyph = ?1), ?2)", (&hieroglyph, &new_filename)).unwrap();
|
// conn.execute("INSERT OR REPLACE INTO cards (id, imagename) VALUES ((SELECT id FROM cards WHERE hieroglyph = ?1), ?2)", (&hieroglyph, &new_filename)).unwrap();
|
||||||
conn.execute("UPDATE cards SET is_learning = TRUE WHERE hieroglyph = ?1", [&hieroglyph]).unwrap();
|
conn.execute("UPDATE cards SET is_learning = TRUE WHERE hieroglyph = ?1", [&hieroglyph]).unwrap();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
mod imp;
|
mod imp;
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Application, Button, ListBox};
|
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Application, Button};
|
||||||
|
|
||||||
glib::wrapper! {
|
glib::wrapper! {
|
||||||
pub struct MemoryCardsEditScene(ObjectSubclass<imp::MemoryCardsEditScene>)
|
pub struct MemoryCardsEditScene(ObjectSubclass<imp::MemoryCardsEditScene>)
|
||||||
|
|
Loading…
Reference in New Issue