diff --git a/apps/calculation/history_controller.cpp b/apps/calculation/history_controller.cpp index a9bbc1e1e..e2cbf20f2 100644 --- a/apps/calculation/history_controller.cpp +++ b/apps/calculation/history_controller.cpp @@ -40,7 +40,7 @@ void HistoryController::reload() { if (numberOfRows() > 0) { m_selectableTableView.scrollToCell(0, numberOfRows()-1); // Force to reload last added cell (hide the burger and exact output if necessary) - tableViewDidChangeSelection(&m_selectableTableView, 0, numberOfRows()-1); + tableViewDidChangeSelectionAndDidScroll(&m_selectableTableView, 0, numberOfRows()-1); } } @@ -128,7 +128,7 @@ bool HistoryController::handleEvent(Ion::Events::Event event) { return true; } m_selectableTableView.selectCellAtLocation(0, focusRow > 0 ? focusRow - 1 : 0); - tableViewDidChangeSelection(&m_selectableTableView, 0, (subviewType == SubviewType::Input) ? selectedRow() : -1); + tableViewDidChangeSelectionAndDidScroll(&m_selectableTableView, 0, (subviewType == SubviewType::Input) ? selectedRow() : -1); m_selectableTableView.scrollToCell(0, selectedRow()); return true; } @@ -151,7 +151,7 @@ Shared::ExpiringPointer HistoryController::calculationAtIndex(int i return m_calculationStore->calculationAtIndex(storeIndex(i)); } -void HistoryController::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) { +void HistoryController::tableViewDidChangeSelectionAndDidScroll(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) { if (withinTemporarySelection || previousSelectedCellY == selectedRow()) { return; } diff --git a/apps/calculation/history_controller.h b/apps/calculation/history_controller.h index 2cb20840a..64d75755c 100644 --- a/apps/calculation/history_controller.h +++ b/apps/calculation/history_controller.h @@ -31,7 +31,7 @@ public: void willDisplayCellForIndex(HighlightCell * cell, int index) override; KDCoordinate rowHeight(int j) override; int typeAtLocation(int i, int j) override; - void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection = false) override; + void tableViewDidChangeSelectionAndDidScroll(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection = false) override; private: int storeIndex(int i) { return numberOfRows() - i - 1; } Shared::ExpiringPointer calculationAtIndex(int i); diff --git a/apps/code/console_controller.cpp b/apps/code/console_controller.cpp index 8bae83090..de947fa9c 100644 --- a/apps/code/console_controller.cpp +++ b/apps/code/console_controller.cpp @@ -285,7 +285,7 @@ void ConsoleController::willDisplayCellAtLocation(HighlightCell * cell, int i, i } } -void ConsoleController::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) { +void ConsoleController::tableViewDidChangeSelectionAndDidScroll(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) { if (withinTemporarySelection) { return; } diff --git a/apps/code/console_controller.h b/apps/code/console_controller.h index cd3cae701..ff79e7b51 100644 --- a/apps/code/console_controller.h +++ b/apps/code/console_controller.h @@ -53,7 +53,7 @@ public: void willDisplayCellAtLocation(HighlightCell * cell, int i, int j) override; // SelectableTableViewDelegate - void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) override; + void tableViewDidChangeSelectionAndDidScroll(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) override; // TextFieldDelegate bool textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) override; diff --git a/apps/home/controller.cpp b/apps/home/controller.cpp index b2f779d1a..50af28bfb 100644 --- a/apps/home/controller.cpp +++ b/apps/home/controller.cpp @@ -140,7 +140,21 @@ int Controller::numberOfIcons() const { } void Controller::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) { - AppsContainer * container = AppsContainer::sharedAppsContainer(); + if (withinTemporarySelection) { + return; + } + /* To prevent the selectable table view to select cells that are unvisible, + * we reselect the previous selected cell as soon as the selected cell is + * unvisible. This trick does not create an endless loop as we ensure not to + * stay on a unvisible cell and to initialize the first cell on a visible one + * (so the previous one is always visible). */ + int appIndex = (t->selectedColumn()+t->selectedRow()*k_numberOfColumns)+1; + if (appIndex >= AppsContainer::sharedAppsContainer()->numberOfApps()) { + t->selectCellAtLocation(previousSelectedCellX, previousSelectedCellY); + } +} + +void Controller::tableViewDidChangeSelectionAndDidScroll(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) { if (withinTemporarySelection) { return; } @@ -153,16 +167,7 @@ void Controller::tableViewDidChangeSelection(SelectableTableView * t, int previo * background complete redrawing but the code is a bit * clumsy. */ if (t->selectedRow() == numberOfRows()-1) { - m_view.reloadBottomRow(this, container->numberOfApps()-1, k_numberOfColumns); - } - /* To prevent the selectable table view to select cells that are unvisible, - * we reselect the previous selected cell as soon as the selected cell is - * unvisible. This trick does not create an endless loop as we ensure not to - * stay on a unvisible cell and to initialize the first cell on a visible one - * (so the previous one is always visible). */ - int appIndex = (t->selectedColumn()+t->selectedRow()*k_numberOfColumns)+1; - if (appIndex >= container->numberOfApps()) { - t->selectCellAtLocation(previousSelectedCellX, previousSelectedCellY); + m_view.reloadBottomRow(this, AppsContainer::sharedAppsContainer()->numberOfApps()-1, k_numberOfColumns); } } diff --git a/apps/home/controller.h b/apps/home/controller.h index 730541718..9fc7fb381 100644 --- a/apps/home/controller.h +++ b/apps/home/controller.h @@ -24,6 +24,7 @@ public: int reusableCellCount() const override; void willDisplayCellAtLocation(HighlightCell * cell, int i, int j) override; void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) override; + void tableViewDidChangeSelectionAndDidScroll(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) override; private: int numberOfIcons() const; SelectableTableViewDataSource * selectionDataSource() const; diff --git a/apps/sequence/list/list_parameter_controller.cpp b/apps/sequence/list/list_parameter_controller.cpp index b40cab658..ebdd85905 100644 --- a/apps/sequence/list/list_parameter_controller.cpp +++ b/apps/sequence/list/list_parameter_controller.cpp @@ -87,7 +87,7 @@ bool ListParameterController::textFieldDidFinishEditing(TextField * textField, c return true; } -void ListParameterController::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) { +void ListParameterController::tableViewDidChangeSelectionAndDidScroll(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) { if (withinTemporarySelection || (previousSelectedCellX == t->selectedColumn() && previousSelectedCellY == t->selectedRow())) { return; } diff --git a/apps/sequence/list/list_parameter_controller.h b/apps/sequence/list/list_parameter_controller.h index 6aaddb713..cc5ddae78 100644 --- a/apps/sequence/list/list_parameter_controller.h +++ b/apps/sequence/list/list_parameter_controller.h @@ -19,7 +19,7 @@ public: bool textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) override; bool textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) override; - void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) override; + void tableViewDidChangeSelectionAndDidScroll(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) override; // ListViewDataSource HighlightCell * reusableCell(int index, int type) override; diff --git a/escher/include/escher/selectable_table_view_delegate.h b/escher/include/escher/selectable_table_view_delegate.h index c7e20ee7b..b94d6b20f 100644 --- a/escher/include/escher/selectable_table_view_delegate.h +++ b/escher/include/escher/selectable_table_view_delegate.h @@ -13,6 +13,7 @@ public: * the previous selected cell. We might implement different course of action * when the selection change is 'real' or within temporary selection. */ virtual void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection = false) {} + virtual void tableViewDidChangeSelectionAndDidScroll(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection = false) {} }; #endif diff --git a/escher/src/selectable_table_view.cpp b/escher/src/selectable_table_view.cpp index bb07591f0..9b4aab505 100644 --- a/escher/src/selectable_table_view.cpp +++ b/escher/src/selectable_table_view.cpp @@ -102,6 +102,10 @@ bool SelectableTableView::selectCellAtLocation(int i, int j, bool setFirstRespon scrollToCell(selectedColumn(), selectedRow()); } + if (m_delegate) { + m_delegate->tableViewDidChangeSelectionAndDidScroll(this, previousX, previousY, withinTemporarySelection); + } + HighlightCell * cell = selectedCell(); if (cell) { // Update first responder