mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit Book: Allow restricting a search to the files currently open for editing
This commit is contained in:
parent
94e908b3c0
commit
78553a8284
@ -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):
|
||||
|
@ -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('<style>dd {margin-bottom: 1.5ex}</style>' + _(
|
||||
'''
|
||||
Where to search/replace:
|
||||
@ -130,6 +130,8 @@ class WhereBox(QComboBox):
|
||||
<dd>Search in all style (CSS) files</dd>
|
||||
<dt><b>Selected files</b></dt>
|
||||
<dd>Search in the files currently selected in the Files Browser</dd>
|
||||
<dt><b>Open files</b></dt>
|
||||
<dd>Search in the files currently open in the editor</dd>
|
||||
<dt><b>Marked text</b></dt>
|
||||
<dd>Search only within the marked text in the currently opened file. You can mark text using the Search menu.</dd>
|
||||
</dl>'''))
|
||||
@ -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
|
||||
|
@ -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('<style>dd {margin-bottom: 1.5ex}</style>' + _(
|
||||
'''
|
||||
Where to search/replace:
|
||||
@ -58,6 +58,8 @@ class WhereBox(QComboBox):
|
||||
<dd>Search in all text (HTML) files</dd>
|
||||
<dt><b>Selected files</b></dt>
|
||||
<dd>Search in the files currently selected in the Files Browser</dd>
|
||||
<dt><b>Open files</b></dt>
|
||||
<dd>Search in the files currently open in the editor</dd>
|
||||
</dl>'''))
|
||||
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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user