[apps/sequence] Make controllers inherit from StorageFunction controllers when required

This commit is contained in:
Émilie Feral
2019-02-28 14:51:22 +01:00
parent 184d2f0802
commit 2bc2506b60
29 changed files with 270 additions and 285 deletions

View File

@@ -9,13 +9,12 @@ using namespace Shared;
namespace Sequence {
ListParameterController::ListParameterController(::InputEventHandlerDelegate * inputEventHandlerDelegate, ListController * listController, SequenceStore * sequenceStore) :
Shared::ListParameterController(listController, sequenceStore, I18n::Message::SequenceColor, I18n::Message::DeleteSequence, this),
ListParameterController::ListParameterController(::InputEventHandlerDelegate * inputEventHandlerDelegate, ListController * listController) :
Shared::StorageListParameterController(listController, I18n::Message::SequenceColor, I18n::Message::DeleteSequence, this),
m_typeCell(I18n::Message::SequenceType),
m_initialRankCell(&m_selectableTableView, inputEventHandlerDelegate, this, m_draftTextBuffer, I18n::Message::FirstTermIndex),
m_typeParameterController(this, sequenceStore, listController, TableCell::Layout::Horizontal, Metric::CommonTopMargin, Metric::CommonRightMargin,
Metric::CommonBottomMargin, Metric::CommonLeftMargin),
m_sequence(nullptr)
m_typeParameterController(this, listController, TableCell::Layout::Horizontal, Metric::CommonTopMargin, Metric::CommonRightMargin,
Metric::CommonBottomMargin, Metric::CommonLeftMargin)
{
static_cast<ExpressionView *>(m_typeCell.subAccessoryView())->setHorizontalMargin(Metric::ExpressionViewHorizontalMargin);
}
@@ -24,11 +23,6 @@ const char * ListParameterController::title() {
return I18n::translate(I18n::Message::SequenceOptions);
}
void ListParameterController::setFunction(Shared::Function * function) {
Shared::ListParameterController::setFunction(function);
m_sequence = (Sequence *)function;
}
bool ListParameterController::handleEvent(Ion::Events::Event event) {
bool hasAdditionalRow = hasInitialRankRow();
#if FUNCTION_COLOR_CHOICE
@@ -46,7 +40,7 @@ bool ListParameterController::handleEvent(Ion::Events::Event event) {
if (selectedRowIndex == 0) {
#endif
StackViewController * stack = (StackViewController *)(parentResponder());
m_typeParameterController.setSequence(m_sequence);
m_typeParameterController.setRecord(m_record);
stack->push(&m_typeParameterController);
return true;
}
@@ -63,25 +57,13 @@ bool ListParameterController::handleEvent(Ion::Events::Event event) {
#else
if (selectedRowIndex == 2+hasAdditionalRow) {
#endif
if (m_functionStore->numberOfModels() > 0) {
m_functionStore->removeModel(m_function);
static_cast<App *>(app())->localContext()->resetCache();
StackViewController * stack = (StackViewController *)(parentResponder());
stack->pop();
return true;
}
static_cast<App *>(app())->localContext()->resetCache();
return handleEnterOnRow(selectedRowIndex-hasAdditionalRow-1);
}
}
return false;
}
int ListParameterController::numberOfRows() {
if (hasInitialRankRow()) {
return k_totalNumberOfCell;
}
return k_totalNumberOfCell-1;
};
HighlightCell * ListParameterController::reusableCell(int index) {
switch (index) {
/*case 0:
@@ -93,27 +75,23 @@ HighlightCell * ListParameterController::reusableCell(int index) {
return &m_initialRankCell;
}
default:
return Shared::ListParameterController::reusableCell(index-1-hasInitialRankRow());
return Shared::StorageListParameterController::reusableCell(index-1-hasInitialRankRow());
}
}
int ListParameterController::reusableCellCount() {
return k_totalNumberOfCell;
}
void ListParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
cell->setHighlighted(index == selectedRow()); // See FIXME in SelectableTableView::reloadData()
Shared::ListParameterController::willDisplayCellForIndex(cell, index);
if (cell == &m_typeCell && m_sequence != nullptr) {
m_typeCell.setLayout(m_sequence->definitionName());
Shared::StorageListParameterController::willDisplayCellForIndex(cell, index);
if (cell == &m_typeCell && !m_record.isNull()) {
m_typeCell.setLayout(sequence()->definitionName());
}
if (cell == &m_initialRankCell && m_sequence != nullptr) {
if (cell == &m_initialRankCell && !m_record.isNull()) {
MessageTableCellWithEditableText * myCell = (MessageTableCellWithEditableText *) cell;
if (myCell->isEditing()) {
return;
}
char buffer[Sequence::k_initialRankNumberOfDigits+1];
Poincare::Integer(m_sequence->initialRank()).serialize(buffer, Sequence::k_initialRankNumberOfDigits+1);
Poincare::Integer(sequence()->initialRank()).serialize(buffer, Sequence::k_initialRankNumberOfDigits+1);
myCell->setAccessoryText(buffer);
}
}
@@ -138,7 +116,7 @@ bool ListParameterController::textFieldDidFinishEditing(TextField * textField, c
app()->displayWarning(I18n::Message::ForbiddenValue);
return false;
}
m_sequence->setInitialRank(index);
sequence()->setInitialRank(index);
// Invalidate sequence context cache when changing sequence type
static_cast<App *>(app())->localContext()->resetCache();
m_selectableTableView.reloadCellAtLocation(0, selectedRow());
@@ -178,8 +156,15 @@ TextFieldDelegateApp * ListParameterController::textFieldDelegateApp() {
return (TextFieldDelegateApp *)app();
}
bool ListParameterController::hasInitialRankRow() {
return m_sequence && m_sequence->type() != Sequence::Type::Explicit;
int ListParameterController::totalNumberOfCells() const {
if (hasInitialRankRow()) {
return k_totalNumberOfCell;
}
return k_totalNumberOfCell-1;
};
bool ListParameterController::hasInitialRankRow() const {
return !m_record.isNull() && const_cast<ListParameterController *>(this)->sequence()->type() != Sequence::Type::Explicit;
}
}