diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index c1f36621c8..976780dd77 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -18,7 +18,7 @@ from calibre import prints, isbytestring from calibre.ptempfile import PersistentTemporaryDirectory, TemporaryDirectory from calibre.ebooks.oeb.base import urlnormalize 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.css import filter_css from calibre.ebooks.oeb.polish.pretty import fix_all_html, pretty_all @@ -677,11 +677,21 @@ class Boss(QObject): def filter_css(self): 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: self.add_savepoint(_('Before: Filter style information')) with BusyCursor(): - changed = filter_css(current_container(), d.filtered_properties) + changed = filter_css(current_container(), d.filtered_properties, names=d.filter_names) if changed: self.apply_container_update_to_gui() self.show_current_diff() diff --git a/src/calibre/gui2/tweak_book/widgets.py b/src/calibre/gui2/tweak_book/widgets.py index d82ea589e1..fc50c53b71 100644 --- a/src/calibre/gui2/tweak_book/widgets.py +++ b/src/calibre/gui2/tweak_book/widgets.py @@ -926,7 +926,8 @@ class InsertSemantics(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) def setup_ui(self): @@ -951,8 +952,18 @@ class FilterCSS(Dialog): # {{{ l.addRow(_('&Other CSS properties:'), o) 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) + @property + def filter_names(self): + if self.current_name is not None and self.filter_current.isChecked(): + return (self.current_name,) + return () + @property def filtered_properties(self): ans = set()