forked from qt-creator/qt-creator
Editor: add and use editor toolbar outline setter
Simplifies switching between c++ builtin code model and clangd since we can now react on new outlines in the c++ editor widget. Fixes: QTCREATORBUG-27594 Change-Id: I76bdc301d78572cbdf4196658f751b5204743fbb Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -165,7 +165,7 @@ void CppEditorOutline::updateIndex()
|
|||||||
void CppEditorOutline::updateIndexNow()
|
void CppEditorOutline::updateIndexNow()
|
||||||
{
|
{
|
||||||
if (m_model->editorRevision() != m_editorWidget->document()->revision()) {
|
if (m_model->editorRevision() != m_editorWidget->document()->revision()) {
|
||||||
m_updateIndexTimer->start();
|
m_editorWidget->cppEditorDocument()->updateOutline();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -411,8 +411,6 @@ public:
|
|||||||
|
|
||||||
CppEditorDocument *m_cppEditorDocument;
|
CppEditorDocument *m_cppEditorDocument;
|
||||||
CppEditorOutline *m_cppEditorOutline = nullptr;
|
CppEditorOutline *m_cppEditorOutline = nullptr;
|
||||||
QAction *m_outlineAction = nullptr;
|
|
||||||
QTimer m_outlineTimer;
|
|
||||||
|
|
||||||
QTimer m_updateFunctionDeclDefLinkTimer;
|
QTimer m_updateFunctionDeclDefLinkTimer;
|
||||||
SemanticInfo m_lastSemanticInfo;
|
SemanticInfo m_lastSemanticInfo;
|
||||||
@@ -489,7 +487,7 @@ void CppEditorWidget::finalizeInitialization()
|
|||||||
connect(&d->m_localRenaming, &CppLocalRenaming::processKeyPressNormally,
|
connect(&d->m_localRenaming, &CppLocalRenaming::processKeyPressNormally,
|
||||||
this, &CppEditorWidget::processKeyNormally);
|
this, &CppEditorWidget::processKeyNormally);
|
||||||
connect(this, &QPlainTextEdit::cursorPositionChanged, this, [this] {
|
connect(this, &QPlainTextEdit::cursorPositionChanged, this, [this] {
|
||||||
if (d->shouldOfferOutline())
|
if (d->m_cppEditorOutline)
|
||||||
d->m_cppEditorOutline->updateIndex();
|
d->m_cppEditorOutline->updateIndex();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -527,8 +525,7 @@ void CppEditorWidget::finalizeInitialization()
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Toolbar: Outline/Overview combo box
|
// Toolbar: Outline/Overview combo box
|
||||||
d->m_outlineAction = insertExtraToolBarWidget(TextEditorWidget::Left,
|
setToolbarOutline(d->m_cppEditorOutline->widget());
|
||||||
d->m_cppEditorOutline->widget());
|
|
||||||
|
|
||||||
// clang-format on
|
// clang-format on
|
||||||
// Toolbar: '#' Button
|
// Toolbar: '#' Button
|
||||||
@@ -546,17 +543,8 @@ void CppEditorWidget::finalizeInitialization()
|
|||||||
insertExtraToolBarWidget(TextEditorWidget::Left, d->m_preprocessorButton);
|
insertExtraToolBarWidget(TextEditorWidget::Left, d->m_preprocessorButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
d->m_outlineTimer.setInterval(5000);
|
connect(this, &TextEditor::TextEditorWidget::toolbarOutlineChanged,
|
||||||
d->m_outlineTimer.setSingleShot(true);
|
this, &CppEditorWidget::handleOutlineChanged);
|
||||||
connect(&d->m_outlineTimer, &QTimer::timeout, this, [this] {
|
|
||||||
d->m_outlineAction->setVisible(d->shouldOfferOutline());
|
|
||||||
if (d->m_outlineAction->isVisible())
|
|
||||||
d->m_cppEditorDocument->updateOutline();
|
|
||||||
});
|
|
||||||
connect(&ClangdSettings::instance(), &ClangdSettings::changed,
|
|
||||||
&d->m_outlineTimer, qOverload<>(&QTimer::start));
|
|
||||||
connect(d->m_cppEditorDocument, &CppEditorDocument::changed,
|
|
||||||
&d->m_outlineTimer, qOverload<>(&QTimer::start));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppEditorWidget::finalizeInitializationAfterDuplication(TextEditorWidget *other)
|
void CppEditorWidget::finalizeInitializationAfterDuplication(TextEditorWidget *other)
|
||||||
@@ -758,6 +746,20 @@ const ProjectPart *CppEditorWidget::projectPart() const
|
|||||||
ProjectExplorer::ProjectTree::currentProject());
|
ProjectExplorer::ProjectTree::currentProject());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CppEditorWidget::handleOutlineChanged(const QWidget *newOutline)
|
||||||
|
{
|
||||||
|
if (d->m_cppEditorOutline && newOutline != d->m_cppEditorOutline->widget()) {
|
||||||
|
delete d->m_cppEditorOutline;
|
||||||
|
d->m_cppEditorOutline = nullptr;
|
||||||
|
}
|
||||||
|
if (newOutline == nullptr) {
|
||||||
|
if (!d->m_cppEditorOutline)
|
||||||
|
d->m_cppEditorOutline = new CppEditorOutline(this);
|
||||||
|
d->m_cppEditorOutline->updateIndex();
|
||||||
|
setToolbarOutline(d->m_cppEditorOutline->widget());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
using Utils::Text::selectAt;
|
using Utils::Text::selectAt;
|
||||||
|
|||||||
@@ -149,6 +149,8 @@ private:
|
|||||||
|
|
||||||
const ProjectPart *projectPart() const;
|
const ProjectPart *projectPart() const;
|
||||||
|
|
||||||
|
void handleOutlineChanged(const QWidget* newOutline);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<Internal::CppEditorWidgetPrivate> d;
|
QScopedPointer<Internal::CppEditorWidgetPrivate> d;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -183,7 +183,6 @@ void CppOutlineWidget::updateIndexNow()
|
|||||||
const auto revision = static_cast<unsigned>(m_editor->document()->revision());
|
const auto revision = static_cast<unsigned>(m_editor->document()->revision());
|
||||||
if (m_model->editorRevision() != revision) {
|
if (m_model->editorRevision() != revision) {
|
||||||
m_editor->cppEditorDocument()->updateOutline();
|
m_editor->cppEditorDocument()->updateOutline();
|
||||||
m_updateIndexTimer.start();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ void OverviewModel::update(CPlusPlus::Document::Ptr doc)
|
|||||||
|
|
||||||
int OverviewModel::editorRevision()
|
int OverviewModel::editorRevision()
|
||||||
{
|
{
|
||||||
return m_cppDocument ? m_cppDocument->editorRevision() : 0;
|
return m_cppDocument ? m_cppDocument->editorRevision() : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverviewModel::rebuild()
|
void OverviewModel::rebuild()
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ public:
|
|||||||
|
|
||||||
QPointer<QAction> m_popupAction;
|
QPointer<QAction> m_popupAction;
|
||||||
QPointer<Client> m_client;
|
QPointer<Client> m_client;
|
||||||
QPointer<QAction> m_outlineAction;
|
QPointer<QWidget> m_outline;
|
||||||
};
|
};
|
||||||
|
|
||||||
void updateEditorToolBar(Core::IEditor *editor)
|
void updateEditorToolBar(Core::IEditor *editor)
|
||||||
@@ -292,19 +292,16 @@ void updateEditorToolBar(Core::IEditor *editor)
|
|||||||
|
|
||||||
if (!extras->m_client || !client || extras->m_client != client
|
if (!extras->m_client || !client || extras->m_client != client
|
||||||
|| !client->supportsDocumentSymbols(document)) {
|
|| !client->supportsDocumentSymbols(document)) {
|
||||||
if (extras->m_outlineAction) {
|
if (extras->m_outline && widget->toolbarOutlineWidget() == extras->m_outline)
|
||||||
widget->toolBar()->removeAction(extras->m_outlineAction);
|
widget->setToolbarOutline(nullptr);
|
||||||
delete extras->m_outlineAction;
|
|
||||||
}
|
|
||||||
extras->m_client.clear();
|
extras->m_client.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!extras->m_client) {
|
if (!extras->m_client) {
|
||||||
QWidget *comboBox = LanguageClientOutlineWidgetFactory::createComboBox(client, textEditor);
|
extras->m_outline = LanguageClientOutlineWidgetFactory::createComboBox(client, textEditor);
|
||||||
if (comboBox) {
|
if (extras->m_outline) {
|
||||||
|
widget->setToolbarOutline(extras->m_outline);
|
||||||
extras->m_client = client;
|
extras->m_client = client;
|
||||||
extras->m_outlineAction = widget->insertExtraToolBarWidget(TextEditorWidget::Left,
|
|
||||||
comboBox);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -658,6 +658,8 @@ public:
|
|||||||
QWidget *m_toolBarWidget = nullptr;
|
QWidget *m_toolBarWidget = nullptr;
|
||||||
QToolBar *m_toolBar = nullptr;
|
QToolBar *m_toolBar = nullptr;
|
||||||
QWidget *m_stretchWidget = nullptr;
|
QWidget *m_stretchWidget = nullptr;
|
||||||
|
QAction *m_stretchAction = nullptr;
|
||||||
|
QAction *m_toolbarOutlineAction = nullptr;
|
||||||
LineColumnLabel *m_cursorPositionLabel = nullptr;
|
LineColumnLabel *m_cursorPositionLabel = nullptr;
|
||||||
FixedSizeClickLabel *m_fileEncodingLabel = nullptr;
|
FixedSizeClickLabel *m_fileEncodingLabel = nullptr;
|
||||||
QAction *m_fileEncodingLabelAction = nullptr;
|
QAction *m_fileEncodingLabelAction = nullptr;
|
||||||
@@ -945,7 +947,7 @@ TextEditorWidgetPrivate::TextEditorWidgetPrivate(TextEditorWidget *parent)
|
|||||||
m_stretchWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
m_stretchWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||||
m_toolBar = new QToolBar;
|
m_toolBar = new QToolBar;
|
||||||
m_toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
|
m_toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
|
||||||
m_toolBar->addWidget(m_stretchWidget);
|
m_stretchAction = m_toolBar->addWidget(m_stretchWidget);
|
||||||
m_toolBarWidget->layout()->addWidget(m_toolBar);
|
m_toolBarWidget->layout()->addWidget(m_toolBar);
|
||||||
|
|
||||||
m_cursorPositionLabel = new LineColumnLabel(q);
|
m_cursorPositionLabel = new LineColumnLabel(q);
|
||||||
@@ -7894,11 +7896,8 @@ QWidget *BaseTextEditor::toolBar()
|
|||||||
QAction * TextEditorWidget::insertExtraToolBarWidget(TextEditorWidget::Side side,
|
QAction * TextEditorWidget::insertExtraToolBarWidget(TextEditorWidget::Side side,
|
||||||
QWidget *widget)
|
QWidget *widget)
|
||||||
{
|
{
|
||||||
if (widget->sizePolicy().horizontalPolicy() & QSizePolicy::ExpandFlag) {
|
if (widget->sizePolicy().horizontalPolicy() & QSizePolicy::ExpandFlag)
|
||||||
if (d->m_stretchWidget)
|
d->m_stretchAction->setVisible(false);
|
||||||
d->m_stretchWidget->deleteLater();
|
|
||||||
d->m_stretchWidget = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (side == Left) {
|
if (side == Left) {
|
||||||
QAction *before = Utils::findOr(d->m_toolBar->actions(),
|
QAction *before = Utils::findOr(d->m_toolBar->actions(),
|
||||||
@@ -7912,6 +7911,46 @@ QAction * TextEditorWidget::insertExtraToolBarWidget(TextEditorWidget::Side side
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextEditorWidget::setToolbarOutline(QWidget *widget)
|
||||||
|
{
|
||||||
|
if (d->m_toolbarOutlineAction) {
|
||||||
|
if (d->m_toolBar->widgetForAction(d->m_toolbarOutlineAction) == widget)
|
||||||
|
return;
|
||||||
|
d->m_toolBar->removeAction(d->m_toolbarOutlineAction);
|
||||||
|
delete d->m_toolbarOutlineAction;
|
||||||
|
d->m_toolbarOutlineAction = nullptr;
|
||||||
|
} else if (!widget) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (widget) {
|
||||||
|
if (widget->sizePolicy().horizontalPolicy() & QSizePolicy::ExpandFlag)
|
||||||
|
d->m_stretchAction->setVisible(false);
|
||||||
|
|
||||||
|
d->m_toolbarOutlineAction = d->m_toolBar->insertWidget(d->m_stretchAction, widget);
|
||||||
|
} else {
|
||||||
|
// check for a widget with an expanding size policy otherwise re-enable the stretcher
|
||||||
|
for (auto action : d->m_toolBar->actions()) {
|
||||||
|
if (QWidget *toolbarWidget = d->m_toolBar->widgetForAction(action)) {
|
||||||
|
if (toolbarWidget->isVisible()
|
||||||
|
&& toolbarWidget->sizePolicy().horizontalPolicy() & QSizePolicy::ExpandFlag) {
|
||||||
|
d->m_stretchAction->setVisible(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d->m_stretchAction->setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit toolbarOutlineChanged(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QWidget *TextEditorWidget::toolbarOutlineWidget()
|
||||||
|
{
|
||||||
|
return d->m_toolbarOutlineAction ? d->m_toolBar->widgetForAction(d->m_toolbarOutlineAction)
|
||||||
|
: nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void TextEditorWidget::keepAutoCompletionHighlight(bool keepHighlight)
|
void TextEditorWidget::keepAutoCompletionHighlight(bool keepHighlight)
|
||||||
{
|
{
|
||||||
d->m_keepAutoCompletionHighlight = keepHighlight;
|
d->m_keepAutoCompletionHighlight = keepHighlight;
|
||||||
|
|||||||
@@ -332,6 +332,8 @@ public:
|
|||||||
|
|
||||||
enum Side { Left, Right };
|
enum Side { Left, Right };
|
||||||
QAction *insertExtraToolBarWidget(Side side, QWidget *widget);
|
QAction *insertExtraToolBarWidget(Side side, QWidget *widget);
|
||||||
|
void setToolbarOutline(QWidget* widget);
|
||||||
|
const QWidget *toolbarOutlineWidget();
|
||||||
|
|
||||||
// keep the auto completion even if the focus is lost
|
// keep the auto completion even if the focus is lost
|
||||||
void keepAutoCompletionHighlight(bool keepHighlight);
|
void keepAutoCompletionHighlight(bool keepHighlight);
|
||||||
@@ -501,6 +503,7 @@ signals:
|
|||||||
void requestUsages(const QTextCursor &cursor);
|
void requestUsages(const QTextCursor &cursor);
|
||||||
void requestRename(const QTextCursor &cursor);
|
void requestRename(const QTextCursor &cursor);
|
||||||
void optionalActionMaskChanged();
|
void optionalActionMaskChanged();
|
||||||
|
void toolbarOutlineChanged(QWidget *newOutline);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QTextBlock blockForVisibleRow(int row) const;
|
QTextBlock blockForVisibleRow(int row) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user