ScriptConsole: Enable for mixed debugging

Change-Id: I00f3ebd2d6fff34424b1c3c291e8bd715387acfb
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
This commit is contained in:
Aurindam Jana
2012-01-31 16:23:34 +01:00
parent 27275a0748
commit 84b82446e0
3 changed files with 47 additions and 41 deletions

View File

@@ -1229,7 +1229,6 @@ void DebuggerEngine::setState(DebuggerState state, bool forced)
showMessage(msg, LogDebug); showMessage(msg, LogDebug);
updateViews(); updateViews();
if (isMasterEngine())
emit stateChanged(d->m_state); emit stateChanged(d->m_state);
if (isSlaveEngine()) if (isSlaveEngine())

View File

@@ -75,7 +75,8 @@ public:
prompt(_("> ")), prompt(_("> ")),
startOfEditableArea(-1), startOfEditableArea(-1),
lastKnownPosition(0), lastKnownPosition(0),
inferiorStopped(false) inferiorStopped(false),
hasContext(false)
{ {
scriptHistory.append(QString()); scriptHistory.append(QString());
scriptHistoryIndex = scriptHistory.count(); scriptHistoryIndex = scriptHistory.count();
@@ -96,6 +97,7 @@ public:
InteractiveInterpreter interpreter; InteractiveInterpreter interpreter;
bool inferiorStopped; bool inferiorStopped;
bool hasContext;
QFlags<QmlJSScriptConsole::DebugLevelFlag> debugLevel; QFlags<QmlJSScriptConsole::DebugLevelFlag> debugLevel;
}; };
@@ -189,7 +191,7 @@ void QmlJSScriptConsoleWidget::setEngine(DebuggerEngine *engine)
{ {
if (m_console->engine()) if (m_console->engine())
disconnect(m_console->engine(), SIGNAL(stateChanged(Debugger::DebuggerState)), disconnect(m_console->engine(), SIGNAL(stateChanged(Debugger::DebuggerState)),
this, SLOT(engineStateChanged(Debugger::DebuggerState))); this, SLOT(onEngineStateChanged(Debugger::DebuggerState)));
QmlEngine *qmlEngine = qobject_cast<QmlEngine *>(engine); QmlEngine *qmlEngine = qobject_cast<QmlEngine *>(engine);
QmlCppEngine *qmlCppEngine = qobject_cast<QmlCppEngine *>(engine); QmlCppEngine *qmlCppEngine = qobject_cast<QmlCppEngine *>(engine);
@@ -199,9 +201,9 @@ void QmlJSScriptConsoleWidget::setEngine(DebuggerEngine *engine)
//Supports only QML Engine //Supports only QML Engine
if (qmlEngine) { if (qmlEngine) {
connect(qmlEngine, SIGNAL(stateChanged(Debugger::DebuggerState)), connect(qmlEngine, SIGNAL(stateChanged(Debugger::DebuggerState)),
this, SLOT(engineStateChanged(Debugger::DebuggerState))); this, SLOT(onEngineStateChanged(Debugger::DebuggerState)));
engineStateChanged(qmlEngine->state()); onEngineStateChanged(qmlEngine->state());
} }
m_console->setEngine(qmlEngine); m_console->setEngine(qmlEngine);
@@ -228,7 +230,7 @@ void QmlJSScriptConsoleWidget::setDebugLevel()
m_console->setDebugLevel(level); m_console->setDebugLevel(level);
} }
void QmlJSScriptConsoleWidget::engineStateChanged(Debugger::DebuggerState state) void QmlJSScriptConsoleWidget::onEngineStateChanged(Debugger::DebuggerState state)
{ {
if (state == InferiorRunOk || state == InferiorStopOk) { if (state == InferiorRunOk || state == InferiorStopOk) {
setEnabled(true); setEnabled(true);
@@ -301,11 +303,10 @@ void QmlJSScriptConsole::setEngine(QmlEngine *eng)
clear(); clear();
} }
DebuggerEngine *QmlJSScriptConsole::engine() DebuggerEngine *QmlJSScriptConsole::engine() const
{ {
if (d->adapter) { if (d->adapter)
return d->adapter->debuggerEngine(); return d->adapter->debuggerEngine();
}
return 0; return 0;
} }
@@ -364,9 +365,11 @@ void QmlJSScriptConsole::onSelectionChanged()
{ {
if (d->adapter) { if (d->adapter) {
const QString context = d->inferiorStopped ? const QString context = d->inferiorStopped ?
engine()->stackHandler()->currentFrame().function : d->adapter->debuggerEngine()->stackHandler()->currentFrame().function :
d->adapter->currentSelectedDisplayName(); d->adapter->currentSelectedDisplayName();
emit updateStatusMessage(tr("Context: %1").arg(context), 0);
d->hasContext = !context.isEmpty();
emit updateStatusMessage(tr("Context: ").append(context), 0);
} }
} }
@@ -562,22 +565,21 @@ void QmlJSScriptConsole::displayPrompt()
void QmlJSScriptConsole::handleReturnKey() void QmlJSScriptConsole::handleReturnKey()
{ {
QString currentScript = getCurrentScript(); QString currentScript = getCurrentScript();
bool scriptEvaluated = false; bool showPrompt = true;
bool showInvalidContextError = false;
//Check if string is only white spaces //Check if string is only white spaces
if (currentScript.trimmed().isEmpty()) { if (!currentScript.trimmed().isEmpty()) {
scriptEvaluated = true; //Check for a valid context
} if (d->hasContext) {
if (!scriptEvaluated) {
//check if it can be evaluated //check if it can be evaluated
if (d->canEvaluateScript(currentScript)) { if (d->canEvaluateScript(currentScript)) {
//Evaluate expression based on engine state
//Select the engine for evaluation based on //When engine->state() == InferiorStopOk, the expression
//inferior state //is sent to V8DebugService. In all other cases, the
//expression is evaluated by QDeclarativeEngine.
if (!d->inferiorStopped) { if (!d->inferiorStopped) {
QTC_ASSERT(d->adapter, return);
if (d->adapter) {
QDeclarativeEngineDebug *engineDebug = d->adapter->engineDebugClient(); QDeclarativeEngineDebug *engineDebug = d->adapter->engineDebugClient();
int id = d->adapter->currentSelectedDebugId(); int id = d->adapter->currentSelectedDebugId();
if (engineDebug && id != -1) { if (engineDebug && id != -1) {
@@ -585,26 +587,28 @@ void QmlJSScriptConsole::handleReturnKey()
engineDebug->queryExpressionResult(id, currentScript, this); engineDebug->queryExpressionResult(id, currentScript, this);
connect(query, SIGNAL(stateChanged(QmlJsDebugClient::QDeclarativeDebugQuery::State)), connect(query, SIGNAL(stateChanged(QmlJsDebugClient::QDeclarativeDebugQuery::State)),
this, SLOT(onStateChanged(QmlJsDebugClient::QDeclarativeDebugQuery::State))); this, SLOT(onStateChanged(QmlJsDebugClient::QDeclarativeDebugQuery::State)));
scriptEvaluated = true;
} }
} } else {
}
if (!scriptEvaluated) {
emit evaluateExpression(currentScript); emit evaluateExpression(currentScript);
scriptEvaluated = true;
} }
if (scriptEvaluated) {
d->appendToHistory(currentScript); d->appendToHistory(currentScript);
} } else {
} //The expression is not complete, wait for more input
} //Move to next line and do not show prompt
if (!scriptEvaluated) {
QPlainTextEdit::appendPlainText(QString()); QPlainTextEdit::appendPlainText(QString());
moveCursor(QTextCursor::EndOfLine); moveCursor(QTextCursor::EndOfLine);
showPrompt = false;
}
} else { } else {
//Incase of invalid context, append the expression to history
//and show Error message
d->appendToHistory(currentScript);
showInvalidContextError = true;
}
}
if (showPrompt) {
QTextCursor cur = textCursor(); QTextCursor cur = textCursor();
cur.movePosition(QTextCursor::End); cur.movePosition(QTextCursor::End);
cur.insertText(_("\n")); cur.insertText(_("\n"));
@@ -612,6 +616,9 @@ void QmlJSScriptConsole::handleReturnKey()
displayPrompt(); displayPrompt();
} }
//Show an error message
if (showInvalidContextError)
appendResult(QLatin1String("Cannot evaluate without a valid QML/JS Context"));
} }
void QmlJSScriptConsole::handleUpKey() void QmlJSScriptConsole::handleUpKey()

View File

@@ -72,7 +72,7 @@ signals:
private slots: private slots:
void setDebugLevel(); void setDebugLevel();
void engineStateChanged(Debugger::DebuggerState state); void onEngineStateChanged(Debugger::DebuggerState state);
private: private:
QmlJSScriptConsole *m_console; QmlJSScriptConsole *m_console;
@@ -110,7 +110,7 @@ public:
void setInferiorStopped(bool inferiorStopped); void setInferiorStopped(bool inferiorStopped);
void setEngine(QmlEngine *engine); void setEngine(QmlEngine *engine);
DebuggerEngine *engine(); DebuggerEngine *engine() const;
void appendResult(const QString &message, const QColor &color = QColor(Qt::darkGray)); void appendResult(const QString &message, const QColor &color = QColor(Qt::darkGray));