diff --git a/apps/sequence/list/sequence_expression_cell.cpp b/apps/sequence/list/sequence_expression_cell.cpp index c73030218..4c6f0ea3b 100644 --- a/apps/sequence/list/sequence_expression_cell.cpp +++ b/apps/sequence/list/sequence_expression_cell.cpp @@ -1,4 +1,5 @@ #include "sequence_expression_cell.h" +#include "../app.h" using namespace Shared; @@ -46,6 +47,10 @@ void SequenceExpressionCell::setSequence(Sequence * sequence) { layoutSubviews(); } +Sequence * SequenceExpressionCell::sequence() { + return m_sequence; +} + void SequenceExpressionCell::setHighlighted(bool highlight) { TableViewCell::setHighlighted(highlight); m_expressionView.setHighlighted(false); @@ -120,7 +125,78 @@ bool SequenceExpressionCell::handleEvent(Ion::Events::Event event) { selectSubCell(m_selectedSubCell-1); return true; } + if (event == Ion::Events::OK) { + editExpression(event); + return true; + } + if (event.hasText() || event == Ion::Events::XNT) { + editExpression(event); + return true; + } return false; } +void SequenceExpressionCell::editExpression(Ion::Events::Event event) { + char * initialText = nullptr; + char initialTextContent[255]; + if (event == Ion::Events::OK) { + char * text = (char *)m_sequence->text(); + if (m_selectedSubCell == 1) { + text = (char *)m_sequence->firstInitialConditionText(); + } + if (m_selectedSubCell == 2) { + text = (char *)m_sequence->secondInitialConditionText(); + } + strlcpy(initialTextContent, text, sizeof(initialTextContent)); + initialText = initialTextContent; + } + App * myApp = (App *)app(); + InputViewController * inputController = myApp->inputViewController(); + if (m_selectedSubCell == 0) { + inputController->edit(this, event, this, initialText, + [](void * context, void * sender){ + SequenceExpressionCell * myCell = (SequenceExpressionCell *) context; + Sequence * sequence = myCell->sequence(); + InputViewController * myInputViewController = (InputViewController *)sender; + const char * textBody = myInputViewController->textBody(); + sequence->setContent(textBody); + myCell->reloadCell(); + SelectableTableView * table = (SelectableTableView *)myCell->parentResponder(); + table->reloadData(); + }, + [](void * context, void * sender){} + ); + } + if (m_selectedSubCell == 1) { + inputController->edit(this, event, this, initialText, + [](void * context, void * sender){ + SequenceExpressionCell * myCell = (SequenceExpressionCell *) context; + Sequence * sequence = myCell->sequence(); + InputViewController * myInputViewController = (InputViewController *)sender; + const char * textBody = myInputViewController->textBody(); + sequence->setFirstInitialConditionContent(textBody); + myCell->reloadCell(); + SelectableTableView * table = (SelectableTableView *)myCell->parentResponder(); + table->reloadData(); + }, + [](void * context, void * sender){} + ); + } + if (m_selectedSubCell == 2) { + inputController->edit(this, event, this, initialText, + [](void * context, void * sender){ + SequenceExpressionCell * myCell = (SequenceExpressionCell *) context; + Sequence * sequence = myCell->sequence(); + InputViewController * myInputViewController = (InputViewController *)sender; + const char * textBody = myInputViewController->textBody(); + sequence->setSecondInitialConditionContent(textBody); + myCell->reloadCell(); + SelectableTableView * table = (SelectableTableView *)myCell->parentResponder(); + table->reloadData(); + }, + [](void * context, void * sender){} + ); + } +} + } diff --git a/apps/sequence/list/sequence_expression_cell.h b/apps/sequence/list/sequence_expression_cell.h index d55f2971f..49fd1bb2e 100644 --- a/apps/sequence/list/sequence_expression_cell.h +++ b/apps/sequence/list/sequence_expression_cell.h @@ -10,6 +10,7 @@ class SequenceExpressionCell : public Responder, public EvenOddCell { public: SequenceExpressionCell(Responder * parentResponder); void setSequence(Sequence * sequence); + Sequence * sequence(); int selectedSubCell(); void selectSubCell(int index); void setHighlighted(bool highlight) override; @@ -21,6 +22,7 @@ public: bool handleEvent(Ion::Events::Event event) override; private: constexpr static KDCoordinate k_separatorThickness = 1; + void editExpression(Ion::Events::Event event); Sequence * m_sequence; int m_numberOfSubCells; int m_selectedSubCell; diff --git a/apps/sequence/sequence.cpp b/apps/sequence/sequence.cpp index b3626cf39..6c99abdd8 100644 --- a/apps/sequence/sequence.cpp +++ b/apps/sequence/sequence.cpp @@ -33,6 +33,14 @@ Sequence::~Sequence() { } } +const char * Sequence::firstInitialConditionText() { + return m_firstInitialConditionText; +} + +const char * Sequence::secondInitialConditionText() { + return m_secondInitialConditionText; +} + Sequence::Type Sequence::type() { return m_type; } diff --git a/apps/sequence/sequence.h b/apps/sequence/sequence.h index 8a0eeda62..30940f190 100644 --- a/apps/sequence/sequence.h +++ b/apps/sequence/sequence.h @@ -16,6 +16,8 @@ public: ~Sequence(); Type type(); void setType(Type type); + const char * firstInitialConditionText(); + const char * secondInitialConditionText(); Poincare::Expression * firstInitialConditionExpression(); Poincare::Expression * secondInitialConditionExpression(); Poincare::ExpressionLayout * firstInitialConditionLayout();