mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
After bulk edit metadata, reselect previously selected books.
This commit is contained in:
commit
89c3e8ad87
@ -173,6 +173,8 @@ class EditMetadataAction(InterfaceAction):
|
||||
'''
|
||||
rows = [r.row() for r in \
|
||||
self.gui.library_view.selectionModel().selectedRows()]
|
||||
m = self.gui.library_view.model()
|
||||
ids = [m.id(r) for r in rows]
|
||||
if not rows or len(rows) == 0:
|
||||
d = error_dialog(self.gui, _('Cannot edit metadata'),
|
||||
_('No books selected'))
|
||||
@ -191,6 +193,7 @@ class EditMetadataAction(InterfaceAction):
|
||||
self.gui.tags_view.recount()
|
||||
if self.gui.cover_flow:
|
||||
self.gui.cover_flow.dataChanged()
|
||||
self.gui.library_view.select_rows(ids)
|
||||
|
||||
# Merge books {{{
|
||||
def merge_books(self, safe_merge=False):
|
||||
|
@ -220,6 +220,8 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
||||
if val:
|
||||
val.sort(cmp=lambda x,y: cmp(x.lower(), y.lower()))
|
||||
val = val[0]
|
||||
if txt == 'authors':
|
||||
val = val.replace('|', ',')
|
||||
else:
|
||||
val = ''
|
||||
else:
|
||||
@ -303,6 +305,8 @@ class MetadataBulkDialog(QDialog, Ui_MetadataBulkDialog):
|
||||
# The standard tags and authors values want to be lists.
|
||||
# All custom columns are to be strings
|
||||
val = fm['is_multiple'].join(val)
|
||||
elif field == 'authors':
|
||||
val = [v.replace('|', ',') for v in val]
|
||||
else:
|
||||
val = apply_pattern(val)
|
||||
|
||||
|
@ -328,6 +328,9 @@ Future conversion of these books will use the default settings.</string>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
|
@ -479,6 +479,36 @@ class BooksView(QTableView): # {{{
|
||||
sm = self.selectionModel()
|
||||
sm.select(index, sm.ClearAndSelect|sm.Rows)
|
||||
|
||||
def select_rows(self, identifiers, using_ids=True, change_current=True,
|
||||
scroll=True):
|
||||
'''
|
||||
Select rows identified by identifiers. identifiers can be a set of ids,
|
||||
row numbers or QModelIndexes.
|
||||
'''
|
||||
selmode = self.selectionMode()
|
||||
self.setSelectionMode(QAbstractItemView.MultiSelection)
|
||||
try:
|
||||
rows = set([x.row() if hasattr(x, 'row') else x for x in
|
||||
identifiers])
|
||||
if using_ids:
|
||||
rows = set([])
|
||||
identifiers = set(identifiers)
|
||||
m = self.model()
|
||||
for row in range(m.rowCount(QModelIndex())):
|
||||
if m.id(row) in identifiers:
|
||||
rows.add(row)
|
||||
if rows:
|
||||
row = list(sorted(rows))[0]
|
||||
if change_current:
|
||||
self.set_current_row(row, select=False)
|
||||
if scroll:
|
||||
self.scroll_to_row(row)
|
||||
self.clearSelection()
|
||||
for r in rows:
|
||||
self.selectRow(r)
|
||||
finally:
|
||||
self.setSelectionMode(selmode)
|
||||
|
||||
def close(self):
|
||||
self._model.close()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user