editing: Only enable editing action if available
This commit is contained in:
parent
dfe71a61fc
commit
bbf9534bdd
7 changed files with 52 additions and 12 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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>>,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue