mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit book: Add an option to automatically beautify individual files whenever they are opened for editing. Look under "Editor Settings" in the Edit Book Preferences.
This commit is contained in:
parent
37fcd4093b
commit
22d59bac3c
@ -39,6 +39,7 @@ d['preview_minimum_font_size'] = 8
|
|||||||
d['remove_existing_links_when_linking_sheets'] = True
|
d['remove_existing_links_when_linking_sheets'] = True
|
||||||
d['charmap_favorites'] = list(map(ord, '\xa0\u2002\u2003\u2009\xad' '‘’“”‹›«»‚„' '—–§¶†‡©®™' '→⇒•·°±−×÷¼½½¾' '…µ¢£€¿¡¨´¸ˆ˜' 'ÀÁÂÃÄÅÆÇÈÉÊË' 'ÌÍÎÏÐÑÒÓÔÕÖØ' 'ŒŠÙÚÛÜÝŸÞßàá' 'âãäåæçèéêëìí' 'îïðñòóôõöøœš' 'ùúûüýÿþªºαΩ∞')) # noqa
|
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['folders_for_types'] = {'style':'styles', 'image':'images', 'font':'fonts', 'audio':'audio', 'video':'video'}
|
||||||
|
d['pretty_print_on_open'] = False
|
||||||
|
|
||||||
del d
|
del d
|
||||||
|
|
||||||
|
@ -1086,6 +1086,8 @@ class Boss(QObject):
|
|||||||
data = use_template
|
data = use_template
|
||||||
editor = editors[name] = editor_from_syntax(syntax, self.gui.editor_tabs)
|
editor = editors[name] = editor_from_syntax(syntax, self.gui.editor_tabs)
|
||||||
self.init_editor(name, editor, data, use_template=bool(use_template))
|
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)
|
self.show_editor(name)
|
||||||
return editor
|
return editor
|
||||||
|
|
||||||
|
@ -136,6 +136,9 @@ class Editor(QMainWindow):
|
|||||||
def number_of_lines(self):
|
def number_of_lines(self):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def pretty_print(self, name):
|
||||||
|
return False
|
||||||
|
|
||||||
def get_raw_data(self):
|
def get_raw_data(self):
|
||||||
return self.canvas.get_image_data(quality=self.quality)
|
return self.canvas.get_image_data(quality=self.quality)
|
||||||
|
|
||||||
|
@ -283,7 +283,10 @@ class Editor(QMainWindow):
|
|||||||
from calibre.ebooks.oeb.polish.pretty import pretty_html, pretty_css, pretty_xml
|
from calibre.ebooks.oeb.polish.pretty import pretty_html, pretty_css, pretty_xml
|
||||||
if self.syntax in {'css', 'html', 'xml'}:
|
if self.syntax in {'css', 'html', 'xml'}:
|
||||||
func = {'css':pretty_css, 'xml':pretty_xml}.get(self.syntax, pretty_html)
|
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 True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -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'))
|
lw.setText(_('Show the name of the current character before the cursor along with the line and column number'))
|
||||||
l.addRow(lw)
|
l.addRow(lw)
|
||||||
|
|
||||||
|
lw = self('pretty_print_on_open')
|
||||||
|
lw.setText(_('Beautify individual files automatically when they are opened'))
|
||||||
|
lw.setToolTip('<p>' + _(
|
||||||
|
'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):
|
class IntegrationSettings(BasicSettings):
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user