image_view: Switch from expressions to signal groups
Expressions have the leak issue mentioned in the previous commit, but we were using them in a few scenarios where they couldn't be used in UI files. Since these expressions don't set a property but instead trigger behavior, the appropriate API to use is GSignalGroup. This commit switches the expressions on the image to use GSignalGroup instead.
This commit is contained in:
parent
ae41a77521
commit
aab50af31a
1 changed files with 29 additions and 18 deletions
|
|
@ -44,6 +44,8 @@ use std::path::{Path, PathBuf};
|
||||||
const BUFFER: usize = 2;
|
const BUFFER: usize = 2;
|
||||||
|
|
||||||
mod imp {
|
mod imp {
|
||||||
|
use once_cell::sync::OnceCell;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[derive(Debug, Default, CompositeTemplate)]
|
#[derive(Debug, Default, CompositeTemplate)]
|
||||||
|
|
@ -63,6 +65,8 @@ mod imp {
|
||||||
|
|
||||||
pub model: RefCell<LpFileModel>,
|
pub model: RefCell<LpFileModel>,
|
||||||
pub preserve_content: Cell<bool>,
|
pub preserve_content: Cell<bool>,
|
||||||
|
|
||||||
|
pub current_image_signals: OnceCell<glib::SignalGroup>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
|
@ -118,25 +122,32 @@ mod imp {
|
||||||
// Manually mange widget layout, see `WidgetImpl` for details
|
// Manually mange widget layout, see `WidgetImpl` for details
|
||||||
obj.set_layout_manager(None::<gtk::LayoutManager>);
|
obj.set_layout_manager(None::<gtk::LayoutManager>);
|
||||||
|
|
||||||
obj.property_expression("current-page")
|
let signal_group = glib::SignalGroup::new(LpImage::static_type());
|
||||||
.chain_property::<LpImagePage>("image")
|
obj.connect_notify_local(
|
||||||
.chain_property::<LpImage>("path")
|
Some("current-page"),
|
||||||
.watch(
|
clone!(@weak signal_group => move |obj, _| {
|
||||||
glib::Object::NONE,
|
signal_group.set_target(obj.current_image().as_ref());
|
||||||
glib::clone!(@weak obj => move || {
|
}),
|
||||||
obj.current_image_path_changed();
|
);
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
obj.property_expression("current-page")
|
let view = &*obj;
|
||||||
.chain_property::<LpImagePage>("image")
|
signal_group.connect_closure(
|
||||||
.chain_property::<LpImage>("is-deleted")
|
"notify::path",
|
||||||
.watch(
|
true,
|
||||||
glib::Object::NONE,
|
glib::closure_local!(@watch view => move |_: LpImage, _: glib::ParamSpec| {
|
||||||
glib::clone!(@weak obj => move || {
|
view.current_image_path_changed();
|
||||||
obj.current_image_path_changed();
|
}),
|
||||||
}),
|
);
|
||||||
);
|
|
||||||
|
signal_group.connect_closure(
|
||||||
|
"notify::is-deleted",
|
||||||
|
true,
|
||||||
|
glib::closure_local!(@watch view => move |_: LpImage, _: glib::ParamSpec| {
|
||||||
|
view.current_image_path_changed();
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
self.current_image_signals.set(signal_group).unwrap();
|
||||||
|
|
||||||
let source = gtk::DragSource::new();
|
let source = gtk::DragSource::new();
|
||||||
source.set_exclusive(true);
|
source.set_exclusive(true);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue