Grammalecte  Diff

Differences From Artifact [82dc69b48f]:

To Artifact [fb4690325a]:


1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
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
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)
                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
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
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)