Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/scripting/kexiscripting/kexiscriptdesignview.cpp
Show All 16 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License | ||
18 | along with this program; see the file COPYING. If not, write to | 18 | along with this program; see the file COPYING. If not, write to | ||
19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
20 | * Boston, MA 02110-1301, USA. | 20 | * Boston, MA 02110-1301, USA. | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include "kexiscriptdesignview.h" | 23 | #include "kexiscriptdesignview.h" | ||
24 | #include "kexiscripteditor.h" | 24 | #include "kexiscripteditor.h" | ||
25 | #include "kexiscriptadaptor.h" | ||||
26 | | ||||
25 | #include <KexiIcon.h> | 27 | #include <KexiIcon.h> | ||
26 | #include <KexiMainWindowIface.h> | 28 | #include <KexiMainWindowIface.h> | ||
27 | 29 | #include <kexipart.h> | |||
28 | #include <Kross/Manager> | | |||
29 | #include <Kross/Action> | | |||
30 | #include <Kross/Interpreter> | | |||
31 | 30 | | |||
32 | #include <KDbConnection> | 31 | #include <KDbConnection> | ||
33 | 32 | | |||
34 | #include <KActionMenu> | 33 | #include <KActionMenu> | ||
35 | #include <KMessageBox> | 34 | #include <KMessageBox> | ||
36 | 35 | | |||
37 | #include <QSplitter> | 36 | #include <QSplitter> | ||
38 | #include <QTimer> | 37 | #include <QTimer> | ||
39 | #include <QDomDocument> | 38 | #include <QDomDocument> | ||
40 | #include <QTextBrowser> | 39 | #include <QTextBrowser> | ||
41 | #include <QDebug> | 40 | #include <QDebug> | ||
42 | #include <QFileDialog> | 41 | #include <QFileDialog> | ||
42 | #include <QMenu> | ||||
43 | #include <QJSEngine> | ||||
44 | #include <QJSValue> | ||||
43 | 45 | | |||
44 | /// @internal | 46 | /// @internal | ||
45 | class KexiScriptDesignViewPrivate | 47 | class KexiScriptDesignViewPrivate | ||
46 | { | 48 | { | ||
47 | public: | 49 | public: | ||
48 | 50 | | |||
49 | QSplitter* splitter; | 51 | QSplitter* splitter; | ||
50 | 52 | | |||
51 | /** | 53 | /** | ||
52 | * The \a Kross::Action instance which provides | 54 | * The \a QJSEngine which allows | ||
53 | * us access to the scripting framework Kross. | 55 | * the script program to be executed | ||
54 | */ | 56 | */ | ||
55 | Kross::Action* scriptaction; | 57 | QJSEngine scriptEngine; | ||
58 | | ||||
59 | KexiScriptAdaptor adaptor; | ||||
56 | 60 | | |||
57 | /// The \a KexiScriptEditor to edit the scripting code. | 61 | /// The \a KexiScriptEditor to edit the scripting code. | ||
58 | KexiScriptEditor* editor; | 62 | KexiScriptEditor* editor; | ||
59 | 63 | | |||
60 | /// The \a KPropertySet used in the propertyeditor. | 64 | /// The \a KPropertySet used in the propertyeditor. | ||
61 | KPropertySet* properties; | 65 | KPropertySet* properties; | ||
62 | 66 | | |||
63 | /// Boolean flag to avoid infinite recursion. | 67 | /// Boolean flag to avoid infinite recursion. | ||
64 | bool updatesProperties; | 68 | bool updatesProperties; | ||
65 | 69 | | |||
66 | /// Used to display statusmessages. | 70 | /// Used to display statusmessages. | ||
67 | QTextBrowser* statusbrowser; | 71 | QTextBrowser* statusbrowser; | ||
68 | 72 | | |||
69 | /** The type of script | 73 | /** The type of script | ||
70 | * executable = regular script that can be executed by the user | 74 | * executable = regular script that can be executed by the user | ||
71 | * module = a script which doesn't contain a 'main', only | 75 | * module = a script which doesn't contain a 'main', only | ||
72 | * functions that can be used by other scripts | 76 | * functions that can be used by other scripts | ||
73 | * object = a script which contains code to be loaded into another | 77 | * object = a script which contains code to be loaded into another | ||
74 | object such as a report or form | 78 | object such as a report or form | ||
75 | */ | 79 | */ | ||
76 | QString scriptType; | 80 | QString scriptType; | ||
77 | }; | 81 | }; | ||
78 | 82 | | |||
79 | KexiScriptDesignView::KexiScriptDesignView( | 83 | KexiScriptDesignView::KexiScriptDesignView( | ||
80 | QWidget *parent, Kross::Action* scriptaction) | 84 | QWidget *parent) | ||
81 | : KexiView(parent) | 85 | : KexiView(parent) | ||
82 | , d(new KexiScriptDesignViewPrivate()) | 86 | , d(new KexiScriptDesignViewPrivate()) | ||
83 | { | 87 | { | ||
84 | setObjectName("KexiScriptDesignView"); | 88 | setObjectName("KexiScriptDesignView"); | ||
85 | d->scriptaction = scriptaction; | 89 | | ||
90 | QJSValue val = d->scriptEngine.newQObject(&d->adaptor); | ||||
91 | d->scriptEngine.globalObject().setProperty("Kexi", val); | ||||
92 | | ||||
86 | d->updatesProperties = false; | 93 | d->updatesProperties = false; | ||
87 | 94 | | |||
88 | d->splitter = new QSplitter(this); | 95 | d->splitter = new QSplitter(this); | ||
89 | d->splitter->setOrientation(Qt::Vertical); | 96 | d->splitter->setOrientation(Qt::Vertical); | ||
90 | 97 | | |||
91 | d->editor = new KexiScriptEditor(d->splitter); | 98 | d->editor = new KexiScriptEditor(d->splitter); | ||
92 | d->splitter->addWidget(d->editor); | 99 | d->splitter->addWidget(d->editor); | ||
93 | d->editor->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); | 100 | d->editor->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); | ||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Line(s) | |||||
168 | a->setObjectName("script_export"); | 175 | a->setObjectName("script_export"); | ||
169 | a->setToolTip(xi18n("Export script")); | 176 | a->setToolTip(xi18n("Export script")); | ||
170 | a->setWhatsThis(xi18n("Exports script to a file.")); | 177 | a->setWhatsThis(xi18n("Exports script to a file.")); | ||
171 | connect(a, SIGNAL(triggered(bool)), this, SLOT(slotExport())); | 178 | connect(a, SIGNAL(triggered(bool)), this, SLOT(slotExport())); | ||
172 | mainMenuActions << a; | 179 | mainMenuActions << a; | ||
173 | 180 | | |||
174 | setMainMenuActions(mainMenuActions); | 181 | setMainMenuActions(mainMenuActions); | ||
175 | 182 | | |||
176 | loadData(); | | |||
177 | | ||||
178 | d->properties = new KPropertySet(this); | 183 | d->properties = new KPropertySet(this); | ||
179 | connect(d->properties, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), | 184 | connect(d->properties, SIGNAL(propertyChanged(KPropertySet&,KProperty&)), | ||
180 | this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); | 185 | this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); | ||
181 | 186 | | |||
182 | // To schedule the initialize fixes a crasher in Kate. | 187 | loadData(); | ||
183 | QTimer::singleShot(50, this, SLOT(initialize())); | | |||
184 | } | 188 | } | ||
185 | 189 | | |||
186 | KexiScriptDesignView::~KexiScriptDesignView() | 190 | KexiScriptDesignView::~KexiScriptDesignView() | ||
187 | { | 191 | { | ||
188 | delete d->properties; | 192 | delete d->properties; | ||
189 | delete d; | 193 | delete d; | ||
190 | } | 194 | } | ||
191 | 195 | | |||
192 | Kross::Action* KexiScriptDesignView::scriptAction() const | 196 | #if 0 | ||
197 | QString KexiScriptDesignView::scriptAction() const | ||||
193 | { | 198 | { | ||
194 | return d->scriptaction; | 199 | return d->scriptaction; | ||
195 | } | 200 | } | ||
201 | #endif | ||||
196 | 202 | | |||
197 | void KexiScriptDesignView::initialize() | 203 | void KexiScriptDesignView::initialize(const QString &program) | ||
198 | { | 204 | { | ||
199 | setDirty(false); | 205 | setDirty(false); | ||
200 | updateProperties(); | 206 | updateProperties(); | ||
201 | d->editor->initialize(d->scriptaction); | 207 | d->editor->initialize(program); | ||
202 | connect(d->editor, SIGNAL(textChanged()), this, SLOT(setDirty())); | 208 | connect(d->editor, SIGNAL(textChanged()), this, SLOT(setDirty())); | ||
203 | d->splitter->setSizes( QList<int>() << height() * 2 / 3 << height() * 1 / 3 ); | 209 | d->splitter->setSizes( QList<int>() << height() * 2 / 3 << height() * 1 / 3 ); | ||
204 | } | 210 | } | ||
205 | 211 | | |||
206 | void KexiScriptDesignView::slotImport() | 212 | void KexiScriptDesignView::slotImport() | ||
207 | { | 213 | { | ||
208 | QStringList filters; | | |||
209 | foreach(const QString &interpreter, Kross::Manager::self().interpreters()) { | | |||
210 | filters << Kross::Manager::self().interpreterInfo(interpreter)->mimeTypes(); | | |||
211 | } | | |||
212 | //! @todo KEXI3 add equivalent of kfiledialog:/// | | |||
213 | //! @todo KEXI3 multiple filters | | |||
214 | // for now support jsut one filter | | |||
215 | QString filterString; | | |||
216 | if (filters.count() == 1) { | | |||
217 | const QMimeDatabase db; | | |||
218 | const QString filterString = db.mimeTypeForName(filters.first()).filterString(); | | |||
219 | } | | |||
220 | //QUrl("kfiledialog:///kexiscriptingdesigner"), | 214 | //QUrl("kfiledialog:///kexiscriptingdesigner"), | ||
221 | const QUrl result = QFileDialog::getOpenFileUrl(this, xi18nc("@title:window", "Import Script"), | 215 | const QUrl result = QFileDialog::getOpenFileUrl(this, xi18nc("@title:window", "Import Script"), | ||
222 | QUrl(), filterString); | 216 | QUrl(), "Javascript (*.js)"); | ||
223 | if (!result.isValid()) { | 217 | if (!result.isValid()) { | ||
224 | return; | 218 | return; | ||
225 | } | 219 | } | ||
226 | //! @todo support remote files? | 220 | //! @todo support remote files? | ||
227 | QFile f(result.toLocalFile()); | 221 | QFile f(result.toLocalFile()); | ||
228 | if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { | 222 | if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { | ||
229 | KMessageBox::sorry(this, | 223 | KMessageBox::sorry(this, | ||
230 | xi18nc("@info", "Could not read <filename>%1</filename>.", file)); | 224 | xi18nc("@info", "Could not read <filename>%1</filename>.", result.toLocalFile())); | ||
231 | return; | 225 | return; | ||
232 | } | 226 | } | ||
233 | d->editor->setText(f.readAll()); | 227 | d->editor->setText(f.readAll()); | ||
234 | f.close(); | 228 | f.close(); | ||
235 | } | 229 | } | ||
236 | 230 | | |||
237 | void KexiScriptDesignView::slotExport() | 231 | void KexiScriptDesignView::slotExport() | ||
238 | { | 232 | { | ||
239 | QStringList filters; | 233 | const QUrl result = QFileDialog::getSaveFileUrl(this, xi18nc("@title:window", "Export Script"), | ||
240 | foreach(const QString &interpreter, Kross::Manager::self().interpreters()) { | 234 | QUrl("kfiledialog:///kexiscriptingdesigner"), "Javascript (*.js)" ); | ||
241 | filters << Kross::Manager::self().interpreterInfo(interpreter)->mimeTypes(); | 235 | if (!result.isValid()) | ||
242 | } | | |||
243 | const QString file = KFileDialog::getSaveFileName( | | |||
244 | QUrl("kfiledialog:///kexiscriptingdesigner"), | | |||
245 | filters.join(" "), this, xi18nc("@title:window", "Export Script")); | | |||
246 | if (file.isEmpty()) | | |||
247 | return; | 236 | return; | ||
248 | QFile f(file); | 237 | QFile f(result.toLocalFile()); | ||
249 | if (! f.open(QIODevice::WriteOnly | QIODevice::Text)) { | 238 | if (! f.open(QIODevice::WriteOnly | QIODevice::Text)) { | ||
250 | KMessageBox::sorry(this, | 239 | KMessageBox::sorry(this, | ||
251 | xi18nc("@info", "Could not write <filename>%1</filename>.", file)); | 240 | xi18nc("@info", "Could not write <filename>%1</filename>.", result.toLocalFile())); | ||
252 | return; | 241 | return; | ||
253 | } | 242 | } | ||
254 | f.write(d->editor->text().toUtf8()); | 243 | f.write(d->editor->text().toUtf8()); | ||
255 | f.close(); | 244 | f.close(); | ||
256 | } | 245 | } | ||
257 | 246 | | |||
258 | void KexiScriptDesignView::updateProperties() | 247 | void KexiScriptDesignView::updateProperties() | ||
259 | { | 248 | { | ||
260 | if (d->updatesProperties) | 249 | if (d->updatesProperties) | ||
261 | return; | 250 | return; | ||
262 | d->updatesProperties = true; | 251 | d->updatesProperties = true; | ||
263 | 252 | | |||
264 | Kross::Manager* manager = &Kross::Manager::self(); | | |||
265 | | ||||
266 | QString interpretername = d->scriptaction->interpreter(); | | |||
267 | Kross::InterpreterInfo* info = interpretername.isEmpty() ? 0 : manager->interpreterInfo(interpretername); | | |||
268 | | ||||
269 | if (!info) { | | |||
270 | // if interpreter isn't defined or invalid, try to fallback. | | |||
271 | foreach (const QString& interpretername, | | |||
272 | QStringList() << "python" << "ruby" << "qtscript" << "javascript" << "java") | | |||
273 | { | | |||
274 | info = manager->interpreterInfo(interpretername); | | |||
275 | if (info) { | | |||
276 | d->scriptaction->setInterpreter(interpretername); | | |||
277 | break; | | |||
278 | } | | |||
279 | } | | |||
280 | } | | |||
281 | | ||||
282 | if (!info) { | | |||
283 | d->updatesProperties = false; | | |||
284 | return; | | |||
285 | } | | |||
286 | | ||||
287 | d->properties->clear(); | 253 | d->properties->clear(); | ||
288 | 254 | | |||
289 | QStringList types; | 255 | QStringList types; | ||
290 | types << "executable" << "module" << "object"; | 256 | types << "executable" << "module" << "object"; | ||
291 | KPropertyListData* typelist = new KPropertyListData(types, types); | 257 | KPropertyListData* typelist = new KPropertyListData(types, types); | ||
292 | KProperty* t = new KProperty( | 258 | KProperty* t = new KProperty( | ||
293 | "type", // name | 259 | "type", // name | ||
294 | typelist, // ListData | 260 | typelist, // ListData | ||
295 | (d->scriptType.isEmpty() ? "executable" : d->scriptType), // value | 261 | (d->scriptType.isEmpty() ? "executable" : d->scriptType), // value | ||
296 | xi18n("Script Type"), // caption | 262 | xi18n("Script Type"), // caption | ||
297 | xi18n("The type of script"), // description | 263 | xi18n("The type of script"), // description | ||
298 | KProperty::List // type | 264 | KProperty::List // type | ||
299 | ); | 265 | ); | ||
300 | d->properties->addProperty(t); | 266 | d->properties->addProperty(t); | ||
301 | 267 | | |||
302 | QStringList interpreters = manager->interpreters(); | | |||
303 | | ||||
304 | qDebug() << interpreters; | | |||
305 | | ||||
306 | KPropertyListData* proplist = new KPropertyListData(interpreters, interpreters); | | |||
307 | KProperty* prop = new KProperty( | | |||
308 | "language", // name | | |||
309 | proplist, // ListData | | |||
310 | d->scriptaction->interpreter(), // value | | |||
311 | xi18n("Interpreter"), // caption | | |||
312 | xi18n("The used scripting interpreter."), // description | | |||
313 | KProperty::List // type | | |||
314 | ); | | |||
315 | d->properties->addProperty(prop); | | |||
316 | | ||||
317 | Kross::InterpreterInfo::Option::Map options = info->options(); | | |||
318 | Kross::InterpreterInfo::Option::Map::ConstIterator it, end(options.constEnd()); | | |||
319 | for (it = options.constBegin(); it != end; ++it) { | | |||
320 | Kross::InterpreterInfo::Option* option = it.value(); | | |||
321 | KProperty* prop = new KProperty( | | |||
322 | it.key().toLatin1(), // name | | |||
323 | d->scriptaction->option(it.key(), option->value), // value | | |||
324 | it.key(), // caption | | |||
325 | option->comment, // description | | |||
326 | KProperty::Auto // type | | |||
327 | ); | | |||
328 | d->properties->addProperty(prop); | | |||
329 | } | | |||
330 | | ||||
331 | //propertySetSwitched(); | 268 | //propertySetSwitched(); | ||
332 | propertySetReloaded(true); | 269 | propertySetReloaded(true); | ||
333 | d->updatesProperties = false; | 270 | d->updatesProperties = false; | ||
334 | } | 271 | } | ||
335 | 272 | | |||
336 | KPropertySet* KexiScriptDesignView::propertySet() | 273 | KPropertySet* KexiScriptDesignView::propertySet() | ||
337 | { | 274 | { | ||
338 | return d->properties; | 275 | return d->properties; | ||
339 | } | 276 | } | ||
340 | 277 | | |||
341 | void KexiScriptDesignView::slotPropertyChanged(KPropertySet& /*set*/, KProperty& property) | 278 | void KexiScriptDesignView::slotPropertyChanged(KPropertySet& /*set*/, KProperty& property) | ||
342 | { | 279 | { | ||
343 | if (property.isNull()) | 280 | if (property.isNull()) | ||
344 | return; | 281 | return; | ||
345 | 282 | | |||
346 | if (property.name() == "language") { | 283 | if (property.name() == "type") { | ||
347 | QString language = property.value().toString(); | | |||
348 | qDebug() << "language:" << language; | | |||
349 | d->scriptaction->setInterpreter(language); | | |||
350 | // We assume Kross and the HighlightingInterface are using same | | |||
351 | // names for the support languages... | | |||
352 | d->editor->setHighlightMode(language); | | |||
353 | updateProperties(); | | |||
354 | } | | |||
355 | else if (property.name() == "type") { | | |||
356 | d->scriptType = property.value().toString(); | 284 | d->scriptType = property.value().toString(); | ||
357 | } | 285 | } | ||
358 | else { | 286 | else { | ||
359 | bool ok = d->scriptaction->setOption(property.name(), property.value()); | | |||
360 | if (! ok) { | | |||
361 | qWarning() << "unknown property:" << property.name(); | 287 | qWarning() << "unknown property:" << property.name(); | ||
362 | return; | 288 | return; | ||
363 | } | 289 | } | ||
364 | } | | |||
365 | 290 | | |||
366 | setDirty(true); | 291 | setDirty(true); | ||
367 | } | 292 | } | ||
368 | 293 | | |||
369 | void KexiScriptDesignView::execute() | 294 | void KexiScriptDesignView::execute() | ||
370 | { | 295 | { | ||
371 | d->statusbrowser->clear(); | 296 | d->statusbrowser->clear(); | ||
372 | QTime time; | 297 | QTime time; | ||
373 | time.start(); | 298 | time.start(); | ||
374 | d->statusbrowser->append(xi18nc("@info", | 299 | d->statusbrowser->append(xi18nc("@info", | ||
375 | "Execution of the script <resource>%1</resource> started.", | 300 | "Execution of the script <resource>%1</resource> started.", | ||
376 | d->scriptaction->name())); | 301 | part()->instanceName())); | ||
377 | 302 | | |||
378 | d->scriptaction->trigger(); | 303 | QJSValue result = d->scriptEngine.evaluate(d->editor->text().toUtf8()); | ||
379 | if (d->scriptaction->hadError()) { | | |||
380 | QString errormessage = d->scriptaction->errorMessage(); | | |||
381 | d->statusbrowser->append(QString("<b>%2</b><br>").arg(errormessage.toHtmlEscaped())); | | |||
382 | 304 | | |||
383 | QString tracedetails = d->scriptaction->errorTrace(); | 305 | if (result.isError()) { | ||
384 | d->statusbrowser->append(tracedetails.toHtmlEscaped()); | 306 | QString errormessage = result.toString(); | ||
307 | d->statusbrowser->append(QString("<b>%2</b><br>").arg(errormessage.toHtmlEscaped())); | ||||
385 | 308 | | |||
386 | long lineno = d->scriptaction->errorLineNo(); | 309 | long lineno = result.property("lineNumber").toInt(); | ||
387 | if (lineno >= 0) | 310 | if (lineno >= 0) | ||
388 | d->editor->setLineNo(lineno); | 311 | d->editor->setLineNo(lineno); | ||
389 | } | 312 | } | ||
390 | else { | 313 | else { | ||
391 | // xgettext: no-c-format | 314 | // xgettext: no-c-format | ||
392 | d->statusbrowser->append(xi18n("Successfully executed. Time elapsed: %1ms", time.elapsed())); | 315 | d->statusbrowser->append(xi18n("Successfully executed. Time elapsed: %1ms", time.elapsed())); | ||
393 | } | 316 | } | ||
394 | } | 317 | } | ||
Show All 9 Lines | 320 | { | |||
404 | QString errMsg; | 327 | QString errMsg; | ||
405 | int errLine; | 328 | int errLine; | ||
406 | int errCol; | 329 | int errCol; | ||
407 | 330 | | |||
408 | QDomDocument domdoc; | 331 | QDomDocument domdoc; | ||
409 | bool parsed = domdoc.setContent(data, false, &errMsg, &errLine, &errCol); | 332 | bool parsed = domdoc.setContent(data, false, &errMsg, &errLine, &errCol); | ||
410 | 333 | | |||
411 | if (! parsed) { | 334 | if (! parsed) { | ||
412 | qDebug() << "XML parsing error line: " << errLine << " col: " << errCol << " message: " << errMsg; | 335 | qDebug() << "XML parsing error line: " << errLine << " col: " << errCol << " message: " << errMsg; | ||
staniek: -> KexiScriptingWarning | |||||
413 | return false; | 336 | return false; | ||
414 | } | 337 | } | ||
415 | 338 | | |||
416 | QDomElement scriptelem = domdoc.namedItem("script").toElement(); | 339 | QDomElement scriptelem = domdoc.namedItem("script").toElement(); | ||
417 | if (scriptelem.isNull()) { | 340 | if (scriptelem.isNull()) { | ||
418 | qDebug() << "script domelement is null"; | 341 | qDebug() << "script domelement is null"; | ||
staniek: -> KexiScriptingWarning | |||||
419 | return false; | 342 | return false; | ||
420 | } | 343 | } | ||
421 | 344 | | |||
422 | d->scriptType = scriptelem.attribute("scripttype"); | 345 | d->scriptType = scriptelem.attribute("scripttype"); | ||
423 | if (d->scriptType.isEmpty()) { | 346 | if (d->scriptType.isEmpty()) { | ||
424 | d->scriptType = "executable"; | 347 | d->scriptType = "executable"; | ||
425 | } | 348 | } | ||
426 | 349 | | |||
427 | QString interpretername = scriptelem.attribute("language"); | 350 | initialize(scriptelem.text().toUtf8()); | ||
428 | Kross::Manager* manager = &Kross::Manager::self(); | | |||
429 | Kross::InterpreterInfo* info = interpretername.isEmpty() ? 0 : manager->interpreterInfo(interpretername); | | |||
430 | if (info) { | | |||
431 | d->scriptaction->setInterpreter(interpretername); | | |||
432 | | ||||
433 | Kross::InterpreterInfo::Option::Map options = info->options(); | | |||
434 | Kross::InterpreterInfo::Option::Map::ConstIterator it, end = options.constEnd(); | | |||
435 | for (it = options.constBegin(); it != end; ++it) { | | |||
436 | QString value = scriptelem.attribute(it.key()); | | |||
437 | if (! value.isNull()) { | | |||
438 | QVariant v(value); | | |||
439 | if (v.convert(it.value()->value.type())) // preserve the QVariant's type | | |||
440 | d->scriptaction->setOption(it.key(), v); | | |||
441 | } | | |||
442 | } | | |||
443 | } | | |||
444 | | ||||
445 | d->scriptaction->setCode(scriptelem.text().toUtf8()); | | |||
446 | 351 | | |||
447 | return true; | 352 | return true; | ||
448 | } | 353 | } | ||
449 | 354 | | |||
450 | KDbObject* KexiScriptDesignView::storeNewData(const KDbObject& object, | 355 | KDbObject* KexiScriptDesignView::storeNewData(const KDbObject& object, | ||
451 | KexiView::StoreNewDataOptions options, | 356 | KexiView::StoreNewDataOptions options, | ||
452 | bool *cancel) | 357 | bool *cancel) | ||
453 | { | 358 | { | ||
Show All 14 Lines | 367 | if (! storeData()) { | |||
468 | return 0; | 373 | return 0; | ||
469 | } | 374 | } | ||
470 | 375 | | |||
471 | return s; | 376 | return s; | ||
472 | } | 377 | } | ||
473 | 378 | | |||
474 | tristate KexiScriptDesignView::storeData(bool /*dontAsk*/) | 379 | tristate KexiScriptDesignView::storeData(bool /*dontAsk*/) | ||
475 | { | 380 | { | ||
381 | qDebug() << "Saving script" << d->editor->text().toUtf8(); | ||||
476 | QDomDocument domdoc("script"); | 382 | QDomDocument domdoc("script"); | ||
477 | QDomElement scriptelem = domdoc.createElement("script"); | 383 | QDomElement scriptelem = domdoc.createElement("script"); | ||
478 | domdoc.appendChild(scriptelem); | 384 | domdoc.appendChild(scriptelem); | ||
479 | 385 | | |||
480 | QString language = d->scriptaction->interpreter(); | 386 | scriptelem.setAttribute("language", "javascript"); | ||
481 | scriptelem.setAttribute("language", language); | | |||
482 | //! @todo move different types to their own part?? | 387 | //! @todo move different types to their own part?? | ||
483 | scriptelem.setAttribute("scripttype", d->scriptType); | 388 | scriptelem.setAttribute("scripttype", d->scriptType); | ||
484 | 389 | | |||
485 | Kross::InterpreterInfo* info = Kross::Manager::self().interpreterInfo(language); | 390 | QDomText scriptcode = domdoc.createTextNode(d->editor->text().toUtf8()); | ||
486 | if (info) { | | |||
487 | Kross::InterpreterInfo::Option::Map defoptions = info->options(); | | |||
488 | QMap<QString, QVariant> options = d->scriptaction->options(); | | |||
489 | QMap<QString, QVariant>::ConstIterator it, end(options.constEnd()); | | |||
490 | for (it = options.constBegin(); it != end; ++it) | | |||
491 | if (defoptions.contains(it.key())) // only remember options which the InterpreterInfo knows about... | | |||
492 | scriptelem.setAttribute(it.key(), it.value().toString()); | | |||
493 | } | | |||
494 | | ||||
495 | QDomText scriptcode = domdoc.createTextNode(d->scriptaction->code()); | | |||
496 | scriptelem.appendChild(scriptcode); | 391 | scriptelem.appendChild(scriptcode); | ||
497 | 392 | | |||
498 | return storeDataBlock(domdoc.toString()); | 393 | return storeDataBlock(domdoc.toString()); | ||
499 | } | 394 | } | ||
500 | 395 | | |||
501 | 396 | | |||
BTW staniek: BTW
Can we have have check for Qt version in CMake and if < 5.8 then disable scritping. I am OK… | |||||
staniek: Sorry for confusion wrt disabling scripting. |
-> KexiScriptingWarning