Index: gc_core/py/oxt/Grammalecte.py ================================================================== --- gc_core/py/oxt/Grammalecte.py +++ gc_core/py/oxt/Grammalecte.py @@ -1,21 +1,22 @@ -# -*- encoding: UTF-8 -*- # Grammalecte for Writer # License: MPL 2 # A derivative work of Lightproof from László Németh (http://cgit.freedesktop.org/libreoffice/lightproof/) import uno import unohelper +import json import sys import traceback from collections import deque from com.sun.star.linguistic2 import XProofreader, XSupportedLocales from com.sun.star.linguistic2 import ProofreadingResult from com.sun.star.lang import XServiceInfo, XServiceName, XServiceDisplayName from com.sun.star.lang import Locale +import helpers import grammalecte.${lang} as gce #import lightproof_handler_${implname} as opt_handler import Options @@ -36,17 +37,18 @@ gce.load("Writer") # GC options # opt_handler.load(xCurCtx) dOpt = Options.load(xCurCtx) gce.setOptions(dOpt) + # dictionaries options + self.loadUserDictionaries() # store for results of big paragraphs self.dResult = {} self.nMaxRes = 1500 self.lLastRes = deque(maxlen=self.nMaxRes) self.nRes = 0 - #oSpellChecker = gce.getSpellChecker(); - #oSpellChecker.setPersonalDictionary("fr.personal.json") + # XServiceName method implementations def getServiceName (self): return self.ImplementationName @@ -134,12 +136,24 @@ return gce.name # Grammalecte def getSpellChecker (self): return gce.getSpellChecker() + + def loadUserDictionaries (self): + try: + xSettingNode = helpers.getConfigSetting("/org.openoffice.Lightproof_grammalecte/Other/", False) + xChild = xSettingNode.getByName("o_${lang}") + if xChild.getPropertyValue("use_personal_dic"): + sJSON = xChild.getPropertyValue("personal_dic") + if sJSON: + oSpellChecker = gce.getSpellChecker(); + oSpellChecker.setPersonalDictionary(json.loads(sJSON)) + except: + traceback.print_exc() g_ImplementationHelper = unohelper.ImplementationHelper() g_ImplementationHelper.addImplementation(Grammalecte, "org.openoffice.comp.pyuno.Lightproof."+gce.pkg, ("com.sun.star.linguistic2.Proofreader",),) # g_ImplementationHelper.addImplementation( opt_handler.LightproofOptionsEventHandler, \ # "org.openoffice.comp.pyuno.LightproofOptionsEventHandler." + gce.pkg, ("com.sun.star.awt.XContainerWindowEventHandler",),)