From 62eb796b51790a32ea5b2d138cfc98eff3166324 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 9 Mar 2014 18:16:05 +0530 Subject: [PATCH] Edit book: Add a tool to easily open a file inside the book for editing by just typing a few characters from the file name. To use it press Ctrl+T in the editor or go to Edit->Quick open a file to edit' --- src/calibre/gui2/tweak_book/boss.py | 8 ++++++++ src/calibre/gui2/tweak_book/ui.py | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index f81d26cb1e..c20520445c 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -38,6 +38,7 @@ from calibre.gui2.tweak_book.editor import editor_from_syntax, syntax_from_mime from calibre.gui2.tweak_book.editor.insert_resource import get_resource_data, NewBook from calibre.gui2.tweak_book.preferences import Preferences from calibre.gui2.tweak_book.widgets import RationalizeFolders, MultiSplit, ImportForeign +from calibre.gui2.tweak_book.widgets import QuickOpen _diff_dialogs = [] @@ -1129,6 +1130,13 @@ class Boss(QObject): _('Editing files of type %s is not supported' % mime), show=True) return self.edit_file(name, syntax) + def quick_open(self): + c = current_container() + files = [name for name, mime in c.mime_map.iteritems() if c.exists(name) and syntax_from_mime(name, mime) is not None] + d = QuickOpen(files, parent=self.gui) + if d.exec_() == d.Accepted and d.selected_result is not None: + self.edit_file_requested(d.selected_result, None, c.mime_map[d.selected_result]) + # Editor basic controls {{{ def do_editor_undo(self): ed = self.gui.central.current_editor diff --git a/src/calibre/gui2/tweak_book/ui.py b/src/calibre/gui2/tweak_book/ui.py index 6915063535..935e8ba5d5 100644 --- a/src/calibre/gui2/tweak_book/ui.py +++ b/src/calibre/gui2/tweak_book/ui.py @@ -302,6 +302,8 @@ class Main(MainWindow): self.action_new_book = reg('book.png', _('Create &new, empty book'), self.boss.new_book, 'new-book', (), _('Create a new, empty book')) self.action_import_book = reg('book.png', _('&Import an HTML or DOCX file as a new book'), self.boss.import_book, 'import-book', (), _('Import an HTML or DOCX file as a new book')) + self.action_quick_edit = reg('modified.png', _('&Quick open a file to edit'), self.boss.quick_open, 'quick-open', ('Ctrl+T'), _( + 'Quickly open a file from the book to edit it')) # Editor actions group = _('Editor actions') @@ -430,6 +432,7 @@ class Main(MainWindow): f = b.addMenu(_('&File')) f.addAction(self.action_new_file) f.addAction(self.action_import_files) + f.addSeparator() f.addAction(self.action_open_book) f.addAction(self.action_new_book) f.addAction(self.action_import_book) @@ -455,6 +458,7 @@ class Main(MainWindow): e.addAction(self.action_editor_paste) e.addAction(self.action_insert_char) e.addSeparator() + e.addAction(self.action_quick_edit) e.addAction(self.action_preferences) e = b.addMenu(_('&Tools'))