diff --git a/apps/code/python_text_area.cpp b/apps/code/python_text_area.cpp index 480da7304..0cef1875a 100644 --- a/apps/code/python_text_area.cpp +++ b/apps/code/python_text_area.cpp @@ -25,6 +25,9 @@ constexpr KDColor HighlightColor = Palette::CodeBackgroundSelected; constexpr KDColor AutocompleteColor = KDColor::RGB24(0xC6C6C6); // TODO Palette change static inline KDColor TokenColor(mp_token_kind_t tokenKind) { + if(!GlobalPreferences::sharedGlobalPreferences()->syntaxhighlighting()) { + return Palette::CodeText; + } if (tokenKind == MP_TOKEN_STRING) { return StringColor; } @@ -305,6 +308,10 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char tokenFrom += tokenLength; + KDColor color = CommentColor; + if(!GlobalPreferences::sharedGlobalPreferences()->syntaxhighlighting()) { + color = Palette::CodeText; + } // Even if the token is being autocompleted, use CommentColor if (tokenFrom < text + byteLength) { LOG_DRAW("Draw comment \"%.*s\" from %d\n", byteLength - (tokenFrom - text), firstNonSpace, tokenFrom); @@ -312,7 +319,7 @@ void PythonTextArea::ContentView::drawLine(KDContext * ctx, int line, const char UTF8Helper::GlyphOffsetAtCodePoint(text, tokenFrom), tokenFrom, text + byteLength - tokenFrom, - CommentColor, + color, BackgroundColor, selectionStart, selectionEnd, diff --git a/apps/global_preferences.h b/apps/global_preferences.h index 83ee56109..a54a5d8a6 100644 --- a/apps/global_preferences.h +++ b/apps/global_preferences.h @@ -36,6 +36,8 @@ public: void setDfuLevel(int level) { m_dfuLevel = level; } bool autocomplete() const { return m_autoComplete; } void setAutocomplete(bool autocomple) { m_autoComplete = autocomple; } + bool syntaxhighlighting() const { return m_syntaxhighlighting; } + void setSyntaxhighlighting(bool syntaxhighlight) { m_syntaxhighlighting = syntaxhighlight; } int brightnessLevel() const { return m_brightnessLevel; } void setBrightnessLevel(int brightnessLevel); const KDFont * font() const { return m_font; } @@ -53,6 +55,7 @@ private: m_dfuUnlocked(false), m_dfuLevel(0), m_autoComplete(true), + m_syntaxhighlighting(true), m_brightnessLevel(Ion::Backlight::MaxBrightness), m_font(KDFont::LargeFont) {} I18n::Language m_language; @@ -65,6 +68,7 @@ private: bool m_dfuUnlocked; uint8_t m_dfuLevel; bool m_autoComplete; + bool m_syntaxhighlighting; int m_brightnessLevel; const KDFont * m_font; }; diff --git a/apps/settings/base.de.i18n b/apps/settings/base.de.i18n index 6f2b7ef25..1c541c612 100644 --- a/apps/settings/base.de.i18n +++ b/apps/settings/base.de.i18n @@ -69,6 +69,7 @@ Date = "Datum" Time = "Uhrzeit" RTCWarning1 = "Das Aktivieren der Uhr verkürzt die" RTCWarning2 = "Akkulaufzeit im Bereitschaftsmodus." +SyntaxHighlighting = "Syntaxhervorhebung" USBExplanation1= "USB-Schutz schützt Ihren" USBExplanation2= "Taschenrechner vor" USBExplanation3= "unbeabsichtigter Verriegelung" diff --git a/apps/settings/base.en.i18n b/apps/settings/base.en.i18n index 97aedba4b..943b98164 100644 --- a/apps/settings/base.en.i18n +++ b/apps/settings/base.en.i18n @@ -69,6 +69,7 @@ Date = "Date" Time = "Time" RTCWarning1 = "Enabling the clock drains the battery faster" RTCWarning2 = "when the calculator is powered off." +SyntaxHighlighting = "Syntax Highlighting" USBExplanation1= "The USB protection protects" USBExplanation2= "the calculator from" USBExplanation3= "unintentional locking" diff --git a/apps/settings/base.es.i18n b/apps/settings/base.es.i18n index 44465debd..b70d432c7 100644 --- a/apps/settings/base.es.i18n +++ b/apps/settings/base.es.i18n @@ -69,6 +69,7 @@ Date = "Fecha" Time = "Hora" RTCWarning1 = "Activar el reloj gasta la batería más rápido" RTCWarning2 = "cuando la calculadora está apagada." +SyntaxHighlighting = "Resaltado de sintaxis" USBExplanation1= "La protección USB protege" USBExplanation2= "su calculadora del" USBExplanation3= "bloqueo involuntario" diff --git a/apps/settings/base.fr.i18n b/apps/settings/base.fr.i18n index f2affaec3..b44969e73 100644 --- a/apps/settings/base.fr.i18n +++ b/apps/settings/base.fr.i18n @@ -69,6 +69,7 @@ Date = "Date" Time = "Heure" RTCWarning1 = "Activer l'horloge décharge la batterie plus" RTCWarning2 = "vite quand la calculatrice est éteinte." +SyntaxHighlighting = "Coloration syntaxique" USBExplanation1= "La protection USB protège votre" USBExplanation2= "calculatrice contre un verrouillage" USBExplanation3= "non-intentionnel" diff --git a/apps/settings/base.hu.i18n b/apps/settings/base.hu.i18n index f0bc9ad26..a3d4f03ac 100644 --- a/apps/settings/base.hu.i18n +++ b/apps/settings/base.hu.i18n @@ -69,6 +69,7 @@ Date = "Datum" Time = "Óra" RTCWarning1 = "Amikor a számológép alvómódban van, az óra" RTCWarning2 = "használása az elemet gyorsabban meríti ki." +SyntaxHighlighting = "Szintaxis kiemelés" USBExplanation1= "Az USB-védelem megvédi" USBExplanation2= "a számológépet a nem" USBExplanation3= "szándékos reteszeléstől" diff --git a/apps/settings/base.it.i18n b/apps/settings/base.it.i18n index 861b8a073..aec045eff 100644 --- a/apps/settings/base.it.i18n +++ b/apps/settings/base.it.i18n @@ -69,6 +69,7 @@ Date = "Date" Time = "Time" RTCWarning1 = "Enabling the clock drains the battery faster" RTCWarning2 = "when the calculator is powered off." +SyntaxHighlighting = "Evidenziazione della sintassi" USBExplanation1= "La protezione USB protegge" USBExplanation2= "la calcolatrice dal" USBExplanation3= "blocco involontario" diff --git a/apps/settings/base.nl.i18n b/apps/settings/base.nl.i18n index 6bba2ae22..4ea41ec3e 100644 --- a/apps/settings/base.nl.i18n +++ b/apps/settings/base.nl.i18n @@ -69,6 +69,7 @@ Date = "Date" Time = "Time" RTCWarning1 = "Enabling the clock drains the battery faster" RTCWarning2 = "when the calculator is powered off." +SyntaxHighlighting = "Syntax Highlighting" USBExplanation1= "USB-beveiliging beschermt uw" USBExplanation2= "rekenmachine tegen" USBExplanation3= "onbedoelde vergrendeling" diff --git a/apps/settings/base.pt.i18n b/apps/settings/base.pt.i18n index c10264ae4..62bf8063e 100644 --- a/apps/settings/base.pt.i18n +++ b/apps/settings/base.pt.i18n @@ -69,6 +69,7 @@ Date = "Date" Time = "Time" RTCWarning1 = "Enabling the clock drains the battery faster" RTCWarning2 = "when the calculator is powered off." +SyntaxHighlighting = "Destaque da sintaxe" USBExplanation1= "A proteção USB protege" USBExplanation2= "sua calculadora contra" USBExplanation3= "bloqueios não intencionais" diff --git a/apps/settings/main_controller.cpp b/apps/settings/main_controller.cpp index 9bbde50fc..16a187461 100644 --- a/apps/settings/main_controller.cpp +++ b/apps/settings/main_controller.cpp @@ -24,7 +24,7 @@ constexpr SettingsMessageTree s_contributorsChildren[23] = {SettingsMessageTree( // Code Settings #ifdef HAS_CODE -constexpr SettingsMessageTree s_codeChildren[2] = {SettingsMessageTree(I18n::Message::FontSizes, s_modelFontChildren), SettingsMessageTree(I18n::Message::Autocomplete)}; +constexpr SettingsMessageTree s_codeChildren[3] = {SettingsMessageTree(I18n::Message::FontSizes, s_modelFontChildren), SettingsMessageTree(I18n::Message::Autocomplete), SettingsMessageTree(I18n::Message::SyntaxHighlighting)}; #endif constexpr SettingsMessageTree s_modelFontChildren[2] = {SettingsMessageTree(I18n::Message::LargeFont), SettingsMessageTree(I18n::Message::SmallFont)}; diff --git a/apps/settings/main_controller.h b/apps/settings/main_controller.h index b20e47e0d..10896c77d 100644 --- a/apps/settings/main_controller.h +++ b/apps/settings/main_controller.h @@ -24,7 +24,7 @@ extern const Shared::SettingsMessageTree s_symbolChildren[4]; extern const Shared::SettingsMessageTree s_symbolFunctionChildren[3]; extern const Shared::SettingsMessageTree s_modelMathOptionsChildren[6]; extern const Shared::SettingsMessageTree s_modelFontChildren[2]; -extern const Shared::SettingsMessageTree s_codeChildren[2]; +extern const Shared::SettingsMessageTree s_codeChildren[3]; extern const Shared::SettingsMessageTree s_modelDateTimeChildren[3]; extern const Shared::SettingsMessageTree s_accessibilityChildren[6]; extern const Shared::SettingsMessageTree s_contributorsChildren[23]; diff --git a/apps/settings/sub_menu/code_options_controller.cpp b/apps/settings/sub_menu/code_options_controller.cpp index 150198270..824419dba 100644 --- a/apps/settings/sub_menu/code_options_controller.cpp +++ b/apps/settings/sub_menu/code_options_controller.cpp @@ -12,6 +12,7 @@ CodeOptionsController::CodeOptionsController(Responder * parentResponder) : { m_chevronCell.setMessageFont(KDFont::LargeFont); m_switchCell.setMessageFont(KDFont::LargeFont); + m_switchCell_syntax_highlighting.setMessageFont(KDFont::LargeFont); } bool CodeOptionsController::handleEvent(Ion::Events::Event event) { @@ -20,6 +21,10 @@ bool CodeOptionsController::handleEvent(Ion::Events::Event event) { case 1: GlobalPreferences::sharedGlobalPreferences()->setAutocomplete(!GlobalPreferences::sharedGlobalPreferences()->autocomplete()); m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()); + break; + case 2: + GlobalPreferences::sharedGlobalPreferences()->setSyntaxhighlighting(!GlobalPreferences::sharedGlobalPreferences()->syntaxhighlighting()); + m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()); break; default: @@ -43,7 +48,10 @@ HighlightCell * CodeOptionsController::reusableCell(int index, int type) { if (index == 0) { return &m_chevronCell; } - return &m_switchCell; + else if (index == 1) { + return &m_switchCell; + } + return &m_switchCell_syntax_highlighting; } int CodeOptionsController::reusableCellCount(int type) { @@ -68,6 +76,11 @@ void CodeOptionsController::willDisplayCellForIndex(HighlightCell * cell, int in SwitchView * mySwitch = (SwitchView *)mySwitchCell->accessoryView(); mySwitch->setState(GlobalPreferences::sharedGlobalPreferences()->autocomplete()); } + else if (thisLabel == I18n::Message::SyntaxHighlighting) { + MessageTableCellWithSwitch * mySwitchCell = (MessageTableCellWithSwitch *)cell; + SwitchView * mySwitch = (SwitchView *)mySwitchCell->accessoryView(); + mySwitch->setState(GlobalPreferences::sharedGlobalPreferences()->syntaxhighlighting()); + } #endif } diff --git a/apps/settings/sub_menu/code_options_controller.h b/apps/settings/sub_menu/code_options_controller.h index d3a82e336..d7c089b57 100644 --- a/apps/settings/sub_menu/code_options_controller.h +++ b/apps/settings/sub_menu/code_options_controller.h @@ -14,10 +14,11 @@ public: int reusableCellCount(int type) override; void willDisplayCellForIndex(HighlightCell * cell, int index) override; private: - constexpr static int k_totalNumberOfCell = 2; + constexpr static int k_totalNumberOfCell = 3; PreferencesController m_preferencesController; MessageTableCellWithChevronAndMessage m_chevronCell; MessageTableCellWithSwitch m_switchCell; + MessageTableCellWithSwitch m_switchCell_syntax_highlighting; }; }