[apps/code] Handle Home event when in the toolbox

If editing a script, the empty space at the end of the script should be
moved to the end of the storage.
This commit is contained in:
Léa Saviot
2020-01-09 09:53:35 +01:00
parent 67f10d0abd
commit 344ea5a67a
6 changed files with 28 additions and 4 deletions

View File

@@ -38,15 +38,16 @@ void EditorController::setScript(Script script) {
m_editorView.setText(const_cast<char *>(m_script.scriptContent()), newScriptSize - Script::k_importationStatusSize);
}
void EditorController::willExitApp() {
cleanStorageEmptySpace();
}
// 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 || event == Ion::Events::USBEnumeration) {
/* Exit the edition on USB enumeration, because the storage needs to be in a
* "clean" state (with all records packed at the beginning of the storage) */
Ion::Storage::Record::Data scriptValue = m_script.value();
Ion::Storage::sharedStorage()->getAvailableSpaceFromEndOfRecord(
m_script,
scriptValue.size - Script::k_importationStatusSize - (strlen(m_script.scriptContent()) + 1)); // TODO optimize number of script fetches
cleanStorageEmptySpace();
stackController()->pop();
return event != Ion::Events::Home && event != Ion::Events::USBEnumeration;
}
@@ -128,4 +129,15 @@ StackViewController * EditorController::stackController() {
return static_cast<StackViewController *>(parentResponder());
}
void EditorController::cleanStorageEmptySpace() {
if (m_script.isNull()) {
return;
}
Ion::Storage::Record::Data scriptValue = m_script.value();
Ion::Storage::sharedStorage()->getAvailableSpaceFromEndOfRecord(
m_script,
scriptValue.size - Script::k_importationStatusSize - (strlen(m_script.scriptContent()) + 1)); // TODO optimize number of script fetches
}
}