Grammalecte  Check-in [d42cd2d56f]

Overview
Comment:[lo] text formatter editor: securise import/export
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | lo
Files: files | file ages | folders
SHA3-256: d42cd2d56fe7cb04747eeb85dfb027827e27fe94487ef7bff2fa2cec9f889a85
User & Date: olr on 2023-06-11 12:57:21
Other Links: manifest | tags
Context
2023-06-11
12:58
[lo] lexicon editor: add .json to exported file check-in: fc98962a37 user: olr tags: trunk, lo
12:57
[lo] text formatter editor: securise import/export check-in: d42cd2d56f user: olr tags: trunk, lo
11:28
[fr] màj dictionnaires check-in: 7d084c57ca user: olr tags: trunk, fr
Changes

Modified gc_lang/fr/oxt/TextFormatter/TextFormatterEditor.py from [82dc69b48f] to [fb4690325a].

1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
# Text Formatter Editor
# by Olivier R.
# License: MPL 2

import unohelper
import uno
import traceback
import platform

import os
import json
import re

import helpers
import tfe_strings as ui
import grammalecte.graphspell as sc








>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Text Formatter Editor
# by Olivier R.
# License: MPL 2

import unohelper
import uno
import traceback
import platform
import urllib.parse
import os
import json
import re

import helpers
import tfe_strings as ui
import grammalecte.graphspell as sc
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401
402
403
404
    def loadRules (self):
        try:
            xChild = self.xGLOptionNode.getByName("o_${lang}")
            sTFEditorOptions = xChild.getPropertyValue("tfe_rules")
            if not sTFEditorOptions:
                return
            self.dRules = json.loads(sTFEditorOptions)

            xGridDataModel = self.xGridModel.GridDataModel
            for sRuleName in self.dRules:
                xGridDataModel.addRow(xGridDataModel.RowCount + 1, self._getValuesForRow(sRuleName))
            xGridDataModel.sortByColumn(0, True)
        except:
            sMessage = traceback.format_exc()
            MessageBox(self.xDocument, sMessage, ui.get('error'), ERRORBOX)

    @_waitPointer
    def saveRules (self):
        try:







>
|
|
|
|







388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
    def loadRules (self):
        try:
            xChild = self.xGLOptionNode.getByName("o_${lang}")
            sTFEditorOptions = xChild.getPropertyValue("tfe_rules")
            if not sTFEditorOptions:
                return
            self.dRules = json.loads(sTFEditorOptions)
            if self.dRules:
                xGridDataModel = self.xGridModel.GridDataModel
                for sRuleName in self.dRules:
                    xGridDataModel.addRow(xGridDataModel.RowCount + 1, self._getValuesForRow(sRuleName))
                xGridDataModel.sortByColumn(0, True)
        except:
            sMessage = traceback.format_exc()
            MessageBox(self.xDocument, sMessage, ui.get('error'), ERRORBOX)

    @_waitPointer
    def saveRules (self):
        try:
423
424
425
426
427
428
429

430
431
432
433
434
435
436
            if nResult == 1:
                # lFile = xFilePicker.getSelectedFiles()
                lFile = xFilePicker.getFiles()
                #print(lFile)
                spfImported = lFile[0][5:].lstrip("/") # remove file://
                if platform.system() != "Windows":
                    spfImported = "/" + spfImported

        except:
            sMessage = traceback.format_exc()
            MessageBox(self.xDocument, sMessage, ui.get('error'), ERRORBOX)
            return
        if not spfImported or not os.path.isfile(spfImported):
            sMessage = ui.get('file_not_found') + "<" + spfImported + ">"
            MessageBox(self.xDocument, sMessage, ui.get('error'), ERRORBOX)







>







425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
            if nResult == 1:
                # lFile = xFilePicker.getSelectedFiles()
                lFile = xFilePicker.getFiles()
                #print(lFile)
                spfImported = lFile[0][5:].lstrip("/") # remove file://
                if platform.system() != "Windows":
                    spfImported = "/" + spfImported
                spfImported = urllib.parse.unquote(spfImported)
        except:
            sMessage = traceback.format_exc()
            MessageBox(self.xDocument, sMessage, ui.get('error'), ERRORBOX)
            return
        if not spfImported or not os.path.isfile(spfImported):
            sMessage = ui.get('file_not_found') + "<" + spfImported + ">"
            MessageBox(self.xDocument, sMessage, ui.get('error'), ERRORBOX)
472
473
474
475
476
477
478



479
480
481
482
483
484
            nResult = xFilePicker.execute()
            if nResult == 1:
                # lFile = xFilePicker.getSelectedFiles()
                lFile = xFilePicker.getFiles()
                spfExported = lFile[0][5:].lstrip("/") # remove file://
                if platform.system() != "Windows":
                    spfExported = "/" + spfExported



                #spfExported = os.path.join(os.path.expanduser("~"), "fr.personal.json")
                with open(spfExported, "w", encoding="utf-8") as hDst:
                    hDst.write(sText)
        except:
            sMessage = traceback.format_exc()
            MessageBox(self.xDocument, sMessage, ui.get('error'), ERRORBOX)







>
>
>






475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
            nResult = xFilePicker.execute()
            if nResult == 1:
                # lFile = xFilePicker.getSelectedFiles()
                lFile = xFilePicker.getFiles()
                spfExported = lFile[0][5:].lstrip("/") # remove file://
                if platform.system() != "Windows":
                    spfExported = "/" + spfExported
                spfExported = urllib.parse.unquote(spfExported)
                if not spfExported.endswith((".json", ".JSON")):
                    spfExported += ".json"
                #spfExported = os.path.join(os.path.expanduser("~"), "fr.personal.json")
                with open(spfExported, "w", encoding="utf-8") as hDst:
                    hDst.write(sText)
        except:
            sMessage = traceback.format_exc()
            MessageBox(self.xDocument, sMessage, ui.get('error'), ERRORBOX)