mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-02 21:15:14 +02:00
Fix #7271 (Books are deselected after sending to device)
This commit is contained in:
parent
35008f833f
commit
50f100bee8
2 changed files with 34 additions and 2 deletions
|
|
@ -1370,8 +1370,9 @@ def books_uploaded(self, job):
|
|||
# If it does not, then do it here.
|
||||
if not self.set_books_in_library(self.booklists(), reset=True):
|
||||
self.upload_booklists()
|
||||
self.book_on_device(None, reset=True)
|
||||
self.refresh_ondevice()
|
||||
with self.library_view.preserve_selected_books:
|
||||
self.book_on_device(None, reset=True)
|
||||
self.refresh_ondevice()
|
||||
|
||||
view = self.card_a_view if on_card == 'carda' else \
|
||||
self.card_b_view if on_card == 'cardb' else self.memory_view
|
||||
|
|
|
|||
|
|
@ -22,6 +22,26 @@
|
|||
from calibre.constants import filesystem_encoding
|
||||
from calibre import force_unicode
|
||||
|
||||
class PreserveSelection(object): # {{{
|
||||
|
||||
'''
|
||||
Save the set of selected books at enter time. If at exit time there are no
|
||||
selected books, restore the previous selection.
|
||||
'''
|
||||
|
||||
def __init__(self, view):
|
||||
self.view = view
|
||||
self.selected_ids = []
|
||||
|
||||
def __enter__(self):
|
||||
self.selected_ids = self.view.get_selected_ids()
|
||||
|
||||
def __exit__(self, *args):
|
||||
current = self.view.get_selected_ids()
|
||||
if not current:
|
||||
self.view.select_rows(self.selected_ids, using_ids=True)
|
||||
# }}}
|
||||
|
||||
class BooksView(QTableView): # {{{
|
||||
|
||||
files_dropped = pyqtSignal(object)
|
||||
|
|
@ -58,6 +78,7 @@ def __init__(self, parent, modelcls=BooksModel):
|
|||
self.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
self.setSortingEnabled(True)
|
||||
self.selectionModel().currentRowChanged.connect(self._model.current_changed)
|
||||
self.preserve_selected_books = PreserveSelection(self)
|
||||
|
||||
# {{{ Column Header setup
|
||||
self.can_add_columns = True
|
||||
|
|
@ -613,6 +634,16 @@ def select_rows(self, identifiers, using_ids=True, change_current=True,
|
|||
sel.select(m.index(row, 0), m.index(row, max_col))
|
||||
sm.select(sel, sm.ClearAndSelect)
|
||||
|
||||
def get_selected_ids(self):
|
||||
ans = []
|
||||
m = self.model()
|
||||
for idx in self.selectedIndexes():
|
||||
r = idx.row()
|
||||
i = m.id(r)
|
||||
if i not in ans:
|
||||
ans.append(i)
|
||||
return ans
|
||||
|
||||
def close(self):
|
||||
self._model.close()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue