Fix #1051135 (Cursor position after multiple deletes)

This commit is contained in:
Kovid Goyal 2012-10-03 10:34:29 +05:30
parent fb672d3264
commit 030f98bec9
2 changed files with 40 additions and 6 deletions

View File

@ -286,6 +286,14 @@ class DeleteAction(InterfaceAction):
current_row = view.row_count() - 1
view.set_current_row(current_row)
def library_ids_deleted2(self, ids_deleted, next_id=None):
view = self.gui.library_view
current_row = None
if next_id is not None:
rmap = view.ids_to_rows([next_id])
current_row = rmap.get(next_id, None)
self.library_ids_deleted(ids_deleted, current_row=current_row)
def delete_books(self, *args):
'''
Delete selected books from device or library.
@ -325,16 +333,13 @@ class DeleteAction(InterfaceAction):
'removed from your calibre library. Are you sure?')
+'</p>', 'library_delete_books', self.gui):
return
ci = view.currentIndex()
row = None
if ci.isValid():
row = ci.row()
next_id = view.next_id
if len(rows) < 5:
view.model().delete_books_by_id(to_delete_ids)
self.library_ids_deleted(to_delete_ids, row)
self.library_ids_deleted2(to_delete_ids, next_id=next_id)
else:
self.__md = MultiDeleter(self.gui, to_delete_ids,
partial(self.library_ids_deleted, current_row=row))
partial(self.library_ids_deleted2, next_id=next_id))
# Device view is visible.
else:
if self.gui.stack.currentIndex() == 1:

View File

@ -867,6 +867,35 @@ class BooksView(QTableView): # {{{
break
return property(fget=fget, fset=fset)
@property
def next_id(self):
'''
Return the id of the 'next' row (i.e. the first unselected row after
the current row).
'''
ci = self.currentIndex()
if not ci.isValid():
return None
selected_rows = frozenset([i.row() for i in self.selectedIndexes() if
i.isValid()])
column = ci.column()
for i in xrange(ci.row()+1, self.row_count()):
if i in selected_rows: continue
try:
return self.model().id(self.model().index(i, column))
except:
pass
# No unselected rows after the current row, look before
for i in xrange(ci.row()-1, -1, -1):
if i in selected_rows: continue
try:
return self.model().id(self.model().index(i, column))
except:
pass
return None
def close(self):
self._model.close()