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:
Kovid Goyal 2015-04-06 11:59:03 +05:30
parent a73d813da4
commit c9cf3066e8

View File

@ -155,6 +155,7 @@ class FileList(QTreeWidget):
def __init__(self, parent=None): def __init__(self, parent=None):
QTreeWidget.__init__(self, parent) QTreeWidget.__init__(self, parent)
self.ordered_selected_indexes = False
pi = plugins['progress_indicator'][0] pi = plugins['progress_indicator'][0]
if hasattr(pi, 'set_no_activate_on_click'): if hasattr(pi, 'set_no_activate_on_click'):
pi.set_no_activate_on_click(self) pi.set_no_activate_on_click(self)
@ -556,7 +557,22 @@ class FileList(QTreeWidget):
b.setValue(b.minimum()) b.setValue(b.minimum())
QTimer.singleShot(0, lambda : b.setValue(b.maximum())) 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): def dropEvent(self, event):
with self:
text = self.categories['text'] text = self.categories['text']
pre_drop_order = {text.child(i):i for i in xrange(text.childCount())} pre_drop_order = {text.child(i):i for i in xrange(text.childCount())}
super(FileList, self).dropEvent(event) super(FileList, self).dropEvent(event)