forked from qt-creator/qt-creator
QML JS Debugger: Ability to edit properties from the debugger
This commit is contained in:
@@ -517,7 +517,19 @@ void QmlEngine::setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEd
|
|||||||
void QmlEngine::assignValueInDebugger(const QString &expression,
|
void QmlEngine::assignValueInDebugger(const QString &expression,
|
||||||
const QString &value)
|
const QString &value)
|
||||||
{
|
{
|
||||||
XSDEBUG("ASSIGNING: " << expression + '=' + value);
|
QRegExp inObject("@([0-9a-fA-F]+)->(.+)");
|
||||||
|
if (inObject.exactMatch(expression)) {
|
||||||
|
bool ok = false;
|
||||||
|
quint64 objectId = inObject.cap(1).toULongLong(&ok, 16);
|
||||||
|
QString property = inObject.cap(2);
|
||||||
|
if (ok && objectId > 0 && !property.isEmpty()) {
|
||||||
|
QByteArray reply;
|
||||||
|
QDataStream rs(&reply, QIODevice::WriteOnly);
|
||||||
|
rs << QByteArray("SET_PROPERTY");
|
||||||
|
rs << expression.toUtf8() << objectId << property << value;
|
||||||
|
sendMessage(reply);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlEngine::updateWatchData(const WatchData &data)
|
void QmlEngine::updateWatchData(const WatchData &data)
|
||||||
|
@@ -121,6 +121,7 @@ static QList<JSAgentWatchData> expandObject(const QScriptValue &object)
|
|||||||
{
|
{
|
||||||
QList<JSAgentWatchData> result;
|
QList<JSAgentWatchData> result;
|
||||||
QScriptValueIterator it(object);
|
QScriptValueIterator it(object);
|
||||||
|
QByteArray expPrefix = '@' + QByteArray::number(object.objectId(), 16) + "->";
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
if (it.flags() & QScriptValue::SkipInEnumeration)
|
if (it.flags() & QScriptValue::SkipInEnumeration)
|
||||||
@@ -130,7 +131,9 @@ static QList<JSAgentWatchData> expandObject(const QScriptValue &object)
|
|||||||
// and it is not usefull in the debugger.
|
// and it is not usefull in the debugger.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result << JSAgentWatchData::fromScriptValue(it.name(), it.value());
|
JSAgentWatchData data = JSAgentWatchData::fromScriptValue(it.name(), it.value());
|
||||||
|
data.exp.prepend(expPrefix);
|
||||||
|
result << data;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -368,6 +371,31 @@ void JSDebuggerAgent::messageReceived(const QByteArray& message)
|
|||||||
QDataStream rs(&reply, QIODevice::WriteOnly);
|
QDataStream rs(&reply, QIODevice::WriteOnly);
|
||||||
rs << QByteArray("LOCALS") << frameId << locals;
|
rs << QByteArray("LOCALS") << frameId << locals;
|
||||||
sendMessage(reply);
|
sendMessage(reply);
|
||||||
|
|
||||||
|
} else if (command == "SET_PROPERTY") {
|
||||||
|
State oldState = state;
|
||||||
|
state = Stopped;
|
||||||
|
|
||||||
|
QByteArray id;
|
||||||
|
qint64 objectId;
|
||||||
|
QString property;
|
||||||
|
QString value;
|
||||||
|
ds >> id >> objectId >> property >> value;
|
||||||
|
|
||||||
|
if (knownObjectIds.contains(objectId)) {
|
||||||
|
QScriptValue object;
|
||||||
|
object = engine()->objectById(objectId);
|
||||||
|
|
||||||
|
if(object.isObject()) {
|
||||||
|
QScriptValue result = engine()->evaluate(value);
|
||||||
|
object.setProperty(property, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear any exceptions occurred during locals evaluation.
|
||||||
|
engine()->clearExceptions();
|
||||||
|
}
|
||||||
|
state = oldState;
|
||||||
|
//TODO: feedback
|
||||||
} else {
|
} else {
|
||||||
qDebug() << Q_FUNC_INFO << "Unknown command" << command;
|
qDebug() << Q_FUNC_INFO << "Unknown command" << command;
|
||||||
}
|
}
|
||||||
@@ -414,6 +442,7 @@ void JSDebuggerAgent::stopped()
|
|||||||
|
|
||||||
recordKnownObjects(watches);
|
recordKnownObjects(watches);
|
||||||
recordKnownObjects(locals);
|
recordKnownObjects(locals);
|
||||||
|
knownObjectIds << activationObject.objectId();
|
||||||
|
|
||||||
// Clear any exceptions occurred during locals evaluation.
|
// Clear any exceptions occurred during locals evaluation.
|
||||||
engine()->clearExceptions();
|
engine()->clearExceptions();
|
||||||
|
Reference in New Issue
Block a user