3 #include "../shared/toolbox_helpers.h" 14 VariableBoxController::ContentViewController::ContentViewController(
Responder * parentResponder, MenuController * menuController, ScriptStore * scriptStore) :
16 m_scriptNodesCount(0),
17 m_menuController(menuController),
18 m_scriptStore(scriptStore),
19 m_selectableTableView(this)
21 m_selectableTableView.setMargins(0);
22 m_selectableTableView.setShowsIndicators(
false);
23 for (
int i = 0; i < k_maxNumberOfDisplayedRows; i++) {
24 m_leafCells[i].setScriptStore(scriptStore);
28 void VariableBoxController::ContentViewController::setTextInputCaller(
TextInput * textInput) {
29 m_textInputCaller = textInput;
32 void VariableBoxController::ContentViewController::reloadData() {
33 m_selectableTableView.reloadData();
36 void VariableBoxController::ContentViewController::addFunctionAtIndex(
const char * functionName,
int scriptIndex) {
41 void VariableBoxController::ContentViewController::addVariableAtIndex(
const char * variableName,
int scriptIndex) {
46 const char * VariableBoxController::ContentViewController::title() {
51 m_menuController->loadPythonIfNeeded();
52 m_scriptNodesCount = 0;
53 m_scriptStore->scanScriptsForFunctionsAndVariables(
55 [](
void * context,
const char * functionName,
int scriptIndex) {
56 VariableBoxController::ContentViewController * cvc =
static_cast<VariableBoxController::ContentViewController *
>(context);
57 cvc->addFunctionAtIndex(functionName, scriptIndex);},
58 [](
void * context,
const char * variableName,
int scriptIndex) {
59 VariableBoxController::ContentViewController * cvc =
static_cast<VariableBoxController::ContentViewController *
>(context);
60 cvc->addVariableAtIndex(variableName, scriptIndex);});
63 void VariableBoxController::ContentViewController::viewDidDisappear() {
64 m_selectableTableView.deselectTable();
68 void VariableBoxController::ContentViewController::didBecomeFirstResponder() {
69 m_selectableTableView.reloadData();
70 m_selectableTableView.scrollToCell(0,0);
71 selectCellAtLocation(0, 0);
72 app()->setFirstResponder(&m_selectableTableView);
75 bool VariableBoxController::ContentViewController::handleEvent(
Ion::Events::Event event) {
77 app()->dismissModalViewController();
84 if (m_selectableTableView.selectedRow() < 0 || m_selectableTableView.selectedRow() >= m_scriptNodesCount) {
87 ScriptNode selectedScriptNode = m_scriptNodes[m_selectableTableView.selectedRow()];
88 insertTextInCaller(selectedScriptNode.name());
92 m_selectableTableView.deselectTable();
93 app()->dismissModalViewController();
100 return m_scriptNodesCount < k_maxScriptNodesCount ? m_scriptNodesCount : k_maxScriptNodesCount;
103 HighlightCell * VariableBoxController::ContentViewController::reusableCell(
int index) {
104 assert(index >= 0 && index < k_maxNumberOfDisplayedRows);
105 return &m_leafCells[index];
108 int VariableBoxController::ContentViewController::reusableCellCount() {
109 return k_maxNumberOfDisplayedRows;
112 void VariableBoxController::ContentViewController::willDisplayCellForIndex(
HighlightCell * cell,
int index) {
113 ScriptNodeCell * myCell =
static_cast<ScriptNodeCell *
>(cell);
114 myCell->setScriptNode(&m_scriptNodes[index]);
117 void VariableBoxController::ContentViewController::insertTextInCaller(
const char * text) {
118 char commandBuffer[
strlen(text)+1];
120 m_textInputCaller->handleEventWithText(commandBuffer);
125 m_contentViewController(this, menuController, scriptStore)
134 m_contentViewController.setTextInputCaller(textInput);
139 m_contentViewController.reloadData();
static ScriptNode FunctionNode(const char *name, uint16_t scriptIndex)
void viewDidDisappear() override
enum Message uint16_t enum Language uint16_t const char * translate(Message m, Language l=(Language) 0)
void viewDidDisappear() override
void viewWillAppear() override
constexpr KDColor KDColorWhite
size_t strlen(const char *s)
virtual void viewWillAppear()
static constexpr char k_parentheses[]
void viewWillAppear() override
void didBecomeFirstResponder() override
void setFirstResponder(Responder *responder)
VariableBoxController(MenuController *menuController, ScriptStore *scriptStore)
virtual void viewDidDisappear()
constexpr uint8_t numberOfRows
static ScriptNode VariableNode(const char *name, uint16_t scriptIndex)
void setTextInputCaller(TextInput *textInput)