Index: gc_lang/fr/oxt/DictOptions/LexiconEditor.py ================================================================== --- gc_lang/fr/oxt/DictOptions/LexiconEditor.py +++ gc_lang/fr/oxt/DictOptions/LexiconEditor.py @@ -4,10 +4,11 @@ import unohelper import uno import json import re +import os import traceback import helpers import lxe_strings import grammalecte.graphspell as sc @@ -20,10 +21,22 @@ import TagsInfo from com.sun.star.task import XJobExecutor from com.sun.star.awt import XActionListener from com.sun.star.awt import XKeyListener + +from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK +# BUTTONS_OK, BUTTONS_OK_CANCEL, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL, BUTTONS_RETRY_CANCEL, BUTTONS_ABORT_IGNORE_RETRY +# DEFAULT_BUTTON_OK, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_RETRY, DEFAULT_BUTTON_YES, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_IGNORE +from com.sun.star.awt.MessageBoxType import INFOBOX # MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX + +def MessageBox (xDocument, sMsg, sTitle, nBoxType=INFOBOX, nBoxButtons=BUTTONS_OK): + xParentWin = xDocument.CurrentController.Frame.ContainerWindow + ctx = uno.getComponentContext() + xToolkit = ctx.ServiceManager.createInstanceWithContext("com.sun.star.awt.Toolkit", ctx) + xMsgBox = xToolkit.createMessageBox(xParentWin, nBoxType, nBoxButtons, sTitle, sMsg) + return xMsgBox.execute() def _waitPointer (funcDecorated): def wrapper (*args, **kwargs): # self is the first parameter if the decorator is applied on a object @@ -261,10 +274,12 @@ self.xContainer.getControl('add_button').setActionCommand('Add') self.xContainer.getControl('delete_button').addActionListener(self) self.xContainer.getControl('delete_button').setActionCommand('Delete') self.xContainer.getControl('save_button').addActionListener(self) self.xContainer.getControl('save_button').setActionCommand('Save') + self.xContainer.getControl('export_button').addActionListener(self) + self.xContainer.getControl('export_button').setActionCommand('Export') self.xContainer.getControl('close_button').addActionListener(self) self.xContainer.getControl('close_button').setActionCommand('Close') self.xContainer.setVisible(False) xToolkit = self.xSvMgr.createInstanceWithContext('com.sun.star.awt.ExtToolkit', self.ctx) self.xContainer.createPeer(xToolkit, None) @@ -296,10 +311,12 @@ self.saveLexicon() elif xActionEvent.ActionCommand == "Import": self.importDictionary() elif xActionEvent.ActionCommand == "Export": self.exportDictionary() + elif xActionEvent.ActionCommand == 'Info': + pass elif xActionEvent.ActionCommand == "Close": self.xContainer.endExecute() except: traceback.print_exc() @@ -539,20 +556,34 @@ @_waitPointer def importDictionary (self): pass - @_waitPointer def exportDictionary (self): - xFilePicker = self.xSvMgr.createInstanceWithContext('com.sun.star.ui.dialogs.SystemFilePicker', self.ctx) - xFilePicker.appendFilter("Supported files", "*.json; *.bdic") + try: + spfExported = os.path.join(os.environ['USERPROFILE'], "fr.personal.json") + xChild = self.xSettingNode.getByName("o_fr") + sJSON = xChild.getPropertyValue("personal_dic") + if sJSON: + with open(spfExported, "w", encoding="utf-8") as hDst: + hDst.write(sJSON) + sMessage = self.dUI.get('export_message', "#err_msg: %s") % spfExported + else: + sMessage = self.dUI.get('empty_dictionary', "#err") + except: + sMessage = traceback.format_exc() + MessageBox(self.xDocument, sMessage, self.dUI.get('export_title', "#err")) + + # FilePicker doesn’t work at all… + #xFilePicker = self.xSvMgr.createInstanceWithContext('com.sun.star.ui.dialogs.SystemFilePicker', self.ctx) + #xFilePicker.appendFilter("Supported files", "*.json; *.bdic") #xFilePicker.setDisplayDirectory("") #xFilePicker.setMultiSelectionMode(True) - nResult = xFilePicker.execute() - if nResult == 1: - pass + #nResult = xFilePicker.execute() + #if nResult == 1: + #pass #lFile = xFilePicker.getSelectedFiles() #lFile = xFilePicker.getFiles() #g_ImplementationHelper = unohelper.ImplementationHelper() #g_ImplementationHelper.addImplementation(LexiconEditor, 'net.grammalecte.LexiconEditor', ('com.sun.star.task.Job',)) Index: gc_lang/fr/oxt/DictOptions/lxe_strings.py ================================================================== --- gc_lang/fr/oxt/DictOptions/lxe_strings.py +++ gc_lang/fr/oxt/DictOptions/lxe_strings.py @@ -67,10 +67,13 @@ # Dictionary "dictionary_section": "Dictionnaire personnel", "save_date_label": "Date d’enregistrement :", "num_of_entries_label": "Nombre d’entrées :", "export_button": "Exporter", + "export_title": "Exportation du dictionnaire", + "export_message": "Fichier exporté : ‹%s>", + "empty_dictionary": "Le dictionnaire est vide. Aucun fichier créé.", "void": "[néant]", # "close_button": "Fermer", },