forked from qt-creator/qt-creator
Initial support of `Follow symbol under cursor' for QML/JS.
This commit is contained in:
@@ -910,10 +910,26 @@ TextEditor::BaseTextEditor::Link QmlJSTextEditor::findLinkAt(const QTextCursor &
|
||||
|
||||
AST::Node *node = semanticInfo.nodeUnderCursor(cursorPosition);
|
||||
|
||||
Interpreter::Engine interp;
|
||||
Interpreter::Context context(&interp);
|
||||
context.build(semanticInfo.declaringMember(cursorPosition), semanticInfo.document, semanticInfo.snapshot);
|
||||
|
||||
Check check(&context);
|
||||
const Interpreter::Value *value = check.reference(node);
|
||||
QString fileName;
|
||||
int line = 0, column = 0;
|
||||
|
||||
if (! (value && value->getSourceLocation(&fileName, &line, &column)))
|
||||
return Link();
|
||||
|
||||
Link link;
|
||||
link.fileName = fileName;
|
||||
link.line = line;
|
||||
link.column = column - 1; // adjust the column
|
||||
|
||||
if (AST::UiQualifiedId *q = AST::cast<AST::UiQualifiedId *>(node)) {
|
||||
for (AST::UiQualifiedId *tail = q; tail; tail = tail->next) {
|
||||
if (! tail->next && cursorPosition <= tail->identifierToken.end()) {
|
||||
Link link;
|
||||
link.begin = tail->identifierToken.begin();
|
||||
link.end = tail->identifierToken.end();
|
||||
return link;
|
||||
@@ -921,13 +937,11 @@ TextEditor::BaseTextEditor::Link QmlJSTextEditor::findLinkAt(const QTextCursor &
|
||||
}
|
||||
|
||||
} else if (AST::IdentifierExpression *id = AST::cast<AST::IdentifierExpression *>(node)) {
|
||||
Link link;
|
||||
link.begin = id->firstSourceLocation().begin();
|
||||
link.end = id->lastSourceLocation().end();
|
||||
return link;
|
||||
|
||||
} else if (AST::FieldMemberExpression *mem = AST::cast<AST::FieldMemberExpression *>(node)) {
|
||||
Link link;
|
||||
link.begin = mem->lastSourceLocation().begin();
|
||||
link.end = mem->lastSourceLocation().end();
|
||||
return link;
|
||||
@@ -936,6 +950,11 @@ TextEditor::BaseTextEditor::Link QmlJSTextEditor::findLinkAt(const QTextCursor &
|
||||
return Link();
|
||||
}
|
||||
|
||||
void QmlJSTextEditor::followSymbolUnderCursor()
|
||||
{
|
||||
openLink(findLinkAt(textCursor()));
|
||||
}
|
||||
|
||||
void QmlJSTextEditor::contextMenuEvent(QContextMenuEvent *e)
|
||||
{
|
||||
QMenu *menu = new QMenu();
|
||||
|
||||
@@ -135,6 +135,7 @@ public:
|
||||
int documentRevision() const;
|
||||
|
||||
public slots:
|
||||
void followSymbolUnderCursor();
|
||||
virtual void setFontSettings(const TextEditor::FontSettings &);
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -41,6 +41,8 @@ const char * const C_QMLJSEDITOR_ID = "QMLProjectManager.QMLJSEditor";
|
||||
const char * const C_QMLJSEDITOR_DISPLAY_NAME = QT_TRANSLATE_NOOP("OpenWith::Editors", "QMLJS Editor");
|
||||
const char * const TASK_INDEX = "QmlJSEditor.TaskIndex";
|
||||
|
||||
const char * const FOLLOW_SYMBOL_UNDER_CURSOR = "QmlJSEditor.FollowSymbolUnderCursor";
|
||||
|
||||
const char * const QML_MIMETYPE = "application/x-qml";
|
||||
const char * const JS_MIMETYPE = "application/javascript";
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <coreplugin/mimedatabase.h>
|
||||
#include <coreplugin/uniqueidmanager.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <texteditor/fontsettings.h>
|
||||
#include <texteditor/storagesettings.h>
|
||||
@@ -114,9 +115,19 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
|
||||
m_actionHandler->initializeActions();
|
||||
|
||||
Core::ActionManager *am = core->actionManager();
|
||||
Core::ActionContainer *contextMenu= am->createMenu(QmlJSEditor::Constants::M_CONTEXT);
|
||||
Core::Command *cmd = am->command(TextEditor::Constants::AUTO_INDENT_SELECTION);
|
||||
Core::ActionContainer *contextMenu = am->createMenu(QmlJSEditor::Constants::M_CONTEXT);
|
||||
|
||||
Core::Command *cmd = 0;
|
||||
|
||||
QAction *followSymbolUnderCursorAction = new QAction(tr("Follow Symbol Under Cursor"), this);
|
||||
cmd = am->registerAction(followSymbolUnderCursorAction, Constants::FOLLOW_SYMBOL_UNDER_CURSOR, context);
|
||||
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F2));
|
||||
connect(followSymbolUnderCursorAction, SIGNAL(triggered()), this, SLOT(followSymbolUnderCursor()));
|
||||
contextMenu->addAction(cmd);
|
||||
|
||||
cmd = am->command(TextEditor::Constants::AUTO_INDENT_SELECTION);
|
||||
contextMenu->addAction(cmd);
|
||||
|
||||
cmd = am->command(TextEditor::Constants::UN_COMMENT_SELECTION);
|
||||
contextMenu->addAction(cmd);
|
||||
|
||||
@@ -177,4 +188,12 @@ void QmlJSEditorPlugin::initializeEditor(QmlJSEditor::Internal::QmlJSTextEditor
|
||||
TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(TextEditor::ITextEditable*, bool)));
|
||||
}
|
||||
|
||||
void QmlJSEditorPlugin::followSymbolUnderCursor()
|
||||
{
|
||||
Core::EditorManager *em = Core::EditorManager::instance();
|
||||
|
||||
if (QmlJSTextEditor *editor = qobject_cast<QmlJSTextEditor*>(em->currentEditor()->widget()))
|
||||
editor->followSymbolUnderCursor();
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN(QmlJSEditorPlugin)
|
||||
|
||||
@@ -64,6 +64,9 @@ public:
|
||||
|
||||
void initializeEditor(QmlJSTextEditor *editor);
|
||||
|
||||
public Q_SLOTS:
|
||||
void followSymbolUnderCursor();
|
||||
|
||||
private:
|
||||
static QmlJSEditorPlugin *m_instance;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user