diff --git a/src/calibre/gui2/tweak_book/__init__.py b/src/calibre/gui2/tweak_book/__init__.py index e4a6586c94..1f2f5fa1bc 100644 --- a/src/calibre/gui2/tweak_book/__init__.py +++ b/src/calibre/gui2/tweak_book/__init__.py @@ -39,6 +39,7 @@ d['preview_minimum_font_size'] = 8 d['remove_existing_links_when_linking_sheets'] = True d['charmap_favorites'] = list(map(ord, '\xa0\u2002\u2003\u2009\xad' '‘’“”‹›«»‚„' '—–§¶†‡©®™' '→⇒•·°±−×÷¼½½¾' '…µ¢£€¿¡¨´¸ˆ˜' 'ÀÁÂÃÄÅÆÇÈÉÊË' 'ÌÍÎÏÐÑÒÓÔÕÖØ' 'ŒŠÙÚÛÜÝŸÞßàá' 'âãäåæçèéêëìí' 'îïðñòóôõöøœš' 'ùúûüýÿþªºαΩ∞')) # noqa d['folders_for_types'] = {'style':'styles', 'image':'images', 'font':'fonts', 'audio':'audio', 'video':'video'} +d['pretty_print_on_open'] = False del d diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 28a091158a..99fa96c094 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -1086,6 +1086,8 @@ class Boss(QObject): data = use_template editor = editors[name] = editor_from_syntax(syntax, self.gui.editor_tabs) self.init_editor(name, editor, data, use_template=bool(use_template)) + if tprefs['pretty_print_on_open']: + editor.pretty_print(name) self.show_editor(name) return editor diff --git a/src/calibre/gui2/tweak_book/editor/image.py b/src/calibre/gui2/tweak_book/editor/image.py index 070c36bc47..60a1c7a1de 100644 --- a/src/calibre/gui2/tweak_book/editor/image.py +++ b/src/calibre/gui2/tweak_book/editor/image.py @@ -136,6 +136,9 @@ class Editor(QMainWindow): def number_of_lines(self): return 0 + def pretty_print(self, name): + return False + def get_raw_data(self): return self.canvas.get_image_data(quality=self.quality) diff --git a/src/calibre/gui2/tweak_book/editor/widget.py b/src/calibre/gui2/tweak_book/editor/widget.py index 7f5b423223..ea21c4737e 100644 --- a/src/calibre/gui2/tweak_book/editor/widget.py +++ b/src/calibre/gui2/tweak_book/editor/widget.py @@ -283,7 +283,10 @@ class Editor(QMainWindow): from calibre.ebooks.oeb.polish.pretty import pretty_html, pretty_css, pretty_xml if self.syntax in {'css', 'html', 'xml'}: func = {'css':pretty_css, 'xml':pretty_xml}.get(self.syntax, pretty_html) - self.editor.replace_text(func(current_container(), name, unicode(self.editor.toPlainText())).decode('utf-8')) + original_text = unicode(self.editor.toPlainText()) + prettied_text = func(current_container(), name, original_text).decode('utf-8') + if original_text != prettied_text: + self.editor.replace_text(prettied_text) return True return False diff --git a/src/calibre/gui2/tweak_book/preferences.py b/src/calibre/gui2/tweak_book/preferences.py index 8d07fc7221..c605765463 100644 --- a/src/calibre/gui2/tweak_book/preferences.py +++ b/src/calibre/gui2/tweak_book/preferences.py @@ -184,6 +184,13 @@ class EditorSettings(BasicSettings): lw.setText(_('Show the name of the current character before the cursor along with the line and column number')) l.addRow(lw) + lw = self('pretty_print_on_open') + lw.setText(_('Beautify individual files automatically when they are opened')) + lw.setToolTip('
' + _( + 'This will cause the beautify current file action to be performed automatically every' + ' time you open a HTML/CSS/etc. file for editing.')) + l.addRow(lw) + class IntegrationSettings(BasicSettings): def __init__(self, parent=None):