mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 15:59:49 +02:00
Fix running scripts not properly updated when done programmatically
Add a slot to Application to receive ScriptEngine::finished signals. Notify the Running scripts widget of stopped scripts so it can properly move them to the recent scripts list.
This commit is contained in:
parent
98c957f371
commit
d59bedfa96
4 changed files with 16 additions and 11 deletions
|
@ -3405,6 +3405,8 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript
|
||||||
scriptEngine->registerGlobalObject("Clipboard", clipboardScriptable);
|
scriptEngine->registerGlobalObject("Clipboard", clipboardScriptable);
|
||||||
connect(scriptEngine, SIGNAL(finished(const QString&)), clipboardScriptable, SLOT(deleteLater()));
|
connect(scriptEngine, SIGNAL(finished(const QString&)), clipboardScriptable, SLOT(deleteLater()));
|
||||||
|
|
||||||
|
connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(scriptFinished(const QString&)));
|
||||||
|
|
||||||
scriptEngine->registerGlobalObject("Overlays", &_overlays);
|
scriptEngine->registerGlobalObject("Overlays", &_overlays);
|
||||||
|
|
||||||
QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", WindowScriptingInterface::getInstance());
|
QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", WindowScriptingInterface::getInstance());
|
||||||
|
@ -3447,6 +3449,14 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript
|
||||||
return scriptEngine;
|
return scriptEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::scriptFinished(const QString &scriptName) {
|
||||||
|
if (_scriptEnginesHash.remove(scriptName)) {
|
||||||
|
_runningScriptsWidget->scriptStopped(scriptName);
|
||||||
|
_runningScriptsWidget->setRunningScripts(getRunningScripts());
|
||||||
|
bumpSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Application::stopAllScripts(bool restart) {
|
void Application::stopAllScripts(bool restart) {
|
||||||
// stops all current running scripts
|
// stops all current running scripts
|
||||||
for (QHash<QString, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();
|
for (QHash<QString, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();
|
||||||
|
@ -3457,18 +3467,12 @@ void Application::stopAllScripts(bool restart) {
|
||||||
it.value()->stop();
|
it.value()->stop();
|
||||||
qDebug() << "stopping script..." << it.key();
|
qDebug() << "stopping script..." << it.key();
|
||||||
}
|
}
|
||||||
_scriptEnginesHash.clear();
|
|
||||||
_runningScriptsWidget->setRunningScripts(getRunningScripts());
|
|
||||||
bumpSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::stopScript(const QString &scriptName) {
|
void Application::stopScript(const QString &scriptName) {
|
||||||
if (_scriptEnginesHash.contains(scriptName)) {
|
if (_scriptEnginesHash.contains(scriptName)) {
|
||||||
_scriptEnginesHash.value(scriptName)->stop();
|
_scriptEnginesHash.value(scriptName)->stop();
|
||||||
qDebug() << "stopping script..." << scriptName;
|
qDebug() << "stopping script..." << scriptName;
|
||||||
_scriptEnginesHash.remove(scriptName);
|
|
||||||
_runningScriptsWidget->setRunningScripts(getRunningScripts());
|
|
||||||
bumpSettings();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -292,6 +292,7 @@ public slots:
|
||||||
void toggleLogDialog();
|
void toggleLogDialog();
|
||||||
void initAvatarAndViewFrustum();
|
void initAvatarAndViewFrustum();
|
||||||
ScriptEngine* loadScript(const QString& fileNameString, bool loadScriptFromEditor = false);
|
ScriptEngine* loadScript(const QString& fileNameString, bool loadScriptFromEditor = false);
|
||||||
|
void scriptFinished(const QString& scriptName);
|
||||||
void stopAllScripts(bool restart = false);
|
void stopAllScripts(bool restart = false);
|
||||||
void stopScript(const QString& scriptName);
|
void stopScript(const QString& scriptName);
|
||||||
void reloadAllScripts();
|
void reloadAllScripts();
|
||||||
|
|
|
@ -157,6 +157,10 @@ void RunningScriptsWidget::paintEvent(QPaintEvent* event) {
|
||||||
painter.end();
|
painter.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RunningScriptsWidget::scriptStopped(const QString& scriptName) {
|
||||||
|
_recentlyLoadedScripts.prepend(scriptName);
|
||||||
|
}
|
||||||
|
|
||||||
void RunningScriptsWidget::stopScript(int row, int column) {
|
void RunningScriptsWidget::stopScript(int row, int column) {
|
||||||
if (column == 1) { // make sure the user has clicked on the close icon
|
if (column == 1) { // make sure the user has clicked on the close icon
|
||||||
_lastStoppedScript = _runningScriptsTable->item(row, 0)->toolTip();
|
_lastStoppedScript = _runningScriptsTable->item(row, 0)->toolTip();
|
||||||
|
@ -169,11 +173,6 @@ void RunningScriptsWidget::loadScript(int row, int column) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunningScriptsWidget::allScriptsStopped() {
|
void RunningScriptsWidget::allScriptsStopped() {
|
||||||
QStringList list = Application::getInstance()->getRunningScripts();
|
|
||||||
for (int i = 0; i < list.size(); ++i) {
|
|
||||||
_recentlyLoadedScripts.prepend(list.at(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
Application::getInstance()->stopAllScripts();
|
Application::getInstance()->stopAllScripts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ protected:
|
||||||
virtual void paintEvent(QPaintEvent* event);
|
virtual void paintEvent(QPaintEvent* event);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void scriptStopped(const QString& scriptName);
|
||||||
void setBoundary(const QRect& rect);
|
void setBoundary(const QRect& rect);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
Loading…
Reference in a new issue