[apps/code] Add a setting for cursor saving (#125)

This commit is contained in:
Yaya-Cout
2022-01-14 13:42:30 +01:00
committed by GitHub
parent f296778014
commit f862cb023a
14 changed files with 38 additions and 8 deletions

View File

@@ -4,6 +4,7 @@
#include "app.h"
#include <escher/metric.h>
#include <ion.h>
#include "../global_preferences.h"
using namespace Shared;
@@ -63,7 +64,11 @@ void EditorController::didBecomeFirstResponder() {
void EditorController::viewWillAppear() {
ViewController::viewWillAppear();
m_editorView.loadSyntaxHighlighter();
m_editorView.setCursorLocation(m_script.content() + *m_script.CursorPosition());
if(GlobalPreferences::sharedGlobalPreferences()->cursorSaving()) {
m_editorView.setCursorLocation(m_script.content() + *m_script.CursorPosition());
} else {
m_editorView.setCursorLocation(m_editorView.text() + strlen(m_editorView.text()));
}
}
void EditorController::viewDidDisappear() {

View File

@@ -38,6 +38,8 @@ public:
void setAutocomplete(bool autocomple) { m_autoComplete = autocomple; }
bool syntaxhighlighting() const { return m_syntaxhighlighting; }
void setSyntaxhighlighting(bool syntaxhighlight) { m_syntaxhighlighting = syntaxhighlight; }
bool cursorSaving() const { return m_cursorSaving; }
void setCursorSaving(bool cursorsave) { m_cursorSaving = cursorsave; }
int brightnessLevel() const { return m_brightnessLevel; }
void setBrightnessLevel(int brightnessLevel);
const KDFont * font() const { return m_font; }
@@ -56,6 +58,7 @@ private:
m_dfuLevel(0),
m_autoComplete(true),
m_syntaxhighlighting(true),
m_cursorSaving(true),
m_brightnessLevel(Ion::Backlight::MaxBrightness),
m_font(KDFont::LargeFont) {}
I18n::Language m_language;
@@ -69,6 +72,7 @@ private:
uint8_t m_dfuLevel;
bool m_autoComplete;
bool m_syntaxhighlighting;
bool m_cursorSaving;
int m_brightnessLevel;
const KDFont * m_font;
};

View File

@@ -71,6 +71,7 @@ Time = "Uhrzeit"
RTCWarning1 = "Das Aktivieren der Uhr verkürzt die"
RTCWarning2 = "Akkulaufzeit im Bereitschaftsmodus."
SyntaxHighlighting = "Syntaxhervorhebung"
CursorSaving = "Cursor speichern"
USBExplanation1 = "USB-Schutz schützt Ihren"
USBExplanation2 = "Taschenrechner vor"
USBExplanation3 = "unbeabsichtigter Verriegelung"

View File

@@ -71,6 +71,7 @@ Time = "Time"
RTCWarning1 = "Enabling the clock drains the battery faster"
RTCWarning2 = "when the calculator is powered off."
SyntaxHighlighting = "Syntax Highlighting"
CursorSaving = "Cursor saving"
USBExplanation1 = "The USB protection protects"
USBExplanation2 = "the calculator from"
USBExplanation3 = "unintentional locking"

View File

@@ -71,6 +71,7 @@ Time = "Hora"
RTCWarning1 = "Activar el reloj gasta la batería más rápido"
RTCWarning2 = "cuando la calculadora está apagada."
SyntaxHighlighting = "Resaltado de sintaxis"
CursorSaving = "Ahorro de cursor"
USBExplanation1 = "La protección USB protege"
USBExplanation2 = "su calculadora del"
USBExplanation3 = "bloqueo involuntario"

View File

@@ -71,6 +71,7 @@ Time = "Heure"
RTCWarning1 = "Activer l'horloge décharge la batterie plus"
RTCWarning2 = "vite quand la calculatrice est éteinte."
SyntaxHighlighting = "Coloration syntaxique"
CursorSaving = "Sauvegarde du curseur"
USBExplanation1 = "La protection USB protège votre"
USBExplanation2 = "calculatrice contre un verrouillage"
USBExplanation3 = "non-intentionnel"

View File

@@ -71,6 +71,7 @@ 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"
CursorSaving = "Kurzor mentése"
USBExplanation1 = "Az USB-védelem megvédi"
USBExplanation2 = "a számológépet a nem"
USBExplanation3 = "szándékos reteszeléstől"

View File

@@ -71,6 +71,7 @@ Time = "Time"
RTCWarning1 = "Enabling the clock drains the battery faster"
RTCWarning2 = "when the calculator is powered off."
SyntaxHighlighting = "Evidenziazione della sintassi"
CursorSaving = "Salvataggio cursore"
USBExplanation1 = "La protezione USB protegge"
USBExplanation2 = "la calcolatrice dal"
USBExplanation3 = "blocco involontario"

View File

@@ -71,6 +71,7 @@ Time = "Time"
RTCWarning1 = "Enabling the clock drains the battery faster"
RTCWarning2 = "when the calculator is powered off."
SyntaxHighlighting = "Syntax Highlighting"
CursorSaving = "Cursor opslaan"
USBExplanation1 = "USB-beveiliging beschermt uw"
USBExplanation2 = "rekenmachine tegen"
USBExplanation3 = "onbedoelde vergrendeling"

View File

@@ -71,6 +71,7 @@ Time = "Time"
RTCWarning1 = "Enabling the clock drains the battery faster"
RTCWarning2 = "when the calculator is powered off."
SyntaxHighlighting = "Destaque da sintaxe"
CursorSaving = "Economia de cursor"
USBExplanation1 = "A proteção USB protege"
USBExplanation2 = "sua calculadora contra"
USBExplanation3 = "bloqueios não intencionais"

View File

@@ -24,7 +24,7 @@ constexpr SettingsMessageTree s_contributorsChildren[23] = {SettingsMessageTree(
// Code Settings
#ifdef HAS_CODE
constexpr SettingsMessageTree s_codeChildren[3] = {SettingsMessageTree(I18n::Message::FontSizes, s_modelFontChildren), SettingsMessageTree(I18n::Message::Autocomplete), SettingsMessageTree(I18n::Message::SyntaxHighlighting)};
constexpr SettingsMessageTree s_codeChildren[4] = {SettingsMessageTree(I18n::Message::FontSizes, s_modelFontChildren), SettingsMessageTree(I18n::Message::Autocomplete), SettingsMessageTree(I18n::Message::SyntaxHighlighting), SettingsMessageTree(I18n::Message::CursorSaving)};
#endif
constexpr SettingsMessageTree s_modelFontChildren[2] = {SettingsMessageTree(I18n::Message::LargeFont), SettingsMessageTree(I18n::Message::SmallFont)};

View File

@@ -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[3];
extern const Shared::SettingsMessageTree s_codeChildren[4];
extern const Shared::SettingsMessageTree s_modelDateTimeChildren[3];
extern const Shared::SettingsMessageTree s_accessibilityChildren[6];
extern const Shared::SettingsMessageTree s_contributorsChildren[23];

View File

@@ -13,6 +13,7 @@ CodeOptionsController::CodeOptionsController(Responder * parentResponder) :
m_chevronCellFontSize.setMessageFont(KDFont::LargeFont);
m_switchCellAutoCompletion.setMessageFont(KDFont::LargeFont);
m_switchCellSyntaxHighlighting.setMessageFont(KDFont::LargeFont);
m_switchCellCursorSaving.setMessageFont(KDFont::LargeFont);
}
bool CodeOptionsController::handleEvent(Ion::Events::Event event) {
@@ -21,11 +22,15 @@ 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;
break;
case 2:
GlobalPreferences::sharedGlobalPreferences()->setSyntaxhighlighting(!GlobalPreferences::sharedGlobalPreferences()->syntaxhighlighting());
m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow());
break;
case 3:
GlobalPreferences::sharedGlobalPreferences()->setCursorSaving(!GlobalPreferences::sharedGlobalPreferences()->cursorSaving());
m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow());
break;
default:
GenericSubController * subController = nullptr;
subController = &m_preferencesController;
@@ -34,7 +39,6 @@ bool CodeOptionsController::handleEvent(Ion::Events::Event event) {
m_lastSelect = selectedRow();
stack->push(subController);
break;
}
return true;
}
@@ -50,6 +54,9 @@ HighlightCell * CodeOptionsController::reusableCell(int index, int type) {
else if (index == 1) {
return &m_switchCellAutoCompletion;
}
else if (index == 2) {
return &m_switchCellCursorSaving;
}
return &m_switchCellSyntaxHighlighting;
}
@@ -66,9 +73,9 @@ void CodeOptionsController::willDisplayCellForIndex(HighlightCell * cell, int in
MessageTableCellWithChevronAndMessage * myTextCell = (MessageTableCellWithChevronAndMessage *)cell;
myTextCell->setMessage(thisLabel);
GlobalPreferences::sharedGlobalPreferences()->font() == KDFont::LargeFont
? myTextCell->setSubtitle(I18n::Message::LargeFont)
? myTextCell->setSubtitle(I18n::Message::LargeFont)
: myTextCell->setSubtitle(I18n::Message::SmallFont);
}
}
#ifdef HAS_CODE
else if (thisLabel == I18n::Message::Autocomplete) {
MessageTableCellWithSwitch * mySwitchCell = (MessageTableCellWithSwitch *)cell;
@@ -80,6 +87,11 @@ void CodeOptionsController::willDisplayCellForIndex(HighlightCell * cell, int in
SwitchView * mySwitch = (SwitchView *)mySwitchCell->accessoryView();
mySwitch->setState(GlobalPreferences::sharedGlobalPreferences()->syntaxhighlighting());
}
else if (thisLabel == I18n::Message::CursorSaving) {
MessageTableCellWithSwitch * mySwitchCell = (MessageTableCellWithSwitch *)cell;
SwitchView * mySwitch = (SwitchView *)mySwitchCell->accessoryView();
mySwitch->setState(GlobalPreferences::sharedGlobalPreferences()->cursorSaving());
}
#endif
}

View File

@@ -14,11 +14,12 @@ public:
int reusableCellCount(int type) override;
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
private:
constexpr static int k_totalNumberOfCell = 3;
constexpr static int k_totalNumberOfCell = 4;
PreferencesController m_preferencesController;
MessageTableCellWithChevronAndMessage m_chevronCellFontSize;
MessageTableCellWithSwitch m_switchCellAutoCompletion;
MessageTableCellWithSwitch m_switchCellSyntaxHighlighting;
MessageTableCellWithSwitch m_switchCellCursorSaving;
};
}