forked from qt-creator/qt-creator
Move MinimizableInfoBars from CppEditorDocument to IDocument
Similar to the InfoBar. The only thing that an editor implementation needs to do is to set a settings group and the possible info bars in the document constructor. And later call document->minimizableInfoBars()->setInfoVisible(id, visible) to manage the state. Change-Id: I23afb3639b70b1bfccd424579da018280a7fe2cb Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/infobar.h>
|
#include <utils/infobar.h>
|
||||||
|
#include <utils/minimizableinfobars.h>
|
||||||
#include <utils/optional.h>
|
#include <utils/optional.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
@@ -226,6 +227,7 @@ public:
|
|||||||
QString uniqueDisplayName;
|
QString uniqueDisplayName;
|
||||||
Utils::FilePath autoSavePath;
|
Utils::FilePath autoSavePath;
|
||||||
Utils::InfoBar *infoBar = nullptr;
|
Utils::InfoBar *infoBar = nullptr;
|
||||||
|
MinimizableInfoBars *minimizableInfoBars = nullptr;
|
||||||
Id id;
|
Id id;
|
||||||
optional<bool> fileIsReadOnly;
|
optional<bool> fileIsReadOnly;
|
||||||
bool temporary = false;
|
bool temporary = false;
|
||||||
@@ -678,6 +680,13 @@ Utils::InfoBar *IDocument::infoBar()
|
|||||||
return d->infoBar;
|
return d->infoBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MinimizableInfoBars *IDocument::minimizableInfoBars()
|
||||||
|
{
|
||||||
|
if (!d->minimizableInfoBars)
|
||||||
|
d->minimizableInfoBars = new Utils::MinimizableInfoBars(*infoBar());
|
||||||
|
return d->minimizableInfoBars;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Sets the absolute \a filePath of the file that backs this document. The
|
Sets the absolute \a filePath of the file that backs this document. The
|
||||||
default implementation sets the file name and sends the filePathChanged() and
|
default implementation sets the file name and sends the filePathChanged() and
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
namespace Utils {
|
namespace Utils {
|
||||||
class FilePath;
|
class FilePath;
|
||||||
class InfoBar;
|
class InfoBar;
|
||||||
|
class MinimizableInfoBars;
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
@@ -133,6 +134,7 @@ public:
|
|||||||
void setWriteWarning(bool has);
|
void setWriteWarning(bool has);
|
||||||
|
|
||||||
Utils::InfoBar *infoBar();
|
Utils::InfoBar *infoBar();
|
||||||
|
Utils::MinimizableInfoBars *minimizableInfoBars();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// For meta data changes: file name, modified state, ...
|
// For meta data changes: file name, modified state, ...
|
||||||
|
@@ -50,6 +50,7 @@
|
|||||||
#include <utils/executeondestruction.h>
|
#include <utils/executeondestruction.h>
|
||||||
#include <utils/infobar.h>
|
#include <utils/infobar.h>
|
||||||
#include <utils/mimeutils.h>
|
#include <utils/mimeutils.h>
|
||||||
|
#include <utils/minimizableinfobars.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/runextensions.h>
|
#include <utils/runextensions.h>
|
||||||
|
|
||||||
@@ -106,7 +107,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
CppEditorDocument::CppEditorDocument()
|
CppEditorDocument::CppEditorDocument()
|
||||||
: m_minimizableInfoBars(*infoBar())
|
|
||||||
{
|
{
|
||||||
setId(CppEditor::Constants::CPPEDITOR_ID);
|
setId(CppEditor::Constants::CPPEDITOR_ID);
|
||||||
setSyntaxHighlighter(new CppHighlighter);
|
setSyntaxHighlighter(new CppHighlighter);
|
||||||
@@ -130,8 +130,8 @@ CppEditorDocument::CppEditorDocument()
|
|||||||
connect(&m_parseContextModel, &ParseContextModel::preferredParseContextChanged,
|
connect(&m_parseContextModel, &ParseContextModel::preferredParseContextChanged,
|
||||||
this, &CppEditorDocument::reparseWithPreferredParseContext);
|
this, &CppEditorDocument::reparseWithPreferredParseContext);
|
||||||
|
|
||||||
m_minimizableInfoBars.setSettingsGroup(Constants::CPPEDITOR_SETTINGSGROUP);
|
minimizableInfoBars()->setSettingsGroup(Constants::CPPEDITOR_SETTINGSGROUP);
|
||||||
m_minimizableInfoBars.setPossibleInfoBarEntries(
|
minimizableInfoBars()->setPossibleInfoBarEntries(
|
||||||
{{NO_PROJECT_CONFIGURATION,
|
{{NO_PROJECT_CONFIGURATION,
|
||||||
tr("<b>Warning</b>: This file is not part of any project. "
|
tr("<b>Warning</b>: This file is not part of any project. "
|
||||||
"The code model might have issues parsing this file properly.")}});
|
"The code model might have issues parsing this file properly.")}});
|
||||||
@@ -413,25 +413,20 @@ QFuture<CursorInfo> CppEditorDocument::cursorInfo(const CursorInfoParams ¶ms
|
|||||||
return processor()->cursorInfo(params);
|
return processor()->cursorInfo(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Utils::MinimizableInfoBars &CppEditorDocument::minimizableInfoBars() const
|
|
||||||
{
|
|
||||||
return m_minimizableInfoBars;
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseEditorDocumentProcessor *CppEditorDocument::processor()
|
BaseEditorDocumentProcessor *CppEditorDocument::processor()
|
||||||
{
|
{
|
||||||
if (!m_processor) {
|
if (!m_processor) {
|
||||||
m_processor.reset(mm()->createEditorDocumentProcessor(this));
|
m_processor.reset(mm()->createEditorDocumentProcessor(this));
|
||||||
connect(m_processor.data(), &BaseEditorDocumentProcessor::projectPartInfoUpdated,
|
connect(m_processor.data(),
|
||||||
[this] (const ProjectPartInfo &info)
|
&BaseEditorDocumentProcessor::projectPartInfoUpdated,
|
||||||
{
|
[this](const ProjectPartInfo &info) {
|
||||||
const bool hasProjectPart = !(info.hints & ProjectPartInfo::IsFallbackMatch);
|
const bool hasProjectPart = !(info.hints & ProjectPartInfo::IsFallbackMatch);
|
||||||
m_minimizableInfoBars.setInfoVisible(NO_PROJECT_CONFIGURATION, !hasProjectPart);
|
minimizableInfoBars()->setInfoVisible(NO_PROJECT_CONFIGURATION, !hasProjectPart);
|
||||||
m_parseContextModel.update(info);
|
m_parseContextModel.update(info);
|
||||||
const bool isAmbiguous = info.hints & ProjectPartInfo::IsAmbiguousMatch;
|
const bool isAmbiguous = info.hints & ProjectPartInfo::IsAmbiguousMatch;
|
||||||
const bool isProjectFile = info.hints & ProjectPartInfo::IsFromProjectMatch;
|
const bool isProjectFile = info.hints & ProjectPartInfo::IsFromProjectMatch;
|
||||||
showHideInfoBarAboutMultipleParseContexts(isAmbiguous && isProjectFile);
|
showHideInfoBarAboutMultipleParseContexts(isAmbiguous && isProjectFile);
|
||||||
});
|
});
|
||||||
connect(m_processor.data(), &BaseEditorDocumentProcessor::codeWarningsUpdated,
|
connect(m_processor.data(), &BaseEditorDocumentProcessor::codeWarningsUpdated,
|
||||||
[this] (unsigned revision,
|
[this] (unsigned revision,
|
||||||
const QList<QTextEdit::ExtraSelection> selections,
|
const QList<QTextEdit::ExtraSelection> selections,
|
||||||
|
@@ -33,7 +33,6 @@
|
|||||||
#include "editordocumenthandle.h"
|
#include "editordocumenthandle.h"
|
||||||
|
|
||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
#include <utils/minimizableinfobars.h>
|
|
||||||
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
@@ -65,7 +64,6 @@ public:
|
|||||||
|
|
||||||
void scheduleProcessDocument();
|
void scheduleProcessDocument();
|
||||||
|
|
||||||
const Utils::MinimizableInfoBars &minimizableInfoBars() const;
|
|
||||||
ParseContextModel &parseContextModel();
|
ParseContextModel &parseContextModel();
|
||||||
|
|
||||||
QFuture<CursorInfo> cursorInfo(const CursorInfoParams ¶ms);
|
QFuture<CursorInfo> cursorInfo(const CursorInfoParams ¶ms);
|
||||||
@@ -135,7 +133,6 @@ private:
|
|||||||
// (Un)Registration in CppModelManager
|
// (Un)Registration in CppModelManager
|
||||||
QScopedPointer<CppEditorDocumentHandle> m_editorDocumentHandle;
|
QScopedPointer<CppEditorDocumentHandle> m_editorDocumentHandle;
|
||||||
|
|
||||||
Utils::MinimizableInfoBars m_minimizableInfoBars;
|
|
||||||
ParseContextModel m_parseContextModel;
|
ParseContextModel m_parseContextModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -552,10 +552,6 @@ void CppEditorWidget::finalizeInitialization()
|
|||||||
insertExtraToolBarWidget(TextEditorWidget::Left, d->m_preprocessorButton);
|
insertExtraToolBarWidget(TextEditorWidget::Left, d->m_preprocessorButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toolbar: Actions to show minimized info bars
|
|
||||||
d->m_cppEditorDocument->minimizableInfoBars().createShowInfoBarActions(
|
|
||||||
[this](QWidget *w) { return this->insertExtraToolBarWidget(TextEditorWidget::Left, w); });
|
|
||||||
|
|
||||||
d->m_outlineTimer.setInterval(5000);
|
d->m_outlineTimer.setInterval(5000);
|
||||||
d->m_outlineTimer.setSingleShot(true);
|
d->m_outlineTimer.setSingleShot(true);
|
||||||
connect(&d->m_outlineTimer, &QTimer::timeout, this, [this] {
|
connect(&d->m_outlineTimer, &QTimer::timeout, this, [this] {
|
||||||
|
@@ -80,6 +80,7 @@
|
|||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/infobar.h>
|
#include <utils/infobar.h>
|
||||||
#include <utils/mimeutils.h>
|
#include <utils/mimeutils.h>
|
||||||
|
#include <utils/minimizableinfobars.h>
|
||||||
#include <utils/multitextcursor.h>
|
#include <utils/multitextcursor.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/styledbar.h>
|
#include <utils/styledbar.h>
|
||||||
@@ -8534,6 +8535,12 @@ BaseTextEditor *TextEditorFactoryPrivate::createEditorHelper(const TextDocumentP
|
|||||||
if (m_useGenericHighlighter)
|
if (m_useGenericHighlighter)
|
||||||
textEditorWidget->setupGenericHighlighter();
|
textEditorWidget->setupGenericHighlighter();
|
||||||
textEditorWidget->finalizeInitialization();
|
textEditorWidget->finalizeInitialization();
|
||||||
|
|
||||||
|
// Toolbar: Actions to show minimized info bars
|
||||||
|
document->minimizableInfoBars()->createShowInfoBarActions([textEditorWidget](QWidget *w) {
|
||||||
|
return textEditorWidget->insertExtraToolBarWidget(TextEditorWidget::Left, w);
|
||||||
|
});
|
||||||
|
|
||||||
editor->finalizeInitialization();
|
editor->finalizeInitialization();
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user