implemented delete card entry

This commit is contained in:
2024-04-06 07:04:19 +03:00
parent fa260bb8f5
commit 193db81657
4 changed files with 42 additions and 27 deletions

View File

@@ -1,9 +1,7 @@
use std::cell::RefCell;
use std::path::Path;
use glib::subclass::InitializingObject;
use glib::Properties;
use gtk::gio::File;
use gtk::subclass::prelude::*;
use gtk::{glib, prelude::*, Button, CompositeTemplate, Label, Picture};
@@ -18,9 +16,9 @@ pub struct CardEntry {
#[template_child]
pub reading_label: TemplateChild<Label>,
#[template_child]
pub edit_button: TemplateChild<Button>,
pub delete_button: TemplateChild<Button>,
#[property(get, set)]
imagepath: RefCell<String>,
pub imagepath: RefCell<String>,
#[property(get, set)]
hieroglyph: RefCell<String>,
#[property(get, set)]
@@ -47,12 +45,6 @@ impl ObjectImpl for CardEntry {
fn constructed(&self) {
self.parent_constructed();
let picture_binding: &Picture = self.picture.as_ref();
let picture_file: File =
File::for_path(Path::new(&String::from(&*self.imagepath.borrow())));
picture_binding.set_file(glib::bitflags::__private::core::option::Option::Some(
&picture_file,
));
let hieroglyph_label_binding: &Label = self.hieroglyph_label.as_ref();
self.obj()
@@ -65,6 +57,7 @@ impl ObjectImpl for CardEntry {
.bind_property("reading", reading_label_binding, "label")
.sync_create()
.build();
}
fn dispose(&self) {

View File

@@ -1,7 +1,11 @@
mod imp;
use glib::Object;
use gtk::{gio, glib::{self, subclass::types::ObjectSubclassIsExt}, Picture};
use gtk::{
gio,
glib::{self, subclass::types::ObjectSubclassIsExt},
Button, Picture,
};
glib::wrapper! {
pub struct CardEntry(ObjectSubclass<imp::CardEntry>)
@@ -22,4 +26,14 @@ impl CardEntry {
pub fn get_picture_widget(&self) -> &Picture {
self.imp().picture.as_ref()
}
pub fn get_delete_button_widget(&self) -> &Button {
self.imp().delete_button.as_ref()
}
pub fn update_file_for_picture(&self) {
let picture_binding: &Picture = self.imp().picture.as_ref();
let path: &str = &*self.imp().imagepath.borrow().clone().to_string();
picture_binding.set_file(Some(&gio::File::for_path(path)));
}
}