mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[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:
@@ -105,6 +105,10 @@ bool App::handleEvent(Ion::Events::Event event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void App::willExitResponderChain(Responder * nextFirstResponder) {
|
||||
m_menuController.willExitApp();
|
||||
}
|
||||
|
||||
Toolbox * App::toolboxForInputEventHandler(InputEventHandler * textInput) {
|
||||
return &m_toolbox;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ public:
|
||||
|
||||
/* Responder */
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
void willExitResponderChain(Responder * nextFirstResponder) override;
|
||||
|
||||
/* InputEventHandlerDelegate */
|
||||
Toolbox * toolboxForInputEventHandler(InputEventHandler * textInput) override;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class EditorController : public ViewController, public TextAreaDelegate, public
|
||||
public:
|
||||
EditorController(MenuController * menuController, App * pythonDelegate);
|
||||
void setScript(Script script);
|
||||
void willExitApp();
|
||||
|
||||
/* ViewController */
|
||||
View * view() override { return &m_editorView; }
|
||||
@@ -33,6 +34,7 @@ public:
|
||||
VariableBoxController * variableBoxForInputEventHandler(InputEventHandler * textInput) override;
|
||||
|
||||
private:
|
||||
void cleanStorageEmptySpace();
|
||||
StackViewController * stackController();
|
||||
EditorView m_editorView;
|
||||
Script m_script;
|
||||
|
||||
@@ -156,6 +156,10 @@ void MenuController::scriptContentEditionDidFinish() {
|
||||
reloadConsole();
|
||||
}
|
||||
|
||||
void MenuController::willExitApp() {
|
||||
m_editorController.willExitApp();
|
||||
}
|
||||
|
||||
int MenuController::numberOfRows() const {
|
||||
return m_scriptStore->numberOfScripts() + m_shouldDisplayAddScriptRow;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
void reloadConsole();
|
||||
void openConsoleWithScript(Script script);
|
||||
void scriptContentEditionDidFinish();
|
||||
void willExitApp();
|
||||
|
||||
/* ViewController */
|
||||
View * view() override { return &m_selectableTableView; }
|
||||
|
||||
Reference in New Issue
Block a user