mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps] VariableBoxController: enable to lock pages from deletion
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user