2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-01-15 17:20:03 +01:00
|
|
|
#include "qmljseditor.h"
|
2014-01-23 14:00:21 +01:00
|
|
|
|
2014-08-19 12:12:45 +02:00
|
|
|
#include "qmljsautocompleter.h"
|
2014-08-20 01:47:42 +02:00
|
|
|
#include "qmljscompletionassist.h"
|
2010-01-15 17:20:03 +01:00
|
|
|
#include "qmljseditorconstants.h"
|
2014-01-23 14:00:21 +01:00
|
|
|
#include "qmljseditordocument.h"
|
2010-01-15 17:20:03 +01:00
|
|
|
#include "qmljseditorplugin.h"
|
2010-09-24 14:05:34 +02:00
|
|
|
#include "qmljsfindreferences.h"
|
2011-04-15 16:19:23 +02:00
|
|
|
#include "qmljsquickfixassist.h"
|
2014-08-20 01:47:42 +02:00
|
|
|
#include "qmloutlinemodel.h"
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-07-16 11:16:22 +02:00
|
|
|
#include <qmljs/qmljsbind.h>
|
2010-11-16 14:39:54 +01:00
|
|
|
#include <qmljs/qmljsevaluate.h>
|
2010-07-07 13:09:30 +02:00
|
|
|
#include <qmljs/qmljsicontextpane.h>
|
2010-11-11 10:05:05 +01:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
2011-10-07 14:04:06 +02:00
|
|
|
#include <qmljs/qmljsutils.h>
|
2009-09-11 14:42:50 +02:00
|
|
|
|
2013-12-11 10:49:32 +01:00
|
|
|
#include <qmljstools/qmljstoolsconstants.h>
|
2014-08-20 01:47:42 +02:00
|
|
|
#include <qmldesigner/qmldesignerconstants.h>
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2010-11-11 10:05:05 +01:00
|
|
|
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2014-08-20 01:47:42 +02:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2014-08-20 01:47:42 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/designmode.h>
|
2010-07-14 12:21:23 +02:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2010-01-15 17:41:12 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2014-08-20 01:47:42 +02:00
|
|
|
#include <coreplugin/id.h>
|
2010-01-15 17:41:12 +01:00
|
|
|
#include <coreplugin/mimedatabase.h>
|
2014-08-20 01:47:42 +02:00
|
|
|
#include <coreplugin/modemanager.h>
|
|
|
|
|
|
2009-09-04 16:51:11 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2014-08-20 01:47:42 +02:00
|
|
|
|
2009-04-22 15:21:04 +02:00
|
|
|
#include <texteditor/basetextdocument.h>
|
|
|
|
|
#include <texteditor/fontsettings.h>
|
2010-10-29 15:20:10 +02:00
|
|
|
#include <texteditor/tabsettings.h>
|
2009-04-22 15:21:04 +02:00
|
|
|
#include <texteditor/texteditorconstants.h>
|
2010-07-09 14:47:18 +02:00
|
|
|
#include <texteditor/syntaxhighlighter.h>
|
2010-08-05 10:44:50 +02:00
|
|
|
#include <texteditor/refactoroverlay.h>
|
2011-04-15 16:19:23 +02:00
|
|
|
#include <texteditor/codeassist/genericproposal.h>
|
|
|
|
|
#include <texteditor/codeassist/basicproposalitemlistmodel.h>
|
2014-08-20 01:47:42 +02:00
|
|
|
#include <texteditor/texteditoractionhandler.h>
|
|
|
|
|
|
2009-12-02 17:59:27 +01:00
|
|
|
#include <utils/changeset.h>
|
2009-05-14 16:37:17 +02:00
|
|
|
#include <utils/uncommentselection.h>
|
2011-08-09 12:18:56 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2012-06-04 12:52:49 +02:00
|
|
|
#include <utils/annotateditemdelegate.h>
|
2009-05-14 16:37:17 +02:00
|
|
|
|
2014-08-20 01:47:42 +02:00
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QCoreApplication>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
2014-08-20 01:47:42 +02:00
|
|
|
#include <QHeaderView>
|
|
|
|
|
#include <QMenu>
|
2013-02-18 15:12:09 +01:00
|
|
|
#include <QPointer>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QScopedPointer>
|
2014-08-20 01:47:42 +02:00
|
|
|
#include <QSignalMapper>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTextCodec>
|
2014-08-20 01:47:42 +02:00
|
|
|
#include <QTimer>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTreeView>
|
2009-04-22 15:21:04 +02:00
|
|
|
|
|
|
|
|
enum {
|
2010-07-12 17:03:49 +02:00
|
|
|
UPDATE_USES_DEFAULT_INTERVAL = 150,
|
2010-12-16 12:05:48 +01:00
|
|
|
UPDATE_OUTLINE_INTERVAL = 500 // msecs after new semantic info has been arrived / cursor has moved
|
2009-04-22 15:21:04 +02:00
|
|
|
};
|
|
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
using namespace Core;
|
2009-06-11 11:22:26 +02:00
|
|
|
using namespace QmlJS;
|
|
|
|
|
using namespace QmlJS::AST;
|
2012-04-12 15:51:56 +02:00
|
|
|
using namespace QmlJSTools;
|
2014-08-20 01:47:42 +02:00
|
|
|
using namespace TextEditor;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2013-06-03 19:31:32 +02:00
|
|
|
namespace QmlJSEditor {
|
2014-02-07 14:21:58 +01:00
|
|
|
namespace Internal {
|
2013-06-03 19:31:32 +02:00
|
|
|
|
2014-08-20 01:47:42 +02:00
|
|
|
//
|
|
|
|
|
// QmlJSEditorWidget
|
|
|
|
|
//
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
QmlJSEditorWidget::QmlJSEditorWidget(BaseTextDocumentPtr doc)
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2014-08-18 17:49:04 +02:00
|
|
|
setTextDocument(doc);
|
2014-08-19 12:12:45 +02:00
|
|
|
setAutoCompleter(new AutoCompleter);
|
2014-01-09 18:04:45 +01:00
|
|
|
|
2014-08-18 17:49:04 +02:00
|
|
|
m_qmlJsEditorDocument = static_cast<QmlJSEditorDocument *>(doc.data());
|
2014-01-09 18:04:45 +01:00
|
|
|
m_outlineCombo = 0;
|
|
|
|
|
m_contextPane = 0;
|
|
|
|
|
m_findReferences = new FindReferences(this);
|
|
|
|
|
|
2009-09-16 13:56:06 +02:00
|
|
|
setParenthesesMatchingEnabled(true);
|
|
|
|
|
setMarksVisible(true);
|
|
|
|
|
setCodeFoldingSupported(true);
|
2013-12-11 10:49:32 +01:00
|
|
|
setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-01-14 16:30:48 +01:00
|
|
|
m_updateUsesTimer = new QTimer(this);
|
|
|
|
|
m_updateUsesTimer->setInterval(UPDATE_USES_DEFAULT_INTERVAL);
|
|
|
|
|
m_updateUsesTimer->setSingleShot(true);
|
2014-01-29 13:53:08 +01:00
|
|
|
connect(m_updateUsesTimer, SIGNAL(timeout()), this, SLOT(updateUses()));
|
|
|
|
|
connect(this, SIGNAL(cursorPositionChanged()), m_updateUsesTimer, SLOT(start()));
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-07-13 11:24:16 +02:00
|
|
|
m_updateOutlineIndexTimer = new QTimer(this);
|
|
|
|
|
m_updateOutlineIndexTimer->setInterval(UPDATE_OUTLINE_INTERVAL);
|
|
|
|
|
m_updateOutlineIndexTimer->setSingleShot(true);
|
|
|
|
|
connect(m_updateOutlineIndexTimer, SIGNAL(timeout()), this, SLOT(updateOutlineIndexNow()));
|
2010-07-12 17:03:49 +02:00
|
|
|
|
2014-08-01 23:31:56 +02:00
|
|
|
textDocument()->setCodec(QTextCodec::codecForName("UTF-8")); // qml files are defined to be utf-8
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2012-05-04 10:56:54 +02:00
|
|
|
m_modelManager = QmlJS::ModelManagerInterface::instance();
|
2012-06-18 11:34:15 +02:00
|
|
|
m_contextPane = ExtensionSystem::PluginManager::getObject<QmlJS::IContextPane>();
|
2010-08-13 13:59:41 +02:00
|
|
|
|
2014-04-29 16:39:16 +02:00
|
|
|
m_modelManager->activateScan();
|
|
|
|
|
|
2014-01-30 15:48:24 +01:00
|
|
|
m_contextPaneTimer = new QTimer(this);
|
|
|
|
|
m_contextPaneTimer->setInterval(UPDATE_OUTLINE_INTERVAL);
|
|
|
|
|
m_contextPaneTimer->setSingleShot(true);
|
|
|
|
|
connect(m_contextPaneTimer, SIGNAL(timeout()), this, SLOT(updateContextPane()));
|
2010-08-13 13:59:41 +02:00
|
|
|
if (m_contextPane) {
|
2014-01-30 15:48:24 +01:00
|
|
|
connect(this, SIGNAL(cursorPositionChanged()), m_contextPaneTimer, SLOT(start()));
|
2010-08-13 13:59:41 +02:00
|
|
|
connect(m_contextPane, SIGNAL(closed()), this, SLOT(showTextMarker()));
|
|
|
|
|
}
|
2010-07-13 11:25:45 +02:00
|
|
|
m_oldCursorPosition = -1;
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2014-01-24 16:53:16 +01:00
|
|
|
connect(this->document(), SIGNAL(modificationChanged(bool)), this, SLOT(modificationChanged(bool)));
|
2010-02-16 10:36:09 +01:00
|
|
|
|
2014-01-30 17:18:35 +01:00
|
|
|
connect(m_qmlJsEditorDocument, SIGNAL(updateCodeWarnings(QmlJS::Document::Ptr)),
|
|
|
|
|
this, SLOT(updateCodeWarnings(QmlJS::Document::Ptr)));
|
2014-01-24 16:53:16 +01:00
|
|
|
connect(m_qmlJsEditorDocument, SIGNAL(semanticInfoUpdated(QmlJSTools::SemanticInfo)),
|
|
|
|
|
this, SLOT(semanticInfoUpdated(QmlJSTools::SemanticInfo)));
|
2010-03-17 18:41:14 +01:00
|
|
|
|
2010-07-07 13:56:39 +02:00
|
|
|
setRequestMarkEnabled(true);
|
2014-08-19 00:54:45 +02:00
|
|
|
createToolBar();
|
2009-04-22 15:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
QmlJSEditorWidget::~QmlJSEditorWidget()
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
QModelIndex QmlJSEditorWidget::outlineModelIndex()
|
2010-07-12 14:45:22 +02:00
|
|
|
{
|
2010-07-12 16:40:15 +02:00
|
|
|
if (!m_outlineModelIndex.isValid()) {
|
|
|
|
|
m_outlineModelIndex = indexForPosition(position());
|
|
|
|
|
emit outlineModelIndexChanged(m_outlineModelIndex);
|
|
|
|
|
}
|
2010-07-12 14:45:22 +02:00
|
|
|
return m_outlineModelIndex;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-07 14:41:57 +01:00
|
|
|
IEditor *QmlJSEditor::duplicate()
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2014-08-21 09:56:08 +02:00
|
|
|
auto editor = new QmlJSEditor;
|
2014-08-25 20:01:46 +02:00
|
|
|
auto widget = new QmlJSEditorWidget(editorWidget()->textDocumentPtr());
|
2014-08-21 09:56:08 +02:00
|
|
|
editor->setEditorWidget(widget);
|
|
|
|
|
editor->configureCodeAssistant();
|
|
|
|
|
return editor;
|
2009-04-22 15:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
2013-06-03 19:31:32 +02:00
|
|
|
bool QmlJSEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
2010-01-15 17:41:12 +01:00
|
|
|
{
|
2014-08-20 01:47:42 +02:00
|
|
|
bool b = BaseTextEditor::open(errorString, fileName, realFileName);
|
2014-08-01 23:31:56 +02:00
|
|
|
textDocument()->setMimeType(MimeDatabase::findByFile(QFileInfo(fileName)).type());
|
2010-01-15 17:41:12 +01:00
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-23 16:11:58 +01:00
|
|
|
static void appendExtraSelectionsForMessages(
|
|
|
|
|
QList<QTextEdit::ExtraSelection> *selections,
|
|
|
|
|
const QList<DiagnosticMessage> &messages,
|
|
|
|
|
const QTextDocument *document)
|
|
|
|
|
{
|
|
|
|
|
foreach (const DiagnosticMessage &d, messages) {
|
|
|
|
|
const int line = d.loc.startLine;
|
|
|
|
|
const int column = qMax(1U, d.loc.startColumn);
|
|
|
|
|
|
|
|
|
|
QTextEdit::ExtraSelection sel;
|
|
|
|
|
QTextCursor c(document->findBlockByNumber(line - 1));
|
|
|
|
|
sel.cursor = c;
|
|
|
|
|
|
|
|
|
|
sel.cursor.setPosition(c.position() + column - 1);
|
|
|
|
|
|
|
|
|
|
if (d.loc.length == 0) {
|
|
|
|
|
if (sel.cursor.atBlockEnd())
|
|
|
|
|
sel.cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
|
|
|
|
|
else
|
|
|
|
|
sel.cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
|
|
|
|
} else {
|
|
|
|
|
sel.cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, d.loc.length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d.isWarning())
|
|
|
|
|
sel.format.setUnderlineColor(Qt::darkYellow);
|
|
|
|
|
else
|
|
|
|
|
sel.format.setUnderlineColor(Qt::red);
|
|
|
|
|
|
|
|
|
|
sel.format.setUnderlineStyle(QTextCharFormat::WaveUnderline);
|
|
|
|
|
sel.format.setToolTip(d.message);
|
|
|
|
|
|
|
|
|
|
selections->append(sel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::updateCodeWarnings(QmlJS::Document::Ptr doc)
|
2009-09-04 16:51:11 +02:00
|
|
|
{
|
2010-01-26 12:09:07 +01:00
|
|
|
if (doc->ast()) {
|
2013-02-07 00:10:05 +01:00
|
|
|
setExtraSelections(CodeWarningsSelection, QList<QTextEdit::ExtraSelection>());
|
2014-07-22 19:06:44 +02:00
|
|
|
} else if (doc->language().isFullySupportedLanguage()) {
|
2010-03-31 14:55:05 +02:00
|
|
|
// show parsing errors
|
2010-02-23 16:11:58 +01:00
|
|
|
QList<QTextEdit::ExtraSelection> selections;
|
|
|
|
|
appendExtraSelectionsForMessages(&selections, doc->diagnosticMessages(), document());
|
|
|
|
|
setExtraSelections(CodeWarningsSelection, selections);
|
2013-03-05 14:35:15 +01:00
|
|
|
} else {
|
|
|
|
|
setExtraSelections(CodeWarningsSelection, QList<QTextEdit::ExtraSelection>());
|
2009-09-04 16:51:11 +02:00
|
|
|
}
|
2009-04-22 15:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::modificationChanged(bool changed)
|
2010-04-16 12:42:12 +02:00
|
|
|
{
|
|
|
|
|
if (!changed && m_modelManager)
|
2014-08-01 23:31:56 +02:00
|
|
|
m_modelManager->fileChangedOnDisk(textDocument()->filePath());
|
2010-04-16 12:42:12 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::jumpToOutlineElement(int /*index*/)
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2010-07-13 11:24:16 +02:00
|
|
|
QModelIndex index = m_outlineCombo->view()->currentIndex();
|
2014-01-30 17:18:35 +01:00
|
|
|
AST::SourceLocation location = m_qmlJsEditorDocument->outlineModel()->sourceLocation(index);
|
2010-08-25 13:21:38 +02:00
|
|
|
|
|
|
|
|
if (!location.isValid())
|
|
|
|
|
return;
|
2010-07-12 14:45:22 +02:00
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
EditorManager::cutForwardNavigationHistory();
|
|
|
|
|
EditorManager::addCurrentPositionToNavigationHistory();
|
2010-07-14 12:21:23 +02:00
|
|
|
|
2010-07-12 14:45:22 +02:00
|
|
|
QTextCursor cursor = textCursor();
|
|
|
|
|
cursor.setPosition(location.offset);
|
|
|
|
|
setTextCursor(cursor);
|
|
|
|
|
|
|
|
|
|
setFocus();
|
2009-04-22 15:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::updateOutlineIndexNow()
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2014-01-30 17:18:35 +01:00
|
|
|
if (!m_qmlJsEditorDocument->outlineModel()->document())
|
2010-07-12 17:03:49 +02:00
|
|
|
return;
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2014-02-07 13:45:51 +01:00
|
|
|
if (m_qmlJsEditorDocument->outlineModel()->document()->editorRevision() != document()->revision()) {
|
2010-07-13 11:24:16 +02:00
|
|
|
m_updateOutlineIndexTimer->start();
|
2010-07-12 17:03:49 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-07-12 16:40:15 +02:00
|
|
|
m_outlineModelIndex = QModelIndex(); // invalidate
|
|
|
|
|
QModelIndex comboIndex = outlineModelIndex();
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-07-12 14:45:22 +02:00
|
|
|
if (comboIndex.isValid()) {
|
2010-07-13 11:24:16 +02:00
|
|
|
bool blocked = m_outlineCombo->blockSignals(true);
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-07-12 14:45:22 +02:00
|
|
|
// There is no direct way to select a non-root item
|
2010-07-13 11:24:16 +02:00
|
|
|
m_outlineCombo->setRootModelIndex(comboIndex.parent());
|
|
|
|
|
m_outlineCombo->setCurrentIndex(comboIndex.row());
|
|
|
|
|
m_outlineCombo->setRootModelIndex(QModelIndex());
|
2010-07-12 14:45:22 +02:00
|
|
|
|
2010-07-13 11:24:16 +02:00
|
|
|
m_outlineCombo->blockSignals(blocked);
|
2009-09-16 13:56:06 +02:00
|
|
|
}
|
2010-01-14 16:30:48 +01:00
|
|
|
}
|
2014-02-07 14:21:58 +01:00
|
|
|
} // namespace Internal
|
2013-06-03 19:31:32 +02:00
|
|
|
} // namespace QmlJSEditor
|
|
|
|
|
|
2011-08-12 09:25:01 +02:00
|
|
|
class QtQuickToolbarMarker {};
|
|
|
|
|
Q_DECLARE_METATYPE(QtQuickToolbarMarker)
|
|
|
|
|
|
2013-06-03 19:31:32 +02:00
|
|
|
namespace QmlJSEditor {
|
2014-02-07 14:21:58 +01:00
|
|
|
namespace Internal {
|
2013-06-03 19:31:32 +02:00
|
|
|
|
2011-08-12 09:25:01 +02:00
|
|
|
template <class T>
|
2014-08-20 01:47:42 +02:00
|
|
|
static QList<RefactorMarker> removeMarkersOfType(const QList<RefactorMarker> &markers)
|
2011-08-12 09:25:01 +02:00
|
|
|
{
|
2014-08-20 01:47:42 +02:00
|
|
|
QList<RefactorMarker> result;
|
|
|
|
|
foreach (const RefactorMarker &marker, markers) {
|
2011-08-12 09:25:01 +02:00
|
|
|
if (!marker.data.canConvert<T>())
|
|
|
|
|
result += marker;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::updateContextPane()
|
2010-08-05 10:44:50 +02:00
|
|
|
{
|
2014-01-24 16:53:16 +01:00
|
|
|
const SemanticInfo info = m_qmlJsEditorDocument->semanticInfo();
|
|
|
|
|
if (m_contextPane && document() && info.isValid()
|
|
|
|
|
&& document()->revision() == info.document->editorRevision())
|
2010-08-27 10:37:15 +02:00
|
|
|
{
|
2014-01-24 16:53:16 +01:00
|
|
|
Node *oldNode = info.declaringMemberNoProperties(m_oldCursorPosition);
|
|
|
|
|
Node *newNode = info.declaringMemberNoProperties(position());
|
2010-08-13 17:20:33 +02:00
|
|
|
if (oldNode != newNode && m_oldCursorPosition != -1)
|
2014-01-24 16:53:16 +01:00
|
|
|
m_contextPane->apply(editor(), info.document, 0, newNode, false);
|
2011-08-12 09:25:01 +02:00
|
|
|
|
2014-01-24 16:53:16 +01:00
|
|
|
if (m_contextPane->isAvailable(editor(), info.document, newNode) &&
|
2010-08-05 15:35:52 +02:00
|
|
|
!m_contextPane->widget()->isVisible()) {
|
2014-08-20 01:47:42 +02:00
|
|
|
QList<RefactorMarker> markers = removeMarkersOfType<QtQuickToolbarMarker>(refactorMarkers());
|
2010-08-05 10:44:50 +02:00
|
|
|
if (UiObjectMember *m = newNode->uiObjectMemberCast()) {
|
2010-09-08 16:34:49 +02:00
|
|
|
const int start = qualifiedTypeNameId(m)->identifierToken.begin();
|
2010-08-05 10:44:50 +02:00
|
|
|
for (UiQualifiedId *q = qualifiedTypeNameId(m); q; q = q->next) {
|
|
|
|
|
if (! q->next) {
|
|
|
|
|
const int end = q->identifierToken.end();
|
2010-09-08 16:34:49 +02:00
|
|
|
if (position() >= start && position() <= end) {
|
2014-08-20 01:47:42 +02:00
|
|
|
RefactorMarker marker;
|
2010-09-08 16:34:49 +02:00
|
|
|
QTextCursor tc(document());
|
|
|
|
|
tc.setPosition(end);
|
|
|
|
|
marker.cursor = tc;
|
|
|
|
|
marker.tooltip = tr("Show Qt Quick ToolBar");
|
2011-08-12 09:25:01 +02:00
|
|
|
marker.data = QVariant::fromValue(QtQuickToolbarMarker());
|
2010-09-08 16:34:49 +02:00
|
|
|
markers.append(marker);
|
|
|
|
|
}
|
2010-08-05 10:44:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
setRefactorMarkers(markers);
|
2010-09-01 11:54:35 +02:00
|
|
|
} else if (oldNode != newNode) {
|
2011-08-12 09:25:01 +02:00
|
|
|
setRefactorMarkers(removeMarkersOfType<QtQuickToolbarMarker>(refactorMarkers()));
|
2010-08-05 10:44:50 +02:00
|
|
|
}
|
|
|
|
|
m_oldCursorPosition = position();
|
2010-08-27 10:37:15 +02:00
|
|
|
|
|
|
|
|
setSelectedElements();
|
2010-08-05 10:44:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::showTextMarker()
|
2010-08-13 13:59:41 +02:00
|
|
|
{
|
|
|
|
|
m_oldCursorPosition = -1;
|
2014-01-30 15:48:24 +01:00
|
|
|
updateContextPane();
|
2010-08-13 13:59:41 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::updateUses()
|
2010-01-14 16:30:48 +01:00
|
|
|
{
|
2014-01-29 13:53:08 +01:00
|
|
|
if (m_qmlJsEditorDocument->isSemanticInfoOutdated()) // will be updated when info is updated
|
2010-01-14 16:30:48 +01:00
|
|
|
return;
|
2009-05-04 18:58:36 +02:00
|
|
|
|
2009-09-16 13:56:06 +02:00
|
|
|
QList<QTextEdit::ExtraSelection> selections;
|
2014-01-24 16:53:16 +01:00
|
|
|
foreach (const AST::SourceLocation &loc,
|
|
|
|
|
m_qmlJsEditorDocument->semanticInfo().idLocations.value(wordUnderCursor())) {
|
2009-09-16 13:56:06 +02:00
|
|
|
if (! loc.isValid())
|
|
|
|
|
continue;
|
2009-05-05 10:46:58 +02:00
|
|
|
|
2009-09-16 13:56:06 +02:00
|
|
|
QTextEdit::ExtraSelection sel;
|
2014-08-01 23:31:56 +02:00
|
|
|
sel.format = textDocument()->fontSettings().toTextCharFormat(TextEditor::C_OCCURRENCES);
|
2009-09-16 13:56:06 +02:00
|
|
|
sel.cursor = textCursor();
|
|
|
|
|
sel.cursor.setPosition(loc.begin());
|
|
|
|
|
sel.cursor.setPosition(loc.end(), QTextCursor::KeepAnchor);
|
|
|
|
|
selections.append(sel);
|
|
|
|
|
}
|
2009-05-04 18:58:36 +02:00
|
|
|
|
2009-09-16 13:56:06 +02:00
|
|
|
setExtraSelections(CodeSemanticsSelection, selections);
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SelectedElement: protected Visitor
|
|
|
|
|
{
|
2010-07-27 11:57:06 +02:00
|
|
|
unsigned m_cursorPositionStart;
|
|
|
|
|
unsigned m_cursorPositionEnd;
|
|
|
|
|
QList<UiObjectMember *> m_selectedMembers;
|
2010-07-08 11:34:51 +02:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
SelectedElement()
|
2010-07-27 11:57:06 +02:00
|
|
|
: m_cursorPositionStart(0), m_cursorPositionEnd(0) {}
|
2010-07-08 11:34:51 +02:00
|
|
|
|
2011-08-08 12:26:22 +02:00
|
|
|
QList<UiObjectMember *> operator()(const Document::Ptr &doc, unsigned startPosition, unsigned endPosition)
|
2010-07-08 11:34:51 +02:00
|
|
|
{
|
2010-07-27 11:57:06 +02:00
|
|
|
m_cursorPositionStart = startPosition;
|
|
|
|
|
m_cursorPositionEnd = endPosition;
|
|
|
|
|
m_selectedMembers.clear();
|
2011-08-08 12:26:22 +02:00
|
|
|
Node::accept(doc->qmlProgram(), this);
|
2010-07-27 11:57:06 +02:00
|
|
|
return m_selectedMembers;
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2010-07-13 16:13:26 +02:00
|
|
|
|
2010-07-27 11:57:06 +02:00
|
|
|
bool isSelectable(UiObjectMember *member) const
|
2010-07-13 16:13:26 +02:00
|
|
|
{
|
2011-10-07 14:04:06 +02:00
|
|
|
UiQualifiedId *id = qualifiedTypeNameId(member);
|
2010-07-13 16:13:26 +02:00
|
|
|
if (id) {
|
2011-09-13 09:57:24 +02:00
|
|
|
const QStringRef &name = id->name;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (!name.isEmpty() && name.at(0).isUpper())
|
2010-07-13 16:13:26 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-24 15:13:50 +02:00
|
|
|
inline bool isIdBinding(UiObjectMember *member) const
|
2010-07-08 11:34:51 +02:00
|
|
|
{
|
|
|
|
|
if (UiScriptBinding *script = cast<UiScriptBinding *>(member)) {
|
|
|
|
|
if (! script->qualifiedId)
|
|
|
|
|
return false;
|
2011-09-13 09:57:24 +02:00
|
|
|
else if (script->qualifiedId->name.isEmpty())
|
2010-07-08 11:34:51 +02:00
|
|
|
return false;
|
|
|
|
|
else if (script->qualifiedId->next)
|
|
|
|
|
return false;
|
|
|
|
|
|
2011-09-13 09:57:24 +02:00
|
|
|
const QStringRef &propertyName = script->qualifiedId->name;
|
2010-07-08 11:34:51 +02:00
|
|
|
|
|
|
|
|
if (propertyName == QLatin1String("id"))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-24 15:13:50 +02:00
|
|
|
inline bool containsCursor(unsigned begin, unsigned end)
|
2010-07-12 17:18:05 +02:00
|
|
|
{
|
2010-07-27 11:57:06 +02:00
|
|
|
return m_cursorPositionStart >= begin && m_cursorPositionEnd <= end;
|
2010-07-12 17:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-24 15:13:50 +02:00
|
|
|
inline bool intersectsCursor(unsigned begin, unsigned end)
|
2010-07-12 17:18:05 +02:00
|
|
|
{
|
2010-07-27 11:57:06 +02:00
|
|
|
return (m_cursorPositionEnd >= begin && m_cursorPositionStart <= end);
|
2010-07-12 17:18:05 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-24 15:13:50 +02:00
|
|
|
inline bool isRangeSelected() const
|
2010-07-15 10:53:49 +02:00
|
|
|
{
|
2010-07-27 11:57:06 +02:00
|
|
|
return (m_cursorPositionStart != m_cursorPositionEnd);
|
2010-07-15 10:53:49 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-24 15:13:50 +02:00
|
|
|
void postVisit(Node *ast)
|
2010-07-08 11:34:51 +02:00
|
|
|
{
|
2010-07-27 11:57:06 +02:00
|
|
|
if (!isRangeSelected() && !m_selectedMembers.isEmpty())
|
2010-07-12 17:18:05 +02:00
|
|
|
return; // nothing to do, we already have the results.
|
2010-07-08 11:34:51 +02:00
|
|
|
|
|
|
|
|
if (UiObjectMember *member = ast->uiObjectMemberCast()) {
|
|
|
|
|
unsigned begin = member->firstSourceLocation().begin();
|
|
|
|
|
unsigned end = member->lastSourceLocation().end();
|
|
|
|
|
|
2010-07-15 10:53:49 +02:00
|
|
|
if ((isRangeSelected() && intersectsCursor(begin, end))
|
|
|
|
|
|| (!isRangeSelected() && containsCursor(begin, end)))
|
2010-07-12 17:18:05 +02:00
|
|
|
{
|
2011-10-07 14:04:06 +02:00
|
|
|
if (initializerOfObject(member) && isSelectable(member)) {
|
2010-07-27 11:57:06 +02:00
|
|
|
m_selectedMembers << member;
|
|
|
|
|
// move start towards end; this facilitates multiselection so that root is usually ignored.
|
|
|
|
|
m_cursorPositionStart = qMin(end, m_cursorPositionEnd);
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::setSelectedElements()
|
2010-07-08 11:34:51 +02:00
|
|
|
{
|
2012-05-10 17:06:29 +02:00
|
|
|
if (!receivers(SIGNAL(selectedElementsChanged(QList<QmlJS::AST::UiObjectMember*>,QString))))
|
2010-08-24 15:13:50 +02:00
|
|
|
return;
|
|
|
|
|
|
2010-07-08 11:34:51 +02:00
|
|
|
QTextCursor tc = textCursor();
|
2010-07-12 17:18:05 +02:00
|
|
|
QString wordAtCursor;
|
2012-05-10 17:06:29 +02:00
|
|
|
QList<UiObjectMember *> offsets;
|
2010-07-12 17:18:05 +02:00
|
|
|
|
|
|
|
|
unsigned startPos;
|
|
|
|
|
unsigned endPos;
|
|
|
|
|
|
|
|
|
|
if (tc.hasSelection()) {
|
|
|
|
|
startPos = tc.selectionStart();
|
|
|
|
|
endPos = tc.selectionEnd();
|
|
|
|
|
} else {
|
|
|
|
|
tc.movePosition(QTextCursor::StartOfWord);
|
|
|
|
|
tc.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
|
|
|
|
|
|
|
|
|
startPos = textCursor().position();
|
|
|
|
|
endPos = textCursor().position();
|
|
|
|
|
}
|
2010-07-08 11:34:51 +02:00
|
|
|
|
2014-01-24 16:53:16 +01:00
|
|
|
if (m_qmlJsEditorDocument->semanticInfo().isValid()) {
|
2010-07-12 17:18:05 +02:00
|
|
|
SelectedElement selectedMembers;
|
2014-01-24 16:53:16 +01:00
|
|
|
QList<UiObjectMember *> members
|
|
|
|
|
= selectedMembers(m_qmlJsEditorDocument->semanticInfo().document, startPos, endPos);
|
2010-07-12 17:18:05 +02:00
|
|
|
if (!members.isEmpty()) {
|
2012-11-28 20:44:03 +02:00
|
|
|
foreach (UiObjectMember *m, members) {
|
2012-05-10 17:06:29 +02:00
|
|
|
offsets << m;
|
2010-07-12 17:18:05 +02:00
|
|
|
}
|
2010-07-08 11:34:51 +02:00
|
|
|
}
|
|
|
|
|
}
|
2010-07-12 17:18:05 +02:00
|
|
|
wordAtCursor = tc.selectedText();
|
|
|
|
|
|
|
|
|
|
emit selectedElementsChanged(offsets, wordAtCursor);
|
2009-04-22 15:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::applyFontSettings()
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2014-08-20 01:47:42 +02:00
|
|
|
BaseTextEditorWidget::applyFontSettings();
|
2014-02-06 12:59:00 +01:00
|
|
|
if (!m_qmlJsEditorDocument->isSemanticInfoOutdated())
|
2014-01-30 12:48:30 +01:00
|
|
|
updateUses();
|
2009-04-22 15:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-15 12:27:25 +01:00
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
QString QmlJSEditorWidget::wordUnderCursor() const
|
2009-05-05 15:33:39 +02:00
|
|
|
{
|
2009-09-16 13:56:06 +02:00
|
|
|
QTextCursor tc = textCursor();
|
2013-04-18 18:21:17 +02:00
|
|
|
const QChar ch = document()->characterAt(tc.position() - 1);
|
2010-03-25 14:47:14 +01:00
|
|
|
// make sure that we're not at the start of the next word.
|
|
|
|
|
if (ch.isLetterOrNumber() || ch == QLatin1Char('_'))
|
|
|
|
|
tc.movePosition(QTextCursor::Left);
|
2009-09-16 13:56:06 +02:00
|
|
|
tc.movePosition(QTextCursor::StartOfWord);
|
|
|
|
|
tc.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
2010-03-25 14:47:14 +01:00
|
|
|
const QString word = tc.selectedText();
|
2009-09-16 13:56:06 +02:00
|
|
|
return word;
|
2009-05-05 15:33:39 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
bool QmlJSEditorWidget::isClosingBrace(const QList<Token> &tokens) const
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2009-09-16 13:56:06 +02:00
|
|
|
|
2009-11-16 12:38:47 +01:00
|
|
|
if (tokens.size() == 1) {
|
2010-01-19 12:54:17 +01:00
|
|
|
const Token firstToken = tokens.first();
|
2009-09-16 13:56:06 +02:00
|
|
|
|
2010-01-19 12:54:17 +01:00
|
|
|
return firstToken.is(Token::RightBrace) || firstToken.is(Token::RightBracket);
|
2009-11-16 12:38:47 +01:00
|
|
|
}
|
2009-09-16 13:56:06 +02:00
|
|
|
|
2009-11-16 12:38:47 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2009-09-16 13:56:06 +02:00
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
BaseTextEditor *QmlJSEditorWidget::createEditor()
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2014-08-21 09:56:08 +02:00
|
|
|
QTC_ASSERT("should not happen anymore" && false, return 0);
|
2009-04-22 15:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::createToolBar()
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2010-07-13 11:24:16 +02:00
|
|
|
m_outlineCombo = new QComboBox;
|
|
|
|
|
m_outlineCombo->setMinimumContentsLength(22);
|
2014-01-30 17:18:35 +01:00
|
|
|
m_outlineCombo->setModel(m_qmlJsEditorDocument->outlineModel());
|
2010-07-12 14:45:22 +02:00
|
|
|
|
|
|
|
|
QTreeView *treeView = new QTreeView;
|
2012-06-04 12:52:49 +02:00
|
|
|
|
|
|
|
|
Utils::AnnotatedItemDelegate *itemDelegate = new Utils::AnnotatedItemDelegate(this);
|
|
|
|
|
itemDelegate->setDelimiter(QLatin1String(" "));
|
|
|
|
|
itemDelegate->setAnnotationRole(QmlOutlineModel::AnnotationRole);
|
|
|
|
|
treeView->setItemDelegateForColumn(0, itemDelegate);
|
|
|
|
|
|
2010-07-12 14:45:22 +02:00
|
|
|
treeView->header()->hide();
|
|
|
|
|
treeView->setItemsExpandable(false);
|
2010-07-12 15:49:03 +02:00
|
|
|
treeView->setRootIsDecorated(false);
|
2010-07-13 11:24:16 +02:00
|
|
|
m_outlineCombo->setView(treeView);
|
2010-07-12 14:45:22 +02:00
|
|
|
treeView->expandAll();
|
|
|
|
|
|
2010-07-13 11:24:16 +02:00
|
|
|
//m_outlineCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2009-09-16 13:56:06 +02:00
|
|
|
// Make the combo box prefer to expand
|
2010-07-13 11:24:16 +02:00
|
|
|
QSizePolicy policy = m_outlineCombo->sizePolicy();
|
2009-09-16 13:56:06 +02:00
|
|
|
policy.setHorizontalPolicy(QSizePolicy::Expanding);
|
2010-07-13 11:24:16 +02:00
|
|
|
m_outlineCombo->setSizePolicy(policy);
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2010-07-13 11:25:45 +02:00
|
|
|
connect(m_outlineCombo, SIGNAL(activated(int)), this, SLOT(jumpToOutlineElement(int)));
|
2014-01-30 17:18:35 +01:00
|
|
|
connect(m_qmlJsEditorDocument->outlineModel(), SIGNAL(updated()),
|
|
|
|
|
m_outlineCombo->view()/*QTreeView*/, SLOT(expandAll()));
|
|
|
|
|
connect(m_qmlJsEditorDocument->outlineModel(), SIGNAL(updated()),
|
|
|
|
|
this, SLOT(updateOutlineIndexNow()));
|
|
|
|
|
|
2010-07-13 11:24:16 +02:00
|
|
|
connect(this, SIGNAL(cursorPositionChanged()), m_updateOutlineIndexTimer, SLOT(start()));
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2014-08-20 01:47:42 +02:00
|
|
|
insertExtraToolBarWidget(BaseTextEditorWidget::Left, m_outlineCombo);
|
2009-04-22 15:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
BaseTextEditorWidget::Link QmlJSEditorWidget::findLinkAt(const QTextCursor &cursor,
|
2014-08-20 01:47:42 +02:00
|
|
|
bool /*resolveTarget*/,
|
|
|
|
|
bool /*inNextSplit*/)
|
2009-09-11 14:42:50 +02:00
|
|
|
{
|
2014-01-24 16:53:16 +01:00
|
|
|
const SemanticInfo semanticInfo = m_qmlJsEditorDocument->semanticInfo();
|
2010-09-08 10:11:44 +02:00
|
|
|
if (! semanticInfo.isValid())
|
|
|
|
|
return Link();
|
|
|
|
|
|
2010-02-02 13:18:56 +01:00
|
|
|
const unsigned cursorPosition = cursor.position();
|
2010-02-01 16:14:34 +01:00
|
|
|
|
2011-08-09 12:18:56 +02:00
|
|
|
AST::Node *node = semanticInfo.astNodeAt(cursorPosition);
|
|
|
|
|
QTC_ASSERT(node, return Link());
|
2010-02-01 16:14:34 +01:00
|
|
|
|
2010-07-16 11:16:22 +02:00
|
|
|
if (AST::UiImport *importAst = cast<AST::UiImport *>(node)) {
|
|
|
|
|
// if it's a file import, link to the file
|
2011-08-08 12:47:49 +02:00
|
|
|
foreach (const ImportInfo &import, semanticInfo.document->bind()->imports()) {
|
2013-10-16 14:59:28 +02:00
|
|
|
if (import.ast() == importAst && import.type() == ImportType::File) {
|
2011-09-21 12:42:27 +02:00
|
|
|
BaseTextEditorWidget::Link link(import.path());
|
2013-02-06 14:23:18 +01:00
|
|
|
link.linkTextStart = importAst->firstSourceLocation().begin();
|
|
|
|
|
link.linkTextEnd = importAst->lastSourceLocation().end();
|
2010-07-16 11:16:22 +02:00
|
|
|
return link;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Link();
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-09 11:10:53 +02:00
|
|
|
// string literals that could refer to a file link to them
|
|
|
|
|
if (StringLiteral *literal = cast<StringLiteral *>(node)) {
|
2011-09-13 09:57:24 +02:00
|
|
|
const QString &text = literal->value.toString();
|
2011-08-09 11:10:53 +02:00
|
|
|
BaseTextEditorWidget::Link link;
|
2013-02-06 14:23:18 +01:00
|
|
|
link.linkTextStart = literal->literalToken.begin();
|
|
|
|
|
link.linkTextEnd = literal->literalToken.end();
|
2011-08-09 11:10:53 +02:00
|
|
|
if (semanticInfo.snapshot.document(text)) {
|
2013-02-06 14:23:18 +01:00
|
|
|
link.targetFileName = text;
|
2011-08-09 11:10:53 +02:00
|
|
|
return link;
|
|
|
|
|
}
|
2012-11-26 21:17:34 +02:00
|
|
|
const QString relative = QString::fromLatin1("%1/%2").arg(
|
2011-08-09 11:10:53 +02:00
|
|
|
semanticInfo.document->path(),
|
|
|
|
|
text);
|
|
|
|
|
if (semanticInfo.snapshot.document(relative)) {
|
2013-02-06 14:23:18 +01:00
|
|
|
link.targetFileName = relative;
|
2011-08-09 11:10:53 +02:00
|
|
|
return link;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-08 12:47:49 +02:00
|
|
|
const ScopeChain scopeChain = semanticInfo.scopeChain(semanticInfo.rangePath(cursorPosition));
|
2011-08-08 12:26:22 +02:00
|
|
|
Evaluate evaluator(&scopeChain);
|
2011-08-08 12:47:49 +02:00
|
|
|
const Value *value = evaluator.reference(node);
|
2010-02-08 12:50:10 +01:00
|
|
|
|
|
|
|
|
QString fileName;
|
|
|
|
|
int line = 0, column = 0;
|
|
|
|
|
|
|
|
|
|
if (! (value && value->getSourceLocation(&fileName, &line, &column)))
|
|
|
|
|
return Link();
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
BaseTextEditorWidget::Link link;
|
2013-02-06 14:23:18 +01:00
|
|
|
link.targetFileName = fileName;
|
|
|
|
|
link.targetLine = line;
|
|
|
|
|
link.targetColumn = column - 1; // adjust the column
|
2010-02-08 12:50:10 +01:00
|
|
|
|
2010-02-02 13:18:56 +01:00
|
|
|
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()) {
|
2013-02-06 14:23:18 +01:00
|
|
|
link.linkTextStart = tail->identifierToken.begin();
|
|
|
|
|
link.linkTextEnd = tail->identifierToken.end();
|
2010-02-01 16:14:34 +01:00
|
|
|
return link;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-02 13:18:56 +01:00
|
|
|
} else if (AST::IdentifierExpression *id = AST::cast<AST::IdentifierExpression *>(node)) {
|
2013-02-06 14:23:18 +01:00
|
|
|
link.linkTextStart = id->firstSourceLocation().begin();
|
|
|
|
|
link.linkTextEnd = id->lastSourceLocation().end();
|
2010-02-02 13:18:56 +01:00
|
|
|
return link;
|
2010-02-01 16:14:34 +01:00
|
|
|
|
2010-02-02 13:18:56 +01:00
|
|
|
} else if (AST::FieldMemberExpression *mem = AST::cast<AST::FieldMemberExpression *>(node)) {
|
2013-02-06 14:23:18 +01:00
|
|
|
link.linkTextStart = mem->lastSourceLocation().begin();
|
|
|
|
|
link.linkTextEnd = mem->lastSourceLocation().end();
|
2010-02-02 13:18:56 +01:00
|
|
|
return link;
|
2010-02-01 16:14:34 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-02 13:18:56 +01:00
|
|
|
return Link();
|
2009-09-11 14:42:50 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::findUsages()
|
2010-09-24 14:05:34 +02:00
|
|
|
{
|
2014-08-01 23:31:56 +02:00
|
|
|
m_findReferences->findUsages(textDocument()->filePath(), textCursor().position());
|
2010-09-24 14:05:34 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::renameUsages()
|
2011-07-11 12:53:05 +02:00
|
|
|
{
|
2014-08-01 23:31:56 +02:00
|
|
|
m_findReferences->renameUsages(textDocument()->filePath(), textCursor().position());
|
2011-07-11 12:53:05 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::showContextPane()
|
2010-08-04 13:50:15 +02:00
|
|
|
{
|
2014-01-24 16:53:16 +01:00
|
|
|
const SemanticInfo info = m_qmlJsEditorDocument->semanticInfo();
|
|
|
|
|
if (m_contextPane && info.isValid()) {
|
|
|
|
|
Node *newNode = info.declaringMemberNoProperties(position());
|
|
|
|
|
ScopeChain scopeChain = info.scopeChain(info.rangePath(position()));
|
|
|
|
|
m_contextPane->apply(editor(), info.document,
|
2011-08-08 12:26:22 +02:00
|
|
|
&scopeChain,
|
|
|
|
|
newNode, false, true);
|
2010-08-04 13:50:15 +02:00
|
|
|
m_oldCursorPosition = position();
|
2011-08-12 09:25:01 +02:00
|
|
|
setRefactorMarkers(removeMarkersOfType<QtQuickToolbarMarker>(refactorMarkers()));
|
2010-08-04 13:50:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::performQuickFix(int index)
|
2010-09-16 12:57:07 +02:00
|
|
|
{
|
2014-08-20 01:47:42 +02:00
|
|
|
QuickFixOperation::Ptr op = m_quickFixes.at(index);
|
2010-09-16 12:57:07 +02:00
|
|
|
op->perform();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2013-02-18 15:12:09 +01:00
|
|
|
QPointer<QMenu> menu(new QMenu(this));
|
2009-09-16 13:56:06 +02:00
|
|
|
|
2010-09-16 12:57:07 +02:00
|
|
|
QMenu *refactoringMenu = new QMenu(tr("Refactoring"), menu);
|
2009-09-16 13:56:06 +02:00
|
|
|
|
2010-09-16 12:57:07 +02:00
|
|
|
QSignalMapper mapper;
|
|
|
|
|
connect(&mapper, SIGNAL(mapped(int)), this, SLOT(performQuickFix(int)));
|
2014-01-24 16:53:16 +01:00
|
|
|
if (!m_qmlJsEditorDocument->isSemanticInfoOutdated()) {
|
2014-08-20 01:47:42 +02:00
|
|
|
IAssistInterface *interface = createAssistInterface(QuickFix, ExplicitlyInvoked);
|
2011-04-15 16:19:23 +02:00
|
|
|
if (interface) {
|
2014-08-20 01:47:42 +02:00
|
|
|
QScopedPointer<IAssistProcessor> processor(
|
2011-04-15 16:19:23 +02:00
|
|
|
QmlJSEditorPlugin::instance()->quickFixAssistProvider()->createProcessor());
|
2014-08-20 01:47:42 +02:00
|
|
|
QScopedPointer<IAssistProposal> proposal(processor->perform(interface));
|
2011-04-15 16:19:23 +02:00
|
|
|
if (!proposal.isNull()) {
|
2014-08-20 01:47:42 +02:00
|
|
|
BasicProposalItemListModel *model = static_cast<BasicProposalItemListModel *>(proposal->model());
|
2011-04-15 16:19:23 +02:00
|
|
|
for (int index = 0; index < model->size(); ++index) {
|
2014-08-20 01:47:42 +02:00
|
|
|
BasicProposalItem *item = static_cast<BasicProposalItem *>(model->proposalItem(index));
|
|
|
|
|
QuickFixOperation::Ptr op = item->data().value<QuickFixOperation::Ptr>();
|
2011-04-15 16:19:23 +02:00
|
|
|
m_quickFixes.append(op);
|
|
|
|
|
QAction *action = refactoringMenu->addAction(op->description());
|
|
|
|
|
mapper.setMapping(action, index);
|
|
|
|
|
connect(action, SIGNAL(triggered()), &mapper, SLOT(map()));
|
|
|
|
|
}
|
|
|
|
|
delete model;
|
2010-09-16 12:57:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
refactoringMenu->setEnabled(!refactoringMenu->isEmpty());
|
|
|
|
|
|
2013-08-30 16:38:57 +02:00
|
|
|
if (ActionContainer *mcontext = ActionManager::actionContainer(Constants::M_CONTEXT)) {
|
2010-09-16 12:57:07 +02:00
|
|
|
QMenu *contextMenu = mcontext->menu();
|
|
|
|
|
foreach (QAction *action, contextMenu->actions()) {
|
|
|
|
|
menu->addAction(action);
|
2013-06-03 19:31:32 +02:00
|
|
|
if (action->objectName() == QLatin1String(Constants::M_REFACTORING_MENU_INSERTION_POINT))
|
2010-09-16 12:57:07 +02:00
|
|
|
menu->addMenu(refactoringMenu);
|
2013-06-03 19:31:32 +02:00
|
|
|
if (action->objectName() == QLatin1String(Constants::SHOW_QT_QUICK_HELPER)) {
|
2014-01-24 16:53:16 +01:00
|
|
|
bool enabled = m_contextPane->isAvailable(
|
|
|
|
|
editor(), m_qmlJsEditorDocument->semanticInfo().document,
|
|
|
|
|
m_qmlJsEditorDocument->semanticInfo().declaringMemberNoProperties(position()));
|
2011-07-27 11:22:10 +02:00
|
|
|
action->setEnabled(enabled);
|
|
|
|
|
}
|
2010-09-16 12:57:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-09 17:35:20 +01:00
|
|
|
appendStandardContextMenuActions(menu);
|
|
|
|
|
|
2009-09-16 13:56:06 +02:00
|
|
|
menu->exec(e->globalPos());
|
2013-02-18 15:12:09 +01:00
|
|
|
if (!menu)
|
|
|
|
|
return;
|
2010-09-16 12:57:07 +02:00
|
|
|
m_quickFixes.clear();
|
2013-02-18 15:12:09 +01:00
|
|
|
delete menu;
|
2009-04-22 15:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
bool QmlJSEditorWidget::event(QEvent *e)
|
2010-07-07 13:09:30 +02:00
|
|
|
{
|
|
|
|
|
switch (e->type()) {
|
|
|
|
|
case QEvent::ShortcutOverride:
|
|
|
|
|
if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape && m_contextPane) {
|
2010-07-20 15:01:06 +02:00
|
|
|
if (hideContextPane()) {
|
2010-07-15 16:40:19 +02:00
|
|
|
e->accept();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-07-07 13:09:30 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
return BaseTextEditorWidget::event(e);
|
2010-07-07 13:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::wheelEvent(QWheelEvent *event)
|
2010-07-07 13:09:30 +02:00
|
|
|
{
|
2010-07-20 15:01:06 +02:00
|
|
|
bool visible = false;
|
|
|
|
|
if (m_contextPane && m_contextPane->widget()->isVisible())
|
|
|
|
|
visible = true;
|
|
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
BaseTextEditorWidget::wheelEvent(event);
|
2010-07-20 15:01:06 +02:00
|
|
|
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (visible)
|
2014-01-24 16:53:16 +01:00
|
|
|
m_contextPane->apply(editor(), m_qmlJsEditorDocument->semanticInfo().document, 0,
|
|
|
|
|
m_qmlJsEditorDocument->semanticInfo().declaringMemberNoProperties(m_oldCursorPosition),
|
|
|
|
|
false, true);
|
2010-07-20 15:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::resizeEvent(QResizeEvent *event)
|
2010-07-20 15:01:06 +02:00
|
|
|
{
|
2011-02-21 16:02:26 +01:00
|
|
|
BaseTextEditorWidget::resizeEvent(event);
|
2010-07-20 15:01:06 +02:00
|
|
|
hideContextPane();
|
2010-07-07 13:09:30 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::scrollContentsBy(int dx, int dy)
|
2010-07-20 15:01:06 +02:00
|
|
|
{
|
2011-02-21 16:02:26 +01:00
|
|
|
BaseTextEditorWidget::scrollContentsBy(dx, dy);
|
2010-07-20 15:01:06 +02:00
|
|
|
hideContextPane();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
QmlJSEditorDocument *QmlJSEditorWidget::qmlJsEditorDocument() const
|
2014-02-07 13:45:51 +01:00
|
|
|
{
|
|
|
|
|
return m_qmlJsEditorDocument;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::semanticInfoUpdated(const SemanticInfo &semanticInfo)
|
2010-02-16 10:36:09 +01:00
|
|
|
{
|
2014-01-30 17:18:35 +01:00
|
|
|
if (isVisible()) {
|
|
|
|
|
// trigger semantic highlighting and model update if necessary
|
2014-08-01 23:31:56 +02:00
|
|
|
textDocument()->triggerPendingUpdates();
|
2014-01-30 17:18:35 +01:00
|
|
|
}
|
2014-02-06 12:59:00 +01:00
|
|
|
|
2010-08-05 15:35:52 +02:00
|
|
|
if (m_contextPane) {
|
2014-01-24 16:53:16 +01:00
|
|
|
Node *newNode = semanticInfo.declaringMemberNoProperties(position());
|
2010-08-05 15:35:52 +02:00
|
|
|
if (newNode) {
|
2011-08-08 12:26:22 +02:00
|
|
|
m_contextPane->apply(editor(), semanticInfo.document, 0, newNode, true);
|
2014-01-30 15:48:24 +01:00
|
|
|
m_contextPaneTimer->start(); //update text marker
|
2010-07-07 13:09:30 +02:00
|
|
|
}
|
2010-02-16 10:36:09 +01:00
|
|
|
}
|
|
|
|
|
|
2014-01-29 13:53:08 +01:00
|
|
|
updateUses();
|
2010-02-16 10:36:09 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
void QmlJSEditorWidget::onRefactorMarkerClicked(const RefactorMarker &marker)
|
2010-08-05 10:44:50 +02:00
|
|
|
{
|
2011-08-12 09:25:01 +02:00
|
|
|
if (marker.data.canConvert<QtQuickToolbarMarker>())
|
|
|
|
|
showContextPane();
|
2010-08-05 10:44:50 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
QModelIndex QmlJSEditorWidget::indexForPosition(unsigned cursorPosition, const QModelIndex &rootIndex) const
|
2010-07-12 14:45:22 +02:00
|
|
|
{
|
|
|
|
|
QModelIndex lastIndex = rootIndex;
|
|
|
|
|
|
2014-01-30 17:18:35 +01:00
|
|
|
QmlOutlineModel *model = m_qmlJsEditorDocument->outlineModel();
|
|
|
|
|
const int rowCount = model->rowCount(rootIndex);
|
2010-07-12 14:45:22 +02:00
|
|
|
for (int i = 0; i < rowCount; ++i) {
|
2014-01-30 17:18:35 +01:00
|
|
|
QModelIndex childIndex = model->index(i, 0, rootIndex);
|
|
|
|
|
AST::SourceLocation location = model->sourceLocation(childIndex);
|
2010-07-12 14:45:22 +02:00
|
|
|
|
|
|
|
|
if ((cursorPosition >= location.offset)
|
|
|
|
|
&& (cursorPosition <= location.offset + location.length)) {
|
|
|
|
|
lastIndex = childIndex;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-07-07 13:09:30 +02:00
|
|
|
}
|
2010-07-12 14:45:22 +02:00
|
|
|
|
|
|
|
|
if (lastIndex != rootIndex) {
|
|
|
|
|
// recurse
|
|
|
|
|
lastIndex = indexForPosition(cursorPosition, lastIndex);
|
|
|
|
|
}
|
|
|
|
|
return lastIndex;
|
2010-02-16 10:36:09 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
bool QmlJSEditorWidget::hideContextPane()
|
2010-07-20 15:01:06 +02:00
|
|
|
{
|
|
|
|
|
bool b = (m_contextPane) && m_contextPane->widget()->isVisible();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (b)
|
2014-01-24 16:53:16 +01:00
|
|
|
m_contextPane->apply(editor(), m_qmlJsEditorDocument->semanticInfo().document, 0, 0, false);
|
2010-07-20 15:01:06 +02:00
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
IAssistInterface *QmlJSEditorWidget::createAssistInterface(
|
2011-04-15 16:19:23 +02:00
|
|
|
TextEditor::AssistKind assistKind,
|
|
|
|
|
TextEditor::AssistReason reason) const
|
|
|
|
|
{
|
|
|
|
|
if (assistKind == TextEditor::Completion) {
|
|
|
|
|
return new QmlJSCompletionAssistInterface(document(),
|
|
|
|
|
position(),
|
2013-07-04 13:30:26 +02:00
|
|
|
editor()->document()->filePath(),
|
2011-04-15 16:19:23 +02:00
|
|
|
reason,
|
2014-01-24 16:53:16 +01:00
|
|
|
m_qmlJsEditorDocument->semanticInfo());
|
2011-04-15 16:19:23 +02:00
|
|
|
} else if (assistKind == TextEditor::QuickFix) {
|
2014-08-25 20:01:46 +02:00
|
|
|
return new QmlJSQuickFixAssistInterface(const_cast<QmlJSEditorWidget *>(this), reason);
|
2011-04-15 16:19:23 +02:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-09-14 22:16:28 +02:00
|
|
|
|
2014-08-25 20:01:46 +02:00
|
|
|
QString QmlJSEditorWidget::foldReplacementText(const QTextBlock &block) const
|
2011-09-14 22:16:28 +02:00
|
|
|
{
|
2011-10-24 09:28:02 +02:00
|
|
|
const int curlyIndex = block.text().indexOf(QLatin1Char('{'));
|
|
|
|
|
|
2014-01-24 16:53:16 +01:00
|
|
|
if (curlyIndex != -1 && m_qmlJsEditorDocument->semanticInfo().isValid()) {
|
2011-10-24 09:28:02 +02:00
|
|
|
const int pos = block.position() + curlyIndex;
|
2014-01-24 16:53:16 +01:00
|
|
|
Node *node = m_qmlJsEditorDocument->semanticInfo().rangeAt(pos);
|
2011-10-24 09:28:02 +02:00
|
|
|
|
|
|
|
|
const QString objectId = idOfObject(node);
|
|
|
|
|
if (!objectId.isEmpty())
|
|
|
|
|
return QLatin1String("id: ") + objectId + QLatin1String("...");
|
2011-09-14 22:16:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TextEditor::BaseTextEditorWidget::foldReplacementText(block);
|
|
|
|
|
}
|
2013-06-03 19:31:32 +02:00
|
|
|
|
2014-08-20 01:47:42 +02:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// QmlJSEditor
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
QmlJSEditor::QmlJSEditor()
|
|
|
|
|
{
|
|
|
|
|
addContext(Constants::C_QMLJSEDITOR_ID);
|
|
|
|
|
addContext(ProjectExplorer::Constants::LANG_QMLJS);
|
|
|
|
|
setDuplicateSupported(true);
|
|
|
|
|
setCommentStyle(Utils::CommentDefinition::CppStyle);
|
|
|
|
|
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlJSEditor::isDesignModePreferred() const
|
|
|
|
|
{
|
|
|
|
|
// stay in design mode if we are there
|
|
|
|
|
IMode *mode = ModeManager::currentMode();
|
|
|
|
|
return mode && mode->id() == Core::Constants::MODE_DESIGN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// QmlJSEditorFactory
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
QmlJSEditorFactory::QmlJSEditorFactory()
|
|
|
|
|
{
|
|
|
|
|
setId(Constants::C_QMLJSEDITOR_ID);
|
|
|
|
|
setDisplayName(qApp->translate("OpenWith::Editors", Constants::C_QMLJSEDITOR_DISPLAY_NAME));
|
|
|
|
|
|
|
|
|
|
addMimeType(QmlJSTools::Constants::QML_MIMETYPE);
|
|
|
|
|
addMimeType(QmlJSTools::Constants::QMLPROJECT_MIMETYPE);
|
|
|
|
|
addMimeType(QmlJSTools::Constants::QBS_MIMETYPE);
|
|
|
|
|
addMimeType(QmlJSTools::Constants::QMLTYPES_MIMETYPE);
|
|
|
|
|
addMimeType(QmlJSTools::Constants::JS_MIMETYPE);
|
|
|
|
|
addMimeType(QmlJSTools::Constants::JSON_MIMETYPE);
|
|
|
|
|
new TextEditorActionHandler(this, Constants::C_QMLJSEDITOR_ID,
|
|
|
|
|
TextEditorActionHandler::Format
|
|
|
|
|
| TextEditorActionHandler::UnCommentSelection
|
|
|
|
|
| TextEditorActionHandler::UnCollapseAll
|
|
|
|
|
| TextEditorActionHandler::FollowSymbolUnderCursor);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEditor *QmlJSEditorFactory::createEditor()
|
|
|
|
|
{
|
2014-08-21 09:56:08 +02:00
|
|
|
auto editor = new QmlJSEditor;
|
2014-08-25 20:01:46 +02:00
|
|
|
editor->setEditorWidget(new QmlJSEditorWidget(BaseTextDocumentPtr(new QmlJSEditorDocument)));
|
2014-08-21 09:56:08 +02:00
|
|
|
editor->configureCodeAssistant();
|
|
|
|
|
return editor;
|
2014-08-20 01:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-07 14:21:58 +01:00
|
|
|
} // namespace Internal
|
2013-06-03 19:31:32 +02:00
|
|
|
} // namespace QmlJSEditor
|