diff --git a/apps/code/menu_controller.cpp b/apps/code/menu_controller.cpp index e80ad401e..31169af7a 100644 --- a/apps/code/menu_controller.cpp +++ b/apps/code/menu_controller.cpp @@ -72,10 +72,8 @@ void MenuController::configureScript() { } void MenuController::addScript() { - m_selectableTableView.selectCellAtLocation(0, 0); m_scriptStore->addNewScript(); m_selectableTableView.reloadData(); - m_selectableTableView.selectCellAtLocation(0, numberOfRows()-2); } void MenuController::renameScriptAtIndex(int i) { @@ -149,14 +147,11 @@ int MenuController::typeAtLocation(int i, int j) { void MenuController::willDisplayCellForIndex(HighlightCell * cell, int index) { if (index < m_scriptStore->numberOfScripts()) { - EvenOddEditableTextCell * myCell = static_cast(cell); - myCell->editableTextCell()->textField()->setText(m_scriptStore->scriptAtIndex(index).name()); - myCell->setEven(index%2 == 0); - } else { - assert(index == m_scriptStore->numberOfScripts()); - Shared::NewFunctionCell * myCell = static_cast(cell); - myCell->setEven(index%2 == 0); + EditableTextCell * editableTextCell = static_cast(cell)->editableTextCell(); + editableTextCell->textField()->setText(m_scriptStore->scriptAtIndex(index).name()); } + static_cast(cell)->setEven(index%2 == 0); + cell->setHighlighted(index == selectedRow()); } bool MenuController::textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) { diff --git a/escher/include/escher/highlight_cell.h b/escher/include/escher/highlight_cell.h index 61f939aef..74153790a 100644 --- a/escher/include/escher/highlight_cell.h +++ b/escher/include/escher/highlight_cell.h @@ -7,7 +7,7 @@ class HighlightCell : public View { public: HighlightCell(); virtual void setHighlighted(bool highlight); - bool isHighlighted() const; + bool isHighlighted() const { return m_highlighted; } virtual void reloadCell(); protected: bool m_highlighted; diff --git a/escher/src/highlight_cell.cpp b/escher/src/highlight_cell.cpp index a897e6741..2d781d3d7 100644 --- a/escher/src/highlight_cell.cpp +++ b/escher/src/highlight_cell.cpp @@ -7,12 +7,10 @@ HighlightCell::HighlightCell() : } void HighlightCell::setHighlighted(bool highlight) { - m_highlighted = highlight; - reloadCell(); -} - -bool HighlightCell::isHighlighted() const { - return m_highlighted; + if (m_highlighted != highlight) { + m_highlighted = highlight; + reloadCell(); + } } void HighlightCell::reloadCell() { diff --git a/escher/src/selectable_table_view.cpp b/escher/src/selectable_table_view.cpp index 3641674aa..7141d4f70 100644 --- a/escher/src/selectable_table_view.cpp +++ b/escher/src/selectable_table_view.cpp @@ -33,6 +33,12 @@ void SelectableTableView::reloadData() { int col = selectedColumn(); int row = selectedRow(); deselectTable(); + /* FIXME: The problem with calling deselectTable is that at this point in time + * the datasource's model is very likely to have changed. Therefore it's + * rather complicated to get a pointer to the currently selected cell (in + * order to deselect it). */ + /* As a workaround, datasources can reset the highlighted state in their + * willDisplayCell callback. */ TableView::reloadData(); selectCellAtLocation(col, row); }