diff --git a/hyperplane/item.py b/hyperplane/item.py index 91ffd67..9e73f98 100644 --- a/hyperplane/item.py +++ b/hyperplane/item.py @@ -18,6 +18,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later """An item representing a file to be set up through a `GtkSignalListItemFactory`.""" +import logging from pathlib import Path from typing import Any, Optional @@ -353,17 +354,15 @@ def __drag_end( self, _src: Gtk.DragSource, _drag: Gdk.Drag, delete_data: bool ) -> None: self.page.view.set_enable_rubberband(True) - if delete_data and shared.last_drop_internal: - for gfile in self.dragged_gfiles: - rm(gfile) - shared.last_drop_internal = False + if delete_data: + # This is to prevent data loss + logging.debug("Dropped data should be deleted but won't be.") def __drag_cancel( self, _src: Gtk.DragSource, _drag: Gdk.Drag, _reason: Gdk.DragCancelReason ) -> None: self.page.view.set_enable_rubberband(True) - shared.last_drop_internal = False def __dir_children_cb(self, gfile: Gio.File, result: Gio.AsyncResult) -> None: try: diff --git a/hyperplane/shared.py.in b/hyperplane/shared.py.in index 08adf84..8c2b35f 100644 --- a/hyperplane/shared.py.in +++ b/hyperplane/shared.py.in @@ -38,10 +38,6 @@ search = "" # pylint: disable=invalid-name right_clicked_file = None # pylint: disable=invalid-name undo_queue = {} -# This is so Hyperplane only deletes files moved during DnD if they were moved whithin the app. -# See https://bugzilla.mozilla.org/show_bug.cgi?id=1877555 -last_drop_internal = False # pylint: disable=invalid-name - grid_view = state_schema.get_boolean("grid-view") show_hidden = state_schema.get_boolean("show-hidden") sort_by = state_schema.get_string("sort-by") diff --git a/hyperplane/window.py b/hyperplane/window.py index 0510b7d..3278683 100644 --- a/hyperplane/window.py +++ b/hyperplane/window.py @@ -42,6 +42,7 @@ get_gfile_display_name, get_gfile_path, get_paste_gfile, + move, trash, validate_name, ) @@ -1053,7 +1054,7 @@ def __drop( def __drop_file_list(self, file_list: Gdk.FileList, action: Gdk.DragAction) -> bool: dst = self.get_visible_page().get_dst() - move = action == Gdk.DragAction.MOVE + should_move = action == Gdk.DragAction.MOVE files = [] @@ -1070,22 +1071,30 @@ def __drop_file_list(self, file_list: Gdk.FileList, action: Gdk.DragAction) -> b logging.warning("Cannot drop files: Can't get child for display name.") return False - try: - copy(src, child) - except FileExistsError: + if should_move: try: - copy(src, get_paste_gfile(child)) - except (FileExistsError, FileNotFoundError) as error: - logging.warning("Cannot drop files: %s", error) - return False - - files.append((src, child) if move else child) - - shared.undo_queue[time()] = ("move" if move else "copy", files) + move(src, child) + except FileExistsError: + # TODO: Export this toast to a public method + self.send_toast( + _("A folder with that name already exists") + if src.query_file_type(Gio.FileQueryInfoFlags.NONE) + == Gio.FileType.DIRECTORY + else _("A file with that name already exists") + ) + else: + try: + copy(src, child) + except FileExistsError: + try: + copy(src, get_paste_gfile(child)) + except (FileExistsError, FileNotFoundError) as error: + logging.warning("Cannot drop files: %s", error) + return False - if move: - shared.last_drop_internal = True + files.append((src, child) if should_move else child) + shared.undo_queue[time()] = ("move" if should_move else "copy", files) return True def __drop_texture(self, texture: Gdk.Texture) -> None: