Numworks Epsilon  1.4.1
Graphing Calculator Operating System
app.cpp
Go to the documentation of this file.
1 #include "app.h"
2 #include "../apps_container.h"
3 #include "code_icon.h"
4 #include "../i18n.h"
5 #include "helpers.h"
6 
7 namespace Code {
8 
9 I18n::Message App::Descriptor::name() {
10  return I18n::Message::CodeApp;
11 }
12 
13 I18n::Message App::Descriptor::upperName() {
14  return I18n::Message::CodeAppCapital;
15 }
16 
18  return ImageStore::CodeIcon;
19 }
20 
22 #if EPSILON_GETOPT
23  m_lockOnConsole(false),
24 #endif
25  m_scriptStore()
26 {
27 }
28 
30  return new App(container, this);
31 }
32 
34  m_scriptStore.deleteAllScripts();
35 }
36 
38  static Descriptor descriptor;
39  return &descriptor;
40 }
41 
43  return &m_scriptStore;
44 }
45 
46 #if EPSILON_GETOPT
47 bool App::Snapshot::lockOnConsole() const {
48  return m_lockOnConsole;
49 }
50 
51 void App::Snapshot::setOpt(const char * name, char * value) {
52  if (strcmp(name, "script") == 0) {
53  m_scriptStore.deleteAllScripts();
54  char * separator = strchr(value, ':');
55  if (!separator) {
56  return;
57  }
58  *separator = 0;
59  const char * scriptName = value;
60  const char * scriptContent = separator+1;
61  Code::ScriptTemplate script(scriptName, scriptContent);
62  m_scriptStore.addScriptFromTemplate(&script);
63  return;
64  }
65  if (strcmp(name, "lock-on-console") == 0) {
66  m_lockOnConsole = true;
67  return;
68  }
69 }
70 #endif
71 
72 App::App(Container * container, Snapshot * snapshot) :
73  ::App(container, snapshot, &m_codeStackViewController, I18n::Message::Warning),
74  m_listFooter(&m_codeStackViewController, &m_menuController, &m_menuController, ButtonRowController::Position::Bottom, ButtonRowController::Style::EmbossedGrey, ButtonRowController::Size::Large),
75  m_menuController(&m_listFooter, snapshot->scriptStore(), &m_listFooter
76 #if EPSILON_GETOPT
77  , snapshot->lockOnConsole()
78 #endif
79  ),
80  m_codeStackViewController(&m_modalViewController, &m_listFooter),
81  m_variableBoxController(&m_menuController, snapshot->scriptStore())
82 {
83 }
84 
86  const char * pythonText = Helpers::PythonTextForEvent(event);
87  if (pythonText != nullptr) {
88  textInput->handleEventWithText(pythonText);
89  return true;
90  }
91  if (event == Ion::Events::Var) {
92  m_variableBoxController.setTextInputCaller(textInput);
94  return true;
95  }
96  return false;
97 }
98 
99 }
constexpr Event Var
Definition: events.h:74
Definition: app.h:13
Definition: i18n.h:6
void reset() override
Definition: app.cpp:33
void displayModalViewController(ViewController *vc, float verticalAlignment, float horizontalAlignment, KDCoordinate topMargin=0, KDCoordinate leftMargin=0, KDCoordinate bottomMargin=0, KDCoordinate rightMargin=0)
Definition: app.cpp:85
Snapshot * snapshot()
Definition: app.cpp:41
I18n::Message name() override
Definition: app.cpp:9
Definition: image.h:6
ScriptStore * scriptStore()
Definition: app.cpp:42
virtual bool handleEventWithText(const char *text, bool indenting=false)=0
App(Container *container, Snapshot *snapshot, ViewController *rootViewController, I18n::Message warningMessage=(I18n::Message) 0)
Definition: app.cpp:30
App * unpack(Container *container) override
Definition: app.cpp:29
ModalViewController m_modalViewController
Definition: app.h:65
I18n::Message upperName() override
Definition: app.cpp:13
Definition: app.cpp:7
char * strchr(const char *s, int c)
Definition: strchr.c:3
#define false
Definition: stdbool.h:9
Descriptor * descriptor() override
Definition: app.cpp:37
static constexpr KDCoordinate PopUpTopMargin
Definition: metric.h:23
Definition: app.h:23
const Image * icon() override
Definition: app.cpp:17
const Container * container() const
Definition: app.cpp:102
int strcmp(const char *s1, const char *s2)
Definition: strcmp.c:3
static constexpr KDCoordinate PopUpRightMargin
Definition: metric.h:22
bool textInputDidReceiveEvent(TextInput *textInput, Ion::Events::Event event)
Definition: app.cpp:85
void setTextInputCaller(TextInput *textInput)
const char * PythonTextForEvent(Ion::Events::Event event)
Definition: helpers.cpp:37
static constexpr KDCoordinate PopUpLeftMargin
Definition: metric.h:21