1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #include "cpptoolsbridgeqtcreatorimplementation.h" 27 28 #include "baseeditordocumentparser.h" 29 #include "cppmodelmanager.h" 30 #include "projectpart.h" 31 #include "editordocumenthandle.h" 32 33 #include <coreplugin/editormanager/editormanager.h> 34 35 namespace CppTools { 36 37 namespace Internal { 38 39 CppEditorDocumentHandle * cppEditorDocument(const QString & filePath) const40CppToolsBridgeQtCreatorImplementation::cppEditorDocument(const QString &filePath) const 41 { 42 return CppModelManager::instance()->cppEditorDocument(filePath); 43 } 44 45 namespace { 46 projectPartForFile(const QString & filePath)47CppTools::ProjectPart::Ptr projectPartForFile(const QString &filePath) 48 { 49 if (const auto parser = BaseEditorDocumentParser::get(filePath)) 50 return parser->projectPartInfo().projectPart; 51 52 return CppTools::ProjectPart::Ptr(); 53 } 54 isProjectPartValid(const CppTools::ProjectPart::Ptr projectPart)55bool isProjectPartValid(const CppTools::ProjectPart::Ptr projectPart) 56 { 57 if (projectPart) 58 return !CppTools::CppModelManager::instance()->projectPartForId(projectPart->id()).isNull(); 59 60 return false; 61 } 62 63 } // anonymous namespace 64 projectPartIdForFile(const QString & filePath) const65QString CppToolsBridgeQtCreatorImplementation::projectPartIdForFile(const QString &filePath) const 66 { 67 const CppTools::ProjectPart::Ptr projectPart = projectPartForFile(filePath); 68 69 if (isProjectPartValid(projectPart)) 70 return projectPart->id(); // OK, Project Part is still loaded 71 72 return QString(); 73 } 74 75 BaseEditorDocumentProcessor * baseEditorDocumentProcessor(const QString & filePath) const76CppToolsBridgeQtCreatorImplementation::baseEditorDocumentProcessor(const QString &filePath) const 77 { 78 auto *document = cppEditorDocument(filePath); 79 if (document) 80 return document->processor(); 81 82 return nullptr; 83 } 84 finishedRefreshingSourceFiles(const QSet<QString> & filePaths) const85void CppToolsBridgeQtCreatorImplementation::finishedRefreshingSourceFiles( 86 const QSet<QString> &filePaths) const 87 { 88 CppModelManager::instance()->finishedRefreshingSourceFiles(filePaths); 89 } 90 visibleEditors() const91QList<Core::IEditor *> CppToolsBridgeQtCreatorImplementation::visibleEditors() const 92 { 93 return Core::EditorManager::visibleEditors(); 94 } 95 96 } // namespace Internal 97 98 } // namespace CppTools 99