mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/code] Load varbox before returning it in console
This commit is contained in:
@@ -30,7 +30,7 @@ ConsoleController::ConsoleController(Responder * parentResponder, App * pythonDe
|
||||
m_pythonDelegate(pythonDelegate),
|
||||
m_importScriptsWhenViewAppears(false),
|
||||
m_selectableTableView(this, this, this, this),
|
||||
m_editCell(this, pythonDelegate, this),
|
||||
m_editCell(this, this, this),
|
||||
m_scriptStore(scriptStore),
|
||||
m_sandboxController(this),
|
||||
m_inputRunLoopActive(false)
|
||||
@@ -378,6 +378,12 @@ bool ConsoleController::textFieldDidAbortEditing(TextField * textField) {
|
||||
return true;
|
||||
}
|
||||
|
||||
VariableBoxController * ConsoleController::variableBoxForInputEventHandler(InputEventHandler * textInput) {
|
||||
VariableBoxController * varBox = App::app()->variableBoxController();
|
||||
varBox->loadVariablesImportedFromScripts();
|
||||
return varBox;
|
||||
}
|
||||
|
||||
void ConsoleController::resetSandbox() {
|
||||
if (stackViewController()->topViewController() != sandbox()) {
|
||||
return;
|
||||
|
||||
@@ -9,12 +9,14 @@
|
||||
#include "console_store.h"
|
||||
#include "sandbox_controller.h"
|
||||
#include "script_store.h"
|
||||
#include "variable_box_controller.h"
|
||||
#include "../shared/input_event_handler_delegate.h"
|
||||
|
||||
namespace Code {
|
||||
|
||||
class App;
|
||||
|
||||
class ConsoleController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource, public SelectableTableViewDelegate, public TextFieldDelegate, public MicroPython::ExecutionEnvironment {
|
||||
class ConsoleController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource, public SelectableTableViewDelegate, public TextFieldDelegate, public Shared::InputEventHandlerDelegate, public MicroPython::ExecutionEnvironment {
|
||||
public:
|
||||
ConsoleController(Responder * parentResponder, App * pythonDelegate, ScriptStore * scriptStore
|
||||
#if EPSILON_GETOPT
|
||||
@@ -59,6 +61,9 @@ public:
|
||||
bool textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) override;
|
||||
bool textFieldDidAbortEditing(TextField * textField) override;
|
||||
|
||||
// InputEventHandlerDelegate
|
||||
VariableBoxController * variableBoxForInputEventHandler(InputEventHandler * textInput) override;
|
||||
|
||||
// MicroPython::ExecutionEnvironment
|
||||
ViewController * sandbox() override { return &m_sandboxController; }
|
||||
void resetSandbox() override;
|
||||
|
||||
@@ -159,9 +159,7 @@ int VariableBoxController::typeAtLocation(int i, int j) {
|
||||
|
||||
void VariableBoxController::loadFunctionsAndVariables(int scriptIndex, const char * textToAutocomplete, int textToAutocompleteLength) {
|
||||
// Reset the node counts
|
||||
m_currentScriptNodesCount = 0;
|
||||
m_builtinNodesCount = 0;
|
||||
m_importedNodesCount = 0;
|
||||
empty();
|
||||
|
||||
if (scriptIndex < 0) {
|
||||
/* If not script index is given, the variable box is loaded from console. We
|
||||
@@ -241,6 +239,16 @@ const char * VariableBoxController::autocompletionAlternativeAtIndex(int textToA
|
||||
return currentName + textToAutocompleteLength;
|
||||
}
|
||||
|
||||
void VariableBoxController::loadVariablesImportedFromScripts() {
|
||||
const int scriptsCount = m_scriptStore->numberOfScripts();
|
||||
for (int i = 0; i < scriptsCount; i++) {
|
||||
Script script = m_scriptStore->scriptAtIndex(i);
|
||||
if (script.contentFetchedFromConsole()) {
|
||||
loadGlobalAndImportedVariablesInScriptAsImported(script.fullName(), script.scriptContent(), nullptr, -1, false); // TODO optimize number of script fetches
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VariableBoxController::empty() {
|
||||
m_builtinNodesCount = 0;
|
||||
m_currentScriptNodesCount = 0;
|
||||
@@ -382,16 +390,6 @@ void VariableBoxController::insertTextInCaller(const char * text, int textLength
|
||||
sender()->handleEventWithText(commandBuffer);
|
||||
}
|
||||
|
||||
void VariableBoxController::loadVariablesImportedFromScripts() {
|
||||
const int scriptsCount = m_scriptStore->numberOfScripts();
|
||||
for (int i = 0; i < scriptsCount; i++) {
|
||||
Script script = m_scriptStore->scriptAtIndex(i);
|
||||
if (script.contentFetchedFromConsole()) {
|
||||
loadGlobalAndImportedVariablesInScriptAsImported(script.fullName(), script.scriptContent(), nullptr, -1, false); // TODO optimize number of script fetches
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VariableBoxController::loadBuiltinNodes(const char * textToAutocomplete, int textToAutocompleteLength) {
|
||||
//TODO LEA could be great to use strings defined in STATIC const char *const tok_kw[] from python/lexer.c
|
||||
//TODO LEA Prune these (check all are usable in our Python, but just comment those which aren't -> there might become usable later)
|
||||
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
void loadFunctionsAndVariables(int scriptIndex, const char * textToAutocomplete, int textToAutocompleteLength);
|
||||
const char * autocompletionForText(int scriptIndex, const char * textToAutocomplete, int textToAutocompleteLength, int * textToInsertLength, bool * addParentheses);
|
||||
const char * autocompletionAlternativeAtIndex(int textToAutocompleteLength, int * textToInsertLength, bool * addParentheses, int index, int * indexToUpdate = nullptr);
|
||||
void loadVariablesImportedFromScripts();
|
||||
void empty();
|
||||
|
||||
private:
|
||||
@@ -86,7 +87,6 @@ private:
|
||||
void insertTextInCaller(const char * text, int textLength = -1);
|
||||
|
||||
// Loading
|
||||
void loadVariablesImportedFromScripts();
|
||||
void loadBuiltinNodes(const char * textToAutocomplete, int textToAutocompleteLength);
|
||||
void loadImportedVariablesInScript(const char * scriptContent, const char * textToAutocomplete, int textToAutocompleteLength);
|
||||
void loadCurrentVariablesInScript(const char * scriptContent, const char * textToAutocomplete, int textToAutocompleteLength);
|
||||
|
||||
Reference in New Issue
Block a user