2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2009-04-22 15:21:04 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
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"
|
2015-01-08 22:43:39 +03:00
|
|
|
#include "qmljshighlighter.h"
|
2014-09-30 13:08:05 +02:00
|
|
|
#include "qmljshoverhandler.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 <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>
|
|
|
|
|
#include <coreplugin/modemanager.h>
|
|
|
|
|
|
2009-09-04 16:51:11 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2014-08-20 01:47:42 +02:00
|
|
|
|
2014-09-26 09:14:03 +02:00
|
|
|
#include <texteditor/textdocument.h>
|
2009-04-22 15:21:04 +02:00
|
|
|
#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>
|
2015-12-09 12:24:53 +01:00
|
|
|
#include <texteditor/texteditorsettings.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>
|
2014-09-04 00:04:18 +02:00
|
|
|
#include <texteditor/codeassist/genericproposalmodel.h>
|
2014-08-20 01:47:42 +02:00
|
|
|
#include <texteditor/texteditoractionhandler.h>
|
|
|
|
|
|
2015-01-08 22:43:39 +03:00
|
|
|
#include <utils/annotateditemdelegate.h>
|
2009-12-02 17:59:27 +01:00
|
|
|
#include <utils/changeset.h>
|
2011-08-09 12:18:56 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2015-01-08 22:43:39 +03:00
|
|
|
#include <utils/uncommentselection.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-23 00:19:48 +02:00
|
|
|
QmlJSEditorWidget::QmlJSEditorWidget()
|
2009-04-22 15:21:04 +02:00
|
|
|
{
|
2014-01-09 18:04:45 +01:00
|
|
|
m_outlineCombo = 0;
|
|
|
|
|
m_contextPane = 0;
|
|
|
|
|
m_findReferences = new FindReferences(this);
|
|
|
|
|
|
2013-12-11 10:49:32 +01:00
|
|
|
setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
|
2014-08-23 00:19:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJSEditorWidget::finalizeInitialization()
|
|
|
|
|
{
|
|
|
|
|
m_qmlJsEditorDocument = static_cast<QmlJSEditorDocument *>(textDocument());
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2014-08-26 17:15:37 +02:00
|
|
|
m_updateUsesTimer.setInterval(UPDATE_USES_DEFAULT_INTERVAL);
|
|
|
|
|
m_updateUsesTimer.setSingleShot(true);
|
|
|
|
|
connect(&m_updateUsesTimer, &QTimer::timeout, this, &QmlJSEditorWidget::updateUses);
|
|
|
|
|
connect(this, &QPlainTextEdit::cursorPositionChanged,
|
|
|
|
|
&m_updateUsesTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2014-08-26 17:15:37 +02:00
|
|
|
m_updateOutlineIndexTimer.setInterval(UPDATE_OUTLINE_INTERVAL);
|
|
|
|
|
m_updateOutlineIndexTimer.setSingleShot(true);
|
|
|
|
|
connect(&m_updateOutlineIndexTimer, &QTimer::timeout,
|
|
|
|
|
this, &QmlJSEditorWidget::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
|
|
|
|
2015-02-03 23:48:57 +02:00
|
|
|
m_modelManager = ModelManagerInterface::instance();
|
|
|
|
|
m_contextPane = ExtensionSystem::PluginManager::getObject<IContextPane>();
|
2010-08-13 13:59:41 +02:00
|
|
|
|
2014-04-29 16:39:16 +02:00
|
|
|
m_modelManager->activateScan();
|
|
|
|
|
|
2014-08-26 17:15:37 +02:00
|
|
|
m_contextPaneTimer.setInterval(UPDATE_OUTLINE_INTERVAL);
|
|
|
|
|
m_contextPaneTimer.setSingleShot(true);
|
|
|
|
|
connect(&m_contextPaneTimer, &QTimer::timeout, this, &QmlJSEditorWidget::updateContextPane);
|
2010-08-13 13:59:41 +02:00
|
|
|
if (m_contextPane) {
|
2014-08-26 17:15:37 +02:00
|
|
|
connect(this, &QmlJSEditorWidget::cursorPositionChanged,
|
|
|
|
|
&m_contextPaneTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
|
|
|
|
connect(m_contextPane, &IContextPane::closed, this, &QmlJSEditorWidget::showTextMarker);
|
2010-08-13 13:59:41 +02:00
|
|
|
}
|
2010-07-13 11:25:45 +02:00
|
|
|
m_oldCursorPosition = -1;
|
2009-09-04 16:51:11 +02:00
|
|
|
|
2014-08-26 17:15:37 +02:00
|
|
|
connect(this->document(), &QTextDocument::modificationChanged,
|
|
|
|
|
this, &QmlJSEditorWidget::modificationChanged);
|
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-08-26 17:15:37 +02:00
|
|
|
|
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
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 12:24:53 +01:00
|
|
|
const auto fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
|
|
|
|
|
|
2010-02-23 16:11:58 +01:00
|
|
|
if (d.isWarning())
|
2015-12-09 12:24:53 +01:00
|
|
|
sel.format = fontSettings.toTextCharFormat(TextEditor::C_WARNING);
|
2010-02-23 16:11:58 +01:00
|
|
|
else
|
2015-12-09 12:24:53 +01:00
|
|
|
sel.format = fontSettings.toTextCharFormat(TextEditor::C_ERROR);
|
2010-02-23 16:11:58 +01:00
|
|
|
|
|
|
|
|
sel.format.setToolTip(d.message);
|
|
|
|
|
|
|
|
|
|
selections->append(sel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:48:57 +02:00
|
|
|
void QmlJSEditorWidget::updateCodeWarnings(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-12-21 21:54:30 +02:00
|
|
|
m_modelManager->fileChangedOnDisk(textDocument()->filePath().toString());
|
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()) {
|
2014-08-26 17:15:37 +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-09-01 12:54:03 +02:00
|
|
|
m_contextPane->apply(this, info.document, 0, newNode, false);
|
2011-08-12 09:25:01 +02:00
|
|
|
|
2014-09-01 12:54:03 +02:00
|
|
|
if (m_contextPane->isAvailable(this, 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;
|
2015-02-03 23:48:57 +02:00
|
|
|
sel.format = textDocument()->fontSettings().toTextCharFormat(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-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget::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
|
|
|
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()));
|
|
|
|
|
|
2014-08-26 17:15:37 +02:00
|
|
|
connect(this, &QmlJSEditorWidget::cursorPositionChanged,
|
|
|
|
|
&m_updateOutlineIndexTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
2009-04-22 15:21:04 +02:00
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
insertExtraToolBarWidget(TextEditorWidget::Left, m_outlineCombo);
|
2009-04-22 15:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-08 22:43:39 +03:00
|
|
|
class CodeModelInspector : public MemberProcessor
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit CodeModelInspector(const CppComponentValue *processingValue, QTextStream *stream) :
|
|
|
|
|
m_processingValue(processingValue),
|
|
|
|
|
m_stream(stream),
|
|
|
|
|
m_indent(QLatin1String(" "))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool processProperty(const QString &name, const Value *value,
|
|
|
|
|
const PropertyInfo &propertyInfo) override
|
|
|
|
|
{
|
|
|
|
|
QString type;
|
|
|
|
|
if (const CppComponentValue *cpp = value->asCppComponentValue())
|
|
|
|
|
type = cpp->metaObject()->className();
|
|
|
|
|
else
|
|
|
|
|
type = m_processingValue->propertyType(name);
|
|
|
|
|
|
|
|
|
|
if (propertyInfo.isList())
|
|
|
|
|
type = QStringLiteral("list<%1>").arg(type);
|
|
|
|
|
|
|
|
|
|
*m_stream << m_indent;
|
|
|
|
|
if (!propertyInfo.isWriteable())
|
|
|
|
|
*m_stream << "readonly ";
|
|
|
|
|
*m_stream << "property " << type << " " << name << endl;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
bool processSignal(const QString &name, const Value *value) override
|
|
|
|
|
{
|
|
|
|
|
*m_stream << m_indent << "signal " << name << stringifyFunctionParameters(value) << endl;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
bool processSlot(const QString &name, const Value *value) override
|
|
|
|
|
{
|
|
|
|
|
*m_stream << m_indent << "function " << name << stringifyFunctionParameters(value) << endl;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
bool processGeneratedSlot(const QString &name, const Value *value) override
|
|
|
|
|
{
|
|
|
|
|
*m_stream << m_indent << "/*generated*/ function " << name
|
|
|
|
|
<< stringifyFunctionParameters(value) << endl;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QString stringifyFunctionParameters(const Value *value) const
|
|
|
|
|
{
|
|
|
|
|
QStringList params;
|
|
|
|
|
const QmlJS::MetaFunction *metaFunction = value->asMetaFunction();
|
|
|
|
|
if (metaFunction) {
|
|
|
|
|
QStringList paramNames = metaFunction->fakeMetaMethod().parameterNames();
|
|
|
|
|
QStringList paramTypes = metaFunction->fakeMetaMethod().parameterTypes();
|
|
|
|
|
for (int i = 0; i < paramTypes.size(); ++i) {
|
|
|
|
|
QString typeAndNamePair = paramTypes.at(i);
|
|
|
|
|
if (paramNames.size() > i) {
|
|
|
|
|
QString paramName = paramNames.at(i);
|
|
|
|
|
if (!paramName.isEmpty())
|
|
|
|
|
typeAndNamePair += QLatin1Char(' ') + paramName;
|
|
|
|
|
}
|
|
|
|
|
params.append(typeAndNamePair);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QLatin1Char('(') + params.join(QLatin1String(", ")) + QLatin1Char(')');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const CppComponentValue *m_processingValue;
|
|
|
|
|
QTextStream *m_stream;
|
|
|
|
|
const QString m_indent;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const CppComponentValue *findCppComponentToInspect(const SemanticInfo &semanticInfo,
|
|
|
|
|
const unsigned cursorPosition)
|
|
|
|
|
{
|
|
|
|
|
AST::Node *node = semanticInfo.astNodeAt(cursorPosition);
|
|
|
|
|
if (!node)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
const ScopeChain scopeChain = semanticInfo.scopeChain(semanticInfo.rangePath(cursorPosition));
|
|
|
|
|
Evaluate evaluator(&scopeChain);
|
|
|
|
|
const Value *value = evaluator.reference(node);
|
|
|
|
|
if (!value)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return value->asCppComponentValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString inspectCppComponent(const CppComponentValue *cppValue)
|
|
|
|
|
{
|
|
|
|
|
QString result;
|
|
|
|
|
QTextStream bufWriter(&result);
|
|
|
|
|
|
|
|
|
|
// for QtObject
|
|
|
|
|
QString superClassName = cppValue->metaObject()->superclassName();
|
|
|
|
|
if (superClassName.isEmpty())
|
|
|
|
|
superClassName = cppValue->metaObject()->className();
|
|
|
|
|
|
|
|
|
|
bufWriter << "import QtQuick " << cppValue->importVersion().toString() << endl
|
|
|
|
|
<< "// " << cppValue->metaObject()->className()
|
|
|
|
|
<< " imported as " << cppValue->moduleName() << " "
|
|
|
|
|
<< cppValue->importVersion().toString() << endl
|
|
|
|
|
<< endl
|
|
|
|
|
<< superClassName << " {" << endl;
|
|
|
|
|
|
|
|
|
|
CodeModelInspector insp(cppValue, &bufWriter);
|
|
|
|
|
cppValue->processMembers(&insp);
|
|
|
|
|
|
|
|
|
|
bufWriter << endl;
|
|
|
|
|
const int enumeratorCount = cppValue->metaObject()->enumeratorCount();
|
|
|
|
|
for (int index = cppValue->metaObject()->enumeratorOffset(); index < enumeratorCount; ++index) {
|
|
|
|
|
LanguageUtils::FakeMetaEnum enumerator = cppValue->metaObject()->enumerator(index);
|
|
|
|
|
bufWriter << " // Enum " << enumerator.name() << " { " <<
|
|
|
|
|
enumerator.keys().join(QLatin1Char(',')) << " }" << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bufWriter << "}" << endl;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QmlJSEditorWidget::inspectElementUnderCursor() const
|
|
|
|
|
{
|
|
|
|
|
const QTextCursor cursor = textCursor();
|
|
|
|
|
|
|
|
|
|
const unsigned cursorPosition = cursor.position();
|
|
|
|
|
const SemanticInfo semanticInfo = m_qmlJsEditorDocument->semanticInfo();
|
|
|
|
|
if (!semanticInfo.isValid())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const CppComponentValue *cppValue = findCppComponentToInspect(semanticInfo, cursorPosition);
|
|
|
|
|
if (!cppValue) {
|
|
|
|
|
QString title = tr("Code Model Not Available");
|
|
|
|
|
const QString nothingToShow = QStringLiteral("nothingToShow");
|
|
|
|
|
EditorManager::openEditorWithContents(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID, &title,
|
|
|
|
|
tr("Code model not available.").toUtf8(), nothingToShow,
|
|
|
|
|
EditorManager::IgnoreNavigationHistory);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString title = tr("Code Model of %1").arg(cppValue->metaObject()->className());
|
|
|
|
|
IEditor *outputEditor = EditorManager::openEditorWithContents(
|
|
|
|
|
Core::Constants::K_DEFAULT_TEXT_EDITOR_ID, &title, QByteArray(),
|
|
|
|
|
cppValue->metaObject()->className(), EditorManager::IgnoreNavigationHistory);
|
|
|
|
|
|
|
|
|
|
if (!outputEditor)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
auto widget = qobject_cast<TextEditor::TextEditorWidget *>(outputEditor->widget());
|
|
|
|
|
if (!widget)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
widget->setReadOnly(true);
|
|
|
|
|
widget->textDocument()->setTemporary(true);
|
|
|
|
|
widget->textDocument()->setSyntaxHighlighter(new QmlJSHighlighter(widget->document()));
|
|
|
|
|
|
|
|
|
|
const QString buf = inspectCppComponent(cppValue);
|
|
|
|
|
widget->textDocument()->setPlainText(buf);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget::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) {
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget::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();
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget::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();
|
|
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget::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-12-21 21:54:30 +02:00
|
|
|
m_findReferences->findUsages(textDocument()->filePath().toString(), 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-12-21 21:54:30 +02:00
|
|
|
m_findReferences->renameUsages(textDocument()->filePath().toString(), 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()));
|
2014-09-01 12:54:03 +02:00
|
|
|
m_contextPane->apply(this, 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-09-23 19:02:30 +02:00
|
|
|
m_quickFixes.at(index)->perform();
|
2010-09-16 12:57:07 +02:00
|
|
|
}
|
|
|
|
|
|
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-09-04 00:04:18 +02:00
|
|
|
AssistInterface *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-09-04 00:04:18 +02:00
|
|
|
GenericProposalModel *model = static_cast<GenericProposalModel *>(proposal->model());
|
2011-04-15 16:19:23 +02:00
|
|
|
for (int index = 0; index < model->size(); ++index) {
|
2014-09-04 00:04:18 +02:00
|
|
|
AssistProposalItem *item = static_cast<AssistProposalItem *>(model->proposalItem(index));
|
2014-08-20 01:47:42 +02:00
|
|
|
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(
|
2014-09-01 12:54:03 +02:00
|
|
|
this, m_qmlJsEditorDocument->semanticInfo().document,
|
2014-01-24 16:53:16 +01:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
return TextEditorWidget::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;
|
|
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget::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-09-01 12:54:03 +02:00
|
|
|
m_contextPane->apply(this, m_qmlJsEditorDocument->semanticInfo().document, 0,
|
2014-01-24 16:53:16 +01:00
|
|
|
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
|
|
|
{
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget::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
|
|
|
{
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget::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) {
|
2014-09-01 12:54:03 +02:00
|
|
|
m_contextPane->apply(this, semanticInfo.document, 0, newNode, true);
|
2014-08-26 17:15:37 +02: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-09-01 12:54:03 +02:00
|
|
|
m_contextPane->apply(this, m_qmlJsEditorDocument->semanticInfo().document, 0, 0, false);
|
2010-07-20 15:01:06 +02:00
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-04 00:04:18 +02:00
|
|
|
AssistInterface *QmlJSEditorWidget::createAssistInterface(
|
2015-02-03 23:48:57 +02:00
|
|
|
AssistKind assistKind,
|
|
|
|
|
AssistReason reason) const
|
2011-04-15 16:19:23 +02:00
|
|
|
{
|
2015-02-03 23:48:57 +02:00
|
|
|
if (assistKind == Completion) {
|
2011-04-15 16:19:23 +02:00
|
|
|
return new QmlJSCompletionAssistInterface(document(),
|
|
|
|
|
position(),
|
2014-12-21 21:54:30 +02:00
|
|
|
textDocument()->filePath().toString(),
|
2011-04-15 16:19:23 +02:00
|
|
|
reason,
|
2014-01-24 16:53:16 +01:00
|
|
|
m_qmlJsEditorDocument->semanticInfo());
|
2015-02-03 23:48:57 +02:00
|
|
|
} else if (assistKind == 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
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:48:57 +02:00
|
|
|
return TextEditorWidget::foldReplacementText(block);
|
2011-09-14 22:16:28 +02:00
|
|
|
}
|
2013-06-03 19:31:32 +02:00
|
|
|
|
2014-08-20 01:47:42 +02:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// QmlJSEditor
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
QmlJSEditor::QmlJSEditor()
|
|
|
|
|
{
|
|
|
|
|
addContext(ProjectExplorer::Constants::LANG_QMLJS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlJSEditor::isDesignModePreferred() const
|
|
|
|
|
{
|
2014-10-14 10:10:58 +02:00
|
|
|
|
|
|
|
|
bool alwaysPreferDesignMode = false;
|
|
|
|
|
// always prefer design mode for .ui.qml files
|
|
|
|
|
if (textDocument() && textDocument()->mimeType() == QLatin1String(QmlJSTools::Constants::QMLUI_MIMETYPE))
|
|
|
|
|
alwaysPreferDesignMode = true;
|
|
|
|
|
|
2014-08-20 01:47:42 +02:00
|
|
|
// stay in design mode if we are there
|
2016-03-25 20:00:19 +01:00
|
|
|
Id mode = ModeManager::currentMode();
|
|
|
|
|
return alwaysPreferDesignMode || mode == Core::Constants::MODE_DESIGN;
|
2014-08-20 01:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 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);
|
2014-08-23 00:19:48 +02:00
|
|
|
|
|
|
|
|
setDocumentCreator([]() { return new QmlJSEditorDocument; });
|
|
|
|
|
setEditorWidgetCreator([]() { return new QmlJSEditorWidget; });
|
|
|
|
|
setEditorCreator([]() { return new QmlJSEditor; });
|
|
|
|
|
setAutoCompleterCreator([]() { return new AutoCompleter; });
|
2014-09-01 16:16:44 +02:00
|
|
|
setCommentStyle(Utils::CommentDefinition::CppStyle);
|
2014-10-15 00:36:39 +02:00
|
|
|
setParenthesesMatchingEnabled(true);
|
|
|
|
|
setMarksVisible(true);
|
|
|
|
|
setCodeFoldingSupported(true);
|
2014-08-23 00:19:48 +02:00
|
|
|
|
2014-09-30 13:08:05 +02:00
|
|
|
addHoverHandler(new QmlJSHoverHandler);
|
2014-10-01 22:39:47 +02:00
|
|
|
setCompletionAssistProvider(new QmlJSCompletionAssistProvider);
|
2014-09-30 13:08:05 +02:00
|
|
|
|
2014-09-02 12:25:20 +02:00
|
|
|
setEditorActionHandlers(TextEditorActionHandler::Format
|
2014-08-20 01:47:42 +02:00
|
|
|
| TextEditorActionHandler::UnCommentSelection
|
|
|
|
|
| TextEditorActionHandler::UnCollapseAll
|
|
|
|
|
| TextEditorActionHandler::FollowSymbolUnderCursor);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-07 14:21:58 +01:00
|
|
|
} // namespace Internal
|
2013-06-03 19:31:32 +02:00
|
|
|
} // namespace QmlJSEditor
|