Numworks Epsilon  1.4.1
Graphing Calculator Operating System
script_parameter_controller.cpp
Go to the documentation of this file.
2 #include "menu_controller.h"
3 
4 namespace Code {
5 
6 ScriptParameterController::ScriptParameterController(Responder * parentResponder, I18n::Message title, MenuController * menuController) :
7  ViewController(parentResponder),
8  m_pageTitle(title),
9  m_executeScript(I18n::Message::ExecuteScript),
10  m_renameScript(I18n::Message::RenameScript),
11  m_autoImportScript(I18n::Message::AutoImportScript),
12  m_deleteScript(I18n::Message::DeleteScript),
13  m_selectableTableView(this),
14  m_script(Ion::Storage::Record()),
15  m_menuController(menuController)
16 {
17 }
18 
20  m_script = script;
21 }
22 
24  m_script = Script(Ion::Storage::Record());
25  stackViewController()->pop();
26 }
27 
29  return I18n::translate(m_pageTitle);
30 }
31 
33  if (event == Ion::Events::OK || event == Ion::Events::EXE) {
34  Script s = m_script;
35  switch (selectedRow()) {
36  case 0:
38  m_menuController->openConsoleWithScript(s);
39  return true;
40  case 1:
42  m_menuController->renameSelectedScript();
43  return true;
44  case 2:
45  m_script.toggleImportationStatus();
46  m_selectableTableView.reloadData();
47  m_menuController->reloadConsole();
48  app()->setFirstResponder(&m_selectableTableView);
49  return true;
50  case 3:
52  m_menuController->deleteScript(s);
53  m_menuController->reloadConsole();
54  return true;
55  default:
56  assert(false);
57  return false;
58  }
59  }
60  return false;
61 }
62 
64  m_selectableTableView.reloadData();
65  m_selectableTableView.selectCellAtLocation(0,0);
66 }
67 
70  app()->setFirstResponder(&m_selectableTableView);
71 }
72 
74  assert(index >= 0);
75  assert(index < k_totalNumberOfCell);
76  HighlightCell * cells[] = {&m_executeScript, &m_renameScript, &m_autoImportScript, &m_deleteScript};
77  return cells[index];
78 }
79 
81  if (cell == &m_autoImportScript) {
82  SwitchView * switchView = (SwitchView *)m_autoImportScript.accessoryView();
83  switchView->setState(m_script.importationStatus());
84  }
85 }
86 
87 StackViewController * ScriptParameterController::stackViewController() {
88  return static_cast<StackViewController *>(parentResponder());
89 }
90 
91 }
Definition: i18n.h:6
ScriptParameterController(Responder *parentResponder, I18n::Message title, MenuController *menuController)
#define assert(e)
Definition: assert.h:9
constexpr Event EXE
Definition: events.h:114
Responder * parentResponder() const
Definition: responder.cpp:12
bool selectCellAtLocation(int i, int j, bool setFirstResponder=true)
void reloadData(bool setFirstResponder=true)
enum Message uint16_t enum Language uint16_t const char * translate(Message m, Language l=(Language) 0)
Definition: i18n.cpp:5
Definition: app.cpp:7
void openConsoleWithScript(Script script)
HighlightCell * reusableCell(int index) override
void toggleImportationStatus()
Definition: script.cpp:16
void willDisplayCellForIndex(HighlightCell *cell, int index) override
bool importationStatus() const
Definition: script.cpp:10
void setFirstResponder(Responder *responder)
Definition: app.cpp:62
bool handleEvent(Ion::Events::Event event) override
App * app()
Definition: responder.cpp:77
constexpr Event OK
Definition: events.h:65
Definition: backlight.h:6
void setState(bool state)
Definition: switch_view.cpp:45
void deleteScript(Script script)