mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps] Code: merge actions for text input in ConsoleController and
EditorController
This commit is contained in:
committed by
EmilieNumworks
parent
aade7cb2fe
commit
3db86a8111
@@ -2,6 +2,7 @@
|
||||
#include "../apps_container.h"
|
||||
#include "code_icon.h"
|
||||
#include "../i18n.h"
|
||||
#include "helpers.h"
|
||||
|
||||
namespace Code {
|
||||
|
||||
@@ -77,16 +78,22 @@ App::App(Container * container, Snapshot * snapshot) :
|
||||
#endif
|
||||
),
|
||||
m_codeStackViewController(&m_modalViewController, &m_listFooter),
|
||||
m_toolboxActionForTextArea([](void * sender, const char * text) {
|
||||
TextArea * textArea = static_cast<TextArea *>(sender);
|
||||
textArea->handleEventWithText(text, true);
|
||||
}),
|
||||
m_toolboxActionForTextField([](void * sender, const char * text) {
|
||||
TextField * textField = static_cast<TextField *>(sender);
|
||||
textField->handleEventWithText(text);
|
||||
}),
|
||||
m_variableBoxController(&m_menuController, snapshot->scriptStore())
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,18 +37,14 @@ public:
|
||||
ScriptStore m_scriptStore;
|
||||
};
|
||||
StackViewController * stackViewController() { return &m_codeStackViewController; }
|
||||
VariableBoxController * scriptsVariableBoxController() { return &m_variableBoxController; }
|
||||
PythonToolbox * pythonToolbox() { return &m_toolbox; }
|
||||
PythonToolbox::Action toolboxActionForTextArea() { return m_toolboxActionForTextArea; }
|
||||
PythonToolbox::Action toolboxActionForTextField() { return m_toolboxActionForTextField; }
|
||||
bool textInputDidReceiveEvent(TextInput * textInput, Ion::Events::Event event);
|
||||
private:
|
||||
App(Container * container, Snapshot * snapshot);
|
||||
ButtonRowController m_listFooter;
|
||||
MenuController m_menuController;
|
||||
StackViewController m_codeStackViewController;
|
||||
PythonToolbox m_toolbox;
|
||||
PythonToolbox::Action m_toolboxActionForTextArea;
|
||||
PythonToolbox::Action m_toolboxActionForTextField;
|
||||
VariableBoxController m_variableBoxController;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "app.h"
|
||||
#include "script.h"
|
||||
#include "variable_box_controller.h"
|
||||
#include "helpers.h"
|
||||
#include <apps/i18n.h>
|
||||
#include <assert.h>
|
||||
#include <escher/metric.h>
|
||||
@@ -267,17 +266,8 @@ bool ConsoleController::textFieldDidReceiveEvent(TextField * textField, Ion::Eve
|
||||
if (!textField->isEditing()) {
|
||||
textField->setEditing(true);
|
||||
}
|
||||
VariableBoxController * varBoxController = (static_cast<App *>(textField->app()))->scriptsVariableBoxController();
|
||||
varBoxController->setTextFieldCaller(textField);
|
||||
textField->app()->displayModalViewController(varBoxController, 0.f, 0.f, Metric::PopUpTopMargin, Metric::PopUpLeftMargin, 0, Metric::PopUpRightMargin);
|
||||
return true;
|
||||
}
|
||||
const char * pythonText = Helpers::PythonTextForEvent(event);
|
||||
if (pythonText == nullptr) {
|
||||
return false;
|
||||
}
|
||||
textField->handleEventWithText(pythonText);
|
||||
return true;
|
||||
return static_cast<App *>(textField->app())->textInputDidReceiveEvent(textField, event);
|
||||
}
|
||||
|
||||
bool ConsoleController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
|
||||
@@ -315,7 +305,6 @@ bool ConsoleController::textFieldDidAbortEditing(TextField * textField, const ch
|
||||
|
||||
Toolbox * ConsoleController::toolboxForTextInput(TextInput * textInput) {
|
||||
Code::App * codeApp = static_cast<Code::App *>(app());
|
||||
codeApp->pythonToolbox()->setAction(codeApp->toolboxActionForTextField());
|
||||
return codeApp->pythonToolbox();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "menu_controller.h"
|
||||
#include "script_parameter_controller.h"
|
||||
#include "variable_box_controller.h"
|
||||
#include "helpers.h"
|
||||
#include <apps/code/app.h>
|
||||
#include <escher/metric.h>
|
||||
|
||||
@@ -45,19 +44,9 @@ bool EditorController::textAreaShouldFinishEditing(TextArea * textArea, Ion::Eve
|
||||
}
|
||||
|
||||
bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events::Event event) {
|
||||
const char * pythonText = Helpers::PythonTextForEvent(event);
|
||||
if (pythonText != nullptr) {
|
||||
textArea->handleEventWithText(pythonText);
|
||||
if (static_cast<App *>(textArea->app())->textInputDidReceiveEvent(textArea, event)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event == Ion::Events::Var) {
|
||||
VariableBoxController * varBoxController = (static_cast<App *>(textArea->app()))->scriptsVariableBoxController();
|
||||
varBoxController->setTextAreaCaller(textArea);
|
||||
textArea->app()->displayModalViewController(varBoxController, 0.f, 0.f, Metric::PopUpTopMargin, Metric::PopUpLeftMargin, 0, Metric::PopUpRightMargin);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event == Ion::Events::EXE) {
|
||||
// Auto-Indent
|
||||
char * text = const_cast<char *>(textArea->text());
|
||||
@@ -79,7 +68,7 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events:
|
||||
indentationIndex++;
|
||||
}
|
||||
}
|
||||
char indentationBuffer[indentationSize+2]; // FIXME
|
||||
char indentationBuffer[50]; // FIXME
|
||||
indentationBuffer[0] = '\n';
|
||||
for (int i = 0; i < indentationSize; i++) {
|
||||
indentationBuffer[i+1] = ' ';
|
||||
@@ -131,7 +120,6 @@ bool EditorController::textAreaDidReceiveEvent(TextArea * textArea, Ion::Events:
|
||||
|
||||
Toolbox * EditorController::toolboxForTextInput(TextInput * textInput) {
|
||||
Code::App * codeApp = static_cast<Code::App *>(app());
|
||||
codeApp->pythonToolbox()->setAction(codeApp->toolboxActionForTextArea());
|
||||
return codeApp->pythonToolbox();
|
||||
}
|
||||
|
||||
|
||||
@@ -259,10 +259,6 @@ PythonToolbox::PythonToolbox() :
|
||||
{
|
||||
}
|
||||
|
||||
void PythonToolbox::setAction(Action action) {
|
||||
m_action = action;
|
||||
}
|
||||
|
||||
bool PythonToolbox::handleEvent(Ion::Events::Event event) {
|
||||
if (Toolbox::handleEvent(event)) {
|
||||
return true;
|
||||
@@ -297,7 +293,8 @@ bool PythonToolbox::selectLeaf(ToolboxMessageTree * selectedMessageTree) {
|
||||
const char * editedText = I18n::translate(node->insertedText());
|
||||
char strippedEditedText[strlen(editedText)+1];
|
||||
Shared::ToolboxHelpers::TextToInsertForCommandMessage(node->insertedText(), strippedEditedText);
|
||||
m_action(sender(), const_cast<const char *>(strippedEditedText));
|
||||
TextInput * textInput = static_cast<TextInput *>(sender());
|
||||
textInput->handleEventWithText(strippedEditedText, true);
|
||||
app()->dismissModalViewController();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ class PythonToolbox : public Toolbox {
|
||||
public:
|
||||
typedef void (*Action)(void * sender, const char * text);
|
||||
PythonToolbox();
|
||||
void setAction(Action action);
|
||||
|
||||
// StackViewController
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
|
||||
@@ -23,14 +23,8 @@ VariableBoxController::ContentViewController::ContentViewController(Responder *
|
||||
}
|
||||
}
|
||||
|
||||
void VariableBoxController::ContentViewController::setTextFieldCaller(TextField * textField) {
|
||||
m_textFieldCaller = textField;
|
||||
m_textAreaCaller = nullptr;
|
||||
}
|
||||
|
||||
void VariableBoxController::ContentViewController::setTextAreaCaller(TextArea * textArea) {
|
||||
m_textAreaCaller = textArea;
|
||||
m_textFieldCaller = nullptr;
|
||||
void VariableBoxController::ContentViewController::setTextInputCaller(TextInput * textInput) {
|
||||
m_textInputCaller = textInput;
|
||||
}
|
||||
|
||||
void VariableBoxController::ContentViewController::reloadData() {
|
||||
@@ -121,13 +115,7 @@ void VariableBoxController::ContentViewController::willDisplayCellForIndex(Highl
|
||||
void VariableBoxController::ContentViewController::insertTextInCaller(const char * text) {
|
||||
char commandBuffer[strlen(text)+1];
|
||||
Shared::ToolboxHelpers::TextToInsertForCommandText(text, commandBuffer);
|
||||
if (m_textFieldCaller != nullptr) {
|
||||
m_textFieldCaller->handleEventWithText(commandBuffer);
|
||||
return;
|
||||
}
|
||||
if (m_textAreaCaller != nullptr) {
|
||||
m_textAreaCaller->handleEventWithText(commandBuffer);
|
||||
}
|
||||
m_textInputCaller->handleEventWithText(commandBuffer);
|
||||
}
|
||||
|
||||
VariableBoxController::VariableBoxController(MenuController * menuController, ScriptStore * scriptStore) :
|
||||
@@ -140,12 +128,8 @@ void VariableBoxController::didBecomeFirstResponder() {
|
||||
app()->setFirstResponder(&m_contentViewController);
|
||||
}
|
||||
|
||||
void VariableBoxController::setTextFieldCaller(TextField * textField) {
|
||||
m_contentViewController.setTextFieldCaller(textField);
|
||||
}
|
||||
|
||||
void VariableBoxController::setTextAreaCaller(TextArea * textArea) {
|
||||
m_contentViewController.setTextAreaCaller(textArea);
|
||||
void VariableBoxController::setTextInputCaller(TextInput * textInput) {
|
||||
m_contentViewController.setTextInputCaller(textInput);
|
||||
}
|
||||
|
||||
void VariableBoxController::viewWillAppear() {
|
||||
|
||||
@@ -13,16 +13,14 @@ class VariableBoxController : public StackViewController {
|
||||
public:
|
||||
VariableBoxController(MenuController * menuController, ScriptStore * scriptStore);
|
||||
void didBecomeFirstResponder() override;
|
||||
void setTextFieldCaller(TextField * textField);
|
||||
void setTextAreaCaller(TextArea * textArea);
|
||||
void setTextInputCaller(TextInput * textInput);
|
||||
void viewWillAppear() override;
|
||||
void viewDidDisappear() override;
|
||||
private:
|
||||
class ContentViewController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource {
|
||||
public:
|
||||
ContentViewController(Responder * parentResponder, MenuController * menuController, ScriptStore * scriptStore);
|
||||
void setTextFieldCaller(TextField * textField);
|
||||
void setTextAreaCaller(TextArea * textArea);
|
||||
void setTextInputCaller(TextInput * textInput);
|
||||
void reloadData();
|
||||
|
||||
void addFunctionAtIndex(const char * functionName, int scriptIndex);
|
||||
@@ -52,8 +50,7 @@ private:
|
||||
ScriptNode m_scriptNodes[k_maxScriptNodesCount];
|
||||
MenuController * m_menuController;
|
||||
ScriptStore * m_scriptStore;
|
||||
TextField * m_textFieldCaller;
|
||||
TextArea * m_textAreaCaller;
|
||||
TextInput * m_textInputCaller;
|
||||
ScriptNodeCell m_leafCells[k_maxNumberOfDisplayedRows];
|
||||
SelectableTableView m_selectableTableView;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user