#include "SourceGroupCxxCodeblocks.h" #include "CxxIndexerCommandProvider.h" #include "IndexerCommandCxx.h" #include "ApplicationSettings.h" #include "SourceGroupSettingsCxxCodeblocks.h" #include "MessageStatus.h" #include "CodeblocksProject.h" #include "utility.h" #include "Application.h" SourceGroupCxxCodeblocks::SourceGroupCxxCodeblocks(std::shared_ptr settings) : m_settings(settings) { } bool SourceGroupCxxCodeblocks::prepareIndexing() { FilePath codeblocksProjectPath = m_settings->getCodeblocksProjectPathExpandedAndAbsolute(); if (!codeblocksProjectPath.empty() && !codeblocksProjectPath.exists()) { std::wstring error = L"Can't refresh project. The referenced Code::Blocks project does not exist anymore: " + codeblocksProjectPath.wstr(); MessageStatus(error, true).dispatch(); Application::getInstance()->handleDialog(error, { L"Ok" }); return false; } return true; } std::set SourceGroupCxxCodeblocks::filterToContainedFilePaths(const std::set& filePaths) const { return SourceGroup::filterToContainedFilePaths( filePaths, getAllSourceFilePaths(), utility::toSet(m_settings->getIndexedHeaderPathsExpandedAndAbsolute()), m_settings->getExcludeFiltersExpandedAndAbsolute() ); } std::set SourceGroupCxxCodeblocks::getAllSourceFilePaths() const { std::set sourceFilePaths; if (std::shared_ptr project = Codeblocks::Project::load( m_settings->getCodeblocksProjectPathExpandedAndAbsolute() )) { const std::vector excludeFilters = m_settings->getExcludeFiltersExpandedAndAbsolute(); for (const FilePath& filePath : project->getAllSourceFilePathsCanonical(m_settings->getSourceExtensions())) { bool isExcluded = false; for (const FilePathFilter& excludeFilter : excludeFilters) { if (excludeFilter.isMatching(filePath)) { isExcluded = true; break; } } if (!isExcluded && filePath.exists()) { sourceFilePaths.insert(filePath); } } } return sourceFilePaths; } std::shared_ptr SourceGroupCxxCodeblocks::getIndexerCommandProvider(const std::set& filesToIndex) const { std::shared_ptr provider = std::make_shared(); if (std::shared_ptr project = Codeblocks::Project::load( m_settings->getCodeblocksProjectPathExpandedAndAbsolute() )) { for (std::shared_ptr indexerCommand: project->getIndexerCommands(m_settings, ApplicationSettings::getInstance())) { if (filesToIndex.find(indexerCommand->getSourceFilePath()) != filesToIndex.end()) { provider->addCommand(indexerCommand); } } } return provider; } std::vector> SourceGroupCxxCodeblocks::getIndexerCommands(const std::set& filesToIndex) const { return getIndexerCommandProvider(filesToIndex)->consumeAllCommands(); } std::shared_ptr SourceGroupCxxCodeblocks::getSourceGroupSettings() { return m_settings; } std::shared_ptr SourceGroupCxxCodeblocks::getSourceGroupSettings() const { return m_settings; }