mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/code] Add a setting for syntax highlighting (#85)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)};
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user