forked from qt-creator/qt-creator
CppEditor: Convert to new construction scheme
Change-Id: I947f76b4dbc3a197cd49993855c3b0f5e3dc7b49 Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -148,21 +148,26 @@ CppEditorWidgetPrivate::CppEditorWidgetPrivate(CppEditorWidget *q)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CppEditorWidget::CppEditorWidget(TextEditor::BaseTextDocumentPtr doc, CppEditor *editor)
|
CppEditorWidget::CppEditorWidget()
|
||||||
|
: d(new CppEditorWidgetPrivate(this))
|
||||||
{
|
{
|
||||||
qRegisterMetaType<SemanticInfo>("CppTools::SemanticInfo");
|
qRegisterMetaType<SemanticInfo>("CppTools::SemanticInfo");
|
||||||
|
}
|
||||||
|
|
||||||
editor->setEditorWidget(this);
|
void CppEditorWidget::finalizeInitialization()
|
||||||
|
{
|
||||||
|
d->m_cppEditorDocument = qobject_cast<CppEditorDocument *>(textDocument());
|
||||||
|
|
||||||
setTextDocument(doc);
|
|
||||||
d.reset(new CppEditorWidgetPrivate(this));
|
|
||||||
setAutoCompleter(new CppAutoCompleter);
|
|
||||||
setLanguageSettingsId(CppTools::Constants::CPP_SETTINGS_ID);
|
setLanguageSettingsId(CppTools::Constants::CPP_SETTINGS_ID);
|
||||||
setCodeFoldingSupported(true);
|
setCodeFoldingSupported(true);
|
||||||
setMarksVisible(true);
|
setMarksVisible(true);
|
||||||
setParenthesesMatchingEnabled(true);
|
setParenthesesMatchingEnabled(true);
|
||||||
setRevisionsVisible(true);
|
setRevisionsVisible(true);
|
||||||
|
|
||||||
|
// function combo box sorting
|
||||||
|
connect(CppEditorPlugin::instance(), &CppEditorPlugin::outlineSortingChanged,
|
||||||
|
outline(), &CppEditorOutline::setSorted);
|
||||||
|
|
||||||
connect(d->m_cppEditorDocument, &CppEditorDocument::codeWarningsUpdated,
|
connect(d->m_cppEditorDocument, &CppEditorDocument::codeWarningsUpdated,
|
||||||
this, &CppEditorWidget::onCodeWarningsUpdated);
|
this, &CppEditorWidget::onCodeWarningsUpdated);
|
||||||
connect(d->m_cppEditorDocument, &CppEditorDocument::ifdefedOutBlocksUpdated,
|
connect(d->m_cppEditorDocument, &CppEditorDocument::ifdefedOutBlocksUpdated,
|
||||||
@@ -222,6 +227,12 @@ CppEditorWidget::CppEditorWidget(TextEditor::BaseTextDocumentPtr doc, CppEditor
|
|||||||
connect(d->m_preprocessorButton, SIGNAL(clicked()), this, SLOT(showPreProcessorWidget()));
|
connect(d->m_preprocessorButton, SIGNAL(clicked()), this, SLOT(showPreProcessorWidget()));
|
||||||
insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Left, d->m_preprocessorButton);
|
insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Left, d->m_preprocessorButton);
|
||||||
insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Left, d->m_cppEditorOutline->widget());
|
insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Left, d->m_cppEditorOutline->widget());
|
||||||
|
|
||||||
|
// updateSemanticInfo(semanticInfo());
|
||||||
|
// updateFunctionDeclDefLink();
|
||||||
|
// d->m_cppEditorOutline->update();
|
||||||
|
// const ExtraSelectionKind selectionKind = CodeWarningsSelection;
|
||||||
|
// setExtraSelections(selectionKind, extraSelections(selectionKind));
|
||||||
}
|
}
|
||||||
|
|
||||||
CppEditorWidget::~CppEditorWidget()
|
CppEditorWidget::~CppEditorWidget()
|
||||||
@@ -229,20 +240,6 @@ CppEditorWidget::~CppEditorWidget()
|
|||||||
// non-inline destructor, see section "Forward Declared Pointers" of QScopedPointer.
|
// non-inline destructor, see section "Forward Declared Pointers" of QScopedPointer.
|
||||||
}
|
}
|
||||||
|
|
||||||
CppEditorWidget *CppEditorWidget::duplicate(CppEditor *editor) const
|
|
||||||
{
|
|
||||||
QTC_ASSERT(editor, return 0);
|
|
||||||
|
|
||||||
CppEditorWidget *widget = new CppEditorWidget(textDocumentPtr(), editor);
|
|
||||||
widget->updateSemanticInfo(semanticInfo());
|
|
||||||
widget->updateFunctionDeclDefLink();
|
|
||||||
widget->d->m_cppEditorOutline->update();
|
|
||||||
const ExtraSelectionKind selectionKind = CodeWarningsSelection;
|
|
||||||
widget->setExtraSelections(selectionKind, extraSelections(selectionKind));
|
|
||||||
|
|
||||||
return widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
CppEditorDocument *CppEditorWidget::cppEditorDocument() const
|
CppEditorDocument *CppEditorWidget::cppEditorDocument() const
|
||||||
{
|
{
|
||||||
return d->m_cppEditorDocument;
|
return d->m_cppEditorDocument;
|
||||||
@@ -564,15 +561,6 @@ void CppEditorWidget::keyPressEvent(QKeyEvent *e)
|
|||||||
TextEditor::BaseTextEditorWidget::keyPressEvent(e);
|
TextEditor::BaseTextEditorWidget::keyPressEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IEditor *CppEditor::duplicate()
|
|
||||||
{
|
|
||||||
CppEditor *editor = new CppEditor;
|
|
||||||
CppEditorWidget *widget = qobject_cast<CppEditorWidget *>(editorWidget())->duplicate(editor);
|
|
||||||
CppEditorPlugin::instance()->initializeEditor(widget);
|
|
||||||
editor->configureCodeAssistant();
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CppEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
bool CppEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
|
||||||
{
|
{
|
||||||
if (!TextEditor::BaseTextEditor::open(errorString, fileName, realFileName))
|
if (!TextEditor::BaseTextEditor::open(errorString, fileName, realFileName))
|
||||||
|
|||||||
@@ -57,8 +57,6 @@ class CppEditor : public TextEditor::BaseTextEditor
|
|||||||
public:
|
public:
|
||||||
CppEditor();
|
CppEditor();
|
||||||
|
|
||||||
Core::IEditor *duplicate() QTC_OVERRIDE;
|
|
||||||
|
|
||||||
bool open(QString *errorString,
|
bool open(QString *errorString,
|
||||||
const QString &fileName,
|
const QString &fileName,
|
||||||
const QString &realFileName) QTC_OVERRIDE;
|
const QString &realFileName) QTC_OVERRIDE;
|
||||||
@@ -72,10 +70,10 @@ public:
|
|||||||
static Link linkToSymbol(CPlusPlus::Symbol *symbol);
|
static Link linkToSymbol(CPlusPlus::Symbol *symbol);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CppEditorWidget(TextEditor::BaseTextDocumentPtr doc, CppEditor *editor);
|
CppEditorWidget();
|
||||||
~CppEditorWidget();
|
~CppEditorWidget();
|
||||||
|
|
||||||
CppEditorWidget *duplicate(CppEditor *editor) const;
|
void finalizeInitialization();
|
||||||
|
|
||||||
CppEditorDocument *cppEditorDocument() const;
|
CppEditorDocument *cppEditorDocument() const;
|
||||||
CppEditorOutline *outline() const;
|
CppEditorOutline *outline() const;
|
||||||
|
|||||||
@@ -29,11 +29,12 @@
|
|||||||
|
|
||||||
#include "cppeditorplugin.h"
|
#include "cppeditorplugin.h"
|
||||||
|
|
||||||
|
#include "cppautocompleter.h"
|
||||||
#include "cppclasswizard.h"
|
#include "cppclasswizard.h"
|
||||||
#include "cppcodemodelinspectordialog.h"
|
#include "cppcodemodelinspectordialog.h"
|
||||||
#include "cppeditorconstants.h"
|
#include "cppeditorconstants.h"
|
||||||
#include "cppeditordocument.h"
|
|
||||||
#include "cppeditor.h"
|
#include "cppeditor.h"
|
||||||
|
#include "cppeditordocument.h"
|
||||||
#include "cppeditoroutline.h"
|
#include "cppeditoroutline.h"
|
||||||
#include "cppfilewizard.h"
|
#include "cppfilewizard.h"
|
||||||
#include "cpphighlighter.h"
|
#include "cpphighlighter.h"
|
||||||
@@ -63,6 +64,7 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
using namespace TextEditor;
|
||||||
|
|
||||||
namespace CppEditor {
|
namespace CppEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -73,8 +75,10 @@ enum { QUICKFIX_INTERVAL = 20 };
|
|||||||
|
|
||||||
//////////////////////////// CppEditorFactory /////////////////////////////
|
//////////////////////////// CppEditorFactory /////////////////////////////
|
||||||
|
|
||||||
CppEditorFactory::CppEditorFactory(CppEditorPlugin *owner) :
|
class CppEditorFactory : public BaseTextEditorFactory
|
||||||
m_owner(owner)
|
{
|
||||||
|
public:
|
||||||
|
CppEditorFactory()
|
||||||
{
|
{
|
||||||
setId(Constants::CPPEDITOR_ID);
|
setId(Constants::CPPEDITOR_ID);
|
||||||
setDisplayName(qApp->translate("OpenWith::Editors", Constants::CPPEDITOR_DISPLAY_NAME));
|
setDisplayName(qApp->translate("OpenWith::Editors", Constants::CPPEDITOR_DISPLAY_NAME));
|
||||||
@@ -83,11 +87,16 @@ CppEditorFactory::CppEditorFactory(CppEditorPlugin *owner) :
|
|||||||
addMimeType(Constants::CPP_SOURCE_MIMETYPE);
|
addMimeType(Constants::CPP_SOURCE_MIMETYPE);
|
||||||
addMimeType(Constants::CPP_HEADER_MIMETYPE);
|
addMimeType(Constants::CPP_HEADER_MIMETYPE);
|
||||||
|
|
||||||
new TextEditor::TextEditorActionHandler(this, Constants::C_CPPEDITOR,
|
setDocumentCreator([]() { return new CppEditorDocument; });
|
||||||
TextEditor::TextEditorActionHandler::Format
|
setEditorWidgetCreator([]() { return new CppEditorWidget; });
|
||||||
| TextEditor::TextEditorActionHandler::UnCommentSelection
|
setEditorCreator([]() { return new CppEditor; });
|
||||||
| TextEditor::TextEditorActionHandler::UnCollapseAll
|
setAutoCompleterCreator([]() { return new CppAutoCompleter; });
|
||||||
| TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor);
|
|
||||||
|
setEditorActionHandlers(Constants::C_CPPEDITOR,
|
||||||
|
TextEditorActionHandler::Format
|
||||||
|
| TextEditorActionHandler::UnCommentSelection
|
||||||
|
| TextEditorActionHandler::UnCollapseAll
|
||||||
|
| TextEditorActionHandler::FollowSymbolUnderCursor);
|
||||||
|
|
||||||
if (!Utils::HostOsInfo::isMacHost() && !Utils::HostOsInfo::isWindowsHost()) {
|
if (!Utils::HostOsInfo::isMacHost() && !Utils::HostOsInfo::isWindowsHost()) {
|
||||||
FileIconProvider::registerIconOverlayForMimeType(":/cppeditor/images/qt_cpp.png", Constants::CPP_SOURCE_MIMETYPE);
|
FileIconProvider::registerIconOverlayForMimeType(":/cppeditor/images/qt_cpp.png", Constants::CPP_SOURCE_MIMETYPE);
|
||||||
@@ -95,15 +104,7 @@ CppEditorFactory::CppEditorFactory(CppEditorPlugin *owner) :
|
|||||||
FileIconProvider::registerIconOverlayForMimeType(":/cppeditor/images/qt_h.png", Constants::CPP_HEADER_MIMETYPE);
|
FileIconProvider::registerIconOverlayForMimeType(":/cppeditor/images/qt_h.png", Constants::CPP_HEADER_MIMETYPE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
IEditor *CppEditorFactory::createEditor()
|
|
||||||
{
|
|
||||||
CppEditor *editor = new CppEditor;
|
|
||||||
CppEditorWidget *widget = new CppEditorWidget(BaseTextDocumentPtr(new CppEditorDocument), editor);
|
|
||||||
m_owner->initializeEditor(widget);
|
|
||||||
editor->configureCodeAssistant();
|
|
||||||
return editor;
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////// CppEditorPlugin //////////////////////////////////
|
///////////////////////////////// CppEditorPlugin //////////////////////////////////
|
||||||
|
|
||||||
@@ -131,13 +132,6 @@ CppEditorPlugin *CppEditorPlugin::instance()
|
|||||||
return m_instance;
|
return m_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppEditorPlugin::initializeEditor(CppEditorWidget *editor)
|
|
||||||
{
|
|
||||||
// function combo box sorting
|
|
||||||
connect(this, SIGNAL(outlineSortingChanged(bool)),
|
|
||||||
editor->outline(), SLOT(setSorted(bool)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void CppEditorPlugin::setSortedOutline(bool sorted)
|
void CppEditorPlugin::setSortedOutline(bool sorted)
|
||||||
{
|
{
|
||||||
m_sortedOutline = sorted;
|
m_sortedOutline = sorted;
|
||||||
@@ -159,7 +153,7 @@ bool CppEditorPlugin::initialize(const QStringList & /*arguments*/, QString *err
|
|||||||
if (!Core::MimeDatabase::addMimeTypes(QLatin1String(":/cppeditor/CppEditor.mimetypes.xml"), errorMessage))
|
if (!Core::MimeDatabase::addMimeTypes(QLatin1String(":/cppeditor/CppEditor.mimetypes.xml"), errorMessage))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
addAutoReleasedObject(new CppEditorFactory(this));
|
addAutoReleasedObject(new CppEditorFactory);
|
||||||
addAutoReleasedObject(new CppHoverHandler);
|
addAutoReleasedObject(new CppHoverHandler);
|
||||||
addAutoReleasedObject(new CppOutlineWidgetFactory);
|
addAutoReleasedObject(new CppOutlineWidgetFactory);
|
||||||
addAutoReleasedObject(new CppTypeHierarchyFactory);
|
addAutoReleasedObject(new CppTypeHierarchyFactory);
|
||||||
|
|||||||
@@ -62,9 +62,6 @@ public:
|
|||||||
void extensionsInitialized();
|
void extensionsInitialized();
|
||||||
ShutdownFlag aboutToShutdown();
|
ShutdownFlag aboutToShutdown();
|
||||||
|
|
||||||
// Connect editor to settings changed signals.
|
|
||||||
void initializeEditor(CppEditorWidget *editor);
|
|
||||||
|
|
||||||
bool sortedOutline() const;
|
bool sortedOutline() const;
|
||||||
|
|
||||||
CppQuickFixAssistProvider *quickFixProvider() const;
|
CppQuickFixAssistProvider *quickFixProvider() const;
|
||||||
@@ -250,19 +247,6 @@ private:
|
|||||||
QPointer<TextEditor::BaseTextEditor> m_currentEditor;
|
QPointer<TextEditor::BaseTextEditor> m_currentEditor;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CppEditorFactory : public Core::IEditorFactory
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
CppEditorFactory(CppEditorPlugin *owner);
|
|
||||||
|
|
||||||
Core::IEditor *createEditor();
|
|
||||||
|
|
||||||
private:
|
|
||||||
CppEditorPlugin *m_owner;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace CppEditor
|
} // namespace CppEditor
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user