[apps] VariableBoxController: enable to lock pages from deletion

This commit is contained in:
Émilie Feral
2018-10-23 15:01:15 +02:00
parent 19d2cb7cc0
commit ebfa8fb3fa
2 changed files with 16 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ using namespace Ion;
VariableBoxController::VariableBoxController() :
NestedMenuController(nullptr, I18n::Message::Variables),
m_currentPage(Page::RootMenu),
m_lockPageDelete(Page::RootMenu),
m_firstMemoizedLayoutIndex(0)
{
}
@@ -42,9 +43,12 @@ void VariableBoxController::viewDidDisappear() {
}
bool VariableBoxController::handleEvent(Ion::Events::Event event) {
/* We do not want to handle backspace event in that case if the empty
* controller is on. */
if (event == Ion::Events::Backspace && m_currentPage != Page::RootMenu && !isDisplayingEmptyController()) {
/* We do not want to handle backspace event if:
* - On the root menu page
* The deletion on the current page is locked
* - The empty controller is displayed
*/
if (event == Ion::Events::Backspace && m_currentPage != Page::RootMenu && m_lockPageDelete != m_currentPage && !isDisplayingEmptyController()) {
Storage::Record record = recordAtIndex(selectedRow());
record.destroy();
int newSelectedRow = selectedRow() >= numberOfRows() ? numberOfRows()-1 : selectedRow();
@@ -118,6 +122,10 @@ int VariableBoxController::typeAtLocation(int i, int j) {
return 0;
}
void VariableBoxController::lockDeleteEvent(Page page) {
m_lockPageDelete = page;
}
ExpressionTableCellWithExpression * VariableBoxController::leafCellAtIndex(int index) {
assert(index >= 0 && index < k_maxNumberOfDisplayedRows);
return &m_leafCells[index];
@@ -211,10 +219,12 @@ Layout VariableBoxController::expressionLayoutForRecord(Storage::Record record,
}
const char * VariableBoxController::extension() const {
assert(m_currentPage != Page::RootMenu);
return m_currentPage == Page::Function ? GlobalContext::funcExtension : GlobalContext::expExtension;
}
Storage::Record VariableBoxController::recordAtIndex(int rowIndex) {
assert(m_currentPage != Page::RootMenu);
assert(!Storage::sharedStorage()->recordWithExtensionAtIndex(extension(), rowIndex).isNull());
return Storage::sharedStorage()->recordWithExtensionAtIndex(extension(), rowIndex);
}

View File

@@ -27,12 +27,13 @@ public:
int typeAtLocation(int i, int j) override;
// Menu
private:
enum class Page {
RootMenu = 0,
Expression = 1,
Function = 2
};
void lockDeleteEvent(Page page);
private:
// TODO: use the "(x)" define in CartesianFunctionSomething
constexpr static int k_functionArgLength = 3;
constexpr static const char * k_functionArg = "(x)";
@@ -52,6 +53,7 @@ private:
bool displayEmptyController();
bool isDisplayingEmptyController() { return StackViewController::depth() == 2; }
Page m_currentPage;
Page m_lockPageDelete;
ExpressionTableCellWithExpression m_leafCells[k_maxNumberOfDisplayedRows];
MessageTableCellWithChevron m_nodeCells[k_numberOfMenuRows];
VariableBoxEmptyController m_emptyViewController;