mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Edit Book: When dragging and dropping files to re-order them in the file browser, fix the final order being dependent on the order the files were selected in. Fixes #1440598 [Edit Book: Inverted order of files after drag and drop](https://bugs.launchpad.net/calibre/+bug/1440598)
This commit is contained in:
parent
a73d813da4
commit
c9cf3066e8
@ -155,6 +155,7 @@ class FileList(QTreeWidget):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
QTreeWidget.__init__(self, parent)
|
||||
self.ordered_selected_indexes = False
|
||||
pi = plugins['progress_indicator'][0]
|
||||
if hasattr(pi, 'set_no_activate_on_click'):
|
||||
pi.set_no_activate_on_click(self)
|
||||
@ -556,7 +557,22 @@ class FileList(QTreeWidget):
|
||||
b.setValue(b.minimum())
|
||||
QTimer.singleShot(0, lambda : b.setValue(b.maximum()))
|
||||
|
||||
def __enter__(self):
|
||||
self.ordered_selected_indexes = True
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.ordered_selected_indexes = False
|
||||
|
||||
def selectedIndexes(self):
|
||||
ans = QTreeWidget.selectedIndexes(self)
|
||||
if self.ordered_selected_indexes:
|
||||
# The reverse is needed because Qt's implementation of dropEvent
|
||||
# reverses the selectedIndexes when dropping.
|
||||
ans = list(sorted(ans, key=lambda idx:idx.row(), reverse=True))
|
||||
return ans
|
||||
|
||||
def dropEvent(self, event):
|
||||
with self:
|
||||
text = self.categories['text']
|
||||
pre_drop_order = {text.child(i):i for i in xrange(text.childCount())}
|
||||
super(FileList, self).dropEvent(event)
|
||||
|
Loading…
x
Reference in New Issue
Block a user