diff --git a/core/document.cpp b/core/document.cpp --- a/core/document.cpp +++ b/core/document.cpp @@ -1124,7 +1124,18 @@ Action *action = form->additionalAction( FormField::CalculateField ); if (action) { + // Update Text Fields with the result of the calculate script action. m_parent->processAction( action ); + const ScriptAction *scriptAction = dynamic_cast ( action ); + FormFieldText *textField = dynamic_cast ( form ); + if ( scriptAction && textField && m_scripter ) + { + const QString lastResult = m_scripter->lastResult(); + if ( !lastResult.isNull() ) + { + textField->setText( lastResult ); + } + } } else { diff --git a/core/script/executor_kjs.cpp b/core/script/executor_kjs.cpp --- a/core/script/executor_kjs.cpp +++ b/core/script/executor_kjs.cpp @@ -84,7 +84,7 @@ delete d; } -void ExecutorKJS::execute( const QString &script ) +QString ExecutorKJS::execute( const QString &script ) { #if 0 QString script2; @@ -100,13 +100,16 @@ KJSResult result = d->m_interpreter->evaluate( QStringLiteral("okular.js"), 1, script, &d->m_docObject ); KJSContext* ctx = d->m_interpreter->globalContext(); + QString resultValue; if ( result.isException() || ctx->hasException() ) { qCDebug(OkularCoreDebug) << "JS exception" << result.errorMessage(); } else { - qCDebug(OkularCoreDebug) << "result:" << result.value().toString( ctx ); + resultValue = result.value().toString( ctx ); + qCDebug(OkularCoreDebug) << "result:" << resultValue; } JSField::clearCachedFields(); + return resultValue; } diff --git a/core/script/executor_kjs_p.h b/core/script/executor_kjs_p.h --- a/core/script/executor_kjs_p.h +++ b/core/script/executor_kjs_p.h @@ -23,7 +23,7 @@ ExecutorKJS( DocumentPrivate *doc ); ~ExecutorKJS(); - void execute( const QString &script ); + QString execute( const QString &script ); private: friend class ExecutorKJSPrivate; diff --git a/core/scripter.h b/core/scripter.h --- a/core/scripter.h +++ b/core/scripter.h @@ -31,6 +31,11 @@ QString execute( ScriptType type, const QString &script ); + /** + Get the string result of the last execution. + */ + QString lastResult() const; + private: friend class ScripterPrivate; ScripterPrivate* d; diff --git a/core/scripter.cpp b/core/scripter.cpp --- a/core/scripter.cpp +++ b/core/scripter.cpp @@ -31,6 +31,7 @@ DocumentPrivate *m_doc; ExecutorKJS *m_kjs; + QString m_lastResult; }; Scripter::Scripter( DocumentPrivate *doc ) @@ -59,8 +60,13 @@ { d->m_kjs = new ExecutorKJS( d->m_doc ); } - d->m_kjs->execute( script ); + d->m_lastResult = d->m_kjs->execute( QString::fromUtf8(builtin_script) + script ); break; } return QString(); } + +QString Scripter::lastResult() const +{ + return d->m_lastResult; +}