mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-05 08:40:13 -04:00
Edit book: A new action to toggle line wrapping mode in all code editors. Can be assigned via Preferences->Keyboard shortcuts->Global actions
or added to the toolbar via Preferences->Toolbars->Book wide actions
This commit is contained in:
parent
de55056f20
commit
7eb17c1cd5
@ -1844,6 +1844,13 @@ class Boss(QObject):
|
||||
if ed is not None:
|
||||
ed.paste()
|
||||
|
||||
def toggle_line_wrapping_in_all_editors(self):
|
||||
tprefs['editor_line_wrap'] ^= True
|
||||
yes = tprefs['editor_line_wrap']
|
||||
for ed in editors.values():
|
||||
if getattr(ed, 'editor', None) and hasattr(ed.editor, 'apply_line_wrap_mode'):
|
||||
ed.editor.apply_line_wrap_mode(yes)
|
||||
|
||||
def editor_data_changed(self, editor):
|
||||
self.gui.preview.start_refresh_timer()
|
||||
for name, ed in iteritems(editors):
|
||||
|
@ -226,10 +226,13 @@ class TextEdit(PlainTextEdit):
|
||||
def sizeHint(self):
|
||||
return self.size_hint
|
||||
|
||||
def apply_line_wrap_mode(self, yes: bool = True) -> None:
|
||||
self.setLineWrapMode(QPlainTextEdit.LineWrapMode.WidgetWidth if yes else QPlainTextEdit.LineWrapMode.NoWrap)
|
||||
|
||||
def apply_settings(self, prefs=None, dictionaries_changed=False): # {{{
|
||||
prefs = prefs or tprefs
|
||||
self.setAcceptDrops(prefs.get('editor_accepts_drops', True))
|
||||
self.setLineWrapMode(QPlainTextEdit.LineWrapMode.WidgetWidth if prefs['editor_line_wrap'] else QPlainTextEdit.LineWrapMode.NoWrap)
|
||||
self.apply_line_wrap_mode(prefs['editor_line_wrap'])
|
||||
with suppress(Exception):
|
||||
self.setCursorWidth(int(prefs.get('editor_cursor_width', 1)))
|
||||
theme = get_theme(prefs['editor_theme'])
|
||||
|
@ -411,6 +411,9 @@ class Main(MainWindow):
|
||||
self.boss.import_book, 'import-book', (), _('Import an HTML or DOCX file as a new book'))
|
||||
self.action_quick_edit = treg('modified.png', _('&Quick open a file to edit'), self.boss.quick_open, 'quick-open', ('Ctrl+T'), _(
|
||||
'Quickly open a file from the book to edit it'))
|
||||
self.action_editor_toggle_wrap = treg(
|
||||
'format-justify-fill.png', _('Toggle code line &wrapping'), self.boss.toggle_line_wrapping_in_all_editors, 'editor-toggle-wrap', (), _(
|
||||
'Toggle line wrapping in all code editor tabs'))
|
||||
|
||||
# Editor actions
|
||||
group = _('Editor actions')
|
||||
|
Loading…
x
Reference in New Issue
Block a user