[code] EditorController: save script before displaying the variable box

This commit is contained in:
Émilie Feral
2018-10-25 14:51:33 +02:00
parent a4f7d83805
commit ea59e651ee
2 changed files with 16 additions and 8 deletions

View File

@@ -31,19 +31,13 @@ void EditorController::setScript(Script script) {
// TODO: this should be done in textAreaDidFinishEditing maybe??
bool EditorController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK || event == Ion::Events::Back || event == Ion::Events::Home) {
size_t sizeOfValue = strlen(m_areaBuffer+1)+1+1; // size of scriptContent + size of importation status
Script::ErrorStatus err = m_script.setValue({.buffer=m_areaBuffer, .size=sizeOfValue});
if (err == Script::ErrorStatus::NotEnoughSpaceAvailable || err == Script::ErrorStatus::RecordDoesNotExist) {
assert(false); // This should not happen as we set the text area according to the available space in the Kallax
} else {
stackController()->pop();
}
saveScript();
stackController()->pop();
return event != Ion::Events::Home;
}
return false;
}
void EditorController::didBecomeFirstResponder() {
app()->setFirstResponder(&m_editorView);
}
@@ -58,6 +52,11 @@ void EditorController::viewDidDisappear() {
}
bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events::Event event) {
if (event == Ion::Events::Var) {
// We save script before displaying the Variable box to add new functions or variables
saveScript();
return false;
}
if (static_cast<App *>(textArea->app())->textInputDidReceiveEvent(textArea, event)) {
return true;
}
@@ -142,4 +141,12 @@ StackViewController * EditorController::stackController() {
return static_cast<StackViewController *>(parentResponder());
}
void EditorController::saveScript() {
size_t sizeOfValue = strlen(m_areaBuffer+1)+1+1; // size of scriptContent + size of importation status
Script::ErrorStatus err = m_script.setValue({.buffer=m_areaBuffer, .size=sizeOfValue});
if (err == Script::ErrorStatus::NotEnoughSpaceAvailable || err == Script::ErrorStatus::RecordDoesNotExist) {
assert(false); // This should not happen as we set the text area according to the available space in the Kallax
}
}
}