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>
6 #include "console_controller.h"
7 #include "editor_controller.h"
9 #include "script_store.h"
10 
11 namespace Code {
12 
13 class ScriptParameterController;
14 
16 public:
18 #if EPSILON_GETOPT
19  , bool m_lockOnConsole
20 #endif
21  );
22  ConsoleController * consoleController() { return &m_consoleController; }
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);
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;
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
static constexpr KDCoordinate StoreRowHeight
Definition: metric.h:26
int indexFromCumulatedHeight(KDCoordinate offsetY) override
void viewWillAppear() override
bool textFieldDidReceiveEvent(TextField *textField, Ion::Events::Event event) override
KDCoordinate rowHeight(int j) override
#define assert(e)
Definition: assert.h:9
static constexpr int maxBufferSize()
Definition: text_field.h:23
ConsoleController * consoleController()
int numberOfButtons(ButtonRowController::Position position) const override
int16_t KDCoordinate
Definition: coordinate.h:6
Responder * parentResponder() const
Definition: responder.cpp:12
HighlightCell * reusableCell(int index, int type) override
void willExitResponderChain(Responder *nextFirstResponder) override
bool textFieldDidFinishEditing(TextField *textField, const char *text, Ion::Events::Event event) override
bool textFieldDidAbortEditing(TextField *textField, const char *text) override
bool handleEvent(Ion::Events::Event event) override
Definition: app.cpp:7
ButtonRowController * footer()
View * view() override
void tableViewDidChangeSelection(SelectableTableView *t, int previousSelectedCellX, int previousSelectedCellY) override
void openConsoleWithScript(Script script)
int typeAtLocation(int i, int j) override
int numberOfColumns() override
int numberOfRows() override
KDCoordinate columnWidth(int i) override
Button * buttonAtIndex(int index, ButtonRowController::Position position) const override
int reusableCellCount(int type) override
KDCoordinate cumulatedHeightFromIndex(int j) override
StackViewController * stackViewController()
KDCoordinate cumulatedWidthFromIndex(int i) override
void willDisplayScriptTitleCellForIndex(HighlightCell *cell, int index)
MenuController(Responder *parentResponder, ScriptStore *scriptStore, ButtonRowController *footer)
bool textFieldDidHandleEvent(TextField *textField, bool returnValue, bool textHasChanged) override
Definition: view.h:23
Toolbox * toolboxForTextInput(TextInput *textInput) override
bool textFieldShouldFinishEditing(TextField *textField, Ion::Events::Event event) override
Definition: button.h:10
void didBecomeFirstResponder() override
void willDisplayCellAtLocation(HighlightCell *cell, int i, int j) override
int indexFromCumulatedWidth(KDCoordinate offsetX) override
void deleteScript(Script script)