From 89526af6290e3b0c91b8080276ac274a597a47a7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 9 Apr 2014 15:19:38 +0530 Subject: [PATCH] Refresh all editors after changing dictionaries --- src/calibre/gui2/tweak_book/boss.py | 9 ++++----- src/calibre/gui2/tweak_book/editor/image.py | 2 +- src/calibre/gui2/tweak_book/editor/text.py | 4 +++- src/calibre/gui2/tweak_book/editor/widget.py | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index 68ea275085..ef599c9b60 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -28,7 +28,7 @@ from calibre.ebooks.oeb.polish.utils import link_stylesheets, setup_cssutils_ser from calibre.gui2 import error_dialog, choose_files, question_dialog, info_dialog, choose_save_file from calibre.gui2.dialogs.confirm_delete import confirm from calibre.gui2.tweak_book import ( - set_current_container, current_container, tprefs, actions, editors, set_book_locale) + set_current_container, current_container, tprefs, actions, editors, set_book_locale, dictionaries) from calibre.gui2.tweak_book.undo import GlobalUndoHistory from calibre.gui2.tweak_book.file_list import NewFileDialog from calibre.gui2.tweak_book.save import SaveManager, save_container, find_first_existing_ancestor @@ -114,13 +114,12 @@ class Boss(QObject): def preferences(self): p = Preferences(self.gui) if p.exec_() == p.Accepted: + if p.dictionaries_changed: + dictionaries.clear_caches() for ed in editors.itervalues(): - ed.apply_settings() + ed.apply_settings(dictionaries_changed=p.dictionaries_changed) setup_cssutils_serialization() self.gui.apply_settings() - if p.dictionaries_changed: - pass # TODO: Clear dictionary caches and rerun syntax highlighting in - # all open editors so that spellings are updated def mark_requested(self, name, action): self.commit_dirty_opf() diff --git a/src/calibre/gui2/tweak_book/editor/image.py b/src/calibre/gui2/tweak_book/editor/image.py index 60a1c7a1de..a164ceac49 100644 --- a/src/calibre/gui2/tweak_book/editor/image.py +++ b/src/calibre/gui2/tweak_book/editor/image.py @@ -155,7 +155,7 @@ class Editor(QMainWindow): # there is no easy way to check two images for equality self.data = raw - def apply_settings(self, prefs=None): + def apply_settings(self, prefs=None, dictionaries_changed=False): pass def go_to_line(self, *args, **kwargs): diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index ed90f821d7..af095adf92 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -156,7 +156,7 @@ class TextEdit(PlainTextEdit): def sizeHint(self): return self.size_hint - def apply_settings(self, prefs=None): # {{{ + def apply_settings(self, prefs=None, dictionaries_changed=False): # {{{ prefs = prefs or tprefs self.setLineWrapMode(QPlainTextEdit.WidgetWidth if prefs['editor_line_wrap'] else QPlainTextEdit.NoWrap) theme = THEMES.get(prefs['editor_theme'], None) @@ -166,6 +166,8 @@ class TextEdit(PlainTextEdit): w = self.fontMetrics() self.space_width = w.width(' ') self.setTabStopWidth(prefs['editor_tab_stop_width'] * self.space_width) + if dictionaries_changed: + self.highlighter.rehighlight() def apply_theme(self, theme): self.theme = theme diff --git a/src/calibre/gui2/tweak_book/editor/widget.py b/src/calibre/gui2/tweak_book/editor/widget.py index 175eb4d2b0..d23a503c15 100644 --- a/src/calibre/gui2/tweak_book/editor/widget.py +++ b/src/calibre/gui2/tweak_book/editor/widget.py @@ -135,8 +135,8 @@ class Editor(QMainWindow): if current != raw: self.editor.replace_text(raw) - def apply_settings(self, prefs=None): - self.editor.apply_settings(prefs=None) + def apply_settings(self, prefs=None, dictionaries_changed=False): + self.editor.apply_settings(prefs=None, dictionaries_changed=dictionaries_changed) def set_focus(self): self.editor.setFocus(Qt.OtherFocusReason)