Option to run filter style info on only the file being edited currently

This commit is contained in:
Kovid Goyal 2014-05-07 15:26:17 +05:30
parent 1767c90680
commit cc07a5d77d
2 changed files with 25 additions and 4 deletions

View File

@ -18,7 +18,7 @@ from calibre import prints, isbytestring
from calibre.ptempfile import PersistentTemporaryDirectory, TemporaryDirectory from calibre.ptempfile import PersistentTemporaryDirectory, TemporaryDirectory
from calibre.ebooks.oeb.base import urlnormalize from calibre.ebooks.oeb.base import urlnormalize
from calibre.ebooks.oeb.polish.main import SUPPORTED, tweak_polish from calibre.ebooks.oeb.polish.main import SUPPORTED, tweak_polish
from calibre.ebooks.oeb.polish.container import get_container as _gc, clone_container, guess_type, OEB_FONTS from calibre.ebooks.oeb.polish.container import get_container as _gc, clone_container, guess_type, OEB_FONTS, OEB_DOCS, OEB_STYLES
from calibre.ebooks.oeb.polish.cover import mark_as_cover, mark_as_titlepage from calibre.ebooks.oeb.polish.cover import mark_as_cover, mark_as_titlepage
from calibre.ebooks.oeb.polish.css import filter_css from calibre.ebooks.oeb.polish.css import filter_css
from calibre.ebooks.oeb.polish.pretty import fix_all_html, pretty_all from calibre.ebooks.oeb.polish.pretty import fix_all_html, pretty_all
@ -677,11 +677,21 @@ class Boss(QObject):
def filter_css(self): def filter_css(self):
self.commit_all_editors_to_container() self.commit_all_editors_to_container()
d = FilterCSS(parent=self.gui) c = current_container()
ed = self.gui.central.current_editor
for name, q in editors.iteritems():
if ed is q:
current_name = name
break
else:
current_name = None
if current_name and c.mime_map[current_name] not in OEB_DOCS | OEB_STYLES:
current_name = None
d = FilterCSS(current_name=current_name, parent=self.gui)
if d.exec_() == d.Accepted and d.filtered_properties: if d.exec_() == d.Accepted and d.filtered_properties:
self.add_savepoint(_('Before: Filter style information')) self.add_savepoint(_('Before: Filter style information'))
with BusyCursor(): with BusyCursor():
changed = filter_css(current_container(), d.filtered_properties) changed = filter_css(current_container(), d.filtered_properties, names=d.filter_names)
if changed: if changed:
self.apply_container_update_to_gui() self.apply_container_update_to_gui()
self.show_current_diff() self.show_current_diff()

View File

@ -926,7 +926,8 @@ class InsertSemantics(Dialog):
class FilterCSS(Dialog): # {{{ class FilterCSS(Dialog): # {{{
def __init__(self, parent=None): def __init__(self, current_name=None, parent=None):
self.current_name = current_name
Dialog.__init__(self, _('Filter Style Information'), 'filter-css', parent=parent) Dialog.__init__(self, _('Filter Style Information'), 'filter-css', parent=parent)
def setup_ui(self): def setup_ui(self):
@ -951,8 +952,18 @@ class FilterCSS(Dialog): # {{{
l.addRow(_('&Other CSS properties:'), o) l.addRow(_('&Other CSS properties:'), o)
o.setToolTip(f.filter_css_others.toolTip()) o.setToolTip(f.filter_css_others.toolTip())
if self.current_name is not None:
self.filter_current = c = QCheckBox(_('Only filter CSS in the current file (%s)') % self.current_name)
l.addRow(c)
l.addRow(self.bb) l.addRow(self.bb)
@property
def filter_names(self):
if self.current_name is not None and self.filter_current.isChecked():
return (self.current_name,)
return ()
@property @property
def filtered_properties(self): def filtered_properties(self):
ans = set() ans = set()