fix is_learning switch

This commit is contained in:
leca 2024-04-25 01:13:54 +03:00
parent 6a6ecd79d4
commit 78b2a1a272
2 changed files with 12 additions and 2 deletions

View File

@ -15,8 +15,7 @@ use gtk::glib::{clone, closure_local, Object};
use gtk::prelude::WidgetExt;
use gtk::subclass::prelude::*;
use gtk::{
gio, glib, Button, CompositeTemplate, ListView, NoSelection, ScrolledWindow, SearchEntry,
Window,
gio, glib, Button, CompositeTemplate, ListView, NoSelection, ScrolledWindow, SearchEntry, Switch, Window
};
use gtk::{prelude::*, FileDialog};
use gtk::{ListItem, SignalListItemFactory};
@ -125,6 +124,13 @@ impl MemoryCardsEditScene {
.and_downcast::<CardEntry>()
.unwrap();
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 is_learning = is_enabled;
let hieroglyph = card.hieroglyph();
connection.execute("UPDATE cards SET is_learning = ?1 WHERE hieroglyph = ?2", (&is_learning, &hieroglyph)).unwrap();
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| {
let connection = Connection::open(get_db_path()).unwrap();
let imagepath = &card.imagepath();

View File

@ -53,6 +53,10 @@ impl CardEntry {
self.imp().edit_button.as_ref()
}
pub fn get_is_learning_switch_widget(&self) -> &Switch {
self.imp().is_learning_switch.as_ref()
}
pub fn update_file_for_image(&self) {
let image_binding: &Image = self.imp().image.as_ref();
let path: &str = &*self.imp().imagepath.borrow().clone().to_string();