Numworks Epsilon
1.4.1
Graphing Calculator Operating System
menu_controller.h
Go to the documentation of this file.
1
#ifndef CODE_MENU_CONTROLLER_H
2
#define CODE_MENU_CONTROLLER_H
3
4
#include <
escher.h
>
5
#include <
apps/shared/new_function_cell.h
>
6
#include "
console_controller.h
"
7
#include "
editor_controller.h
"
8
#include "
script_parameter_controller.h
"
9
#include "
script_store.h
"
10
11
namespace
Code
{
12
13
class
ScriptParameterController;
14
15
class
MenuController
:
public
ViewController
,
public
TableViewDataSource
,
public
SelectableTableViewDataSource
,
public
SelectableTableViewDelegate
,
public
TextFieldDelegate
,
public
ButtonRowDelegate
{
16
public
:
17
MenuController
(
Responder
*
parentResponder
,
ScriptStore
* scriptStore,
ButtonRowController
*
footer
18
#
if
EPSILON_GETOPT
19
,
bool
m_lockOnConsole
20
#endif
21
);
22
ConsoleController
*
consoleController
() {
return
&m_consoleController; }
23
StackViewController
*
stackViewController
();
24
void
willExitResponderChain
(
Responder
* nextFirstResponder)
override
;
25
void
renameSelectedScript
();
26
void
deleteScript
(
Script
script);
27
void
reloadConsole
();
28
void
loadPythonIfNeeded
();
29
void
openConsoleWithScript
(
Script
script);
30
void
scriptContentEditionDidFinish
();
31
32
/* ViewController */
33
View
*
view
()
override
{
return
&m_selectableTableView; }
34
bool
handleEvent
(
Ion::Events::Event
event)
override
;
35
void
didBecomeFirstResponder
()
override
;
36
void
viewWillAppear
()
override
;
37
38
/* TableViewDataSource */
39
int
numberOfRows
()
override
;
40
int
numberOfColumns
()
override
{
return
2; }
41
void
willDisplayCellAtLocation
(
HighlightCell
* cell,
int
i,
int
j)
override
;
42
KDCoordinate
columnWidth
(
int
i)
override
;
43
KDCoordinate
rowHeight
(
int
j)
override
{
return
Metric::StoreRowHeight
; }
44
KDCoordinate
cumulatedWidthFromIndex
(
int
i)
override
;
45
KDCoordinate
cumulatedHeightFromIndex
(
int
j)
override
;
46
int
indexFromCumulatedWidth
(
KDCoordinate
offsetX)
override
;
47
int
indexFromCumulatedHeight
(
KDCoordinate
offsetY)
override
;
48
HighlightCell
*
reusableCell
(
int
index,
int
type)
override
;
49
int
reusableCellCount
(
int
type)
override
;
50
int
typeAtLocation
(
int
i,
int
j)
override
;
51
void
willDisplayScriptTitleCellForIndex
(
HighlightCell
* cell,
int
index);
52
53
/* SelectableTableViewDelegate */
54
void
tableViewDidChangeSelection
(
SelectableTableView
* t,
int
previousSelectedCellX,
int
previousSelectedCellY)
override
;
55
56
/* TextFieldDelegate */
57
bool
textFieldShouldFinishEditing
(
TextField
* textField,
Ion::Events::Event
event)
override
;
58
bool
textFieldDidReceiveEvent
(
TextField
* textField,
Ion::Events::Event
event)
override
;
59
bool
textFieldDidFinishEditing
(
TextField
* textField,
const
char
* text,
Ion::Events::Event
event)
override
;
60
bool
textFieldDidAbortEditing
(
TextField
* textField,
const
char
* text)
override
;
61
bool
textFieldDidHandleEvent
(
TextField
* textField,
bool
returnValue,
bool
textHasChanged)
override
;
62
Toolbox
*
toolboxForTextInput
(
TextInput
* textInput)
override
{
return
nullptr
; }
63
64
/* ButtonRowDelegate */
65
int
numberOfButtons
(
ButtonRowController::Position
position)
const override
{
return
1; }
66
Button
*
buttonAtIndex
(
int
index,
ButtonRowController::Position
position)
const override
{
67
assert
(index == 0);
68
return
const_cast<
Button
*
>
(&m_consoleButton);
69
}
70
71
private
:
72
static
constexpr
int
k_maxNumberOfDisplayableScriptCells = 5;
// = 240/50
73
static
constexpr
int
k_parametersColumnWidth = 37;
74
static
constexpr
int
AddScriptCellType = 0;
75
static
constexpr
int
ScriptCellType = 1;
76
static
constexpr
int
ScriptParameterCellType = 2;
77
static
constexpr
int
EmptyCellType = 3;
78
static
constexpr
int
k_defaultScriptNameMaxSize = 9 + 2 + 1;
79
// k_defaultScriptNameMaxSize is the length of a name between script1.py and
80
// script99.py.
81
// 9 = strlen("script.py")
82
// 2 = maxLength of integers between 1 and 99.
83
// 1 = length of null terminating char.
84
void
addScript();
85
void
configureScript();
86
void
editScriptAtIndex(
int
scriptIndex);
87
void
numberedDefaultScriptName(
char
* buffer);
88
void
intToText(
int
i,
char
* buffer);
89
void
updateAddScriptRowDisplay();
90
ScriptStore
* m_scriptStore;
91
class
EvenOddEditableTextCell
:
public
::EvenOddEditableTextCell
{
92
public
:
93
Responder
* responder()
override
{
94
if
(editableTextCell()->textField()->isEditing()) {
95
return
this
;
96
}
97
return
nullptr
;
98
}
99
};
100
EvenOddEditableTextCell
m_scriptCells[k_maxNumberOfDisplayableScriptCells];
101
/* In the initializer list of the MenuController constructor, we initialize
102
* m_scriptCells by copying k_maxNumberOfDisplayableScriptCells times the
103
* constructor of an EvenOddEditableTextCell. */
104
char
m_draftTextBuffer[
TextField::maxBufferSize
()];
105
EvenOddCellWithEllipsis
m_scriptParameterCells[k_maxNumberOfDisplayableScriptCells];
106
Shared::NewFunctionCell
m_addNewScriptCell;
107
EvenOddCell
m_emptyCell;
108
Button
m_consoleButton;
109
SelectableTableView
m_selectableTableView;
110
ConsoleController m_consoleController;
111
ScriptParameterController m_scriptParameterController;
112
EditorController m_editorController;
113
bool
m_reloadConsoleWhenBecomingFirstResponder;
114
bool
m_shouldDisplayAddScriptRow;
115
};
116
117
}
118
119
#endif
Metric::StoreRowHeight
static constexpr KDCoordinate StoreRowHeight
Definition:
metric.h:26
Code::MenuController::indexFromCumulatedHeight
int indexFromCumulatedHeight(KDCoordinate offsetY) override
Definition:
menu_controller.cpp:225
Code::MenuController::viewWillAppear
void viewWillAppear() override
Definition:
menu_controller.cpp:87
TextField
Definition:
text_field.h:8
Code::MenuController::textFieldDidReceiveEvent
bool textFieldDidReceiveEvent(TextField *textField, Ion::Events::Event event) override
Definition:
menu_controller.cpp:300
Code::MenuController::rowHeight
KDCoordinate rowHeight(int j) override
Definition:
menu_controller.h:43
Code::ScriptStore
Definition:
script_store.h:14
assert
#define assert(e)
Definition:
assert.h:9
Toolbox
Definition:
toolbox.h:12
TextField::maxBufferSize
static constexpr int maxBufferSize()
Definition:
text_field.h:23
SelectableTableViewDataSource
Definition:
selectable_table_view_data_source.h:8
Code::MenuController::consoleController
ConsoleController * consoleController()
Definition:
menu_controller.h:22
Code::MenuController::numberOfButtons
int numberOfButtons(ButtonRowController::Position position) const override
Definition:
menu_controller.h:65
KDCoordinate
int16_t KDCoordinate
Definition:
coordinate.h:6
Responder::parentResponder
Responder * parentResponder() const
Definition:
responder.cpp:12
ButtonRowController
Definition:
button_row_controller.h:14
Code::MenuController::reusableCell
HighlightCell * reusableCell(int index, int type) override
Definition:
menu_controller.cpp:232
Code::MenuController::willExitResponderChain
void willExitResponderChain(Responder *nextFirstResponder) override
Definition:
menu_controller.cpp:53
escher.h
Code::MenuController::loadPythonIfNeeded
void loadPythonIfNeeded()
Definition:
menu_controller.cpp:152
Code::MenuController::textFieldDidFinishEditing
bool textFieldDidFinishEditing(TextField *textField, const char *text, Ion::Events::Event event) override
Definition:
menu_controller.cpp:312
TableViewDataSource
Definition:
table_view_data_source.h:7
TextFieldDelegate
Definition:
text_field_delegate.h:8
Ion::Events::Event
Definition:
events.h:9
script_parameter_controller.h
Code::MenuController::textFieldDidAbortEditing
bool textFieldDidAbortEditing(TextField *textField, const char *text) override
Definition:
menu_controller.cpp:348
Code::MenuController::handleEvent
bool handleEvent(Ion::Events::Event event) override
Definition:
menu_controller.cpp:91
Shared::NewFunctionCell
Definition:
new_function_cell.h:8
Responder
Definition:
responder.h:9
Code
Definition:
app.cpp:7
ButtonRowDelegate::footer
ButtonRowController * footer()
Definition:
button_row_controller.h:79
Code::MenuController::view
View * view() override
Definition:
menu_controller.h:33
StackViewController
Definition:
stack_view_controller.h:10
Code::MenuController::tableViewDidChangeSelection
void tableViewDidChangeSelection(SelectableTableView *t, int previousSelectedCellX, int previousSelectedCellY) override
Definition:
menu_controller.cpp:289
Code::MenuController::openConsoleWithScript
void openConsoleWithScript(Script script)
Definition:
menu_controller.cpp:156
Code::MenuController::typeAtLocation
int typeAtLocation(int i, int j) override
Definition:
menu_controller.cpp:267
editor_controller.h
HighlightCell
Definition:
highlight_cell.h:7
Code::MenuController::numberOfColumns
int numberOfColumns() override
Definition:
menu_controller.h:40
EvenOddEditableTextCell
Definition:
even_odd_editable_text_cell.h:8
Code::MenuController::numberOfRows
int numberOfRows() override
Definition:
menu_controller.cpp:169
script_store.h
Code::MenuController::columnWidth
KDCoordinate columnWidth(int i) override
Definition:
menu_controller.cpp:181
Code::MenuController::buttonAtIndex
Button * buttonAtIndex(int index, ButtonRowController::Position position) const override
Definition:
menu_controller.h:66
Code::MenuController::reusableCellCount
int reusableCellCount(int type) override
Definition:
menu_controller.cpp:253
Code::MenuController::scriptContentEditionDidFinish
void scriptContentEditionDidFinish()
Definition:
menu_controller.cpp:165
ButtonRowController::Position
Position
Definition:
button_row_controller.h:16
console_controller.h
Code::MenuController::cumulatedHeightFromIndex
KDCoordinate cumulatedHeightFromIndex(int j) override
Definition:
menu_controller.cpp:207
Code::MenuController::stackViewController
StackViewController * stackViewController()
Definition:
menu_controller.cpp:49
Code::MenuController::cumulatedWidthFromIndex
KDCoordinate cumulatedWidthFromIndex(int i) override
Definition:
menu_controller.cpp:193
Code::MenuController::willDisplayScriptTitleCellForIndex
void willDisplayScriptTitleCellForIndex(HighlightCell *cell, int index)
Definition:
menu_controller.cpp:283
EvenOddCellWithEllipsis
Definition:
even_odd_cell_with_ellipsis.h:8
SelectableTableView
Definition:
selectable_table_view.h:18
SelectableTableViewDelegate
Definition:
selectable_table_view_delegate.h:6
Code::MenuController::renameSelectedScript
void renameSelectedScript()
Definition:
menu_controller.cpp:127
Code::Script
Definition:
script.h:11
Code::MenuController::MenuController
MenuController(Responder *parentResponder, ScriptStore *scriptStore, ButtonRowController *footer)
Definition:
menu_controller.cpp:10
Code::MenuController::textFieldDidHandleEvent
bool textFieldDidHandleEvent(TextField *textField, bool returnValue, bool textHasChanged) override
Definition:
menu_controller.cpp:369
View
Definition:
view.h:23
Code::MenuController::toolboxForTextInput
Toolbox * toolboxForTextInput(TextInput *textInput) override
Definition:
menu_controller.h:62
Code::ConsoleController
Definition:
console_controller.h:15
Code::MenuController
Definition:
menu_controller.h:15
EvenOddCell
Definition:
even_odd_cell.h:6
Code::MenuController::textFieldShouldFinishEditing
bool textFieldShouldFinishEditing(TextField *textField, Ion::Events::Event event) override
Definition:
menu_controller.cpp:295
Button
Definition:
button.h:10
Code::MenuController::reloadConsole
void reloadConsole()
Definition:
menu_controller.cpp:147
Code::MenuController::didBecomeFirstResponder
void didBecomeFirstResponder() override
Definition:
menu_controller.cpp:65
ViewController
Definition:
view_controller.h:30
ButtonRowDelegate
Definition:
button_row_controller.h:70
Code::MenuController::willDisplayCellAtLocation
void willDisplayCellAtLocation(HighlightCell *cell, int i, int j) override
Definition:
menu_controller.cpp:173
new_function_cell.h
Code::MenuController::indexFromCumulatedWidth
int indexFromCumulatedWidth(KDCoordinate offsetX) override
Definition:
menu_controller.cpp:211
TextInput
Definition:
text_input.h:10
Code::MenuController::deleteScript
void deleteScript(Script script)
Definition:
menu_controller.cpp:141
epsilon
apps
code
menu_controller.h
Generated by
1.8.14