properties_view: Move expressions to UI files
Currently Loupe leaks expressions created in-code. This is because expressions need to be unwatched in order to be dropped. Since we'd need to hold a reference to the watch ourselves and unwatch them in dispose, our code would become more cumbersome if we were to try to handle this properly. This commit moves the expressions on LpPropertiesView to the UI file, as GTK handles cleaning up the expressions it creates, without any extra consideration on the app side.
This commit is contained in:
parent
34b3fb12de
commit
ae41a77521
2 changed files with 19 additions and 31 deletions
|
|
@ -102,9 +102,7 @@ mod imp {
|
|||
glib::ParamSpecObject::builder::<LpImage>("image")
|
||||
.explicit_notify()
|
||||
.build(),
|
||||
glib::ParamSpecObject::builder::<LpImageMetadata>("metadata")
|
||||
.read_only()
|
||||
.build(),
|
||||
glib::ParamSpecObject::builder::<LpImageMetadata>("metadata").build(),
|
||||
]
|
||||
});
|
||||
|
||||
|
|
@ -131,6 +129,8 @@ mod imp {
|
|||
|
||||
match prop_name {
|
||||
"image" => obj.set_image(value.get().ok().as_ref()),
|
||||
"file" => obj.set_file(value.get().ok().as_ref()),
|
||||
"metadata" => obj.set_metadata(value.get().unwrap()),
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
|
@ -140,34 +140,6 @@ mod imp {
|
|||
|
||||
self.parent_constructed();
|
||||
obj.action_set_enabled("properties.open-folder", false);
|
||||
|
||||
// watch changes to image metadata
|
||||
obj.property_expression("image")
|
||||
.chain_property::<LpImage>("metadata")
|
||||
.watch(
|
||||
glib::Object::NONE,
|
||||
glib::clone!(@weak obj => move || {
|
||||
let metadata = if let Some(image) = obj.image() {
|
||||
image.metadata()
|
||||
} else {
|
||||
LpImageMetadata::default()
|
||||
};
|
||||
|
||||
// set metadata since image might have changed
|
||||
obj.imp().metadata.replace(metadata);
|
||||
obj.notify("metadata");
|
||||
}),
|
||||
);
|
||||
|
||||
// watch changes to image metadata
|
||||
obj.property_expression("image")
|
||||
.chain_property::<LpImage>("path")
|
||||
.watch(
|
||||
glib::Object::NONE,
|
||||
glib::clone!(@weak obj => move || {
|
||||
obj.set_file(obj.image().and_then(|x| x.file()).as_ref());
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -276,6 +248,12 @@ impl LpPropertiesView {
|
|||
});
|
||||
}
|
||||
|
||||
fn set_metadata(&self, metadata: LpImageMetadata) {
|
||||
let imp = self.imp();
|
||||
imp.metadata.replace(metadata);
|
||||
self.notify("metadata");
|
||||
}
|
||||
|
||||
// This is where we handle the results of the future.
|
||||
// This could technically be part of the future, but we keep
|
||||
// them separate for a bit of cleanliness.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue