Commit c655d7e5 authored by hjk's avatar hjk

CppEditor: Convert to new construction scheme

Change-Id: I947f76b4dbc3a197cd49993855c3b0f5e3dc7b49
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent 61276ab6
......@@ -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");
}
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);
setCodeFoldingSupported(true);
setMarksVisible(true);
setParenthesesMatchingEnabled(true);
setRevisionsVisible(true);
// function combo box sorting
connect(CppEditorPlugin::instance(), &CppEditorPlugin::outlineSortingChanged,
outline(), &CppEditorOutline::setSorted);
connect(d->m_cppEditorDocument, &CppEditorDocument::codeWarningsUpdated,
this, &CppEditorWidget::onCodeWarningsUpdated);
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()));
insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Left, d->m_preprocessorButton);
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()
......@@ -229,20 +240,6 @@ CppEditorWidget::~CppEditorWidget()
// 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
{
return d->m_cppEditorDocument;
......@@ -564,15 +561,6 @@ void CppEditorWidget::keyPressEvent(QKeyEvent *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)
{
if (!TextEditor::BaseTextEditor::open(errorString, fileName, realFileName))
......
......@@ -57,8 +57,6 @@ class CppEditor : public TextEditor::BaseTextEditor
public:
CppEditor();
Core::IEditor *duplicate() QTC_OVERRIDE;
bool open(QString *errorString,
const QString &fileName,
const QString &realFileName) QTC_OVERRIDE;
......@@ -72,10 +70,10 @@ public:
static Link linkToSymbol(CPlusPlus::Symbol *symbol);
public:
CppEditorWidget(TextEditor::BaseTextDocumentPtr doc, CppEditor *editor);
CppEditorWidget();
~CppEditorWidget();
CppEditorWidget *duplicate(CppEditor *editor) const;
void finalizeInitialization();
CppEditorDocument *cppEditorDocument() const;
CppEditorOutline *outline() const;
......
......@@ -29,11 +29,12 @@
#include "cppeditorplugin.h"
#include "cppautocompleter.h"
#include "cppclasswizard.h"
#include "cppcodemodelinspectordialog.h"
#include "cppeditorconstants.h"
#include "cppeditordocument.h"
#include "cppeditor.h"
#include "cppeditordocument.h"
#include "cppeditoroutline.h"
#include "cppfilewizard.h"
#include "cpphighlighter.h"
......@@ -63,6 +64,7 @@
#include <QStringList>
using namespace Core;
using namespace TextEditor;
namespace CppEditor {
namespace Internal {
......@@ -73,37 +75,36 @@ enum { QUICKFIX_INTERVAL = 20 };
//////////////////////////// CppEditorFactory /////////////////////////////
CppEditorFactory::CppEditorFactory(CppEditorPlugin *owner) :
m_owner(owner)
class CppEditorFactory : public BaseTextEditorFactory
{
setId(Constants::CPPEDITOR_ID);
setDisplayName(qApp->translate("OpenWith::Editors", Constants::CPPEDITOR_DISPLAY_NAME));
addMimeType(Constants::C_SOURCE_MIMETYPE);
addMimeType(Constants::C_HEADER_MIMETYPE);
addMimeType(Constants::CPP_SOURCE_MIMETYPE);
addMimeType(Constants::CPP_HEADER_MIMETYPE);
new TextEditor::TextEditorActionHandler(this, Constants::C_CPPEDITOR,
TextEditor::TextEditorActionHandler::Format
| TextEditor::TextEditorActionHandler::UnCommentSelection
| TextEditor::TextEditorActionHandler::UnCollapseAll
| TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor);
if (!Utils::HostOsInfo::isMacHost() && !Utils::HostOsInfo::isWindowsHost()) {
FileIconProvider::registerIconOverlayForMimeType(":/cppeditor/images/qt_cpp.png", Constants::CPP_SOURCE_MIMETYPE);
FileIconProvider::registerIconOverlayForMimeType(":/cppeditor/images/qt_c.png", Constants::C_SOURCE_MIMETYPE);
FileIconProvider::registerIconOverlayForMimeType(":/cppeditor/images/qt_h.png", Constants::CPP_HEADER_MIMETYPE);
public:
CppEditorFactory()
{
setId(Constants::CPPEDITOR_ID);
setDisplayName(qApp->translate("OpenWith::Editors", Constants::CPPEDITOR_DISPLAY_NAME));
addMimeType(Constants::C_SOURCE_MIMETYPE);
addMimeType(Constants::C_HEADER_MIMETYPE);
addMimeType(Constants::CPP_SOURCE_MIMETYPE);
addMimeType(Constants::CPP_HEADER_MIMETYPE);
setDocumentCreator([]() { return new CppEditorDocument; });
setEditorWidgetCreator([]() { return new CppEditorWidget; });
setEditorCreator([]() { return new CppEditor; });
setAutoCompleterCreator([]() { return new CppAutoCompleter; });
setEditorActionHandlers(Constants::C_CPPEDITOR,
TextEditorActionHandler::Format
| TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::UnCollapseAll
| TextEditorActionHandler::FollowSymbolUnderCursor);
if (!Utils::HostOsInfo::isMacHost() && !Utils::HostOsInfo::isWindowsHost()) {
FileIconProvider::registerIconOverlayForMimeType(":/cppeditor/images/qt_cpp.png", Constants::CPP_SOURCE_MIMETYPE);
FileIconProvider::registerIconOverlayForMimeType(":/cppeditor/images/qt_c.png", Constants::C_SOURCE_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 //////////////////////////////////
......@@ -131,13 +132,6 @@ CppEditorPlugin *CppEditorPlugin::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)
{
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))
return false;
addAutoReleasedObject(new CppEditorFactory(this));
addAutoReleasedObject(new CppEditorFactory);
addAutoReleasedObject(new CppHoverHandler);
addAutoReleasedObject(new CppOutlineWidgetFactory);
addAutoReleasedObject(new CppTypeHierarchyFactory);
......
......@@ -62,9 +62,6 @@ public:
void extensionsInitialized();
ShutdownFlag aboutToShutdown();
// Connect editor to settings changed signals.
void initializeEditor(CppEditorWidget *editor);
bool sortedOutline() const;
CppQuickFixAssistProvider *quickFixProvider() const;
......@@ -250,19 +247,6 @@ private:
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 CppEditor
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment