diff --git a/build-aux/flatpak/org.gnome.Loupe.Devel.json b/build-aux/flatpak/org.gnome.Loupe.Devel.json index 0c1262c..ae6a5b0 100644 --- a/build-aux/flatpak/org.gnome.Loupe.Devel.json +++ b/build-aux/flatpak/org.gnome.Loupe.Devel.json @@ -111,9 +111,9 @@ ], "sources": [ { - "type": "archive", - "url": "https://download.gnome.org/sources/glycin/1.2/glycin-1.2.beta.1.tar.xz", - "sha256": "f6952ed2854641bf521b430c088c953edf53d39fcfb9e0a30eb6872c7482ec26" + "type": "git", + "url": "https://gitlab.gnome.org/GNOME/glycin.git", + "commit": "52fe5cdb68abf24361ce31c88c2965bd6c203460" } ] }, diff --git a/news.d/48.rc/fixed-dont-show-canceled-error b/news.d/48.rc/fixed-dont-show-canceled-error new file mode 100644 index 0000000..b03cabe --- /dev/null +++ b/news.d/48.rc/fixed-dont-show-canceled-error @@ -0,0 +1 @@ +editing: Don't show error if saving is aborted. Instead handle actual errors correctly. diff --git a/src/widgets/edit_window.rs b/src/widgets/edit_window.rs index 866a68a..3fe349f 100644 --- a/src/widgets/edit_window.rs +++ b/src/widgets/edit_window.rs @@ -248,8 +248,8 @@ mod imp { let obj = self.obj(); self.save.popdown(); - if let Some(current_file) = obj.original_image().file() { - if let Some(current_path) = current_file.path() { + if let Some(original_file) = obj.original_image().file() { + if let Some(current_path) = original_file.path() { if let Some(mut file_stem) = current_path.file_stem().map(|x| x.to_os_string()) { let mut tmp_path = current_path.clone(); @@ -260,7 +260,7 @@ mod imp { } tmp_path.set_file_name(file_stem); - let new_file = gio::File::for_path(&tmp_path); + let tmp_file = gio::File::for_path(&tmp_path); let cancellable = gio::Cancellable::new(); if let Some(old_cancellable) = @@ -270,43 +270,59 @@ mod imp { } let written = self - .save(current_file.clone(), new_file.clone(), cancellable.clone()) + .save(original_file.clone(), tmp_file.clone(), cancellable.clone()) .await; if written { - if let Err(err) = gio::CancellableFuture::new( - current_file.trash_future(glib::Priority::DEFAULT), + log::debug!("Moving image to trash '{}'", original_file.uri()); + let trash_result = gio::CancellableFuture::new( + original_file.trash_future(glib::Priority::DEFAULT), cancellable.clone(), ) - .await - { + .await; + + if trash_result.is_err() { + // Canceled + log::debug!("Trashing image canceled"); + return; + } else if let Ok(Err(err)) = trash_result { obj.window().show_error( &gettext("Failed to save image."), &format!("Failed to move image {current_path:?} to trash and therefore couldn't save image: {err}"), ErrorType::General, ); - } else if let Err(err) = gio::CancellableFuture::new( - new_file + return; + } + + log::debug!("Moving '{}' to '{}'", tmp_file.uri(), original_file.uri()); + let move_result = gio::CancellableFuture::new( + tmp_file .move_future( - ¤t_file, + &original_file, gio::FileCopyFlags::NONE, glib::Priority::DEFAULT, ) .0, cancellable.clone(), ) - .await - { + .await; + + if move_result.is_err() { + // Canceled + log::debug!("Moving image canceled"); + return; + } else if let Ok(Err(err)) = move_result { obj.window().show_error( &gettext("Failed to save image."), &format!( - "Failed to move image image to {current_path:?}: {err} move {:?} to {:?}", new_file.path().unwrap(), current_file.path().unwrap() + "Failed to move image image to {current_path:?}: {err} move {:?} to {:?}", tmp_file.path().unwrap(), original_file.path().unwrap() ), ErrorType::General, ); - } else { - obj.window().show_specific_image(current_file); + return; } + + obj.window().show_specific_image(original_file); } } } @@ -356,21 +372,27 @@ mod imp { Ok(data) => { self.set_saving_status(Some(gettext("Saving Image"))); - if let Err(err) = new_file - .replace_contents_future( + let save_result = gio::CancellableFuture::new( + new_file.replace_contents_future( data, None, true, gio::FileCreateFlags::NONE, - ) - .await - { + ), + cancellable, + ) + .await; + + if save_result.is_err() { + log::debug!("Saving image canceled"); + } else if let Ok(Err(err)) = save_result { obj.window().show_error( &gettext("Failed to Save Image"), &format!("Failed to write file:\n\n{err:?}"), ErrorType::General, ); } else { + log::debug!("Image saved"); return true; } } diff --git a/src/widgets/window.rs b/src/widgets/window.rs index ce78b56..57317ff 100644 --- a/src/widgets/window.rs +++ b/src/widgets/window.rs @@ -248,7 +248,7 @@ impl LpWindow { } pub fn show_specific_image(&self, file: gio::File) { - log::debug!("Showting specific image: {}", file.uri()); + log::debug!("Showing specific image: {}", file.uri()); self.image_view().set_images_from_files(vec![file]); self.show_image(); }