Merge branch 'master' into python_turtle

This commit is contained in:
Léa Saviot
2019-01-08 14:31:49 +01:00
42 changed files with 461 additions and 118 deletions

View File

@@ -46,23 +46,23 @@ bool App::Snapshot::lockOnConsole() const {
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;
/* We include the 0 in the scriptContent to represent the importation
* status. It is set to 1 after addScriptFromTemplate. Indeed, this '/0'
* char has two goals: ending the scriptName and representing the
* importation status; we cannot set it to 1 before adding the script to
* storage. */
const char * scriptContent = separator;
Code::ScriptTemplate script(scriptName, scriptContent);
m_scriptStore.addScriptFromTemplate(&script);
m_scriptStore.scriptNamed(scriptName).toggleImportationStatus(); // set Importation Status to 1
m_scriptStore.deleteAllScripts();
char * separator = strchr(value, ':');
if (!separator) {
return;
}
*separator = 0;
const char * scriptName = value;
/* We include the 0 in the scriptContent to represent the importation
* status. It is set to 1 after addScriptFromTemplate. Indeed, this '/0'
* char has two goals: ending the scriptName and representing the
* importation status; we cannot set it to 1 before adding the script to
* storage. */
const char * scriptContent = separator;
Code::ScriptTemplate script(scriptName, scriptContent);
m_scriptStore.addScriptFromTemplate(&script);
m_scriptStore.scriptNamed(scriptName).toggleImportationStatus(); // set Importation Status to 1
return;
}
if (strcmp(name, "lock-on-console") == 0) {
m_lockOnConsole = true;
@@ -88,15 +88,15 @@ App::App(Container * container, Snapshot * snapshot) :
}
App::~App() {
assert(!m_consoleController.inputRunLoopActive());
deinitPython();
}
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();
/* 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.terminateInputLoop();
if (m_modalViewController.isDisplayingModal()) {
m_modalViewController.dismissModalViewController();
}

View File

@@ -37,6 +37,13 @@ public:
ScriptStore m_scriptStore;
};
~App();
bool prepareForExit() override {
if (m_consoleController.inputRunLoopActive()) {
m_consoleController.terminateInputLoop();
return false;
}
return true;
}
StackViewController * stackViewController() { return &m_codeStackViewController; }
ConsoleController * consoleController() { return &m_consoleController; }

View File

@@ -33,7 +33,7 @@ ConsoleController::ConsoleController(Responder * parentResponder, App * pythonDe
m_sandboxController(this, this),
m_inputRunLoopActive(false)
#if EPSILON_GETOPT
, m_locked(lockOnConsole)
, m_locked(lockOnConsole)
#endif
{
m_selectableTableView.setMargins(0, Metric::CommonRightMargin, 0, Metric::TitleBarExternHorizontalMargin);
@@ -81,21 +81,30 @@ void ConsoleController::runAndPrintForCommand(const char * command) {
m_consoleStore.deleteLastLineIfEmpty();
}
void ConsoleController::terminateInputLoop() {
assert(m_inputRunLoopActive);
m_inputRunLoopActive = false;
interrupt();
}
const char * ConsoleController::inputText(const char * prompt) {
AppsContainer * a = (AppsContainer *)(app()->container());
m_inputRunLoopActive = true;
// Set the prompt text
m_selectableTableView.reloadData();
m_selectableTableView.selectCellAtLocation(0, m_consoleStore.numberOfLines());
m_editCell.setPrompt(prompt);
m_editCell.setText("");
// Run new input loop
a->redrawWindow();
a->runWhile([](void * a){
ConsoleController * c = static_cast<ConsoleController *>(a);
return c->inputRunLoopActive();
}, this);
// Reset the prompt line
flushOutputAccumulationBufferToStore();
m_consoleStore.deleteLastLineIfEmpty();
m_editCell.setPrompt(sStandardPromptText);
@@ -145,9 +154,8 @@ bool ConsoleController::handleEvent(Ion::Events::Event event) {
}
#if EPSILON_GETOPT
if (m_locked && (event == Ion::Events::Home || event == Ion::Events::Back)) {
if (inputRunLoopActive()) {
askInputRunLoopTermination();
interrupt();
if (m_inputRunLoopActive) {
terminateInputLoop();
}
return true;
}
@@ -234,10 +242,10 @@ bool ConsoleController::textFieldShouldFinishEditing(TextField * textField, Ion:
}
bool ConsoleController::textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) {
if (event == Ion::Events::Up && inputRunLoopActive()) {
askInputRunLoopTermination();
// We need to return true here because we want to actually exit from the
// input run loop, which requires ending a dispatchEvent cycle.
if (event == Ion::Events::Up && m_inputRunLoopActive) {
m_inputRunLoopActive = false;
/* We need to return true here because we want to actually exit from the
* input run loop, which requires ending a dispatchEvent cycle. */
return true;
}
if (event == Ion::Events::Up) {
@@ -251,8 +259,8 @@ bool ConsoleController::textFieldDidReceiveEvent(TextField * textField, Ion::Eve
}
bool ConsoleController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
if (inputRunLoopActive()) {
askInputRunLoopTermination();
if (m_inputRunLoopActive) {
m_inputRunLoopActive = false;
return false;
}
runAndPrintForCommand(text);
@@ -266,8 +274,8 @@ bool ConsoleController::textFieldDidFinishEditing(TextField * textField, const c
}
bool ConsoleController::textFieldDidAbortEditing(TextField * textField) {
if (inputRunLoopActive()) {
askInputRunLoopTermination();
if (m_inputRunLoopActive) {
m_inputRunLoopActive = false;
} else {
#if EPSILON_GETOPT
/* In order to lock the console controller, we disable poping controllers

View File

@@ -31,8 +31,8 @@ public:
void autoImport();
void autoImportScript(Script script, bool force = false);
void runAndPrintForCommand(const char * command);
bool inputRunLoopActive() { return m_inputRunLoopActive; }
void askInputRunLoopTermination() { m_inputRunLoopActive = false; }
bool inputRunLoopActive() const { return m_inputRunLoopActive; }
void terminateInputLoop();
// ViewController
View * view() override { return &m_selectableTableView; }