Grammalecte  Check-in [e376521f18]

Overview
Comment:[tb] lexicon editor: export > use OS.File
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tb | multid
Files: files | file ages | folders
SHA3-256: e376521f18dce3b8f834743cd914a7a4d17e555c4f7a10f97c13c7c8f123b18d
User & Date: olr on 2018-03-17 16:48:01
Other Links: branch diff | manifest | tags
Context
2018-03-17
16:50
[tb] lexicon editor: useless function check-in: 187891a915 user: olr tags: tb, multid
16:48
[tb] lexicon editor: export > use OS.File check-in: e376521f18 user: olr tags: tb, multid
16:36
[tb] lexicon editor: export (attempt with FilePicker) check-in: 7260392d1d user: olr tags: tb, multid
Changes

Modified gc_lang/fr/tb/content/lex_editor.js from [bd1a477dcb] to [911ddf9a93].

497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520

521
522
523
524
525
526
527
    export: function () {
        let sJSON = JSON.stringify(this.oIBDAWG.getJSON());
        let xFilePicker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
        xFilePicker.init(window, "Enregistrer sous", Ci.nsIFilePicker.modeSave);
        xFilePicker.appendFilters(Ci.nsIFilePicker.filterAll | Ci.nsIFilePicker.filterText);
        xFilePicker.open(function (nReturnValue) {
            if (nReturnValue == Ci.nsIFilePicker.returnOK || nReturnValue == Ci.nsIFilePicker.returnReplace) {
                // write file 
                // OS.File.writeAtomic(xFilePicker.file.path, sJSON, {tmpPath: "file.txt.tmp"}); 

                // You can also optionally pass a flags parameter here. It defaults to
                // FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE;
                console.log(xFilePicker);
                let xOutStream = FileUtils.openSafeFileOutputStream(xFilePicker.file);
                let xConverter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
                xConverter.charset = "UTF-8";
                let xInStream = xConverter.convertToInputStream(sJSON);
                // The last argument (the callback) is optional.
                NetUtil.asyncCopy(xInStream, xOutStream, function (status) {
                    if (!Components.isSuccessCode(status)) {
                        console.log(status);
                        return;
                    }
                });

             }
        });
    }
}










|
|
|


<











>







497
498
499
500
501
502
503
504
505
506
507
508

509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
    export: function () {
        let sJSON = JSON.stringify(this.oIBDAWG.getJSON());
        let xFilePicker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
        xFilePicker.init(window, "Enregistrer sous", Ci.nsIFilePicker.modeSave);
        xFilePicker.appendFilters(Ci.nsIFilePicker.filterAll | Ci.nsIFilePicker.filterText);
        xFilePicker.open(function (nReturnValue) {
            if (nReturnValue == Ci.nsIFilePicker.returnOK || nReturnValue == Ci.nsIFilePicker.returnReplace) {
                // https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/OSFile.jsm
                OS.File.writeAtomic(xFilePicker.file.path, sJSON, {tmpPath: "file.txt.tmp"}); 
                /*
                // You can also optionally pass a flags parameter here. It defaults to
                // FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE;

                let xOutStream = FileUtils.openSafeFileOutputStream(xFilePicker.file);
                let xConverter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
                xConverter.charset = "UTF-8";
                let xInStream = xConverter.convertToInputStream(sJSON);
                // The last argument (the callback) is optional.
                NetUtil.asyncCopy(xInStream, xOutStream, function (status) {
                    if (!Components.isSuccessCode(status)) {
                        console.log(status);
                        return;
                    }
                });
                */
             }
        });
    }
}