From 34b3ee1138ea2c91d5f9037380f63d51363d791f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 24 Sep 2023 10:03:16 +0530 Subject: [PATCH] Edit book: When copying files do it in order so that the files are pasted in the same order when pasting into another editor instance. Fixes #2037198 [Calibre Editor: "Paste # files from other editor instance" > Files Pasted Out of Order](https://bugs.launchpad.net/calibre/+bug/2037198) --- src/calibre/gui2/tweak_book/file_list.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tweak_book/file_list.py b/src/calibre/gui2/tweak_book/file_list.py index 58d8a5612e..15c696e54b 100644 --- a/src/calibre/gui2/tweak_book/file_list.py +++ b/src/calibre/gui2/tweak_book/file_list.py @@ -876,6 +876,16 @@ class FileList(QTreeWidget, OpenWithHandler): ans.discard('') return ans + @property + def selected_names_in_order(self): + root = self.invisibleRootItem() + for category_item in (root.child(i) for i in range(root.childCount())): + for child in (category_item.child(i) for i in range(category_item.childCount())): + if child.isSelected(): + name = child.data(0, NAME_ROLE) + if name: + yield name + def move_selected_text_items(self, amt: int) -> bool: parent = self.categories['text'] children = tuple(parent.child(i) for i in range(parent.childCount())) @@ -906,7 +916,7 @@ class FileList(QTreeWidget, OpenWithHandler): return changed def copy_selected_files(self): - self.initiate_file_copy.emit(self.selected_names) + self.initiate_file_copy.emit(tuple(self.selected_names_in_order)) def paste_from_other_instance(self): self.initiate_file_paste.emit()