diff --git a/apps/code/console_controller.cpp b/apps/code/console_controller.cpp index 68093dc6b..2b934f17a 100644 --- a/apps/code/console_controller.cpp +++ b/apps/code/console_controller.cpp @@ -77,7 +77,7 @@ void ConsoleController::removeExtensionIfAny(char * name) { if (nameLength<4) { return; } - if (strcmp(&name[nameLength-3], ".py") == 0) { + if (strcmp(&name[nameLength-3], ScriptStore::k_scriptExtension) == 0) { name[nameLength-3] = 0; } } diff --git a/apps/code/menu_controller.cpp b/apps/code/menu_controller.cpp index 54b34087e..b66804d81 100644 --- a/apps/code/menu_controller.cpp +++ b/apps/code/menu_controller.cpp @@ -93,6 +93,7 @@ void MenuController::renameScriptAtIndex(int i) { const char * previousText = myCell->editableTextCell()->textField()->text(); myCell->editableTextCell()->textField()->setEditing(true); myCell->editableTextCell()->textField()->setText(previousText); + myCell->editableTextCell()->textField()->setCursorLocation(strlen(previousText) - strlen(ScriptStore::k_scriptExtension)); app()->setFirstResponder(myCell); } @@ -174,6 +175,12 @@ bool MenuController::textFieldShouldFinishEditing(TextField * textField, Ion::Ev } bool MenuController::textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) { + if (event == Ion::Events::Right + && textField->isEditing() + && textField->cursorLocation() > textField->textLength() - strlen(ScriptStore::k_scriptExtension) -1) + { + return true; + } return false; } diff --git a/apps/code/script_store.cpp b/apps/code/script_store.cpp index a8daa3f34..c3691f040 100644 --- a/apps/code/script_store.cpp +++ b/apps/code/script_store.cpp @@ -4,6 +4,9 @@ namespace Code { +constexpr char ScriptStore::k_scriptExtension[]; +constexpr char ScriptStore::k_defaultScriptName[]; + ScriptStore::ScriptStore() : m_accordion(m_scriptData, k_scriptDataSize) { diff --git a/apps/code/script_store.h b/apps/code/script_store.h index 172a9b9e3..aaf40b455 100644 --- a/apps/code/script_store.h +++ b/apps/code/script_store.h @@ -16,6 +16,8 @@ public: Content }; + static constexpr char k_scriptExtension[] = ".py"; + ScriptStore(); const Script scriptAtIndex(int index, EditableZone zone = EditableZone::None); const Script scriptNamed(const char * name); diff --git a/escher/include/escher/text_field.h b/escher/include/escher/text_field.h index 8fc19b78d..0ecd3f417 100644 --- a/escher/include/escher/text_field.h +++ b/escher/include/escher/text_field.h @@ -18,13 +18,13 @@ public: const char * text() const; int textLength() const; int cursorLocation() const; + void setCursorLocation(int location); void setText(const char * text); void setBackgroundColor(KDColor backgroundColor); KDColor backgroundColor() const; void setTextColor(KDColor textColor); void setAlignment(float horizontalAlignment, float verticalAlignment); virtual void setEditing(bool isEditing, bool reinitDraftBuffer = true); - void setCursorLocation(int location); /* If the text to be appended is too long to be added without overflowing the * buffer, nothing is done (not even adding few letters from the text to reach * the maximum buffer capacity) and false is returned. */ diff --git a/escher/src/text_field.cpp b/escher/src/text_field.cpp index 2d787d0cf..ce40b9795 100644 --- a/escher/src/text_field.cpp +++ b/escher/src/text_field.cpp @@ -259,6 +259,11 @@ int TextField::cursorLocation() const{ return m_contentView.cursorLocation(); } +void TextField::setCursorLocation(int location) { + m_contentView.setCursorLocation(location); + scrollToCursor(); +} + void TextField::setText(const char * text) { reloadScroll(); m_contentView.setText(text); @@ -291,11 +296,6 @@ void TextField::setEditing(bool isEditing, bool reinitDrafBuffer) { } } -void TextField::setCursorLocation(int location) { - m_contentView.setCursorLocation(location); - scrollToCursor(); -} - bool TextField::insertTextAtLocation(const char * text, int location) { if (m_contentView.insertTextAtLocation(text, location)) { layoutSubviews();