Commit 9a817591 authored by Lasse Holmstedt's avatar Lasse Holmstedt
Browse files

manually applied changes from qmlinspector to qmljsinspector

parent 0efb4d69
......@@ -845,6 +845,94 @@ void QmlJSTextEditor::updateUsesNow()
}
setExtraSelections(CodeSemanticsSelection, selections);
setSelectedElement();
}
class SelectedElement: protected Visitor
{
unsigned cursorPosition;
UiObjectMember *selectedMember;
public:
SelectedElement()
: cursorPosition(0), selectedMember(0) {}
UiObjectMember *operator()(Node *root, unsigned position)
{
cursorPosition = position;
selectedMember = 0;
Node::accept(root, this);
return selectedMember;
}
protected:
UiObjectInitializer *initializer(UiObjectMember *member) const
{
if (UiObjectDefinition *def = cast<UiObjectDefinition *>(member))
return def->initializer;
else if (UiObjectBinding *binding = cast<UiObjectBinding *>(member))
return binding->initializer;
return 0;
}
bool isIdBinding(UiObjectMember *member) const
{
if (UiScriptBinding *script = cast<UiScriptBinding *>(member)) {
if (! script->qualifiedId)
return false;
else if (! script->qualifiedId->name)
return false;
else if (script->qualifiedId->next)
return false;
const QString propertyName = script->qualifiedId->name->asString();
if (propertyName == QLatin1String("id"))
return true;
}
return false;
}
virtual void postVisit(Node *ast)
{
if (selectedMember)
return; // nothing to do, we already have the result.
if (UiObjectMember *member = ast->uiObjectMemberCast()) {
unsigned begin = member->firstSourceLocation().begin();
unsigned end = member->lastSourceLocation().end();
if (cursorPosition >= begin && cursorPosition <= end) {
if (UiObjectInitializer *init = initializer(member)) {
for (UiObjectMemberList *it = init->members; it; it = it->next) {
if (isIdBinding(it->member)) {
selectedMember = member;
break;
}
}
}
}
}
}
};
void QmlJSTextEditor::setSelectedElement()
{
QTextCursor tc = textCursor();
tc.movePosition(QTextCursor::StartOfWord);
tc.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
QString wordAtCursor = tc.selectedText();
int offset = -1;
if (Document::Ptr doc = m_semanticInfo.document) {
SelectedElement selectedMember;
if (UiObjectMember *m = selectedMember(doc->qmlProgram(), textCursor().position())) {
offset = m->firstSourceLocation().begin();
}
}
emit selectedElementChanged(offset, wordAtCursor);
}
void QmlJSTextEditor::updateMethodBoxToolTip()
......
......@@ -30,6 +30,8 @@
#ifndef QMLJSEDITOR_H
#define QMLJSEDITOR_H
#include "qmljseditor_global.h"
#include <qmljs/qmljsdocument.h>
#include <qmljs/qmljsscanner.h>
#include <texteditor/basetexteditor.h>
......@@ -199,7 +201,7 @@ private:
QmlJS::ModelManagerInterface *m_modelManager;
};
class QmlJSTextEditor : public TextEditor::BaseTextEditor
class QMLJSEDITOR_EXPORT QmlJSTextEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
......@@ -213,6 +215,9 @@ public:
int documentRevision() const;
bool isOutdated() const;
signals:
void selectedElementChanged(int offset, const QString &wordAtCursor);
public slots:
void followSymbolUnderCursor();
virtual void setFontSettings(const TextEditor::FontSettings &);
......@@ -256,6 +261,7 @@ private:
virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar);
bool isClosingBrace(const QList<QmlJS::Token> &tokens) const;
void setSelectedElement();
QString wordUnderCursor() const;
SemanticHighlighter::Source currentSource(bool force = false);
......
#include "qmlinspectortoolbar.h"
#include "qmljsinspectorconstants.h"
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/icore.h>
#include <debugger/debuggeruiswitcher.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <QHBoxLayout>
#include <QAction>
#include <QToolButton>
namespace QmlJSInspector {
namespace Internal {
static QToolButton *createToolButton(QAction *action)
{
QToolButton *button = new QToolButton;
button->setDefaultAction(action);
return button;
}
QmlInspectorToolbar::QmlInspectorToolbar(QObject *parent) :
QObject(parent),
m_reloadAction(0),
m_playAction(0),
m_pauseAction(0),
m_selectAction(0),
m_selectMarqueeAction(0),
m_zoomAction(0),
m_colorPickerAction(0),
m_toQmlAction(0),
m_fromQmlAction(0),
m_emitSignals(true),
m_isRunning(false),
m_activeTool(NoTool)
{
}
void QmlInspectorToolbar::setEnabled(bool value)
{
m_reloadAction->setEnabled(value);
m_playAction->setEnabled(value);
m_pauseAction->setEnabled(value);
m_selectAction->setEnabled(value);
m_selectMarqueeAction->setEnabled(value);
m_zoomAction->setEnabled(value);
m_colorPickerAction->setEnabled(value);
m_toQmlAction->setEnabled(value);
m_fromQmlAction->setEnabled(value);
}
void QmlInspectorToolbar::enable()
{
setEnabled(true);
}
void QmlInspectorToolbar::disable()
{
changeAnimationSpeed(1.0f);
activateSelectTool();
setEnabled(false);
}
void QmlInspectorToolbar::activateColorPicker()
{
m_emitSignals = false;
activateColorPickerOnClick();
m_emitSignals = true;
}
void QmlInspectorToolbar::activateSelectTool()
{
m_emitSignals = false;
activateSelectToolOnClick();
m_emitSignals = true;
}
void QmlInspectorToolbar::activateMarqueeSelectTool()
{
m_emitSignals = false;
activateMarqueeSelectToolOnClick();
m_emitSignals = true;
}
void QmlInspectorToolbar::activateZoomTool()
{
m_emitSignals = false;
activateZoomOnClick();
m_emitSignals = true;
}
void QmlInspectorToolbar::changeAnimationSpeed(qreal slowdownFactor)
{
m_emitSignals = false;
if (slowdownFactor == 0) {
activatePauseOnClick();
} else {
activatePlayOnClick();
}
m_emitSignals = true;
}
void QmlInspectorToolbar::createActions(const Core::Context &context)
{
Core::ICore *core = Core::ICore::instance();
Core::ActionManager *am = core->actionManager();
ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance();
Debugger::DebuggerUISwitcher *uiSwitcher = pluginManager->getObject<Debugger::DebuggerUISwitcher>();
m_reloadAction = new QAction(QIcon(":/qml/images/reload.png"), "Reload", this);
m_reloadAction->setDisabled(true);
m_playAction = new QAction(QIcon(":/qml/images/play.png"), tr("Play animations"), this);
m_pauseAction = new QAction(QIcon(":/qml/images/pause.png"), tr("Pause animations"), this);
m_selectAction = new QAction(QIcon(":/qml/images/select.png"), tr("Select"), this);
m_selectMarqueeAction = new QAction(QIcon(":/qml/images/select-marquee.png"), tr("Select (Marquee)"), this);
m_zoomAction = new QAction(QIcon(":/qml/images/zoom.png"), tr("Zoom"), this);
m_colorPickerAction = new QAction(QIcon(":/qml/images/color-picker.png"), tr("Color Picker"), this);
m_toQmlAction = new QAction(QIcon(":/qml/images/to-qml.png"), tr("Apply Changes to QML Viewer"), this);
m_fromQmlAction = new QAction(QIcon(":/qml/images/from-qml.png"), tr("Apply Changes to Document"), this);
m_playAction->setCheckable(true);
m_playAction->setChecked(true);
m_pauseAction->setCheckable(true);
m_selectAction->setCheckable(true);
m_selectMarqueeAction->setCheckable(true);
m_zoomAction->setCheckable(true);
m_colorPickerAction->setCheckable(true);
am->registerAction(m_reloadAction, QmlJSInspector::Constants::RELOAD_ACTION, context);
am->registerAction(m_playAction, QmlJSInspector::Constants::PLAY_ACTION, context);
am->registerAction(m_pauseAction, QmlJSInspector::Constants::PAUSE_ACTION, context);
am->registerAction(m_selectAction, QmlJSInspector::Constants::SELECT_ACTION, context);
am->registerAction(m_selectMarqueeAction, QmlJSInspector::Constants::SELECT_MARQUEE_ACTION, context);
am->registerAction(m_zoomAction, QmlJSInspector::Constants::ZOOM_ACTION, context);
am->registerAction(m_colorPickerAction, QmlJSInspector::Constants::COLOR_PICKER_ACTION, context);
am->registerAction(m_toQmlAction, QmlJSInspector::Constants::TO_QML_ACTION, context);
am->registerAction(m_fromQmlAction, QmlJSInspector::Constants::FROM_QML_ACTION, context);
QWidget *configBar = new QWidget;
configBar->setProperty("topBorder", true);
QHBoxLayout *configBarLayout = new QHBoxLayout(configBar);
configBarLayout->setMargin(0);
configBarLayout->setSpacing(5);
configBarLayout->addWidget(createToolButton(am->command(ProjectExplorer::Constants::DEBUG)->action()));
configBarLayout->addWidget(createToolButton(am->command(ProjectExplorer::Constants::STOP)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::RELOAD_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::PLAY_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::PAUSE_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::SELECT_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::SELECT_MARQUEE_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::ZOOM_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::COLOR_PICKER_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::TO_QML_ACTION)->action()));
configBarLayout->addWidget(createToolButton(am->command(QmlJSInspector::Constants::FROM_QML_ACTION)->action()));
configBarLayout->addStretch();
uiSwitcher->setToolbar(QmlJSInspector::Constants::LANG_QML, configBar);
setEnabled(false);
connect(m_colorPickerAction, SIGNAL(triggered()), SLOT(activateColorPickerOnClick()));
connect(m_playAction, SIGNAL(triggered()), SLOT(activatePlayOnClick()));
connect(m_pauseAction, SIGNAL(triggered()), SLOT(activatePauseOnClick()));
connect(m_zoomAction, SIGNAL(triggered()), SLOT(activateZoomOnClick()));
connect(m_colorPickerAction, SIGNAL(triggered()), SLOT(activateColorPickerOnClick()));
connect(m_selectAction, SIGNAL(triggered()), SLOT(activateSelectToolOnClick()));
connect(m_selectMarqueeAction, SIGNAL(triggered()), SLOT(activateMarqueeSelectToolOnClick()));
connect(m_toQmlAction, SIGNAL(triggered()), SLOT(activateToQml()));
connect(m_fromQmlAction, SIGNAL(triggered()), SLOT(activateFromQml()));
}
void QmlInspectorToolbar::activatePlayOnClick()
{
m_pauseAction->setChecked(false);
if (!m_isRunning) {
m_playAction->setChecked(true);
m_isRunning = true;
if (m_emitSignals)
emit animationSpeedChanged(1.0f);
}
}
void QmlInspectorToolbar::activatePauseOnClick()
{
m_playAction->setChecked(false);
if (m_isRunning) {
m_isRunning = false;
m_pauseAction->setChecked(true);
if (m_emitSignals)
emit animationSpeedChanged(0.0f);
}
}
void QmlInspectorToolbar::activateColorPickerOnClick()
{
m_zoomAction->setChecked(false);
m_selectAction->setChecked(false);
m_selectMarqueeAction->setChecked(false);
m_colorPickerAction->setChecked(true);
if (m_activeTool != ColorPickerMode) {
m_activeTool = ColorPickerMode;
if (m_emitSignals)
emit colorPickerSelected();
}
}
void QmlInspectorToolbar::activateSelectToolOnClick()
{
m_zoomAction->setChecked(false);
m_selectMarqueeAction->setChecked(false);
m_colorPickerAction->setChecked(false);
m_selectAction->setChecked(true);
if (m_activeTool != SelectionToolMode) {
m_activeTool = SelectionToolMode;
if (m_emitSignals)
emit selectToolSelected();
}
}
void QmlInspectorToolbar::activateMarqueeSelectToolOnClick()
{
m_zoomAction->setChecked(false);
m_selectAction->setChecked(false);
m_colorPickerAction->setChecked(false);
m_selectMarqueeAction->setChecked(true);
if (m_activeTool != MarqueeSelectionToolMode) {
m_activeTool = MarqueeSelectionToolMode;
if (m_emitSignals)
emit marqueeSelectToolSelected();
}
}
void QmlInspectorToolbar::activateZoomOnClick()
{
m_selectAction->setChecked(false);
m_selectMarqueeAction->setChecked(false);
m_colorPickerAction->setChecked(false);
m_zoomAction->setChecked(true);
if (m_activeTool != ZoomMode) {
m_activeTool = ZoomMode;
if (m_emitSignals)
emit zoomToolSelected();
}
}
void QmlInspectorToolbar::activateFromQml()
{
if (m_emitSignals)
emit applyChangesFromQmlFileSelected();
}
void QmlInspectorToolbar::activateToQml()
{
if (m_emitSignals)
emit applyChangesToQmlFileSelected();
}
} // namespace Internal
} // namespace QmlJSInspector
#ifndef QMLINSPECTORTOOLBAR_H
#define QMLINSPECTORTOOLBAR_H
#include <QObject>
QT_FORWARD_DECLARE_CLASS(QAction);
namespace Core {
class Context;
}
namespace QmlJSInspector {
namespace Internal {
class QmlInspectorToolbar : public QObject
{
Q_OBJECT
public:
enum DesignTool {
NoTool = 0,
SelectionToolMode = 1,
MarqueeSelectionToolMode = 2,
MoveToolMode = 3,
ResizeToolMode = 4,
ColorPickerMode = 5,
ZoomMode = 6
};
explicit QmlInspectorToolbar(QObject *parent = 0);
void createActions(const Core::Context &context);
public slots:
void setEnabled(bool value);
void enable();
void disable();
void activateColorPicker();
void activateSelectTool();
void activateMarqueeSelectTool();
void activateZoomTool();
void changeAnimationSpeed(qreal slowdownFactor);
signals:
void animationSpeedChanged(qreal slowdownFactor = 1.0f);
void colorPickerSelected();
void selectToolSelected();
void marqueeSelectToolSelected();
void zoomToolSelected();
void applyChangesToQmlFileSelected();
void applyChangesFromQmlFileSelected();
private slots:
void activatePlayOnClick();
void activatePauseOnClick();
void activateColorPickerOnClick();
void activateSelectToolOnClick();
void activateMarqueeSelectToolOnClick();
void activateZoomOnClick();
void activateFromQml();
void activateToQml();
private:
QAction *m_reloadAction;
QAction *m_playAction;
QAction *m_pauseAction;
QAction *m_selectAction;
QAction *m_selectMarqueeAction;
QAction *m_zoomAction;
QAction *m_colorPickerAction;
QAction *m_toQmlAction;
QAction *m_fromQmlAction;
bool m_emitSignals;
bool m_isRunning;
DesignTool m_activeTool;
};
} // namespace Internal
} // namespace QmlJSInspector
#endif // QMLINSPECTORTOOLBAR_H
......@@ -29,6 +29,7 @@
#include "qmljsclientproxy.h"
#include "qmljsdebuggerclient.h"
#include "qmljsprivateapi.h"
#include "qmljsdesigndebugclient.h"
#include <utils/qtcassert.h>
......@@ -44,6 +45,7 @@ ClientProxy::ClientProxy(QObject *parent) :
QObject(parent),
m_conn(0),
m_client(0),
m_designClient(0),
m_engineQuery(0),
m_contextQuery(0),
m_objectTreeQuery(0)
......@@ -63,17 +65,29 @@ bool ClientProxy::connectToViewer(const QString &host, quint16 port)
return false;
qDebug() << Q_FUNC_INFO;
if (m_client) {
#warning disconnect selectedItemsChanged here
#if 0
disconnect(m_client, SIGNAL(selectedItemsChanged(QList<QDeclarativeDebugObjectReference>)),
this, SIGNAL(selectedItemsChanged(QList<QDeclarativeDebugObjectReference>)));
#endif
if (m_designClient) {
disconnect(m_designClient, SIGNAL(currentObjectsChanged(QList<QDeclarativeDebugObjectReference>)),
this, SIGNAL(selectedItemsChanged(QList<QDeclarativeDebugObjectReference>)));
disconnect(m_designClient,
SIGNAL(colorPickerActivated()), this, SIGNAL(colorPickerActivated()));
disconnect(m_designClient,
SIGNAL(zoomToolActivated()), this, SIGNAL(zoomToolActivated()));
disconnect(m_designClient,
SIGNAL(selectToolActivated()), this, SIGNAL(selectToolActivated()));
disconnect(m_designClient,
SIGNAL(selectMarqueeToolActivated()), this, SIGNAL(selectMarqueeToolActivated()));
disconnect(m_designClient,
SIGNAL(animationSpeedChanged(qreal)), this, SIGNAL(animationSpeedChanged(qreal)));
emit aboutToDisconnect();
delete m_client;
m_client = 0;
delete m_designClient;
m_designClient = 0;
}
if (m_conn) {
......@@ -145,14 +159,23 @@ void ClientProxy::connectionStateChanged()
if (!m_client) {
qDebug() << "CREATING ENGINE";
m_client = new QDeclarativeEngineDebug(m_conn, this);
m_designClient = new QmlJSDesignDebugClient(m_conn, this);
emit connected(m_client);
#warning add support for selectedItemsChanged here
#if 0
connect(m_client,
SIGNAL(selectedItemsChanged(QList<QDeclarativeDebugObjectReference>)),
connect(m_designClient,
SIGNAL(currentObjectsChanged(QList<QDeclarativeDebugObjectReference>)),
SIGNAL(selectedItemsChanged(QList<QDeclarativeDebugObjectReference>)));
#endif
connect(m_designClient,
SIGNAL(colorPickerActivated()), SIGNAL(colorPickerActivated()));
connect(m_designClient,
SIGNAL(zoomToolActivated()), SIGNAL(zoomToolActivated()));
connect(m_designClient,
SIGNAL(selectToolActivated()), SIGNAL(selectToolActivated()));
connect(m_designClient,
SIGNAL(selectMarqueeToolActivated()), SIGNAL(selectMarqueeToolActivated()));
connect(m_designClient,
SIGNAL(animationSpeedChanged(qreal)), SIGNAL(animationSpeedChanged(qreal)));
}
(void) new DebuggerClient(m_conn);
......@@ -180,19 +203,30 @@ bool ClientProxy::isUnconnected() const
return (!m_conn || m_conn->state() == QAbstractSocket::UnconnectedState);
}