diff --git a/src/plugins/cpptools/cpphighlightingsupport.cpp b/src/plugins/cpptools/cpphighlightingsupport.cpp index 66469fcc877..25346184672 100644 --- a/src/plugins/cpptools/cpphighlightingsupport.cpp +++ b/src/plugins/cpptools/cpphighlightingsupport.cpp @@ -40,7 +40,3 @@ CppHighlightingSupport::CppHighlightingSupport(TextEditor::ITextEditor *editor) CppHighlightingSupport::~CppHighlightingSupport() { } - -CppHighlightingSupportFactory::~CppHighlightingSupportFactory() -{ -} diff --git a/src/plugins/cpptools/cpphighlightingsupport.h b/src/plugins/cpptools/cpphighlightingsupport.h index 2557681d50a..ee085732b29 100644 --- a/src/plugins/cpptools/cpphighlightingsupport.h +++ b/src/plugins/cpptools/cpphighlightingsupport.h @@ -81,14 +81,6 @@ private: TextEditor::ITextEditor *m_editor; }; -class CPPTOOLS_EXPORT CppHighlightingSupportFactory -{ -public: - virtual ~CppHighlightingSupportFactory() = 0; - - virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor) = 0; -}; - } // namespace CppTools #endif // CPPTOOLS_CPPHIGHLIGHTINGSUPPORT_H diff --git a/src/plugins/cpptools/cpphighlightingsupportinternal.cpp b/src/plugins/cpptools/cpphighlightingsupportinternal.cpp index ae39a0a0761..4ad285258ba 100644 --- a/src/plugins/cpptools/cpphighlightingsupportinternal.cpp +++ b/src/plugins/cpptools/cpphighlightingsupportinternal.cpp @@ -92,12 +92,3 @@ QFuture CppHighlightingSupportInternal::highligh LookupContext context(doc, snapshot); return CheckSymbols::go(doc, context, macroUses); } - -CppHighlightingSupportInternalFactory::~CppHighlightingSupportInternalFactory() -{ -} - -CppHighlightingSupport *CppHighlightingSupportInternalFactory::highlightingSupport(TextEditor::ITextEditor *editor) -{ - return new CppHighlightingSupportInternal(editor); -} diff --git a/src/plugins/cpptools/cpphighlightingsupportinternal.h b/src/plugins/cpptools/cpphighlightingsupportinternal.h index ca3f9296acc..7d274864910 100644 --- a/src/plugins/cpptools/cpphighlightingsupportinternal.h +++ b/src/plugins/cpptools/cpphighlightingsupportinternal.h @@ -57,14 +57,6 @@ public: const CPlusPlus::Snapshot &snapshot) const; }; -class CppHighlightingSupportInternalFactory: public CppHighlightingSupportFactory -{ -public: - virtual ~CppHighlightingSupportInternalFactory(); - - virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor); -}; - } // namespace Internal } // namespace CppTools diff --git a/src/plugins/cpptools/cppmodelmanager.cpp b/src/plugins/cpptools/cppmodelmanager.cpp index 0de3470e628..0c0e9a42585 100644 --- a/src/plugins/cpptools/cppmodelmanager.cpp +++ b/src/plugins/cpptools/cppmodelmanager.cpp @@ -31,11 +31,10 @@ #include "abstracteditorsupport.h" #include "builtinindexingsupport.h" -#include "cppcompletionassist.h" #include "cppfindreferences.h" #include "cpphighlightingsupport.h" -#include "cpphighlightingsupportinternal.h" #include "cppindexingsupport.h" +#include "cppmodelmanagersupportinternal.h" #include "cpppreprocessor.h" #include "cpptoolsconstants.h" #include "cpptoolseditorsupport.h" @@ -230,8 +229,6 @@ CppModelManager *CppModelManager::instance() CppModelManager::CppModelManager(QObject *parent) : CppModelManagerInterface(parent) - , m_completionAssistProvider(0) - , m_highlightingFactory(0) , m_indexingSupporter(0) , m_enableGC(true) { @@ -259,16 +256,14 @@ CppModelManager::CppModelManager(QObject *parent) qRegisterMetaType("CPlusPlus::Document::Ptr"); - m_completionFallback.reset(new InternalCompletionAssistProvider); - m_completionAssistProvider = m_completionFallback.data(); - m_highlightingFallback = new CppHighlightingSupportInternalFactory; - m_highlightingFactory = m_highlightingFallback; + m_modelManagerSupportFallback.reset(new ModelManagerSupportInternal); + addModelManagerSupport(m_modelManagerSupportFallback.data()); + m_internalIndexingSupport = new BuiltinIndexingSupport; } CppModelManager::~CppModelManager() { - delete m_highlightingFallback; delete m_internalIndexingSupport; } @@ -911,35 +906,33 @@ void CppModelManager::finishedRefreshingSourceFiles(const QStringList &files) emit sourceFilesRefreshed(files); } -CppCompletionAssistProvider *CppModelManager::completionAssistProvider(Core::IEditor *editor) const +void CppModelManager::addModelManagerSupport(ModelManagerSupport *modelManagerSupport) { - Q_UNUSED(editor); - - return m_completionAssistProvider; + if (!m_codeModelSupporters.contains(modelManagerSupport)) + m_codeModelSupporters.append(modelManagerSupport); } -void CppModelManager::setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider) +ModelManagerSupport *CppModelManager::modelManagerSupportForMimeType(const QString &mimeType) const { - if (completionAssistProvider) - m_completionAssistProvider = completionAssistProvider; - else - m_completionAssistProvider = m_completionFallback.data(); + return m_mimeTypeToCodeModelSupport.value(mimeType, m_modelManagerSupportFallback.data()); +} + +CppCompletionAssistProvider *CppModelManager::completionAssistProvider(Core::IEditor *editor) const +{ + ModelManagerSupport *cms = modelManagerSupportForMimeType(editor->document()->mimeType()); + + return cms->completionAssistProvider(); } CppHighlightingSupport *CppModelManager::highlightingSupport(Core::IEditor *editor) const { - if (TextEditor::ITextEditor *textEditor = qobject_cast(editor)) - return m_highlightingFactory->highlightingSupport(textEditor); - else + TextEditor::ITextEditor *textEditor = qobject_cast(editor); + if (!textEditor) return 0; -} -void CppModelManager::setHighlightingSupportFactory(CppHighlightingSupportFactory *highlightingFactory) -{ - if (highlightingFactory) - m_highlightingFactory = highlightingFactory; - else - m_highlightingFactory = m_highlightingFallback; + ModelManagerSupport *cms = modelManagerSupportForMimeType(editor->document()->mimeType()); + + return cms->highlightingSupport(textEditor); } void CppModelManager::setIndexingSupport(CppIndexingSupport *indexingSupport) diff --git a/src/plugins/cpptools/cppmodelmanager.h b/src/plugins/cpptools/cppmodelmanager.h index 8f6877ff60e..cf25c9d2b51 100644 --- a/src/plugins/cpptools/cppmodelmanager.h +++ b/src/plugins/cpptools/cppmodelmanager.h @@ -105,11 +105,10 @@ public: void finishedRefreshingSourceFiles(const QStringList &files); + virtual void addModelManagerSupport(ModelManagerSupport *codeModelSupport); + virtual ModelManagerSupport *modelManagerSupportForMimeType(const QString &mimeType) const; virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const; - virtual void setCppCompletionAssistProvider(CppCompletionAssistProvider *completionAssistProvider); - virtual CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const; - virtual void setHighlightingSupportFactory(CppHighlightingSupportFactory *highlightingFactory); virtual void setIndexingSupport(CppIndexingSupport *indexingSupport); virtual CppIndexingSupport *indexingSupport(); @@ -202,13 +201,10 @@ private: QMap m_cppEditorSupports; QSet m_extraEditorSupports; - // Completion - CppCompletionAssistProvider *m_completionAssistProvider; - QScopedPointer m_completionFallback; - - // Highlighting - CppHighlightingSupportFactory *m_highlightingFactory; - CppHighlightingSupportFactory *m_highlightingFallback; + // Completion & highlighting + QList m_codeModelSupporters; + QScopedPointer m_modelManagerSupportFallback; + QHash m_mimeTypeToCodeModelSupport; // Indexing CppIndexingSupport *m_indexingSupporter; diff --git a/src/plugins/cpptools/cppmodelmanagerinterface.h b/src/plugins/cpptools/cppmodelmanagerinterface.h index 8a276ece481..33954d47ea0 100644 --- a/src/plugins/cpptools/cppmodelmanagerinterface.h +++ b/src/plugins/cpptools/cppmodelmanagerinterface.h @@ -52,6 +52,7 @@ namespace Utils { class FileName; } namespace CppTools { class AbstractEditorSupport; +class ModelManagerSupport; class CppCompletionAssistProvider; class CppEditorSupport; class CppHighlightingSupport; @@ -243,14 +244,13 @@ public: virtual void setIfdefedOutBlocks(const QString &fileName, const QList &ifdeffedOutBlocks) = 0; + virtual void addModelManagerSupport(ModelManagerSupport *modelManagerSupport) = 0; + virtual ModelManagerSupport *modelManagerSupportForMimeType(const QString &mimeType) const = 0; virtual CppCompletionAssistProvider *completionAssistProvider(Core::IEditor *editor) const = 0; - virtual void setCppCompletionAssistProvider(CppTools::CppCompletionAssistProvider *completionAssistProvider) = 0; - - virtual CppTools::CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const = 0; - virtual void setHighlightingSupportFactory(CppTools::CppHighlightingSupportFactory *highlightingFactory) = 0; + virtual CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const = 0; virtual void setIndexingSupport(CppTools::CppIndexingSupport *indexingSupport) = 0; - virtual CppTools::CppIndexingSupport *indexingSupport() = 0; + virtual CppIndexingSupport *indexingSupport() = 0; signals: /// Project data might be locked while this is emitted. diff --git a/src/plugins/cpptools/cppmodelmanagersupport.cpp b/src/plugins/cpptools/cppmodelmanagersupport.cpp new file mode 100644 index 00000000000..8892dbada48 --- /dev/null +++ b/src/plugins/cpptools/cppmodelmanagersupport.cpp @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "cppmodelmanagersupport.h" + +using namespace CppTools; + +ModelManagerSupport::~ModelManagerSupport() +{ +} diff --git a/src/plugins/cpptools/cppmodelmanagersupport.h b/src/plugins/cpptools/cppmodelmanagersupport.h new file mode 100644 index 00000000000..be738c82a43 --- /dev/null +++ b/src/plugins/cpptools/cppmodelmanagersupport.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CPPTOOLS_CPPMODELMANAGERSUPPORT_H +#define CPPTOOLS_CPPMODELMANAGERSUPPORT_H + +#include "cpptools_global.h" + +#include + +namespace TextEditor { class ITextEditor; } + +namespace CppTools { + +class CppCompletionAssistProvider; +class CppHighlightingSupport; + +class CPPTOOLS_EXPORT ModelManagerSupport +{ +public: + virtual ~ModelManagerSupport() = 0; + + virtual QString id() const = 0; + virtual QString displayName() const = 0; + + virtual CppCompletionAssistProvider *completionAssistProvider() = 0; + virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor) = 0; +}; + +} // CppTools namespace + +#endif // CPPTOOLS_CPPMODELMANAGERSUPPORT_H diff --git a/src/plugins/cpptools/cppmodelmanagersupportinternal.cpp b/src/plugins/cpptools/cppmodelmanagersupportinternal.cpp new file mode 100644 index 00000000000..40527b8027e --- /dev/null +++ b/src/plugins/cpptools/cppmodelmanagersupportinternal.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "cppcompletionassist.h" +#include "cpphighlightingsupportinternal.h" +#include "cppmodelmanagersupportinternal.h" + +#include + +using namespace CppTools; +using namespace CppTools::Internal; + +ModelManagerSupportInternal::ModelManagerSupportInternal() + : m_completionAssistProvider(new InternalCompletionAssistProvider) +{ +} + +ModelManagerSupportInternal::~ModelManagerSupportInternal() +{ +} + +QString ModelManagerSupportInternal::id() const +{ + return QLatin1String("CppTools.BuiltinCodeModel"); +} + +QString ModelManagerSupportInternal::displayName() const +{ + return QCoreApplication::translate("ModelManagerSupportInternal::displayName", + "Qt Creator Built-in"); +} + +CppCompletionAssistProvider *ModelManagerSupportInternal::completionAssistProvider() +{ + return m_completionAssistProvider.data(); +} + +CppHighlightingSupport *ModelManagerSupportInternal::highlightingSupport(TextEditor::ITextEditor *editor) +{ + return new CppHighlightingSupportInternal(editor); +} diff --git a/src/plugins/cpptools/cppmodelmanagersupportinternal.h b/src/plugins/cpptools/cppmodelmanagersupportinternal.h new file mode 100644 index 00000000000..650337358d2 --- /dev/null +++ b/src/plugins/cpptools/cppmodelmanagersupportinternal.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef CPPTOOLS_INTERNAL_CPPMODELMANAGERSUPPORTINTERNAL_H +#define CPPTOOLS_INTERNAL_CPPMODELMANAGERSUPPORTINTERNAL_H + +#include "cppmodelmanagersupport.h" + +#include + +namespace CppTools { +namespace Internal { + +class ModelManagerSupportInternal: public ModelManagerSupport +{ + Q_DISABLE_COPY(ModelManagerSupportInternal) + +public: + ModelManagerSupportInternal(); + virtual ~ModelManagerSupportInternal(); + + virtual QString id() const; + virtual QString displayName() const; + + virtual CppCompletionAssistProvider *completionAssistProvider(); + virtual CppHighlightingSupport *highlightingSupport(TextEditor::ITextEditor *editor); + +private: + QScopedPointer m_completionAssistProvider; +}; + +} // Internal namespace +} // CppTools namespace + +#endif // CPPTOOLS_INTERNAL_CPPMODELMANAGERSUPPORTINTERNAL_H diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index 7ddfa221a1b..5c906e01d27 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -32,6 +32,7 @@ HEADERS += completionsettingspage.h \ doxygengenerator.h \ commentssettings.h \ symbolfinder.h \ + cppmodelmanagersupport.h \ cpphighlightingsupport.h \ cpphighlightingsupportinternal.h \ cppchecksymbols.h \ @@ -45,7 +46,8 @@ HEADERS += completionsettingspage.h \ cppprojectfile.h \ cpppreprocessor.h \ includeutils.h \ - cpplocatordata.h + cpplocatordata.h \ + cppmodelmanagersupportinternal.h SOURCES += completionsettingspage.cpp \ cppclassesfilter.cpp \ @@ -76,6 +78,7 @@ SOURCES += completionsettingspage.cpp \ doxygengenerator.cpp \ commentssettings.cpp \ symbolfinder.cpp \ + cppmodelmanagersupport.cpp \ cpphighlightingsupport.cpp \ cpphighlightingsupportinternal.cpp \ cppchecksymbols.cpp \ @@ -89,7 +92,8 @@ SOURCES += completionsettingspage.cpp \ cppprojectfile.cpp \ cpppreprocessor.cpp \ includeutils.cpp \ - cpplocatordata.cpp + cpplocatordata.cpp \ + cppmodelmanagersupportinternal.cpp FORMS += completionsettingspage.ui \ cppfilesettingspage.ui \ diff --git a/src/plugins/cpptools/cpptools.qbs b/src/plugins/cpptools/cpptools.qbs index ab71d35bdff..0dfbc097a9b 100644 --- a/src/plugins/cpptools/cpptools.qbs +++ b/src/plugins/cpptools/cpptools.qbs @@ -67,6 +67,10 @@ QtcPlugin { "cpplocatorfilter.h", "cppmodelmanager.cpp", "cppmodelmanager.h", + "cppmodelmanagersupport.h", + "cppmodelmanagersupport.cpp", + "cppmodelmanagersupportinternal.h", + "cppmodelmanagersupportinternal.cpp", "cppmodelmanagerinterface.cpp", "cppmodelmanagerinterface.h", "cppqtstyleindenter.cpp",