59 #include <QScriptEngine>
60 #include <QMessageBox>
66 #include "vsiPlugin.hh"
68 #include "baseWidget.hh"
69 #include "parser/context.hh"
70 #include "parser/input.hh"
71 #include "config/dynamicDialog.hh"
98 if (OpenFlipper::Options::nogui ())
101 QMenu *scriptingMenu;
103 emit emit getMenubarMenu(tr(
"&Scripting"), scriptingMenu,
true );
105 QAction* showEditor = scriptingMenu->addAction (
"Visual script editor");
106 showEditor->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"vsi_vsiEditor.png") );
108 connect (showEditor, SIGNAL(triggered()) ,
124 connect (baseWidget_, SIGNAL (codeToScriptEditor (QString)),
128 baseWidget_->show ();
137 QScriptEngine *engine;
138 emit getScriptingEngine (engine);
144 QDir dir = OpenFlipper::Options::dataDir ();
146 dir.cd (
"VsiMetadata");
151 foreach (QString sub, dir.entryList(QDir::Dirs))
158 subdir.makeAbsolute();
160 foreach (QString file, subdir.entryList (QStringList(
"*.xml"), QDir::Files))
162 QFile f (subdir.filePath (file));
163 if (!f.open (QIODevice::ReadOnly))
166 context_->
parse (f.readAll ());
182 return QScriptValue ();
184 QVector<VSI::Input *> inputs;
186 foreach (QString s, _inputs.split (
",", QString::SkipEmptyParts))
196 if (inputs.isEmpty ())
197 return QScriptValue ();
203 QMap<QString, QString> results = d.
getResults ();
205 QString script =
"inputs = { ";
207 foreach (QString s, _inputs.split (
",", QString::SkipEmptyParts))
208 script += s +
": " + results[s] +
",";
210 script.remove (script.length () - 1, 1);
215 QScriptValue rv = context_->
scriptEngine ()->evaluate (script);
216 context_->
scriptEngine ()->globalObject ().setProperty (
"inputs", rv);
230 emit functionExists (
"scripting",
"showScriptInEditor(QString)", ok);
244 msgBox.setText(_message);
254 msgBox.setText(_message);
255 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
256 msgBox.setDefaultButton(QMessageBox::Yes);
257 int ret = msgBox.exec();
258 if (ret == QMessageBox::Yes)
273 if ( msgBox->continueBox() ) {
287 #if QT_VERSION < 0x050000
virtual void addMenubarAction(QAction *_action, QString _name)
Adds an action to the menubar.
void pluginsInitialized()
Register in menubar.
const QString & name() const
Name.
const QString & shortDescription() const
Short description.
const QVector< Input * > & inputs() const
Inputs.
QMap< QString, QString > getResults()
Results.
QScriptValue askForInputs(QString _element, QString _inputs)
Scripting function, that allows to ask the user for inputs during script execution.
bool continueBox(QString _message)
Shows a non blocking stop box for use inside loops.
void showInScriptEditor(QString _script)
Opens the text based script editor with the given script.
Element * element(QString _name)
Returns the element with a given name.
void messageBox(QString _message)
Scripting function, that displays a message box.
#define TOOLSMENU
The Menu will be added inside the Tools Menu.
bool questionBox(QString _message)
Scripting function, that displays a Yes/No message box.
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
static BaseWidget * createBaseWidget(Context *_ctx, QWidget *_parent=NULL)
Singleton constructor.
QScriptEngine * scriptEngine()
Return script engine pointer.
void parse(QByteArray _xml)
Parse xml content.
void initContext()
initalisation
void showScriptEditor()
Shows visual script editor.