Refresh all editors after changing dictionaries

This commit is contained in:
Kovid Goyal 2014-04-09 15:19:38 +05:30
parent 01a034b848
commit 89526af629
4 changed files with 10 additions and 9 deletions

View File

@ -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()

View File

@ -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):

View File

@ -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

View File

@ -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)