3 #include "../apps_container.h" 17 m_scriptStore(scriptStore),
18 m_addNewScriptCell(
I18n::Message::AddScript),
19 m_consoleButton(this,
I18n::Message::Console,
Invocation([](void * context, void * sender) {
21 if (
menu->consoleController()->loadPythonEnvironment()) {
22 menu->stackViewController()->push(
menu->consoleController());
27 m_selectableTableView(
this,
this,
this,
this),
28 m_consoleController(parentResponder, m_scriptStore
33 m_scriptParameterController(
nullptr, I18n::Message::ScriptOptions,
this),
34 m_editorController(
this),
35 m_reloadConsoleWhenBecomingFirstResponder(
false),
36 m_shouldDisplayAddScriptRow(
true)
38 m_selectableTableView.setMargins(0);
39 m_selectableTableView.setShowsIndicators(
false);
40 for (
int i = 0; i < k_maxNumberOfDisplayableScriptCells; i++) {
41 m_scriptCells[i].setParentResponder(&m_selectableTableView);
42 m_scriptCells[i].editableTextCell()->textField()->setDelegate(
this);
43 m_scriptCells[i].editableTextCell()->textField()->setDraftTextBuffer(m_draftTextBuffer);
44 m_scriptCells[i].editableTextCell()->textField()->setAlignment(0.0f, 0.5f);
57 TextField * tf =
static_cast<EvenOddEditableTextCell *
>(m_selectableTableView.
selectedCell())->editableTextCell()->textField();
66 if (m_reloadConsoleWhenBecomingFirstResponder) {
69 if (
footer()->selectedButton() == 0) {
88 updateAddScriptRowDisplay();
98 if (
footer()->selectedButton() == 0) {
108 if (
selectedRow >= 0 && selectedRow < m_scriptStore->numberOfScripts()) {
116 }
else if (m_shouldDisplayAddScriptRow
132 EvenOddEditableTextCell * myCell =
static_cast<EvenOddEditableTextCell *
>(m_selectableTableView.
selectedCell());
134 myCell->setHighlighted(
false);
135 const char * previousText = myCell->editableTextCell()->textField()->text();
136 myCell->editableTextCell()->textField()->setEditing(
true);
137 myCell->editableTextCell()->textField()->setText(previousText);
144 updateAddScriptRowDisplay();
149 m_reloadConsoleWhenBecomingFirstResponder =
false;
162 m_reloadConsoleWhenBecomingFirstResponder =
true;
174 if (i == 0 && j < m_scriptStore->numberOfScripts()) {
177 static_cast<EvenOddCell *
>(cell)->setEven(j%2 == 0);
184 return m_selectableTableView.
bounds().
width()-k_parametersColumnWidth;
186 return k_parametersColumnWidth;
198 return m_selectableTableView.
bounds().
width()-k_parametersColumnWidth;
212 if (offsetX <= m_selectableTableView.
bounds().
width()-k_parametersColumnWidth) {
215 if (offsetX <= m_selectableTableView.
bounds().
width()) {
234 if (type == ScriptCellType) {
235 assert(index >=0 && index < k_maxNumberOfDisplayableScriptCells);
236 return &m_scriptCells[index];
238 if (type == ScriptParameterCellType) {
239 assert(index >=0 && index < k_maxNumberOfDisplayableScriptCells);
240 return &m_scriptParameterCells[index];
242 if (type == AddScriptCellType) {
244 return &m_addNewScriptCell;
246 if(type == EmptyCellType) {
254 if (type == AddScriptCellType) {
257 if (type == ScriptCellType || type == ScriptParameterCellType) {
258 return k_maxNumberOfDisplayableScriptCells;
260 if (type == EmptyCellType) {
271 if (j ==
numberOfRows()-1 && m_shouldDisplayAddScriptRow) {
272 return AddScriptCellType;
274 return ScriptCellType;
277 if (j ==
numberOfRows()-1 && m_shouldDisplayAddScriptRow) {
278 return EmptyCellType;
280 return ScriptParameterCellType;
284 assert(index >= 0 && index < m_scriptStore->numberOfScripts());
285 EditableTextCell * editableTextCell =
static_cast<EvenOddEditableTextCell *
>(cell)->editableTextCell();
313 const char * newName;
314 char numberedDefaultName[k_defaultScriptNameMaxSize];
317 numberedDefaultScriptName(numberedDefaultName);
318 newName =
const_cast<const char *
>(numberedDefaultName);
324 updateAddScriptRowDisplay();
326 int currentRow = m_selectableTableView.
selectedRow();
351 char numberedDefaultName[k_defaultScriptNameMaxSize];
352 numberedDefaultScriptName(numberedDefaultName);
361 updateAddScriptRowDisplay();
377 void MenuController::addScript() {
380 updateAddScriptRowDisplay();
387 void MenuController::configureScript() {
394 void MenuController::editScriptAtIndex(
int scriptIndex) {
395 assert(scriptIndex >=0 && scriptIndex < m_scriptStore->numberOfScripts());
401 void MenuController::numberedDefaultScriptName(
char * buffer) {
402 bool foundNewScriptNumber =
false;
403 int currentScriptNumber = 1;
404 char newName[k_defaultScriptNameMaxSize];
407 while (!foundNewScriptNumber && currentScriptNumber < 100) {
412 foundNewScriptNumber =
true;
414 currentScriptNumber++;
416 if (foundNewScriptNumber) {
423 void MenuController::intToText(
int i,
char * buffer) {
433 buffer[0] = i/10+
'0';
434 buffer[1] = i-10*(i/10)+
'0';
438 void MenuController::updateAddScriptRowDisplay() {
439 m_shouldDisplayAddScriptRow = !m_scriptStore->
isFull();
static constexpr KDCoordinate StoreRowHeight
bool setCursorLocation(int location)
HighlightCell * selectedCell()
void setText(const char *text)
size_t cursorLocation() const
static constexpr KDCoordinate HistoryHorizontalMargin
void push(ViewController *vc, KDColor textColor=Palette::SubTab, KDColor backgroundColor=KDColorWhite, KDColor separatorColor=Palette::GreyBright)
Responder * parentResponder() const
void autoImportScript(Script script, bool force=false)
bool selectCellAtLocation(int i, int j, bool setFirstResponder=true)
virtual void setEditing(bool isEditing, bool reinitDraftBuffer=true)
void setScript(Script script)
void reloadData(bool setFirstResponder=true)
Script scriptNamed(const char *name)
void setShiftAlphaStatus(Ion::Events::ShiftAlphaStatus newStatus)
size_t strlen(const char *s)
void displayWarning(I18n::Message warningMessage)
Script scriptAtIndex(int index)
void setScript(Script script)
const char * name() const
const char * text() const
const Container * container() const
size_t draftTextLength() const
const ToolboxMessageTree menu[menuChildrenCount]
void setFirstResponder(Responder *responder)
KDCoordinate width() const
void unloadPythonEnvironment()
Ion::Storage::Record::ErrorStatus addNewScript()
virtual void setHighlighted(bool highlight)
bool loadPythonEnvironment(bool autoImportScripts=true)
static constexpr char k_defaultScriptName[]
void * memcpy(void *dst, const void *src, size_t n)
static constexpr char k_scriptExtension[]