From 0f276ad5a0d65b86b5cce4e026b2d51441ac901b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 3 Jul 2018 08:24:12 +0530 Subject: [PATCH] Edit book: Add a shortcut (Ctrl+Alt+Down) to edit the next file in the book spine. Fixes #1779616 [Editor: Add a keyboard shortcut to open the next file](https://bugs.launchpad.net/calibre/+bug/1779616) --- src/calibre/gui2/tweak_book/boss.py | 3 +++ src/calibre/gui2/tweak_book/file_list.py | 16 ++++++++++++++++ src/calibre/gui2/tweak_book/ui.py | 5 +++++ 3 files changed, 24 insertions(+) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index d30cdc8038..5964eba9a1 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -1451,6 +1451,9 @@ class Boss(QObject): _('Editing files of type %s is not supported' % mime), show=True) return self.edit_file(name, syntax) + def edit_next_file(self, backwards=False): + self.gui.file_list.edit_next_file(self.currently_editing, backwards) + def quick_open(self): if not self.ensure_book(_('No book is currently open. You must first open a book to edit.')): return diff --git a/src/calibre/gui2/tweak_book/file_list.py b/src/calibre/gui2/tweak_book/file_list.py index 72cce2fc46..78979fc2f2 100644 --- a/src/calibre/gui2/tweak_book/file_list.py +++ b/src/calibre/gui2/tweak_book/file_list.py @@ -734,6 +734,21 @@ class FileList(QTreeWidget): error_dialog(self, _('Cannot edit'), _('No item with the name: %s was found') % name, show=True) + def edit_next_file(self, currently_editing=None, backwards=False): + category = self.categories['text'] + seen_current = False + items = (category.child(i) for i in xrange(category.childCount())) + if backwards: + items = reversed(tuple(items)) + for item in items: + name = unicode(item.data(0, NAME_ROLE) or '') + if seen_current: + self._request_edit(item) + return True + if currently_editing == name: + seen_current = True + return False + @property def all_files(self): return (category.child(i) for category in self.categories.itervalues() for i in xrange(category.childCount())) @@ -982,6 +997,7 @@ class FileListWidget(QWidget): for x in ('delete_done', 'select_name', 'select_names', 'request_edit', 'mark_name_as_current', 'clear_currently_edited_name'): setattr(self, x, getattr(self.file_list, x)) self.setFocusProxy(self.file_list) + self.edit_next_file = self.file_list.edit_next_file def build(self, container, preserve_state=True): self.file_list.build(container, preserve_state=preserve_state) diff --git a/src/calibre/gui2/tweak_book/ui.py b/src/calibre/gui2/tweak_book/ui.py index 1e101e9daa..e1b2e99322 100644 --- a/src/calibre/gui2/tweak_book/ui.py +++ b/src/calibre/gui2/tweak_book/ui.py @@ -337,6 +337,11 @@ class Main(MainWindow): self.action_open_book = treg('document_open.png', _('&Open book'), self.boss.open_book, 'open-book', 'Ctrl+O', _('Open a new book')) self.action_open_book_folder = treg('mimetypes/dir.png', _('Open &folder (unzipped EPUB) as book'), partial(self.boss.open_book, open_folder=True), 'open-folder-as-book', (), _('Open a folder (unzipped EPUB) as a book')) + self.action_edit_next_file = treg('arrow-down.png', _('Edit &next file'), partial(self.boss.edit_next_file, backwards=False), + 'edit-next-file', 'Ctrl+Alt+Down', _('Edit the next file in the spine')) + self.action_edit_previous_file = treg('arrow-up.png', _('Edit &previous file'), partial(self.boss.edit_next_file, backwards=True), + 'edit-previous-file', 'Ctrl+Alt+Up', _('Edit the previous file in the spine')) + # Qt does not generate shortcut overrides for cmd+arrow on os x which # Qt does not generate shortcut overrides for cmd+arrow on os x which # means these shortcuts interfere with editing self.action_global_undo = treg('back.png', _('&Revert to before'), self.boss.do_global_undo, 'global-undo', () if isosx else 'Ctrl+Left',