Skip to content

Commit

Permalink
ToC Editor: Allow bulk renaming of items
Browse files Browse the repository at this point in the history
ToC Editor: Allow bulk renaming of items. Simply select the items you
want to rename, right click and choose bulk rename. Useful if, for
instance, you want to rename all the items to be Chapter 1, Chapter 2
and so on.
  • Loading branch information
kovidgoyal committed Dec 22, 2013
1 parent ff33790 commit 5ffd7bc
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/calibre/gui2/toc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ def title_case(self):
t = unicode(item.data(0, Qt.DisplayRole).toString())
item.setData(0, Qt.DisplayRole, titlecase(t))

def bulk_rename(self):
from calibre.gui2.tweak_book.file_list import get_bulk_rename_settings
sort_map = {item:i for i, item in enumerate(self.iteritems())}
items = sorted(self.selectedItems(), key=lambda x:sort_map.get(x, -1))
fmt, num = get_bulk_rename_settings(self, len(items), msg=_(
'All selected items will be renamed to the form prefix-number'), sanitize=lambda x:x, leading_zeros=False)
for i, item in enumerate(items):
item.setData(0, Qt.DisplayRole, fmt % (num + i))

def keyPressEvent(self, ev):
if ev.key() == Qt.Key_Left and ev.modifiers() & Qt.CTRL:
self.move_left()
Expand Down Expand Up @@ -531,6 +540,7 @@ def key(k):
m.addAction(QIcon(I('forward.png')), (_('Indent "%s"')%ci)+key(Qt.Key_Right), self.move_right)
m.addAction(QIcon(I('edit_input.png')), _('Change the location this entry points to'), self.edit_item)
m.addAction(_('Change all selected items to title case'), self.title_case)
m.addAction(QIcon(I('modified.png')), _('Bulk rename all selected items'), self.bulk_rename)
m.exec_(QCursor.pos())
# }}}

Expand Down

0 comments on commit 5ffd7bc

Please sign in to comment.