From bf2a2971ab34ed609692176ab7fd289a357ec879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 10 May 2017 13:34:49 +0200 Subject: [PATCH] [apps/sequence][apps/graph] Avoid blinking when deleting functions Change-Id: I820358f4968e65a54162d16f732bd51e19aca4ad --- apps/graph/list/list_controller.cpp | 4 +++- apps/graph/list/list_controller.h | 2 +- apps/sequence/list/list_controller.cpp | 25 +++++++++++++++++-------- apps/shared/list_controller.cpp | 18 ++++++++++-------- apps/shared/list_controller.h | 2 +- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/apps/graph/list/list_controller.cpp b/apps/graph/list/list_controller.cpp index 8ba1a94b6..da471ab3c 100644 --- a/apps/graph/list/list_controller.cpp +++ b/apps/graph/list/list_controller.cpp @@ -95,10 +95,12 @@ void ListController::willDisplayExpressionCellAtIndex(HighlightCell * cell, int myCell->setTextColor(textColor); } -void ListController::removeFunctionRow(Function * function) { +bool ListController::removeFunctionRow(Function * function) { if (m_functionStore->numberOfFunctions() > 1) { m_functionStore->removeFunction(function); + return true; } + return false; } View * ListController::loadView() { diff --git a/apps/graph/list/list_controller.h b/apps/graph/list/list_controller.h index 68c8a3151..2eb9df238 100644 --- a/apps/graph/list/list_controller.h +++ b/apps/graph/list/list_controller.h @@ -25,7 +25,7 @@ private: HighlightCell * expressionCells(int index) override; void willDisplayTitleCellAtIndex(HighlightCell * cell, int j) override; void willDisplayExpressionCellAtIndex(HighlightCell * cell, int j) override; - void removeFunctionRow(Shared::Function * function) override; + bool removeFunctionRow(Shared::Function * function) override; View * loadView() override; void unloadView(View * view) override; constexpr static int k_maxNumberOfRows = 5; diff --git a/apps/sequence/list/list_controller.cpp b/apps/sequence/list/list_controller.cpp index 131c77468..ccd3d98e3 100644 --- a/apps/sequence/list/list_controller.cpp +++ b/apps/sequence/list/list_controller.cpp @@ -254,14 +254,23 @@ void ListController::reinitExpression(Shared::Function * function) { Sequence * sequence = (Sequence *)function; switch (sequenceDefinitionForRow(selectedRow())) { case 1: - sequence->setFirstInitialConditionContent(""); - break; - case 2: - sequence->setSecondInitialConditionContent(""); - break; - default: - sequence->setContent(""); - break; + if (strlen(sequence->firstInitialConditionText()) == 0) { + return; + } + sequence->setFirstInitialConditionContent(""); + break; + case 2: + if (strlen(sequence->secondInitialConditionText()) == 0) { + return; + } + sequence->setSecondInitialConditionContent(""); + break; + default: + if (strlen(sequence->text()) == 0) { + return; + } + sequence->setContent(""); + break; } selectableTableView()->reloadData(); } diff --git a/apps/shared/list_controller.cpp b/apps/shared/list_controller.cpp index e5af7d275..a64f288ae 100644 --- a/apps/shared/list_controller.cpp +++ b/apps/shared/list_controller.cpp @@ -211,12 +211,13 @@ bool ListController::handleEvent(Ion::Events::Event event) { if (selectedColumn() == 1 && !function->isEmpty()) { reinitExpression(function); } else { - removeFunctionRow(function); - selectableTableView()->reloadData(); - selectableTableView()->selectCellAtLocation(selectedColumn(), selectedRow()); - if (selectedRow() >= numberOfRows()) { - selectableTableView()->selectCellAtLocation(0, 0); - selectableTableView()->selectCellAtLocation(selectedColumn(), numberOfRows()-1); + if (removeFunctionRow(function)) { + selectableTableView()->reloadData(); + selectableTableView()->selectCellAtLocation(selectedColumn(), selectedRow()); + if (selectedRow() >= numberOfRows()) { + selectableTableView()->selectCellAtLocation(0, 0); + selectableTableView()->selectCellAtLocation(selectedColumn(), numberOfRows()-1); + } } } return true; @@ -224,7 +225,7 @@ bool ListController::handleEvent(Ion::Events::Event event) { if ((event.hasText() || event == Ion::Events::XNT || event == Ion::Events::Paste) && selectedColumn() == 1 && (selectedRow() != numberOfRows() - 1 - || m_functionStore->numberOfFunctions() == m_functionStore->maxNumberOfFunctions())) { + || m_functionStore->numberOfFunctions() == m_functionStore->maxNumberOfFunctions())) { Shared::Function * function = m_functionStore->functionAtIndex(functionIndexForRow(selectedRow())); editExpression(function, event); return true; @@ -285,8 +286,9 @@ void ListController::addEmptyFunction() { selectableTableView()->reloadData(); } -void ListController::removeFunctionRow(Function * function) { +bool ListController::removeFunctionRow(Function * function) { m_functionStore->removeFunction(function); + return true; } View * ListController::loadView() { diff --git a/apps/shared/list_controller.h b/apps/shared/list_controller.h index 5d0c2f94c..70628072d 100644 --- a/apps/shared/list_controller.h +++ b/apps/shared/list_controller.h @@ -43,7 +43,7 @@ private: virtual int functionIndexForRow(int j); virtual const char * textForRow(int j); virtual void addEmptyFunction(); - virtual void removeFunctionRow(Function * function); + virtual bool removeFunctionRow(Function * function); virtual void editExpression(Function * function, Ion::Events::Event event) = 0; virtual ListParameterController * parameterController() = 0; virtual int maxNumberOfRows() = 0;