From 8c936552b73b9e85a7b03f400fc0077269a80d2d Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Wed, 26 Apr 2023 12:29:32 -0400 Subject: [PATCH] Don't delete selection if copy fails during cut --- paint.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/paint.py b/paint.py index 1c232e2..ee78810 100755 --- a/paint.py +++ b/paint.py @@ -1868,14 +1868,14 @@ class PaintApp(App[None]): def action_cut(self) -> None: """Cut the selection to the clipboard.""" - self.action_copy() - self.action_clear_selection() + if self.action_copy(): + self.action_clear_selection() - def action_copy(self) -> None: + def action_copy(self) -> bool: """Copy the selection to the clipboard.""" sel = self.image.selection if sel is None: - return + return False had_contained_image = sel.contained_image is not None try: if sel.contained_image is None: @@ -1886,14 +1886,16 @@ class PaintApp(App[None]): import pyperclip if not pyperclip.is_available(): self.warning_message_box(_("Paint"), _("Clipboard is not available."), "ok") - return + return False pyperclip.copy(sel.contained_image.get_ansi()) # self.use_clipboard(sel.contained_image.get_ansi()) except Exception as e: self.warning_message_box(_("Paint"), _("Failed to copy to the clipboard.") + "\n\n" + repr(e), "ok") + return False finally: if not had_contained_image: sel.contained_image = None + return True def action_paste(self) -> None: """Paste the clipboard as a selection."""