From 244935d7e20712b1542a9c4bbb3b49c950f809f1 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Thu, 20 Oct 2022 21:44:08 +0200 Subject: [PATCH] Adding settings for editor. Also fixing bug with GreetScreen not setting settings in the menu bar, and adding translations. --- LogarithmPlotter/i18n/lp_de.ts | 67 ++++++++++++++----- LogarithmPlotter/i18n/lp_en.ts | 67 ++++++++++++++----- LogarithmPlotter/i18n/lp_es.ts | 67 ++++++++++++++----- LogarithmPlotter/i18n/lp_fr.ts | 67 ++++++++++++++----- LogarithmPlotter/i18n/lp_hu.ts | 67 ++++++++++++++----- LogarithmPlotter/i18n/lp_nb_NO.ts | 67 ++++++++++++++----- LogarithmPlotter/i18n/lp_template.ts | 67 ++++++++++++++----- .../eu/ad5001/LogarithmPlotter/AppMenuBar.qml | 39 +++++++++++ .../LogarithmPlotter/Popup/GreetScreen.qml | 58 +++++++++++++--- .../Setting/ExpressionEditor.qml | 37 +++++----- LogarithmPlotter/util/config.py | 16 ++++- 11 files changed, 481 insertions(+), 138 deletions(-) diff --git a/LogarithmPlotter/i18n/lp_de.ts b/LogarithmPlotter/i18n/lp_de.ts index 6b28082..e2d67a6 100644 --- a/LogarithmPlotter/i18n/lp_de.ts +++ b/LogarithmPlotter/i18n/lp_de.ts @@ -103,52 +103,72 @@ LaTeX-Rendering aktivieren - + + Expression editor + + + + + Automatically close parenthesises and brackets + + + + + Enable syntax highlighting + + + + + Enable autocompletion + + + + &Help &Hilfe - + &Source code &Quellcode - + &Report a bug Fehler &Melden - + &User manual &Benutzerhandbuch - + &Changelog &Changelog - + &Help translating! &Hilfe beim Übersetzen! - + &Thanks &Danksagungen - + &About &Übrigens - + Save unsaved changes? Änderungen speichern? - + This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? Diese Grafik enthält ungespeicherte Änderungen. Dadurch gehen alle ungespeicherten Daten verloren. Fortfahren? @@ -315,32 +335,47 @@ These settings can be changed at any time from the "Settings" menu. - + Check for updates on startup (requires online connectivity) Beim Start nach Updates suchen (Online-Verbindung erforderlich) - + Reset redo stack when a new action is added to history Redo-Stapel zurücksetzen, wenn eine neue Aktion zur Historie hinzugefügt wird - + Enable LaTeX rendering LaTeX-Rendering aktivieren - + + Automatically close parenthesises and brackets in expressions + + + + + Enable syntax highlighting for expressions + + + + + Enable autocompletion interface in expression editor + + + + User manual Benutzerhandbuch - + Changelog Changelog - + Done Schließen diff --git a/LogarithmPlotter/i18n/lp_en.ts b/LogarithmPlotter/i18n/lp_en.ts index 9471a63..f324ea6 100644 --- a/LogarithmPlotter/i18n/lp_en.ts +++ b/LogarithmPlotter/i18n/lp_en.ts @@ -103,52 +103,72 @@ Enable LaTeX rendering - + + Expression editor + + + + + Automatically close parenthesises and brackets + + + + + Enable syntax highlighting + + + + + Enable autocompletion + + + + &Help &Help - + &Source code &Source code - + &Report a bug &Report a bug - + &User manual &User manual - + &Changelog &Changelog - + &Help translating! &Help translating! - + &Thanks &Thanks - + &About &About - + Save unsaved changes? Save unsaved changes? - + This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? @@ -315,32 +335,47 @@ These settings can be changed at any time from the "Settings" menu. - + Check for updates on startup (requires online connectivity) Check for updates on startup (requires online connectivity) - + Reset redo stack when a new action is added to history Reset redo stack when a new action is added to history - + Enable LaTeX rendering Enable LaTeX rendering - + + Automatically close parenthesises and brackets in expressions + + + + + Enable syntax highlighting for expressions + + + + + Enable autocompletion interface in expression editor + + + + User manual User manual - + Changelog Changelog - + Done Done diff --git a/LogarithmPlotter/i18n/lp_es.ts b/LogarithmPlotter/i18n/lp_es.ts index b07230b..8fd7ba8 100644 --- a/LogarithmPlotter/i18n/lp_es.ts +++ b/LogarithmPlotter/i18n/lp_es.ts @@ -103,52 +103,72 @@ Activar el renderizado de LaTeX - + + Expression editor + + + + + Automatically close parenthesises and brackets + + + + + Enable syntax highlighting + + + + + Enable autocompletion + + + + &Help &Ayuda - + &Source code &Código fuente - + &Report a bug &Informar de un error - + &User manual &Manual del usuario - + &Changelog &Registro de cambios - + &Help translating! &¡Ayuda a la traducción! - + &Thanks &Agradecimientos - + &About &Acerca de - + Save unsaved changes? ¿Guardar los cambios no guardados? - + This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? @@ -283,32 +303,47 @@ These settings can be changed at any time from the "Settings" menu. - + Check for updates on startup (requires online connectivity) - + Reset redo stack when a new action is added to history - + Enable LaTeX rendering Activar el renderizado de LaTeX - + + Automatically close parenthesises and brackets in expressions + + + + + Enable syntax highlighting for expressions + + + + + Enable autocompletion interface in expression editor + + + + User manual - + Changelog - + Done diff --git a/LogarithmPlotter/i18n/lp_fr.ts b/LogarithmPlotter/i18n/lp_fr.ts index b3fa2a5..7108f13 100644 --- a/LogarithmPlotter/i18n/lp_fr.ts +++ b/LogarithmPlotter/i18n/lp_fr.ts @@ -104,52 +104,72 @@ Activer le rendu LaTeX - + + Expression editor + + + + + Automatically close parenthesises and brackets + + + + + Enable syntax highlighting + + + + + Enable autocompletion + + + + &Help &Aide - + &Source code &Code source - + &Report a bug &Rapport de bug - + &User manual Manuel d'&utilisation - + &Changelog &Historique des modifications - + &Help translating! &Aider à la traduction ! - + &Thanks &Remerciements - + &About &À propos - + Save unsaved changes? Sauvegarder les modifications ? - + This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? Ce graphe contient des modifications non sauvegardées. En faisant cela, toutes les données non sauvegardées seront perdues. Continuer ? @@ -317,22 +337,37 @@ These settings can be changed at any time from the "Settings" menu. - + Enable LaTeX rendering Activer le rendu LaTeX - + + Automatically close parenthesises and brackets in expressions + + + + + Enable syntax highlighting for expressions + + + + + Enable autocompletion interface in expression editor + + + + User manual Manuel d'utilisation - + Changelog Historique des modifications - + Done Fermer @@ -343,12 +378,12 @@ These settings can always be changed at any time from the "Settings" m These settings can always be changed at any time from the "Settings" menu. - + Check for updates on startup (requires online connectivity) Vérifier les mises à jour au démarrage (nécessite d'être connecté à internet) - + Reset redo stack when a new action is added to history Réinitialiser la pile d'action "Rétablir" lorsqu'une nouvelle action est ajoutée à l'historique diff --git a/LogarithmPlotter/i18n/lp_hu.ts b/LogarithmPlotter/i18n/lp_hu.ts index e3b5b8c..e70dc44 100644 --- a/LogarithmPlotter/i18n/lp_hu.ts +++ b/LogarithmPlotter/i18n/lp_hu.ts @@ -103,52 +103,72 @@ LaTeX-megjelenítés engedélyezése - + + Expression editor + + + + + Automatically close parenthesises and brackets + + + + + Enable syntax highlighting + + + + + Enable autocompletion + + + + &Help &Súgó - + &Source code &Forráskód - + &Report a bug &Hiba bejelentése - + &User manual &Használati utasítás - + &Changelog &Változásnapló - + &Help translating! &Segítség a fordításban! - + &Thanks &Köszönjük - + &About &Névjegy - + Save unsaved changes? Menti a változtatásokat? - + This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? Ez az ábra nem mentett változtatásokat tartalmaz. Ezzel az összes nem mentett adat elveszik. Folytatja? @@ -315,32 +335,47 @@ These settings can be changed at any time from the "Settings" menu. - + Check for updates on startup (requires online connectivity) Frissítések keresése indításkor (online kapcsolat szükséges) - + Reset redo stack when a new action is added to history Ismétlési verem alaphelyzet visszaállítása, ha új műveletet adnak az előzményekhez - + Enable LaTeX rendering LaTeX-megjelenítés engedélyezése - + + Automatically close parenthesises and brackets in expressions + + + + + Enable syntax highlighting for expressions + + + + + Enable autocompletion interface in expression editor + + + + User manual Használati utasítás - + Changelog Változásnapló - + Done Kész diff --git a/LogarithmPlotter/i18n/lp_nb_NO.ts b/LogarithmPlotter/i18n/lp_nb_NO.ts index 7dc0b9c..32ca1b4 100644 --- a/LogarithmPlotter/i18n/lp_nb_NO.ts +++ b/LogarithmPlotter/i18n/lp_nb_NO.ts @@ -103,52 +103,72 @@ - + + Expression editor + + + + + Automatically close parenthesises and brackets + + + + + Enable syntax highlighting + + + + + Enable autocompletion + + + + &Help &Hjelp - + &Source code - + &Report a bug - + &User manual - + &Changelog - + &Help translating! - + &Thanks - + &About &Om - + Save unsaved changes? - + This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? @@ -315,32 +335,47 @@ These settings can be changed at any time from the "Settings" menu. - + Check for updates on startup (requires online connectivity) Se etter nye versjoner ved programstart. (Krever tilkobling til Internett.) - + Reset redo stack when a new action is added to history Tilbakesitll angrehistorikk når en ny handling legges til - + Enable LaTeX rendering - + + Automatically close parenthesises and brackets in expressions + + + + + Enable syntax highlighting for expressions + + + + + Enable autocompletion interface in expression editor + + + + User manual - + Changelog - + Done diff --git a/LogarithmPlotter/i18n/lp_template.ts b/LogarithmPlotter/i18n/lp_template.ts index 40023b7..81a2ed7 100644 --- a/LogarithmPlotter/i18n/lp_template.ts +++ b/LogarithmPlotter/i18n/lp_template.ts @@ -103,52 +103,72 @@ - + + Expression editor + + + + + Automatically close parenthesises and brackets + + + + + Enable syntax highlighting + + + + + Enable autocompletion + + + + &Help - + &Source code - + &Report a bug - + &User manual - + &Changelog - + &Help translating! - + &Thanks - + &About - + Save unsaved changes? - + This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? @@ -283,32 +303,47 @@ These settings can be changed at any time from the "Settings" menu. - + Check for updates on startup (requires online connectivity) - + Reset redo stack when a new action is added to history - + Enable LaTeX rendering - + + Automatically close parenthesises and brackets in expressions + + + + + Enable syntax highlighting for expressions + + + + + Enable autocompletion interface in expression editor + + + + User manual - + Changelog - + Done diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/AppMenuBar.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/AppMenuBar.qml index 48cf383..748fb4e 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/AppMenuBar.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/AppMenuBar.qml @@ -35,6 +35,7 @@ import "js/math/latex.js" as LatexJS \sa LogarithmPlotter */ MenuBar { + property var settings: settingsMenu Menu { title: qsTr("&File") @@ -123,6 +124,7 @@ MenuBar { } Menu { + id: settingsMenu title: qsTr("&Settings") Action { id: checkForUpdatesMenuSetting @@ -154,6 +156,43 @@ MenuBar { } icon.name: 'Expression' } + + Menu { + title: qsTr("Expression editor") + + Action { + id: autocloseFormulaSetting + text: qsTr("Automatically close parenthesises and brackets") + checkable: true + checked: Helper.getSettingBool("expression_editor.autoclose") + onTriggered: { + Helper.setSettingBool("expression_editor.autoclose", checked) + } + icon.name: 'Text' + } + + Action { + id: colorizeFormulaSetting + text: qsTr("Enable syntax highlighting") + checkable: true + checked: Helper.getSettingBool("expression_editor.colorize") + onTriggered: { + Helper.setSettingBool("expression_editor.colorize", checked) + } + icon.name: 'appearance' + } + + Action { + id: autocompleteFormulaSetting + text: qsTr("Enable autocompletion") + checkable: true + checked: Helper.getSettingBool("autocompletion.enabled") + onTriggered: { + Helper.setSettingBool("autocompletion.enabled", checked) + } + icon.name: 'label' + } + } } Menu { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/GreetScreen.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/GreetScreen.qml index 15c1587..40f2fde 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/GreetScreen.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/GreetScreen.qml @@ -95,39 +95,81 @@ Popup { CheckBox { id: checkForUpdatesSetting - anchors.horizontalCenter: parent.horizontalCenter + anchors.left: parent.left + //anchors.horizontalCenter: parent.horizontalCenter anchors.top: helpText.bottom anchors.topMargin: 10 checked: Helper.getSettingBool("check_for_updates") text: qsTr('Check for updates on startup (requires online connectivity)') onClicked: { Helper.setSettingBool("check_for_updates", checked) - //checkForUpdatesMenuSetting.checked = checked + // Set in the menu bar + appMenu.settings.children[0].checked = checked } } CheckBox { id: resetRedoStackSetting - anchors.horizontalCenter: parent.horizontalCenter + anchors.left: parent.left + //anchors.horizontalCenter: parent.horizontalCenter anchors.top: checkForUpdatesSetting.bottom checked: Helper.getSettingBool("reset_redo_stack") text: qsTr('Reset redo stack when a new action is added to history') onClicked: { Helper.setSettingBool("reset_redo_stack", checked) - //resetRedoStackMenuSetting.checked = checked + appMenu.settings.children[1].checked = checked } } CheckBox { id: enableLatexSetting - anchors.horizontalCenter: parent.horizontalCenter + anchors.left: parent.left + //anchors.horizontalCenter: parent.horizontalCenter anchors.top: resetRedoStackSetting.bottom checked: Helper.getSettingBool("enable_latex") text: qsTr('Enable LaTeX rendering') onClicked: { Helper.setSettingBool("enable_latex", checked) - Latex.enabled = checked - drawCanvas.requestPaint() + appMenu.settings.children[2].checked = checked + } + } + + CheckBox { + id: autocloseFormulaSetting + anchors.left: parent.left + //anchors.horizontalCenter: parent.horizontalCenter + anchors.top: enableLatexSetting.bottom + checked: Helper.getSettingBool("expression_editor.autoclose") + text: qsTr('Automatically close parenthesises and brackets in expressions') + onClicked: { + Helper.setSettingBool("expression_editor.autoclose", checked) + appMenu.settings.children[3].children[0].checked = checked + } + } + + CheckBox { + id: colorizeFormulaSetting + anchors.left: parent.left + //anchors.horizontalCenter: parent.horizontalCenter + anchors.top: autocloseFormulaSetting.bottom + checked: Helper.getSettingBool("expression_editor.colorize") + text: qsTr('Enable syntax highlighting for expressions') + onClicked: { + Helper.setSettingBool("expression_editor.colorize", checked) + appMenu.settings.children[3].children[1].checked = checked + } + } + + CheckBox { + id: autocompleteFormulaSetting + anchors.left: parent.left + //anchors.horizontalCenter: parent.horizontalCenter + anchors.top: colorizeFormulaSetting.bottom + checked: Helper.getSettingBool("autocompletion.enabled") + text: qsTr('Enable autocompletion interface in expression editor') + onClicked: { + Helper.setSettingBool("autocompletion.enabled", checked) + appMenu.settings.children[3].children[2].checked = checked } } @@ -159,7 +201,7 @@ Popup { } } - Component.onCompleted: if(Helper.getSetting("last_install_greet") != Helper.getVersion()) { + Component.onCompleted: if(Helper.getSetting("last_install_greet") != Helper.getVersion()+"a") { greetingPopup.open() } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Setting/ExpressionEditor.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Setting/ExpressionEditor.qml index e4b9840..f0d8f17 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Setting/ExpressionEditor.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Setting/ExpressionEditor.qml @@ -151,13 +151,15 @@ Item { height: parent.height verticalAlignment: TextInput.AlignVCenter horizontalAlignment: control.label == "" ? TextInput.AlignLeft : TextInput.AlignHCenter - //font.pixelSize: 14 text: control.defValue - color: "transparent"//sysPalette.windowText + color: syntaxHighlightingEnabled ? "transparent" : sysPalette.windowText focus: true selectByMouse: true - property var tokens: parent.tokens(text) + property bool autocompleteEnabled: Helper.getSettingBool("autocompletion.enabled") + property bool syntaxHighlightingEnabled: Helper.getSettingBool("expression_editor.colorize") + property bool autoClosing: Helper.getSettingBool("expression_editor.autoclose") + property var tokens: autocompleteEnabled || syntaxHighlightingEnabled ? parent.tokens(text) : [] Keys.priority: Keys.BeforeItem // Required for knowing which key the user presses. @@ -176,25 +178,27 @@ Item { //onTextEdited: acPopupContent.itemSelected = 0 onActiveFocusChanged: { - if(activeFocus) + if(activeFocus && autocompleteEnabled) autocompletePopup.open() else autocompletePopup.close() } Keys.onUpPressed: function(event) { - if(acPopupContent.itemSelected == 0) - acPopupContent.itemSelected = acPopupContent.itemCount-1 - else - acPopupContent.itemSelected = acPopupContent.itemSelected-1 + if(autocompleteEnabled) + if(acPopupContent.itemSelected == 0) + acPopupContent.itemSelected = acPopupContent.itemCount-1 + else + acPopupContent.itemSelected = acPopupContent.itemSelected-1 event.accepted = true } Keys.onDownPressed: function(event) { - if(acPopupContent.itemSelected == Math.min(acPopupContent.itemCount-1)) - acPopupContent.itemSelected = 0 - else - acPopupContent.itemSelected = acPopupContent.itemSelected+1 + if(autocompleteEnabled) + if(acPopupContent.itemSelected == Math.min(acPopupContent.itemCount-1)) + acPopupContent.itemSelected = 0 + else + acPopupContent.itemSelected = acPopupContent.itemSelected+1 event.accepted = true } @@ -202,7 +206,7 @@ Item { // Autocomplete popup events //console.log(acPopupContent.currentToken.dot, acPopupContent.previousToken.dot, "@", acPopupContent.currentToken.identifier, acPopupContent.previousToken.identifier, acPopupContent.previousToken2.identifier, objectPropertiesList.objectName, JSON.stringify(objectPropertiesList.baseText), objectPropertiesList.model.length, JSON.stringify(objectPropertiesList.categoryItems)) //console.log("Pressed key:", event.key, Qt.Key_Return, Qt.Key_Enter, event.text, acPopupContent.itemCount) - if((event.key == Qt.Key_Enter || event.key == Qt.Key_Return) && acPopupContent.itemCount > 0) { + if(autocompleteEnabled && (event.key == Qt.Key_Enter || event.key == Qt.Key_Return) && acPopupContent.itemCount > 0) { acPopupContent.autocomplete() event.accepted = true } else @@ -212,7 +216,7 @@ Item { }*/ - if(event.text in openAndCloseMatches) { + if(event.text in openAndCloseMatches && autoClosing) { let start = selectionStart insert(selectionStart, event.text) insert(selectionEnd, openAndCloseMatches[event.text]) @@ -227,8 +231,9 @@ Item { verticalAlignment: TextInput.AlignVCenter horizontalAlignment: control.label == "" ? TextInput.AlignLeft : TextInput.AlignHCenter textFormat: Text.StyledText - text: colorize(parent.tokens) + text: parent.syntaxHighlightingEnabled ? colorize(parent.tokens) : "" color: sysPalette.windowText + visible: parent.syntaxHighlightingEnabled //font.pixelSize: parent.font.pixelSize //opacity: editor.activeFocus ? 0 : 1 } @@ -537,7 +542,7 @@ Item { parsedText += `${token.value}` break; case Parsing.TokenType.FUNCTION: - parsedText += `${token.value}` + parsedText += `${Utils.escapeHTML(token.value)}` break; case Parsing.TokenType.OPERATOR: parsedText += `${Utils.escapeHTML(token.value)}` diff --git a/LogarithmPlotter/util/config.py b/LogarithmPlotter/util/config.py index 4f7b20c..4f19fd3 100644 --- a/LogarithmPlotter/util/config.py +++ b/LogarithmPlotter/util/config.py @@ -26,7 +26,15 @@ DEFAULT_SETTINGS = { "check_for_updates": True, "reset_redo_stack": True, "last_install_greet": "0", - "enable_latex": False + "enable_latex": False, + "expression_editor": { + "autoclose": True, + "colorize": True, + "color_scheme": 0, + }, + "autocompletion": { + "enabled": True + } } # Create config directory @@ -51,7 +59,11 @@ def init(): if path.exists(CONFIG_FILE): cfg_data = load(open(CONFIG_FILE, 'r', -1, 'utf8')) for setting_name in cfg_data: - setSetting(setting_name, cfg_data[setting_name]) + if type(cfg_data[setting_name]) == dict: + for setting_name2 in cfg_data[setting_name]: + setSetting(setting_name+"."+setting_name2, cfg_data[setting_name][setting_name2]) + else: + setSetting(setting_name, cfg_data[setting_name]) def save(): """