edit: Visual feedback while saving image

Closes #441
This commit is contained in:
Sophie Herold 2025-01-22 20:39:31 +01:00
parent 0943138060
commit 40d425ac80
5 changed files with 86 additions and 1 deletions

3
data/resources/edit.css Normal file
View file

@ -0,0 +1,3 @@
.saving-overlay {
background: rgba(25, 25, 25, 0.8);
}

View file

@ -1,3 +1,4 @@
@import 'edit.css';
@import 'edit_crop.css';
:root {

View file

@ -1,4 +1,5 @@
// Copyright (c) 2024-2025 Sophie Herold
// Copyright (c) 2025 Hubert Figuière
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by

View file

@ -42,6 +42,12 @@ mod imp {
cancel: TemplateChild<gtk::Button>,
#[template_child]
pub(crate) done: TemplateChild<gtk::MenuButton>,
#[template_child]
saving_revealer: TemplateChild<gtk::Revealer>,
#[template_child]
saving_status: TemplateChild<gtk::Label>,
#[template_child]
saving_info: TemplateChild<gtk::Revealer>,
#[property(get, construct_only)]
original_image: OnceCell<LpImage>,
@ -208,6 +214,7 @@ mod imp {
obj.edit_crop().apply_crop();
self.set_saving_status(Some(gettext("Editing Image")));
let editor = glycin::Editor::new(current_file);
if let Some(operations) = obj.operations() {
log::debug!("Computing edited image.");
@ -232,6 +239,8 @@ mod imp {
);
}
Ok(data) => {
self.set_saving_status(Some(gettext("Saving Image")));
if let Err(err) = new_file
.replace_contents_future(
data,
@ -255,8 +264,34 @@ mod imp {
}
}
self.set_saving_status(None);
false
}
fn set_saving_status(&self, message: Option<String>) {
let is_saving = message.is_some();
self.saving_status.set_label(&message.unwrap_or_default());
self.saving_revealer.set_reveal_child(is_saving);
self.done.set_sensitive(!is_saving);
if is_saving {
// Show text and spinner delayed
glib::timeout_add_local_once(
std::time::Duration::from_millis(
self.saving_revealer.transition_duration().into(),
),
glib::clone!(
#[weak(rename_to=imp)]
self,
move || {
imp.saving_info.set_reveal_child(true);
}
),
);
} else {
self.saving_info.set_reveal_child(false);
}
}
}
}

View file

@ -4,7 +4,52 @@
<property name="child">
<object class="AdwToolbarView" id="toolbar_view">
<property name="top-bar-style">raised</property>
<property name="content" bind-source="LpEditWindow" bind-property="edit_crop" />
<property name="content">
<object class="GtkOverlay">
<property name="child" bind-source="LpEditWindow" bind-property="edit_crop" />
<child type="overlay">
<object class="GtkRevealer" id="saving_revealer">
<property name="transition-type">crossfade</property>
<property name="transition-duration">500</property>
<property name="can-target" bind-source="saving_revealer" bind-property="reveal-child" bind-flags="sync-create" />
<property name="child">
<object class="AdwBin">
<style>
<class name="saving-overlay" />
</style>
<property name="child">
<object class="GtkRevealer" id="saving_info">
<property name="transition-type">crossfade</property>
<property name="transition-duration">500</property>
<property name="child">
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="valign">center</property>
<property name="spacing">18</property>
<child>
<object class="AdwSpinner">
<property name="width-request">64</property>
<property name="height-request">64</property>
</object>
</child>
<child>
<object class="GtkLabel" id="saving_status">
<property name="label">Preparing to Save Image</property>
<style>
<class name="title-2" />
</style>
</object>
</child>
</object>
</property>
</object>
</property>
</object>
</property>
</object>
</child>
</object>
</property>
<child type="top">
<object class="AdwHeaderBar">
<property name="show-start-title-buttons">false</property>