Scripting: Pass back old buffers when reopening view

This commit is contained in:
Vicki Pfau 2022-05-25 22:23:33 -07:00
parent 997adecddc
commit edc2e1b7f5
3 changed files with 11 additions and 0 deletions

View File

@ -87,6 +87,10 @@ void ScriptingController::clearController() {
void ScriptingController::reset() {
CoreController::Interrupter interrupter(m_controller);
for (ScriptingTextBuffer* buffer : m_buffers) {
delete buffer;
}
m_buffers.clear();
mScriptContextDetachCore(&m_scriptContext);
mScriptContextDeinit(&m_scriptContext);
m_engines.clear();
@ -105,6 +109,7 @@ void ScriptingController::runCode(const QString& code) {
mScriptTextBuffer* ScriptingController::createTextBuffer(void* context) {
ScriptingController* self = static_cast<ScriptingController*>(context);
ScriptingTextBuffer* buffer = new ScriptingTextBuffer(self);
self->m_buffers.append(buffer);
emit self->textBufferCreated(buffer);
return buffer->textBuffer();
}

View File

@ -33,6 +33,7 @@ public:
bool load(VFileDevice& vf, const QString& name);
mScriptContext* context() { return &m_scriptContext; }
QList<ScriptingTextBuffer*> textBuffers() { return m_buffers; }
signals:
void log(const QString&);
@ -58,6 +59,7 @@ private:
mScriptEngineContext* m_activeEngine = nullptr;
QHash<QString, mScriptEngineContext*> m_engines;
QList<ScriptingTextBuffer*> m_buffers;
std::shared_ptr<CoreController> m_controller;
};

View File

@ -35,6 +35,10 @@ ScriptingView::ScriptingView(ScriptingController* controller, ConfigController*
m_mruFiles = m_config->getMRU(ConfigController::MRU::Script);
updateMRU();
for (ScriptingTextBuffer* buffer : controller->textBuffers()) {
addTextBuffer(buffer);
}
}
void ScriptingView::submitRepl() {