diff --git a/ionCore/ionPulse.js b/ionCore/ionPulse.js index 26d2838..b468459 100644 --- a/ionCore/ionPulse.js +++ b/ionCore/ionPulse.js @@ -26,6 +26,10 @@ function to_string(input) if (is_string(input)) { return input; } + + if (undefined === input) { + return "undefined"; + } if (null === input) { return "null"; } @@ -50,9 +54,12 @@ function alert(text) } -function JsConsoleWidget(parent) { +function JsConsoleWidget(parent) +{ QWidget.call(this, parent); + this.history = []; + this.historyIdx = null; this.textEdit = new QTextEdit(this); this.textEdit.readOnly = true; this.htmlPrefix = " \ @@ -71,6 +78,8 @@ function JsConsoleWidget(parent) { var line = trim(this.lineInput.text); this.lineInput.text = ""; if (line) { + this.history.push(line); + this.historyIdx = null; // wrap to catch thrown exceptions line = "try {ret = "+line+";console.log(typeof(ret)+ret?ret:\"\");} catch (err) {" + "console.error('An error has occurred: '+err.message);" @@ -82,8 +91,6 @@ function JsConsoleWidget(parent) { console.error('An error has occurred: '+err.message); } } - var scrollBar = this.textEdit.verticalScrollBar(); - scrollBar.value = scrollBar.maximum; } ); @@ -105,6 +112,29 @@ function JsConsoleWidget(parent) { } } ); + qs.system.installAppShortcut(Qt.Key_Up, this.lineInput).callback.connect( + this, + function() { + if (null === this.historyIdx) { + this.historyIdx = this.history.length; + } + if (this.historyIdx > 0) { + this.lineInput.text = this.history[--this.historyIdx]; + } + } + ); + qs.system.installAppShortcut(Qt.Key_Down, this.lineInput).callback.connect( + this, + function() { + if (null === this.historyIdx) { + return; + } + if (this.historyIdx < this.history.length) { + this.lineInput.text = this.history[++this.historyIdx]; + } + } + ); + } @@ -112,12 +142,18 @@ JsConsoleWidget.prototype = new QWidget(); JsConsoleWidget.prototype.log = function (text) { this.htmlContent += "
> "+escape(text)+"
"; - this.textEdit.html = this.htmlPrefix + this.htmlContent + this.htmlSuffix; + this.updateHtml(); } JsConsoleWidget.prototype.error = function (text) { this.htmlContent += "
> "+escape(text)+"
"; + this.updateHtml(); +} +JsConsoleWidget.prototype.updateHtml = function() +{ this.textEdit.html = this.htmlPrefix + this.htmlContent + this.htmlSuffix; + var scrollBar = this.textEdit.verticalScrollBar(); + scrollBar.value = scrollBar.maximum; } diff --git a/ionCore/jsengine.cpp b/ionCore/jsengine.cpp index 8d748b1..ae37346 100644 --- a/ionCore/jsengine.cpp +++ b/ionCore/jsengine.cpp @@ -93,7 +93,7 @@ QScriptValue importExtension(QScriptContext *context, QScriptEngine *engine) QScriptValue installAppShortcut(QScriptContext *context, QScriptEngine *engine) { return engine->newQObject( - new AppShortcut((Qt::Key)context->argument(0).toInt32()), + new AppShortcut((Qt::Key)context->argument(0).toInt32(), (context->argumentCount()==2)?context->argument(1).toQObject():NULL), QScriptEngine::ScriptOwnership ); } @@ -152,13 +152,16 @@ void JsEngine::initialiseJsFramework() } -AppShortcut::AppShortcut(Qt::Key key) : key(key) +AppShortcut::AppShortcut(Qt::Key key, QObject *owner) : key(key), owner(owner) { qApp->installEventFilter(this); } bool AppShortcut::eventFilter(QObject *obj, QEvent *event) { + if (owner && (owner != obj)) { + return false; + } if (QEvent::KeyPress == event->type()) { QKeyEvent *kev = static_cast(event); if (kev->key() == key) { diff --git a/ionCore/jsengine.h b/ionCore/jsengine.h index b6e3be0..32679fb 100644 --- a/ionCore/jsengine.h +++ b/ionCore/jsengine.h @@ -29,8 +29,9 @@ class AppShortcut : public QObject { private: Qt::Key key; + QObject *owner; public: - AppShortcut(Qt::Key key); + AppShortcut(Qt::Key key, QObject *owner); protected: bool eventFilter(QObject *obj, QEvent *event);