From 78553a8284c9fe280835e5a819ed8d890c41183f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 26 Aug 2016 11:05:35 +0530 Subject: [PATCH] Edit Book: Allow restricting a search to the files currently open for editing --- src/calibre/gui2/tweak_book/file_list.py | 14 ++++++++++---- src/calibre/gui2/tweak_book/search.py | 8 +++++--- src/calibre/gui2/tweak_book/text_search.py | 6 ++++-- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/tweak_book/file_list.py b/src/calibre/gui2/tweak_book/file_list.py index 838dd75d94..cb7a1d3880 100644 --- a/src/calibre/gui2/tweak_book/file_list.py +++ b/src/calibre/gui2/tweak_book/file_list.py @@ -25,7 +25,7 @@ from calibre.ebooks.oeb.polish.replace import get_recommended_folders from calibre.ebooks.oeb.polish.cover import ( get_cover_page_name, get_raster_cover_name, is_raster_image) from calibre.gui2 import error_dialog, choose_files, question_dialog, elided_text, choose_save_file -from calibre.gui2.tweak_book import current_container, tprefs +from calibre.gui2.tweak_book import current_container, tprefs, editors from calibre.gui2.tweak_book.editor import syntax_from_mime from calibre.gui2.tweak_book.templates import template_for from calibre.utils.icu import sort_key @@ -647,7 +647,7 @@ class FileList(QTreeWidget): @property def searchable_names(self): - ans = {'text':OrderedDict(), 'styles':OrderedDict(), 'selected':OrderedDict()} + ans = {'text':OrderedDict(), 'styles':OrderedDict(), 'selected':OrderedDict(), 'open':OrderedDict()} for item in self.all_files: category = unicode(item.data(0, CATEGORY_ROLE) or '') mime = unicode(item.data(0, MIME_ROLE) or '') @@ -657,8 +657,14 @@ class FileList(QTreeWidget): ans[category][name] = syntax_from_mime(name, mime) if not ok and category == 'misc': ok = mime in {guess_type('a.'+x) for x in ('opf', 'ncx', 'txt', 'xml')} - if ok and item.isSelected(): - ans['selected'][name] = syntax_from_mime(name, mime) + if ok: + cats = [] + if item.isSelected(): + cats.append('selected') + if name in editors: + cats.append('open') + for cat in cats: + ans[cat][name] = syntax_from_mime(name, mime) return ans def export(self, name): diff --git a/src/calibre/gui2/tweak_book/search.py b/src/calibre/gui2/tweak_book/search.py index 619c9bce79..df8c841467 100644 --- a/src/calibre/gui2/tweak_book/search.py +++ b/src/calibre/gui2/tweak_book/search.py @@ -117,7 +117,7 @@ class WhereBox(QComboBox): def __init__(self, parent, emphasize=False): QComboBox.__init__(self) - self.addItems([_('Current file'), _('All text files'), _('All style files'), _('Selected files'), _('Marked text')]) + self.addItems([_('Current file'), _('All text files'), _('All style files'), _('Selected files'), _('Open files'), _('Marked text')]) self.setToolTip('' + _( ''' Where to search/replace: @@ -130,6 +130,8 @@ class WhereBox(QComboBox):
Search in all style (CSS) files
Selected files
Search in the files currently selected in the Files Browser
+
Open files
+
Search in the files currently open in the editor
Marked text
Search only within the marked text in the currently opened file. You can mark text using the Search menu.
''')) @@ -142,7 +144,7 @@ class WhereBox(QComboBox): @dynamic_property def where(self): - wm = {0:'current', 1:'text', 2:'styles', 3:'selected', 4:'selected-text'} + wm = {0:'current', 1:'text', 2:'styles', 3:'selected', 4:'open', 5:'selected-text'} def fget(self): return wm[self.currentIndex()] def fset(self, val): @@ -1185,7 +1187,7 @@ def initialize_search_request(state, action, current_editor, current_editor_name marked = False if where == 'current': editor = current_editor - elif where in {'styles', 'text', 'selected'}: + elif where in {'styles', 'text', 'selected', 'open'}: files = searchable_names[where] if current_editor_name in files: # Start searching in the current editor diff --git a/src/calibre/gui2/tweak_book/text_search.py b/src/calibre/gui2/tweak_book/text_search.py index a754567b95..4af6c11dfc 100644 --- a/src/calibre/gui2/tweak_book/text_search.py +++ b/src/calibre/gui2/tweak_book/text_search.py @@ -47,7 +47,7 @@ class WhereBox(QComboBox): def __init__(self, parent, emphasize=False): QComboBox.__init__(self) - self.addItems([_('Current file'), _('All text files'), _('Selected files')]) + self.addItems([_('Current file'), _('All text files'), _('Selected files'), _('Open files')]) self.setToolTip('' + _( ''' Where to search/replace: @@ -58,6 +58,8 @@ class WhereBox(QComboBox):
Search in all text (HTML) files
Selected files
Search in the files currently selected in the Files Browser
+
Open files
+
Search in the files currently open in the editor
''')) self.emphasize = emphasize self.ofont = QFont(self.font()) @@ -68,7 +70,7 @@ class WhereBox(QComboBox): @dynamic_property def where(self): - wm = {0:'current', 1:'text', 2:'selected'} + wm = {0:'current', 1:'text', 2:'selected', 3:'open'} def fget(self): return wm[self.currentIndex()] def fset(self, val):