#include "console_controller.h" namespace Code { ConsoleController::ConsoleController(Responder * parentResponder) : ViewController(parentResponder), TextFieldDelegate(), m_tableView(this, this, 0, 0), m_editCell(this, this) { } void ConsoleController::viewWillAppear() { m_editCell.setEditing(true); } void ConsoleController::didBecomeFirstResponder() { app()->setFirstResponder(&m_editCell); } int ConsoleController::numberOfRows() { return m_consoleStore.numberOfLines()+1; } KDCoordinate ConsoleController::rowHeight(int j) { return k_rowHeight; } KDCoordinate ConsoleController::cumulatedHeightFromIndex(int j) { return j*rowHeight(0); } int ConsoleController::indexFromCumulatedHeight(KDCoordinate offsetY ){ return offsetY/rowHeight(0); } HighlightCell * ConsoleController::reusableCell(int index, int type) { assert(index >= 0); if (type == LineCellType) { assert(index < k_numberOfLineCells); return m_cells+index; } else { assert(type == EditCellType); assert(index == 0); return &m_editCell; } } int ConsoleController::reusableCellCount(int type) { if (type == LineCellType) { return k_numberOfLineCells; } else { return 1; } } int ConsoleController::typeAtLocation(int i, int j) { assert(i == 0); assert(j >= 0); if (j < m_consoleStore.numberOfLines()) { return LineCellType; } else { assert(j == m_consoleStore.numberOfLines()); return EditCellType; } } void ConsoleController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { assert(i == 0); if (j < m_consoleStore.numberOfLines()) { static_cast(cell)->setLine(m_consoleStore.lineAtIndex(j)); } } bool ConsoleController::textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) { return event == Ion::Events::OK || event == Ion::Events::EXE; } bool ConsoleController::textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) { return false; } bool ConsoleController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) { m_consoleStore.pushCommand(text, strlen(text)); textField->setText(""); m_tableView.reloadData(); m_tableView.scrollToCell(0, m_consoleStore.numberOfLines()); return true; } Toolbox * ConsoleController::toolboxForTextField(TextField * textFied) { return nullptr; } }