editing: Only enable editing action if available

This commit is contained in:
Sophie Herold 2024-12-21 01:16:24 +01:00
parent dfe71a61fc
commit bbf9534bdd
7 changed files with 52 additions and 12 deletions

View file

@ -168,6 +168,12 @@ glib::wrapper! {
}
impl LpEditWindow {
pub const REQUIRED_OPERATIONS: &[glycin::OperationId] = &[
glycin::OperationId::Clip,
glycin::OperationId::MirrorHorizontally,
glycin::OperationId::Rotate,
];
pub fn new(image: LpImage) -> Self {
glib::Object::builder()
.property("original_image", image)

View file

@ -160,6 +160,9 @@ mod imp {
pub(super) fixed_background_color: RefCell<Option<gdk::RGBA>>,
/// Animations disabled
pub(super) still: Cell<bool>,
/// Editor can be used on image
#[property(get)]
pub(super) editable: Cell<bool>,
/// Track changes to this image
pub(super) file_monitor: RefCell<Option<gio::FileMonitor>>,

View file

@ -18,6 +18,8 @@
use decoder::DecoderError;
use crate::widgets::LpEditWindow;
use super::*;
impl imp::LpImage {
@ -284,6 +286,25 @@ impl imp::LpImage {
}
}
}
async fn check_editable(&self) {
let obj = self.obj();
if let Some(mime_type) = dbg!(obj.metadata().mime_type()) {
if let Ok(supported_formats) = dbg!(glycin::config::Config::cached()
.await
.editor(&mime_type.as_str().into()))
{
if dbg!(LpEditWindow::REQUIRED_OPERATIONS
.iter()
.all(|x| supported_formats.operations.contains(x)))
{
self.editable.set(true);
obj.notify_editable();
}
}
};
}
}
impl LpImage {
@ -338,5 +359,7 @@ impl LpImage {
});
imp.decoder.replace(Some(Arc::new(decoder)));
imp.check_editable().await;
}
}

View file

@ -767,6 +767,14 @@ impl LpImageWindow {
for action in ACTIONS_CURRENT {
self.action_set_enabled(action, enabled_current);
}
// Editing related actions
let enable_editing = self
.imp()
.image_view
.current_image()
.map_or(false, |x| x.editable());
self.action_set_enabled(&Action::Edit, enable_editing);
}
/// Handles change in image and availability of images
@ -783,7 +791,7 @@ impl LpImageWindow {
self.update_title();
// Properties view
let current_image = current_page.as_ref().map(|x| x.image());
let current_image: Option<LpImage> = current_page.as_ref().map(|x| x.image());
imp.properties_view.set_image(current_image.as_ref());
let has_image = current_page.is_some();