From 1c6573e8fe8eeda77f0251719a6b2b53c07d29aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 23 Oct 2018 11:25:03 +0200 Subject: [PATCH] [code] When script name edition abort, ask the storage for the previous name --- apps/code/menu_controller.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/code/menu_controller.cpp b/apps/code/menu_controller.cpp index 318d61142..9a8afe1ed 100644 --- a/apps/code/menu_controller.cpp +++ b/apps/code/menu_controller.cpp @@ -334,20 +334,21 @@ bool MenuController::textFieldDidFinishEditing(TextField * textField, const char } bool MenuController::textFieldDidAbortEditing(TextField * textField) { - if (strlen(textField->text()) <= 1 + strlen(ScriptStore::k_scriptExtension)) { + Script script = m_scriptStore->scriptAtIndex(m_selectableTableView.selectedRow()); + const char * scriptName = script.fullName(); + if (strlen(scriptName) <= 1 + strlen(ScriptStore::k_scriptExtension)) { // The previous text was an empty name. Use a numbered default script name. char numberedDefaultName[k_defaultScriptNameMaxSize]; numberedDefaultScriptName(numberedDefaultName); - Script::ErrorStatus error = m_scriptStore->scriptAtIndex(m_selectableTableView.selectedRow()).setName(numberedDefaultName); - if (error != Script::ErrorStatus::None) { - assert(false); - /* Because we use the numbered default name, the name should not be - * already taken. Plus, the script could be added only if the storage has - * enough available space to add a script named 'script99.py' */ - } + scriptName = numberedDefaultName; + Script::ErrorStatus error = script.setName(numberedDefaultName); + /* Because we use the numbered default name, the name should not be + * already taken. Plus, the script could be added only if the storage has + * enough available space to add a script named 'script99.py' */ assert(error == Script::ErrorStatus::None); updateAddScriptRowDisplay(); } + textField->setText(scriptName); m_selectableTableView.selectCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()); app()->setFirstResponder(&m_selectableTableView); static_cast(const_cast(app()->container()))->setShiftAlphaStatus(Ion::Events::ShiftAlphaStatus::Default);