Commit 2f3475e1 authored by Jan Möbius's avatar Jan Möbius

Added statusbar and error messages with line numbers

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@12436 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 9fa3363e
......@@ -100,7 +100,11 @@ void ScriptingPlugin::pluginsInitialized() {
icon.addFile(iconPath+"window-close.png");
scriptWidget_->actionClose->setIcon(icon);
QToolBar* toolBar = new QToolBar(tr("File Actions"));
// ==================================================================
// Add a toolbar
// ==================================================================
QToolBar* toolBar = new QToolBar(tr("Scripting Toolbar"));
QAction* openButton = new QAction(QIcon(iconPath + "document-open.png"), "Open", toolBar);
......@@ -123,6 +127,16 @@ void ScriptingPlugin::pluginsInitialized() {
scriptWidget_->addToolBar(toolBar);
// ==================================================================
// Create a status bar
// ==================================================================
statusBar_ = new QStatusBar();
scriptWidget_->setStatusBar( statusBar_ );
// ==================================================================
scriptWidget_->hide();
scriptWidget_->resize(scriptWidget_->width() , std::min(QApplication::desktop()->screenGeometry().height() - 150 , 800) );
......@@ -235,6 +249,10 @@ void ScriptingPlugin::slotScriptInfo( QString _pluginName , QString _functionNam
}
void ScriptingPlugin::slotExecuteScript( QString _script ) {
if ( OpenFlipper::Options::gui())
statusBar_->showMessage(tr("Executing Script"));
QScriptEngine* engine;
emit getScriptingEngine( engine );
......@@ -245,13 +263,25 @@ void ScriptingPlugin::slotExecuteScript( QString _script ) {
// Get the filename of the script and set it in the scripting environment
engine->globalObject().setProperty("ScriptPath",QScriptValue(engine,lastFile_.section(OpenFlipper::Options::dirSeparator(), 0, -2)));
// Execute the script
engine->evaluate( _script );
// Catch errors and print some reasonable error message to log and statusbar
bool error = false;
if ( engine->hasUncaughtException() ) {
error = true;
QScriptValue result = engine->uncaughtException();
QString exception = result.toString();
emit log( LOGERR , tr("Script execution failed with : ") + exception );
int lineNumber = engine->uncaughtExceptionLineNumber();
emit log( LOGERR , tr("Script execution failed at line %1, with : %2 ").arg(lineNumber).arg(exception) );
if ( OpenFlipper::Options::gui())
statusBar_->showMessage(tr("Script execution failed at line %1, with : %2 ").arg(lineNumber).arg(exception));
}
if ( OpenFlipper::Options::gui() && !error)
statusBar_->clearMessage();
/// Switch scripting mode off
OpenFlipper::Options::scripting(false);
}
......@@ -543,7 +573,6 @@ void ScriptingPlugin::showScriptInEditor(QString _code)
}
void ScriptingPlugin::clearEditor() {
std::cerr<< "Slotclear editor " << std::endl;
scriptWidget_->currentScript->clear();
}
......
......@@ -182,11 +182,13 @@ private :
private :
ScriptWidget* scriptWidget_;
Highlighter* highlighterCurrent_;
Highlighter* highlighterLive_;
Highlighter* highlighterList_;
QStatusBar* statusBar_;
QString lastFile_;
Highlighter* highlighterCurrent_;
Highlighter* highlighterLive_;
Highlighter* highlighterList_;
QString lastFile_;
public slots:
QString version() { return QString("1.0"); };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment