mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Fix #1888251 [Selecting multiple entries in menu editor only moves one](https://bugs.launchpad.net/calibre/+bug/1888251)
This commit is contained in:
parent
14ba9d1461
commit
68f624addd
@ -6,8 +6,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
from PyQt5.Qt import QAbstractListModel, Qt, QIcon, \
|
from PyQt5.Qt import QAbstractListModel, Qt, QIcon
|
||||||
QItemSelectionModel
|
|
||||||
|
|
||||||
from calibre import force_unicode
|
from calibre import force_unicode
|
||||||
from calibre.gui2.preferences.toolbar_ui import Ui_Form
|
from calibre.gui2.preferences.toolbar_ui import Ui_Form
|
||||||
@ -167,9 +166,7 @@ class CurrentModel(BaseModel):
|
|||||||
|
|
||||||
def move(self, idx, delta):
|
def move(self, idx, delta):
|
||||||
row = idx.row()
|
row = idx.row()
|
||||||
if row < 0 or row >= len(self._data):
|
nrow = (row + delta + len(self._data)) % len(self._data)
|
||||||
return
|
|
||||||
nrow = row + delta
|
|
||||||
if nrow < 0 or nrow >= len(self._data):
|
if nrow < 0 or nrow >= len(self._data):
|
||||||
return
|
return
|
||||||
t = self._data[row]
|
t = self._data[row]
|
||||||
@ -180,6 +177,14 @@ class CurrentModel(BaseModel):
|
|||||||
self.dataChanged.emit(ni, ni)
|
self.dataChanged.emit(ni, ni)
|
||||||
return ni
|
return ni
|
||||||
|
|
||||||
|
def move_many(self, indices, delta):
|
||||||
|
indices = sorted(indices, key=lambda i: i.row(), reverse=delta > 0)
|
||||||
|
ans = {}
|
||||||
|
for idx in indices:
|
||||||
|
ni = self.move(idx, delta)
|
||||||
|
ans[idx.row()] = ni
|
||||||
|
return ans
|
||||||
|
|
||||||
def add(self, names):
|
def add(self, names):
|
||||||
actions = []
|
actions = []
|
||||||
reject = set()
|
reject = set()
|
||||||
@ -330,14 +335,18 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
self.changed_signal.emit()
|
self.changed_signal.emit()
|
||||||
|
|
||||||
def move(self, delta, *args):
|
def move(self, delta, *args):
|
||||||
ci = self.current_actions.currentIndex()
|
sm = self.current_actions.selectionModel()
|
||||||
|
x = sm.selectedIndexes()
|
||||||
|
if x and len(x):
|
||||||
|
i = sm.currentIndex().row()
|
||||||
m = self.current_actions.model()
|
m = self.current_actions.model()
|
||||||
if ci.isValid():
|
idx_map = m.move_many(x, delta)
|
||||||
ni = m.move(ci, delta)
|
newci = idx_map.get(i)
|
||||||
if ni is not None:
|
if newci is not None:
|
||||||
self.current_actions.setCurrentIndex(ni)
|
sm.setCurrentIndex(newci, sm.ClearAndSelect)
|
||||||
self.current_actions.selectionModel().select(ni,
|
sm.clear()
|
||||||
QItemSelectionModel.ClearAndSelect)
|
for idx in idx_map.values():
|
||||||
|
sm.select(idx, sm.Select)
|
||||||
self.changed_signal.emit()
|
self.changed_signal.emit()
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user