Blame view

build2/epsilon-master/apps/code/app.cpp 3.13 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  #include "app.h"
  #include "../apps_container.h"
  #include "code_icon.h"
  #include "../i18n.h"
  #include "helpers.h"
  
  namespace Code {
  
  I18n::Message App::Descriptor::name() {
    return I18n::Message::CodeApp;
  }
  
  I18n::Message App::Descriptor::upperName() {
    return I18n::Message::CodeAppCapital;
  }
  
  const Image * App::Descriptor::icon() {
    return ImageStore::CodeIcon;
  }
  
  App::Snapshot::Snapshot() :
  #if EPSILON_GETOPT
    m_lockOnConsole(false),
  #endif
    m_scriptStore()
  {
  }
  
  App * App::Snapshot::unpack(Container * container) {
    return new App(container, this);
  }
  
  void App::Snapshot::reset() {
    m_scriptStore.deleteAllScripts();
  }
  
  App::Descriptor * App::Snapshot::descriptor() {
    static Descriptor descriptor;
    return &descriptor;
  }
  
  ScriptStore * App::Snapshot::scriptStore() {
    return &m_scriptStore;
  }
  
  #if EPSILON_GETOPT
  bool App::Snapshot::lockOnConsole() const {
    return m_lockOnConsole;
  }
  
  void App::Snapshot::setOpt(const char * name, char * value) {
    if (strcmp(name, "script") == 0) {
        m_scriptStore.deleteAllScripts();
        char * separator = strchr(value, ':');
        if (!separator) {
          return;
        }
        *separator = 0;
        const char * scriptName = value;
        const char * scriptContent = separator+1;
        Code::ScriptTemplate script(scriptName, scriptContent);
        m_scriptStore.addScriptFromTemplate(&script);
        return;
    }
    if (strcmp(name, "lock-on-console") == 0) {
      m_lockOnConsole = true;
      return;
    }
  }
  #endif
  
  App::App(Container * container, Snapshot * snapshot) :
    ::App(container, snapshot, &m_codeStackViewController, I18n::Message::Warning),
    m_consoleController(nullptr, snapshot->scriptStore()
  #if EPSILON_GETOPT
        , snapshot->lockOnConsole()
  #endif
        ),
    m_listFooter(&m_codeStackViewController, &m_menuController, &m_menuController, ButtonRowController::Position::Bottom, ButtonRowController::Style::EmbossedGrey, ButtonRowController::Size::Large),
    m_menuController(&m_listFooter, snapshot->scriptStore(), &m_listFooter),
    m_codeStackViewController(&m_modalViewController, &m_listFooter),
    m_variableBoxController(&m_menuController, snapshot->scriptStore())
  {
  }
  
  bool App::handleEvent(Ion::Events::Event event) {
    if (event == Ion::Events::Home && m_consoleController.inputRunLoopActive()) {
      // We need to return true here because we want to actually exit from the
      // input run loop, which requires ending a dispatchEvent cycle.
      m_consoleController.askInputRunLoopTermination();
      m_consoleController.interrupt();
      if (m_modalViewController.isDisplayingModal()) {
        m_modalViewController.dismissModalViewController();
      }
      return true;
    }
    return false;
  }
  
  bool App::textInputDidReceiveEvent(TextInput * textInput, Ion::Events::Event event) {
    const char * pythonText = Helpers::PythonTextForEvent(event);
    if (pythonText != nullptr) {
      textInput->handleEventWithText(pythonText);
      return true;
    }
    if (event == Ion::Events::Var) {
      m_variableBoxController.setTextInputCaller(textInput);
      displayModalViewController(&m_variableBoxController, 0.f, 0.f, Metric::PopUpTopMargin, Metric::PopUpLeftMargin, 0, Metric::PopUpRightMargin);
      return true;
    }
    return false;
  }
  
  }