Blame view

build3/apps/code/script_parameter_controller.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
  #include "script_parameter_controller.h"
  #include "menu_controller.h"
  
  namespace Code {
  
  ScriptParameterController::ScriptParameterController(Responder * parentResponder, I18n::Message title, ScriptStore * scriptStore, 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, this, 0, 1, Metric::CommonTopMargin, Metric::CommonRightMargin,
      Metric::CommonBottomMargin, Metric::CommonLeftMargin, this),
    m_scriptStore(scriptStore),
    m_menuController(menuController),
    m_autoImport(true),
    m_currentScriptIndex(-1)
  {
  }
  
  void ScriptParameterController::setScript(int i){
    Script script = (m_scriptStore->scriptAtIndex(i, ScriptStore::EditableZone::Content));
    m_autoImport = script.autoImport();
    m_currentScriptIndex = i;
  }
  
  void ScriptParameterController::dismissScriptParameterController() {
    m_currentScriptIndex = -1;
    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) {
      int scriptIndex = m_currentScriptIndex;
      switch (selectedRow()) {
        case 0:
          dismissScriptParameterController();
          m_menuController->openConsoleWithScriptAtIndex(scriptIndex);
          return true;
        case 1:
          dismissScriptParameterController();
          m_menuController->renameSelectedScript();
          return true;
        case 2:
          m_scriptStore->switchAutoImportAtIndex(scriptIndex);
          m_autoImport = !m_autoImport;
          m_selectableTableView.reloadData();
          m_menuController->reloadConsole();
          app()->setFirstResponder(&m_selectableTableView);
          return true;
        case 3:
          dismissScriptParameterController();
          m_menuController->deleteScriptAtIndex(scriptIndex);
          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_autoImport);
    }
  }
  
  StackViewController * ScriptParameterController::stackViewController() {
    return static_cast<StackViewController *>(parentResponder());
  }
  
  }