Blame view

build6/epsilon-master/apps/code/script_parameter_controller.cpp 2.73 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
  #include "script_parameter_controller.h"
  #include "menu_controller.h"
  
  namespace Code {
  
  ScriptParameterController::ScriptParameterController(Responder * parentResponder, I18n::Message title, MenuController * menuController) :
    ViewController(parentResponder),
    m_pageTitle(title),
    m_executeScript(I18n::Message::ExecuteScript),
    m_renameScript(I18n::Message::RenameScript),
    m_autoImportScript(I18n::Message::AutoImportScript),
    m_deleteScript(I18n::Message::DeleteScript),
    m_selectableTableView(this),
    m_script(Ion::Storage::Record()),
    m_menuController(menuController)
  {
  }
  
  void ScriptParameterController::setScript(Script script){
    m_script = script;
  }
  
  void ScriptParameterController::dismissScriptParameterController() {
    m_script = Script(Ion::Storage::Record());
    stackViewController()->pop();
  }
  
  const char * ScriptParameterController::title() {
    return I18n::translate(m_pageTitle);
  }
  
  bool ScriptParameterController::handleEvent(Ion::Events::Event event) {
    if (event == Ion::Events::OK || event == Ion::Events::EXE) {
      Script s = m_script;
      switch (selectedRow()) {
        case 0:
          dismissScriptParameterController();
          m_menuController->openConsoleWithScript(s);
          return true;
        case 1:
          dismissScriptParameterController();
          m_menuController->renameSelectedScript();
          return true;
        case 2:
          m_script.toggleImportationStatus();
          m_selectableTableView.reloadData();
          m_menuController->reloadConsole();
          app()->setFirstResponder(&m_selectableTableView);
          return true;
        case 3:
          dismissScriptParameterController();
          m_menuController->deleteScript(s);
          m_menuController->reloadConsole();
          return true;
        default:
          assert(false);
          return false;
      }
    }
    return false;
  }
  
  void ScriptParameterController::viewWillAppear() {
    m_selectableTableView.reloadData();
    m_selectableTableView.selectCellAtLocation(0,0);
  }
  
  void ScriptParameterController::didBecomeFirstResponder() {
    selectCellAtLocation(0, 0);
    app()->setFirstResponder(&m_selectableTableView);
  }
  
  HighlightCell * ScriptParameterController::reusableCell(int index) {
    assert(index >= 0);
    assert(index < k_totalNumberOfCell);
    HighlightCell * cells[] = {&m_executeScript, &m_renameScript, &m_autoImportScript, &m_deleteScript};
    return cells[index];
  }
  
  void ScriptParameterController::willDisplayCellForIndex(HighlightCell * cell, int index) {
    if (cell == &m_autoImportScript) {
      SwitchView * switchView = (SwitchView *)m_autoImportScript.accessoryView();
      switchView->setState(m_script.importationStatus());
    }
  }
  
  StackViewController * ScriptParameterController::stackViewController() {
    return static_cast<StackViewController *>(parentResponder());
  }
  
  }