From 5ffd7bc23f3adb7a9e401d8f1685e6f41bdff546 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 22 Dec 2013 15:53:19 +0530 Subject: [PATCH] ToC Editor: Allow bulk renaming of items 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. --- src/calibre/gui2/toc/main.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/calibre/gui2/toc/main.py b/src/calibre/gui2/toc/main.py index b6c6b081f8..d9fc3ff955 100644 --- a/src/calibre/gui2/toc/main.py +++ b/src/calibre/gui2/toc/main.py @@ -490,6 +490,15 @@ class TreeWidget(QTreeWidget): # {{{ 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() @@ -531,6 +540,7 @@ class TreeWidget(QTreeWidget): # {{{ 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()) # }}}