forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/4.3'
Conflicts: src/plugins/genericprojectmanager/genericproject.cpp src/plugins/genericprojectmanager/genericproject.h src/plugins/genericprojectmanager/genericprojectnodes.cpp src/plugins/genericprojectmanager/genericprojectnodes.h Change-Id: Ie0c870f68c8d200a75489b75860987655b2f6175
This commit is contained in:
@@ -105,10 +105,7 @@ namespace Internal {
|
||||
|
||||
QmlJSEditorWidget::QmlJSEditorWidget()
|
||||
{
|
||||
m_outlineCombo = 0;
|
||||
m_contextPane = 0;
|
||||
m_findReferences = new FindReferences(this);
|
||||
|
||||
setLanguageSettingsId(QmlJSTools::Constants::QML_JS_SETTINGS_ID);
|
||||
}
|
||||
|
||||
@@ -142,7 +139,6 @@ void QmlJSEditorWidget::finalizeInitialization()
|
||||
&m_contextPaneTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
||||
connect(m_contextPane, &IContextPane::closed, this, &QmlJSEditorWidget::showTextMarker);
|
||||
}
|
||||
m_oldCursorPosition = -1;
|
||||
|
||||
connect(this->document(), &QTextDocument::modificationChanged,
|
||||
this, &QmlJSEditorWidget::modificationChanged);
|
||||
@@ -161,7 +157,6 @@ QModelIndex QmlJSEditorWidget::outlineModelIndex()
|
||||
{
|
||||
if (!m_outlineModelIndex.isValid()) {
|
||||
m_outlineModelIndex = indexForPosition(position());
|
||||
emit outlineModelIndexChanged(m_outlineModelIndex);
|
||||
}
|
||||
return m_outlineModelIndex;
|
||||
}
|
||||
@@ -223,6 +218,11 @@ void QmlJSEditorWidget::modificationChanged(bool changed)
|
||||
m_modelManager->fileChangedOnDisk(textDocument()->filePath().toString());
|
||||
}
|
||||
|
||||
bool QmlJSEditorWidget::isOutlineCursorChangesBlocked()
|
||||
{
|
||||
return hasFocus() || m_blockOutLineCursorChanges;
|
||||
}
|
||||
|
||||
void QmlJSEditorWidget::jumpToOutlineElement(int /*index*/)
|
||||
{
|
||||
QModelIndex index = m_outlineCombo->view()->currentIndex();
|
||||
@@ -253,6 +253,7 @@ void QmlJSEditorWidget::updateOutlineIndexNow()
|
||||
|
||||
m_outlineModelIndex = QModelIndex(); // invalidate
|
||||
QModelIndex comboIndex = outlineModelIndex();
|
||||
emit outlineModelIndexChanged(m_outlineModelIndex);
|
||||
|
||||
if (comboIndex.isValid()) {
|
||||
bool blocked = m_outlineCombo->blockSignals(true);
|
||||
@@ -504,18 +505,6 @@ QString QmlJSEditorWidget::wordUnderCursor() const
|
||||
return word;
|
||||
}
|
||||
|
||||
bool QmlJSEditorWidget::isClosingBrace(const QList<Token> &tokens) const
|
||||
{
|
||||
|
||||
if (tokens.size() == 1) {
|
||||
const Token firstToken = tokens.first();
|
||||
|
||||
return firstToken.is(Token::RightBrace) || firstToken.is(Token::RightBracket);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void QmlJSEditorWidget::createToolBar()
|
||||
{
|
||||
m_outlineCombo = new QComboBox;
|
||||
@@ -546,8 +535,6 @@ void QmlJSEditorWidget::createToolBar()
|
||||
this, &QmlJSEditorWidget::jumpToOutlineElement);
|
||||
connect(m_qmlJsEditorDocument->outlineModel(), &QmlOutlineModel::updated,
|
||||
static_cast<QTreeView *>(m_outlineCombo->view()), &QTreeView::expandAll);
|
||||
connect(m_qmlJsEditorDocument->outlineModel(), &QmlOutlineModel::updated,
|
||||
this, &QmlJSEditorWidget::updateOutlineIndexNow);
|
||||
|
||||
connect(this, &QmlJSEditorWidget::cursorPositionChanged,
|
||||
&m_updateOutlineIndexTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
||||
@@ -826,6 +813,7 @@ void QmlJSEditorWidget::showContextPane()
|
||||
|
||||
void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
||||
{
|
||||
m_blockOutLineCursorChanges = true;
|
||||
QPointer<QMenu> menu(new QMenu(this));
|
||||
|
||||
QMenu *refactoringMenu = new QMenu(tr("Refactoring"), menu);
|
||||
@@ -870,6 +858,7 @@ void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
||||
|
||||
menu->exec(e->globalPos());
|
||||
delete menu;
|
||||
m_blockOutLineCursorChanges = false;
|
||||
}
|
||||
|
||||
bool QmlJSEditorWidget::event(QEvent *e)
|
||||
|
||||
@@ -66,6 +66,8 @@ public:
|
||||
QmlJSEditorDocument *qmlJsEditorDocument() const;
|
||||
|
||||
QModelIndex outlineModelIndex();
|
||||
void updateOutlineIndexNow();
|
||||
bool isOutlineCursorChangesBlocked();
|
||||
|
||||
TextEditor::AssistInterface *createAssistInterface(TextEditor::AssistKind assistKind,
|
||||
TextEditor::AssistReason reason) const override;
|
||||
@@ -84,7 +86,6 @@ private:
|
||||
void modificationChanged(bool);
|
||||
|
||||
void jumpToOutlineElement(int index);
|
||||
void updateOutlineIndexNow();
|
||||
void updateContextPane();
|
||||
void showTextMarker();
|
||||
|
||||
@@ -109,24 +110,23 @@ protected:
|
||||
void onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker) override;
|
||||
|
||||
private:
|
||||
bool isClosingBrace(const QList<QmlJS::Token> &tokens) const;
|
||||
|
||||
void setSelectedElements();
|
||||
QString wordUnderCursor() const;
|
||||
|
||||
QModelIndex indexForPosition(unsigned cursorPosition, const QModelIndex &rootIndex = QModelIndex()) const;
|
||||
bool hideContextPane();
|
||||
|
||||
QmlJSEditorDocument *m_qmlJsEditorDocument;
|
||||
QmlJSEditorDocument *m_qmlJsEditorDocument = nullptr;
|
||||
QTimer m_updateUsesTimer; // to wait for multiple text cursor position changes
|
||||
QTimer m_updateOutlineIndexTimer;
|
||||
QTimer m_contextPaneTimer;
|
||||
QComboBox *m_outlineCombo;
|
||||
QModelIndex m_outlineModelIndex;
|
||||
QmlJS::ModelManagerInterface *m_modelManager;
|
||||
bool m_blockOutLineCursorChanges = false;
|
||||
QmlJS::ModelManagerInterface *m_modelManager = nullptr;
|
||||
|
||||
QmlJS::IContextPane *m_contextPane;
|
||||
int m_oldCursorPosition;
|
||||
QmlJS::IContextPane *m_contextPane = nullptr;
|
||||
int m_oldCursorPosition = -1;
|
||||
|
||||
FindReferences *m_findReferences;
|
||||
};
|
||||
|
||||
@@ -455,12 +455,9 @@ namespace QmlJSEditor {
|
||||
namespace Internal {
|
||||
|
||||
QmlJSEditorDocumentPrivate::QmlJSEditorDocumentPrivate(QmlJSEditorDocument *parent)
|
||||
: q(parent),
|
||||
m_semanticInfoDocRevision(-1),
|
||||
m_semanticHighlighter(new SemanticHighlighter(parent)),
|
||||
m_semanticHighlightingNecessary(false),
|
||||
m_outlineModelNeedsUpdate(false),
|
||||
m_outlineModel(new QmlOutlineModel(parent))
|
||||
: q(parent)
|
||||
, m_semanticHighlighter(new SemanticHighlighter(parent))
|
||||
, m_outlineModel(new QmlOutlineModel(parent))
|
||||
{
|
||||
ModelManagerInterface *modelManager = ModelManagerInterface::instance();
|
||||
|
||||
|
||||
@@ -58,19 +58,19 @@ public:
|
||||
void updateOutlineModel();
|
||||
|
||||
public:
|
||||
QmlJSEditorDocument *q;
|
||||
QmlJSEditorDocument *q = nullptr;
|
||||
QTimer m_updateDocumentTimer; // used to compress multiple document changes
|
||||
QTimer m_reupdateSemanticInfoTimer; // used to compress multiple libraryInfo changes
|
||||
int m_semanticInfoDocRevision; // document revision to which the semantic info is currently updated to
|
||||
int m_semanticInfoDocRevision = -1; // document revision to which the semantic info is currently updated to
|
||||
SemanticInfoUpdater *m_semanticInfoUpdater;
|
||||
QmlJSTools::SemanticInfo m_semanticInfo;
|
||||
QVector<QTextLayout::FormatRange> m_diagnosticRanges;
|
||||
Internal::SemanticHighlighter *m_semanticHighlighter;
|
||||
bool m_semanticHighlightingNecessary;
|
||||
bool m_outlineModelNeedsUpdate;
|
||||
Internal::SemanticHighlighter *m_semanticHighlighter = nullptr;
|
||||
bool m_semanticHighlightingNecessary = false;
|
||||
bool m_outlineModelNeedsUpdate = false;
|
||||
bool m_firstSementicInfo = true;
|
||||
QTimer m_updateOutlineModelTimer;
|
||||
Internal::QmlOutlineModel *m_outlineModel;
|
||||
Internal::QmlOutlineModel *m_outlineModel = nullptr;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
|
||||
@@ -94,13 +94,10 @@ void QmlJSOutlineFilterModel::setFilterBindings(bool filterBindings)
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
QmlJSOutlineWidget::QmlJSOutlineWidget(QWidget *parent) :
|
||||
TextEditor::IOutlineWidget(parent),
|
||||
m_treeView(new QmlJSOutlineTreeView(this)),
|
||||
m_filterModel(new QmlJSOutlineFilterModel(this)),
|
||||
m_editor(0),
|
||||
m_enableCursorSync(true),
|
||||
m_blockCursorSync(false)
|
||||
QmlJSOutlineWidget::QmlJSOutlineWidget(QWidget *parent)
|
||||
: TextEditor::IOutlineWidget(parent)
|
||||
, m_treeView(new QmlJSOutlineTreeView(this))
|
||||
, m_filterModel(new QmlJSOutlineFilterModel(this))
|
||||
{
|
||||
m_filterModel->setFilterBindings(false);
|
||||
|
||||
@@ -127,7 +124,7 @@ void QmlJSOutlineWidget::setEditor(QmlJSEditorWidget *editor)
|
||||
m_editor = editor;
|
||||
|
||||
m_filterModel->setSourceModel(m_editor->qmlJsEditorDocument()->outlineModel());
|
||||
modelUpdated();
|
||||
m_treeView->expandAll();
|
||||
|
||||
connect(m_treeView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
this, &QmlJSOutlineWidget::updateSelectionInText);
|
||||
@@ -137,22 +134,21 @@ void QmlJSOutlineWidget::setEditor(QmlJSEditorWidget *editor)
|
||||
|
||||
connect(m_editor, &QmlJSEditorWidget::outlineModelIndexChanged,
|
||||
this, &QmlJSOutlineWidget::updateSelectionInTree);
|
||||
connect(m_editor->qmlJsEditorDocument()->outlineModel(), &QmlOutlineModel::updated,
|
||||
this, &QmlJSOutlineWidget::modelUpdated);
|
||||
connect(m_editor->qmlJsEditorDocument()->outlineModel(), &QmlOutlineModel::updated, this, [this] () {
|
||||
m_treeView->expandAll();
|
||||
m_editor->updateOutlineIndexNow();
|
||||
});
|
||||
}
|
||||
|
||||
QList<QAction*> QmlJSOutlineWidget::filterMenuActions() const
|
||||
{
|
||||
QList<QAction*> list;
|
||||
list.append(m_showBindingsAction);
|
||||
return list;
|
||||
return {m_showBindingsAction};
|
||||
}
|
||||
|
||||
void QmlJSOutlineWidget::setCursorSynchronization(bool syncWithCursor)
|
||||
{
|
||||
m_enableCursorSync = syncWithCursor;
|
||||
if (m_enableCursorSync)
|
||||
updateSelectionInTree(m_editor->outlineModelIndex());
|
||||
m_editor->updateOutlineIndexNow();
|
||||
}
|
||||
|
||||
void QmlJSOutlineWidget::restoreSettings(const QVariantMap &map)
|
||||
@@ -163,14 +159,7 @@ void QmlJSOutlineWidget::restoreSettings(const QVariantMap &map)
|
||||
|
||||
QVariantMap QmlJSOutlineWidget::settings() const
|
||||
{
|
||||
QVariantMap map;
|
||||
map.insert(QLatin1String("QmlJSOutline.ShowBindings"), m_showBindingsAction->isChecked());
|
||||
return map;
|
||||
}
|
||||
|
||||
void QmlJSOutlineWidget::modelUpdated()
|
||||
{
|
||||
m_treeView->expandAll();
|
||||
return {{QLatin1String("QmlJSOutline.ShowBindings"), m_showBindingsAction->isChecked()}};
|
||||
}
|
||||
|
||||
void QmlJSOutlineWidget::updateSelectionInTree(const QModelIndex &index)
|
||||
@@ -206,27 +195,29 @@ void QmlJSOutlineWidget::updateSelectionInText(const QItemSelection &selection)
|
||||
|
||||
void QmlJSOutlineWidget::updateTextCursor(const QModelIndex &index)
|
||||
{
|
||||
QModelIndex sourceIndex = m_filterModel->mapToSource(index);
|
||||
AST::SourceLocation location
|
||||
= m_editor->qmlJsEditorDocument()->outlineModel()->sourceLocation(sourceIndex);
|
||||
if (!m_editor->isOutlineCursorChangesBlocked()) {
|
||||
QModelIndex sourceIndex = m_filterModel->mapToSource(index);
|
||||
AST::SourceLocation location
|
||||
= m_editor->qmlJsEditorDocument()->outlineModel()->sourceLocation(sourceIndex);
|
||||
|
||||
if (!location.isValid())
|
||||
return;
|
||||
if (!location.isValid())
|
||||
return;
|
||||
|
||||
const QTextBlock lastBlock = m_editor->document()->lastBlock();
|
||||
const uint textLength = lastBlock.position() + lastBlock.length();
|
||||
if (location.offset >= textLength)
|
||||
return;
|
||||
const QTextBlock lastBlock = m_editor->document()->lastBlock();
|
||||
const uint textLength = lastBlock.position() + lastBlock.length();
|
||||
if (location.offset >= textLength)
|
||||
return;
|
||||
|
||||
Core::EditorManager::cutForwardNavigationHistory();
|
||||
Core::EditorManager::addCurrentPositionToNavigationHistory();
|
||||
Core::EditorManager::cutForwardNavigationHistory();
|
||||
Core::EditorManager::addCurrentPositionToNavigationHistory();
|
||||
|
||||
QTextCursor textCursor = m_editor->textCursor();
|
||||
m_blockCursorSync = true;
|
||||
textCursor.setPosition(location.offset);
|
||||
m_editor->setTextCursor(textCursor);
|
||||
m_editor->centerCursor();
|
||||
m_blockCursorSync = false;
|
||||
QTextCursor textCursor = m_editor->textCursor();
|
||||
m_blockCursorSync = true;
|
||||
textCursor.setPosition(location.offset);
|
||||
m_editor->setTextCursor(textCursor);
|
||||
m_editor->centerCursor();
|
||||
m_blockCursorSync = false;
|
||||
}
|
||||
}
|
||||
|
||||
void QmlJSOutlineWidget::focusEditor()
|
||||
@@ -237,8 +228,8 @@ void QmlJSOutlineWidget::focusEditor()
|
||||
void QmlJSOutlineWidget::setShowBindings(bool showBindings)
|
||||
{
|
||||
m_filterModel->setFilterBindings(!showBindings);
|
||||
modelUpdated();
|
||||
updateSelectionInTree(m_editor->outlineModelIndex());
|
||||
m_treeView->expandAll();
|
||||
m_editor->updateOutlineIndexNow();
|
||||
}
|
||||
|
||||
bool QmlJSOutlineWidget::syncCursor()
|
||||
|
||||
@@ -31,6 +31,10 @@
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Core { class IEditor; }
|
||||
|
||||
namespace QmlJS { class Editor; }
|
||||
@@ -66,13 +70,12 @@ public:
|
||||
void setEditor(QmlJSEditorWidget *editor);
|
||||
|
||||
// IOutlineWidget
|
||||
virtual QList<QAction*> filterMenuActions() const;
|
||||
virtual void setCursorSynchronization(bool syncWithCursor);
|
||||
virtual void restoreSettings(const QVariantMap &map);
|
||||
virtual QVariantMap settings() const;
|
||||
virtual QList<QAction*> filterMenuActions() const override;
|
||||
virtual void setCursorSynchronization(bool syncWithCursor) override;
|
||||
virtual void restoreSettings(const QVariantMap &map) override;
|
||||
virtual QVariantMap settings() const override;
|
||||
|
||||
private:
|
||||
void modelUpdated();
|
||||
void updateSelectionInTree(const QModelIndex &index);
|
||||
void updateSelectionInText(const QItemSelection &selection);
|
||||
void updateTextCursor(const QModelIndex &index);
|
||||
@@ -81,14 +84,14 @@ private:
|
||||
bool syncCursor();
|
||||
|
||||
private:
|
||||
QmlJSOutlineTreeView *m_treeView;
|
||||
QmlJSOutlineFilterModel *m_filterModel;
|
||||
QmlJSEditorWidget *m_editor;
|
||||
QmlJSOutlineTreeView *m_treeView = nullptr;
|
||||
QmlJSOutlineFilterModel *m_filterModel = nullptr;
|
||||
QmlJSEditorWidget *m_editor = nullptr;
|
||||
|
||||
QAction *m_showBindingsAction;
|
||||
QAction *m_showBindingsAction = nullptr;
|
||||
|
||||
bool m_enableCursorSync;
|
||||
bool m_blockCursorSync;
|
||||
bool m_enableCursorSync = true;
|
||||
bool m_blockCursorSync = false;
|
||||
};
|
||||
|
||||
class QmlJSOutlineWidgetFactory : public TextEditor::IOutlineWidgetFactory
|
||||
|
||||
@@ -436,7 +436,9 @@ protected:
|
||||
const TextEditor::FontSettings &fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
|
||||
|
||||
QTextCharFormat format;
|
||||
if (d.severity == Severity::Warning || d.severity == Severity::MaybeWarning) {
|
||||
if (d.severity == Severity::Warning
|
||||
|| d.severity == Severity::MaybeWarning
|
||||
|| d.severity == Severity::ReadingTypeInfoWarning) {
|
||||
format = fontSettings.toTextCharFormat(TextEditor::C_WARNING);
|
||||
} else if (d.severity == Severity::Error || d.severity == Severity::MaybeError) {
|
||||
format = fontSettings.toTextCharFormat(TextEditor::C_ERROR);
|
||||
|
||||
Reference in New Issue
Block a user