diff --git a/core/script/executor_kjs.cpp b/core/script/executor_kjs.cpp index dcb1d4d4a..59419443b 100644 --- a/core/script/executor_kjs.cpp +++ b/core/script/executor_kjs.cpp @@ -108,4 +108,5 @@ void ExecutorKJS::execute( const QString &script ) { qCDebug(OkularCoreDebug) << "result:" << result.value().toString( ctx ); } + JSField::clearCachedFields(); } diff --git a/core/script/kjs_field.cpp b/core/script/kjs_field.cpp index 4ec1cbade..1e77913bb 100644 --- a/core/script/kjs_field.cpp +++ b/core/script/kjs_field.cpp @@ -22,11 +22,15 @@ #include "../document_p.h" #include "../form.h" #include "../page.h" +#include "../page_p.h" using namespace Okular; static KJSPrototype *g_fieldProto; +typedef QHash< FormField *, Page * > FormCache; +Q_GLOBAL_STATIC( FormCache, g_fieldCache ) + // Field.doc static KJSObject fieldGetDoc( KJSContext *context, void * ) { @@ -109,7 +113,7 @@ static KJSObject fieldGetType( KJSContext *, void *object ) } // Field.value (getter) -static KJSObject fieldGetValue( KJSContext *context, void *object ) +static KJSObject fieldGetValue( KJSContext */*context*/, void *object ) { FormField *field = reinterpret_cast< FormField * >( object ); @@ -156,8 +160,23 @@ static void fieldSetValue( KJSContext *context, void *object, KJSObject value ) } case FormField::FormText: { - FormFieldText *text = static_cast< FormFieldText * >( field ); - text->setText( value.toString( context ) ); + FormFieldText *textField = static_cast< FormFieldText * >( field ); + const QString text = value.toString( context ); + if ( text != textField->text() ) + { + textField->setText( text ); + + Page *page = g_fieldCache->value( field ); + if (page) + { + Document *doc = PagePrivate::get( page )->m_doc->m_parent; + QMetaObject::invokeMethod( doc, "refreshPixmaps", Qt::QueuedConnection, Q_ARG( int, page->number() ) ); + } + else + { + qWarning() << "Could not get page of field" << field; + } + } break; } case FormField::FormChoice: @@ -196,5 +215,14 @@ KJSObject JSField::wrapField( KJSContext *ctx, FormField *field, Page *page ) // ### cache unique wrapper KJSObject f = g_fieldProto->constructObject( ctx, field ); f.setProperty( ctx, QStringLiteral("page"), page->number() ); + g_fieldCache->insert( field, page ); return f; } + +void JSField::clearCachedFields() +{ + if ( g_fieldCache.exists() ) + { + g_fieldCache->clear(); + } +} diff --git a/core/script/kjs_field_p.h b/core/script/kjs_field_p.h index 1b9ce9f6c..bc0a4628f 100644 --- a/core/script/kjs_field_p.h +++ b/core/script/kjs_field_p.h @@ -24,6 +24,7 @@ class JSField public: static void initType( KJSContext *ctx ); static KJSObject wrapField( KJSContext *ctx, FormField *field, Page *page ); + static void clearCachedFields(); }; }