From 82db193c78be92bce9ef300670c166805d505438 Mon Sep 17 00:00:00 2001 From: Manuel Dobusch Date: Wed, 23 Mar 2016 17:06:40 +0100 Subject: [PATCH] logic: solution parsing refactor Refactored solution parser handling to make it more generic Also includes new parser (wip) --- bin/test/data/log/test_log.txt | 168 ++++++++ src/lib/CMakeLists.txt | 8 + .../controller/IDECommunicationController.cpp | 5 +- .../helper/NetworkProtocolHelper.cpp | 16 +- .../controller/helper/NetworkProtocolHelper.h | 10 +- .../messaging/type/MessageProjectNew.h | 13 +- src/lib/utility/solution/ISolutionParser.cpp | 25 ++ src/lib/utility/solution/ISolutionParser.h | 13 + .../solution/SolutionParserCodeBlocks.cpp | 217 ++++++++++ .../solution/SolutionParserCodeBlocks.h | 31 ++ .../solution/SolutionParserEclipse.cpp | 0 .../utility/solution/SolutionParserEclipse.h | 11 + .../solution/SolutionParserManager.cpp | 119 ++++++ .../utility/solution/SolutionParserManager.h | 33 ++ .../solution/SolutionParserUtility.cpp | 310 ++++++++++++++ .../utility/solution/SolutionParserUtility.h | 25 ++ .../solution/SolutionParserVisualStudio.cpp | 391 +++--------------- .../solution/SolutionParserVisualStudio.h | 22 +- src/lib_gui/qt/graphics/QtGraphicsView.h | 2 + src/lib_gui/qt/window/QtMainWindow.cpp | 4 +- .../project_wizzard/QtProjectWizzard.cpp | 166 +++++--- .../window/project_wizzard/QtProjectWizzard.h | 16 +- .../QtProjectWizzardContentBuildFile.cpp | 2 +- .../QtProjectWizzardContentBuildFile.h | 2 +- .../QtProjectWizzardContentSelect.cpp | 57 ++- .../QtProjectWizzardContentSelect.h | 12 +- 26 files changed, 1236 insertions(+), 442 deletions(-) create mode 100644 src/lib/utility/solution/SolutionParserCodeBlocks.cpp create mode 100644 src/lib/utility/solution/SolutionParserCodeBlocks.h create mode 100644 src/lib/utility/solution/SolutionParserEclipse.cpp create mode 100644 src/lib/utility/solution/SolutionParserEclipse.h create mode 100644 src/lib/utility/solution/SolutionParserManager.cpp create mode 100644 src/lib/utility/solution/SolutionParserManager.h create mode 100644 src/lib/utility/solution/SolutionParserUtility.cpp create mode 100644 src/lib/utility/solution/SolutionParserUtility.h diff --git a/bin/test/data/log/test_log.txt b/bin/test/data/log/test_log.txt index c99f7782..523dd8f6 100644 --- a/bin/test/data/log/test_log.txt +++ b/bin/test/data/log/test_log.txt @@ -1,3 +1,171 @@ +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml +Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml Token.cpp ERROR: Location Id was not referenced by this Token. Node.cpp WARNING: Cannot change NodeType after it was already set from namespace to class Edge.cpp ERROR: Nodes are not plain copies. diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 116c0b88..692e03c0 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -279,6 +279,14 @@ add_files( utility/solution/ISolutionParser.cpp utility/solution/ISolutionParser.h + utility/solution/SolutionParserCodeBlocks.cpp + utility/solution/SolutionParserCodeBlocks.h + utility/solution/SolutionParserEclipse.cpp + utility/solution/SolutionParserEclipse.h + utility/solution/SolutionParserManager.cpp + utility/solution/SolutionParserManager.h + utility/solution/SolutionParserUtility.cpp + utility/solution/SolutionParserUtility.h utility/solution/SolutionParserVisualStudio.cpp utility/solution/SolutionParserVisualStudio.h diff --git a/src/lib/component/controller/IDECommunicationController.cpp b/src/lib/component/controller/IDECommunicationController.cpp index 5a2a3160..6d8ab952 100644 --- a/src/lib/component/controller/IDECommunicationController.cpp +++ b/src/lib/component/controller/IDECommunicationController.cpp @@ -99,10 +99,11 @@ void IDECommunicationController::handleCreateProjectMessage(const NetworkProtoco { if (message.valid) { - if (message.ideId == NetworkProtocolHelper::CreateProjectMessage::IDE_ID::VS) + if (message.ideId == "vs") { MessageProjectNew msg; - msg.setVisualStudioSolutionPath(message.solutionFileLocation); + msg.setSolutionPath(message.solutionFileLocation); + msg.ideId = message.ideId; msg.dispatch(); } else diff --git a/src/lib/component/controller/helper/NetworkProtocolHelper.cpp b/src/lib/component/controller/helper/NetworkProtocolHelper.cpp index 6a1d272e..3d9806af 100644 --- a/src/lib/component/controller/helper/NetworkProtocolHelper.cpp +++ b/src/lib/component/controller/helper/NetworkProtocolHelper.cpp @@ -3,8 +3,12 @@ #include #include +#include + #include "utility/logging/logging.h" +#include "utility/solution/SolutionParserVisualStudio.h" + std::string NetworkProtocolHelper::m_divider = ">>"; std::string NetworkProtocolHelper::m_setActiveTokenPrefix = "setActiveToken"; std::string NetworkProtocolHelper::m_moveCursorPrefix = "moveCursor"; @@ -100,14 +104,10 @@ NetworkProtocolHelper::CreateProjectMessage NetworkProtocolHelper::parseCreatePr { networkMessage.solutionFileLocation = fileLocation; - if (ideId == "vs") - { - networkMessage.ideId = CreateProjectMessage::IDE_ID::VS; - } - else - { - networkMessage.ideId = CreateProjectMessage::IDE_ID::UNKNOWN; - } + std::string nonConstId = ideId; + boost::algorithm::to_lower(nonConstId); + + networkMessage.ideId = nonConstId; networkMessage.valid = true; } diff --git a/src/lib/component/controller/helper/NetworkProtocolHelper.h b/src/lib/component/controller/helper/NetworkProtocolHelper.h index 1d79e48a..9bf1b087 100644 --- a/src/lib/component/controller/helper/NetworkProtocolHelper.h +++ b/src/lib/component/controller/helper/NetworkProtocolHelper.h @@ -28,18 +28,12 @@ public: public: CreateProjectMessage() : solutionFileLocation("") - , ideId(IDE_ID::UNKNOWN) + , ideId("") , valid(false) {} - enum IDE_ID - { - UNKNOWN = 0, - VS - }; - std::string solutionFileLocation; - IDE_ID ideId; + std::string ideId; bool valid; }; diff --git a/src/lib/utility/messaging/type/MessageProjectNew.h b/src/lib/utility/messaging/type/MessageProjectNew.h index 245ff6a3..6670b203 100644 --- a/src/lib/utility/messaging/type/MessageProjectNew.h +++ b/src/lib/utility/messaging/type/MessageProjectNew.h @@ -8,6 +8,8 @@ class MessageProjectNew { public: MessageProjectNew() + : solutionPath("") + , ideId("") { } @@ -16,17 +18,18 @@ public: return "MessageProjectNew"; } - bool fromVisualStudioSolution() const + bool fromSolution() const { - return visualStudioSolutionPath.size() > 0; + return solutionPath.size() > 0; } - void setVisualStudioSolutionPath(const std::string& path) + void setSolutionPath(const std::string& path) { - visualStudioSolutionPath = path; + solutionPath = path; } - std::string visualStudioSolutionPath; + std::string solutionPath; + std::string ideId; }; #endif // MESSAGE_PROJECT_NEW_H diff --git a/src/lib/utility/solution/ISolutionParser.cpp b/src/lib/utility/solution/ISolutionParser.cpp index 366ba379..bffb5291 100644 --- a/src/lib/utility/solution/ISolutionParser.cpp +++ b/src/lib/utility/solution/ISolutionParser.cpp @@ -5,6 +5,11 @@ std::string ISolutionParser::getSolutionPath() return m_solutionPath; } +std::string ISolutionParser::getToolID() const +{ + return "NONE"; +} + void ISolutionParser::openSolutionFile(const std::string& solutionFilePath) { m_solution = loadFile(solutionFilePath); @@ -46,3 +51,23 @@ std::string ISolutionParser::loadFile(const std::string& filePath) return file; } + +std::vector ISolutionParser::makePathsAbsolute(const std::vector& paths) +{ + std::vector absolutePaths; + + for (unsigned int i = 0; i < paths.size(); i++) + { + std::string path = paths[i]; + + boost::filesystem::path boostPath(path); + if (boostPath.is_relative()) + { + path = m_solutionPath + path; + } + + absolutePaths.push_back(path); + } + + return absolutePaths; +} diff --git a/src/lib/utility/solution/ISolutionParser.h b/src/lib/utility/solution/ISolutionParser.h index c7248943..4c0ad5b1 100644 --- a/src/lib/utility/solution/ISolutionParser.h +++ b/src/lib/utility/solution/ISolutionParser.h @@ -4,6 +4,8 @@ #include #include +#include "settings/ProjectSettings.h" + class ISolutionParser { public: @@ -13,6 +15,8 @@ public: {}; virtual ~ISolutionParser(){}; + virtual std::string getToolID() const; + void openSolutionFile(const std::string& solutionFilePath); unsigned int getSolutionCharCount() const; @@ -23,9 +27,18 @@ public: virtual std::vector getProjectFiles() = 0; virtual std::vector getProjectItems() = 0; + virtual ProjectSettings getProjectSettings(const std::string& solutionFilePath) = 0; + + virtual std::string getIdeName() const = 0; + virtual std::string getDescription() const = 0; + virtual std::string getIconPath() const = 0; + virtual std::string getFileExtension() const = 0; + protected: std::string loadFile(const std::string& filePath); + std::vector makePathsAbsolute(const std::vector& paths); + std::string m_solutionName; std::string m_solutionPath; std::string m_solution; diff --git a/src/lib/utility/solution/SolutionParserCodeBlocks.cpp b/src/lib/utility/solution/SolutionParserCodeBlocks.cpp new file mode 100644 index 00000000..f666c254 --- /dev/null +++ b/src/lib/utility/solution/SolutionParserCodeBlocks.cpp @@ -0,0 +1,217 @@ +#include "SolutionParserCodeBlocks.h" + +#include + +#include "SolutionParserUtility.h" + +#include "utility/logging/logging.h" + +SolutionParserCodeBlocks::SolutionParserCodeBlocks() +{ + +} + +SolutionParserCodeBlocks::~SolutionParserCodeBlocks() +{ + +} + +std::string SolutionParserCodeBlocks::getToolID() const +{ + return "cb"; +} + +std::string SolutionParserCodeBlocks::getSolutionName() +{ + std::string result = ""; + + if (m_solutionName.size() > 0) + { + size_t pos = m_solutionName.find(".cbp"); + + if (pos != std::string::npos) + { + result = m_solutionName.substr(0, pos); + } + else + { + result = m_solution; + } + } + + return result; +} + +std::vector SolutionParserCodeBlocks::getProjects() +{ + std::vector projectFiles; + + projectFiles.push_back(m_solutionName); + + return projectFiles; +} + +std::vector SolutionParserCodeBlocks::getProjectFiles() +{ + std::vector projectFiles; + std::vector projectFilesNames = getProjects(); + + projectFiles.push_back(loadFile(m_solutionPath + m_solutionName)); + + return projectFiles; +} + +std::vector SolutionParserCodeBlocks::getProjectItems() +{ + std::vector projectItems; + + std::vector projectFilesNames = getProjects(); + std::vector projectFiles = getProjectFiles(); + + std::vector validFileExtensions; + validFileExtensions.push_back(".c"); + validFileExtensions.push_back(".cpp"); + validFileExtensions.push_back(".h"); + validFileExtensions.push_back(".hpp"); + + for (unsigned int i = 0; i < projectFiles.size(); i++) + { + TiXmlDocument doc; + doc.Parse(projectFiles[i].c_str(), 0, TIXML_ENCODING_UTF8); + + std::string error = doc.ErrorDesc(); + + if (error.length() > 0) + { + LOG_ERROR_STREAM(<< "Failed to parse project file " << i << ": " << error); + continue; + } + + std::vector nodes = SolutionParserUtility::getAllTagsByNameWithAttribute(doc.RootElement(), "Unit", "filename"); + + if (nodes.size() > 0) + { + for (unsigned int i = 0; i < nodes.size(); i++) + { + std::string text = nodes[i]->Attribute("filename"); + + if (SolutionParserUtility::checkValidFileExtension(text, validFileExtensions)) + { + if (boost::filesystem::exists(text)) + { + projectItems.push_back(text); + continue; + } + + text = m_solutionPath + "/" + text; + + projectItems.push_back(text); + } + } + } + } + + std::set s(projectItems.begin(), projectItems.end()); + projectItems.assign(s.begin(), s.end()); + + projectItems = SolutionParserUtility::resolveEnvironmentVariables(projectItems); + projectItems = makePathsAbsolute(projectItems); + + return projectItems; +} + +std::vector SolutionParserCodeBlocks::getIncludePaths() +{ + std::vector includePaths; + + std::vector projectFiles = getProjectFiles(); + + std::vector validExtensions; + validExtensions.push_back(".c"); + validExtensions.push_back(".cpp"); + validExtensions.push_back(".h"); + validExtensions.push_back(".hpp"); + + for (unsigned int i = 0; i < projectFiles.size(); i++) + { + TiXmlDocument doc; + doc.Parse(projectFiles[i].c_str(), 0, TIXML_ENCODING_UTF8); + + std::string error = doc.ErrorDesc(); + + if (error.length() > 0) + { + LOG_ERROR_STREAM(<< "Failed to parse project file " << i << ": " << error); + continue; + } + + std::vector nodes = SolutionParserUtility::getAllTagsByNameWithAttribute(doc.RootElement(), "Add", "directory"); + + if (nodes.size() > 0) + { + for (unsigned int i = 0; i < nodes.size(); i++) + { + std::string text = nodes[i]->Attribute("directory"); + + includePaths.push_back(text); + } + } + } + + std::set s(includePaths.begin(), includePaths.end()); + includePaths.assign(s.begin(), s.end()); + + includePaths = SolutionParserUtility::resolveEnvironmentVariables(includePaths); + includePaths = makePathsAbsolute(includePaths); + + return includePaths; +} + +ProjectSettings SolutionParserCodeBlocks::getProjectSettings(const std::string& solutionFilePath) +{ + openSolutionFile(solutionFilePath); + + ProjectSettings settings; + settings.setProjectName(getSolutionName()); + settings.setProjectFileLocation(getSolutionPath()); + settings.setVisualStudioSolutionPath(solutionFilePath); + + std::vector sourceFiles = getProjectItems(); + std::vector sourcePaths; + for (const std::string& p : sourceFiles) + { + sourcePaths.push_back(FilePath(p)); + } + + std::vector includePaths = getIncludePaths(); + std::vector headerPaths; + for (const std::string& p : includePaths) + { + headerPaths.push_back(FilePath(p)); + } + + settings.setSourcePaths(sourcePaths); + settings.setHeaderSearchPaths(headerPaths); + + return settings; +} + +std::string SolutionParserCodeBlocks::getIdeName() const +{ + return "Code Blocks"; +} + +std::string SolutionParserCodeBlocks::getDescription() const +{ + return "idunno"; +} + +std::string SolutionParserCodeBlocks::getIconPath() const +{ + return "icon/project_vs_256_256.png"; +} + +std::string SolutionParserCodeBlocks::getFileExtension() const +{ + return ".cbp"; +} diff --git a/src/lib/utility/solution/SolutionParserCodeBlocks.h b/src/lib/utility/solution/SolutionParserCodeBlocks.h new file mode 100644 index 00000000..077d1fd2 --- /dev/null +++ b/src/lib/utility/solution/SolutionParserCodeBlocks.h @@ -0,0 +1,31 @@ +#ifndef SOLUTION_PARSER_CODE_BLOCKS_H +#define SOLUTION_PARSER_CODE_BLOCKS_H + +#include "ISolutionParser.h" + +#include "tinyxml/tinyxml.h" + +class SolutionParserCodeBlocks : public ISolutionParser +{ +public: + SolutionParserCodeBlocks(); + virtual ~SolutionParserCodeBlocks(); + + virtual std::string getToolID() const; + + virtual std::string getSolutionName(); + + virtual std::vector getProjects(); + virtual std::vector getProjectFiles(); + virtual std::vector getProjectItems(); + virtual std::vector getIncludePaths(); + + virtual ProjectSettings getProjectSettings(const std::string& solutionFilePath); + + virtual std::string getIdeName() const; + virtual std::string getDescription() const; + virtual std::string getIconPath() const; + virtual std::string getFileExtension() const; +}; + +#endif // SOLUTION_PARSER_CODE_BLOCKS_H diff --git a/src/lib/utility/solution/SolutionParserEclipse.cpp b/src/lib/utility/solution/SolutionParserEclipse.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/lib/utility/solution/SolutionParserEclipse.h b/src/lib/utility/solution/SolutionParserEclipse.h new file mode 100644 index 00000000..127f64ec --- /dev/null +++ b/src/lib/utility/solution/SolutionParserEclipse.h @@ -0,0 +1,11 @@ +#ifndef SOLUTION_PARSER_ECLIPSE_H +#define SOLUTION_PARSER_ECLIPSE_H + +#include "ISolutionParser.h" + +class SolutionParserEclipse +{ + +}; + +#endif // SOLUTION_PARSER_ECLIPSE_H \ No newline at end of file diff --git a/src/lib/utility/solution/SolutionParserManager.cpp b/src/lib/utility/solution/SolutionParserManager.cpp new file mode 100644 index 00000000..fbd13429 --- /dev/null +++ b/src/lib/utility/solution/SolutionParserManager.cpp @@ -0,0 +1,119 @@ +#include "SolutionParserManager.h" + +#include + +#include "utility/logging/logging.h" + +SolutionParserManager::SolutionParserManager() + : m_solutionParsers() +{ + +} + +SolutionParserManager::~SolutionParserManager() +{ + +} + +void SolutionParserManager::pushSolutionParser(const std::shared_ptr& solutionParser) +{ + m_solutionParsers.push_back(solutionParser); +} + +bool SolutionParserManager::canParseSolution(const std::string& ideId) const +{ + std::string lIdeId = ideId; + boost::algorithm::to_lower(lIdeId); + + for (unsigned int i = 0; i < m_solutionParsers.size(); i++) + { + std::string parserIdeId = m_solutionParsers[i]->getToolID(); + boost::algorithm::to_lower(parserIdeId); + + if (lIdeId == parserIdeId) + { + return true; + } + } + + return false; +} + +ProjectSettings SolutionParserManager::getProjectSettings(const std::string& ideId, const std::string& solutionFilePath) const +{ + std::string lIdeId = ideId; + boost::algorithm::to_lower(lIdeId); + + for (unsigned int i = 0; i < m_solutionParsers.size(); i++) + { + std::string parserIdeId = m_solutionParsers[i]->getToolID(); + boost::algorithm::to_lower(parserIdeId); + + if (lIdeId == parserIdeId) + { + return m_solutionParsers[i]->getProjectSettings(solutionFilePath); + } + } + + LOG_ERROR_STREAM(<< "Solution type is unknown"); + + return ProjectSettings(); +} + +unsigned int SolutionParserManager::getParserCount() const +{ + return m_solutionParsers.size(); +} + +std::string SolutionParserManager::getParserName(const unsigned int idx) const +{ + if (checkIndex(idx)) + { + return m_solutionParsers[idx]->getIdeName(); + } + + LOG_WARNING_STREAM(<< "Index is out of range, was " << idx << ". Max is " << m_solutionParsers.size() - 1); + + return ""; +} + +std::string SolutionParserManager::getParserDescription(const unsigned int idx) const +{ + if (checkIndex(idx)) + { + return m_solutionParsers[idx]->getDescription(); + } + + LOG_WARNING_STREAM(<< "Index is out of range, was " << idx << ". Max is " << m_solutionParsers.size() - 1); + + return ""; +} + +std::string SolutionParserManager::getParserFileEnding(const unsigned int idx) const +{ + if (checkIndex(idx)) + { + return m_solutionParsers[idx]->getFileExtension(); + } + + LOG_WARNING_STREAM(<< "Index is out of range, was " << idx << ". Max is " << m_solutionParsers.size() - 1); + + return ""; +} + +std::string SolutionParserManager::getParserIdeId(const unsigned int idx) const +{ + if (checkIndex(idx)) + { + return m_solutionParsers[idx]->getToolID(); + } + + LOG_WARNING_STREAM(<< "Index is out of range, was " << idx << ". Max is " << m_solutionParsers.size() - 1); + + return ""; +} + +bool SolutionParserManager::checkIndex(const unsigned int idx) const +{ + return (idx < m_solutionParsers.size()); +} diff --git a/src/lib/utility/solution/SolutionParserManager.h b/src/lib/utility/solution/SolutionParserManager.h new file mode 100644 index 00000000..6e99e6da --- /dev/null +++ b/src/lib/utility/solution/SolutionParserManager.h @@ -0,0 +1,33 @@ +#ifndef SOLUTION_PARSER_MANAGER_H +#define SOLUTION_PARSER_MANAGER_H + +#include + +#include "ISolutionParser.h" + +class SolutionParserManager +{ +public: + SolutionParserManager(); + ~SolutionParserManager(); + + void pushSolutionParser(const std::shared_ptr& solutionParser); + + bool canParseSolution(const std::string& ideId) const; + + ProjectSettings getProjectSettings(const std::string& ideId, const std::string& solutionFilePath) const; + + unsigned int getParserCount() const; + + std::string getParserName(const unsigned int idx) const; + std::string getParserDescription(const unsigned int idx) const; + std::string getParserFileEnding(const unsigned int idx) const; + std::string getParserIdeId(const unsigned int idx) const; + +private: + bool checkIndex(const unsigned int idx) const; + + std::vector> m_solutionParsers; +}; + +#endif // SOLUTION_PARSER_MANAGER_H diff --git a/src/lib/utility/solution/SolutionParserUtility.cpp b/src/lib/utility/solution/SolutionParserUtility.cpp new file mode 100644 index 00000000..1d4b0785 --- /dev/null +++ b/src/lib/utility/solution/SolutionParserUtility.cpp @@ -0,0 +1,310 @@ +#include "SolutionParserUtility.h" + +#include "utility/logging/logging.h" + +#include "utility/messaging/type/MessageStatus.h" + +#include "boost/filesystem/path.hpp" +#include "boost/filesystem.hpp" + +TiXmlElement* SolutionParserUtility::getFirstTagByName(TiXmlElement* root, const std::string& tag) +{ + TiXmlElement* element = root; + + while (element) + { + if (element == NULL) + { + } + + std::string value = element->Value(); + + if (value == tag) // "ClInclude") // || value == "ClCompile") + { + if (element->Parent() != NULL) + { + return element; // ->Parent()->ToElement(); + } + } + + if (element->FirstChildElement() != NULL) + { + element = element->FirstChildElement(); + } + else if (element->NextSiblingElement() != NULL) + { + element = element->NextSiblingElement(); + } + else + { + if (element == NULL) + { + } + + while (element->Parent()->ToElement() != NULL && element->Parent()->NextSiblingElement() == NULL) + { + TiXmlElement* newElement = element->Parent()->ToElement(); + + if (newElement == NULL) + { + } + + element = newElement; + } + if (element->Parent() != NULL && element->Parent()->NextSiblingElement() != NULL) + { + element = element->Parent()->NextSiblingElement(); + } + else + { + return NULL; + } + } + } + + return NULL; +} + +std::vector SolutionParserUtility::getAllTagsByName(TiXmlElement* root, const std::string& tag) +{ + std::vector nodes; + + TiXmlElement* element = root; + + while (element) + { + std::string value = element->Value(); + + if (value == tag) + { + nodes.push_back(element); + } + + if (element->FirstChildElement() != NULL) + { + element = element->FirstChildElement(); + } + else if (element->NextSiblingElement() != NULL) + { + element = element->NextSiblingElement(); + } + else + { + if (element == NULL) + { + } + + while (element->Parent()->ToElement() != NULL && element->Parent()->NextSiblingElement() == NULL) + { + TiXmlElement* newElement = element->Parent()->ToElement(); + + if (newElement == NULL) + { + } + + element = newElement; + } + if (element->Parent() != NULL && element->Parent()->NextSiblingElement() != NULL) + { + element = element->Parent()->NextSiblingElement(); + } + else + { + break; + } + } + } + + return nodes; +} + +TiXmlElement* SolutionParserUtility::getFirstTagByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute) +{ + TiXmlElement* element = root; + + while (element) + { + if (element == NULL) + { + } + + std::string value = element->Value(); + + bool hasAttribute = false; + if (element->Attribute(attribute.c_str()) != NULL) + { + hasAttribute = true; + } + + if (value == tag && hasAttribute) // "ClInclude") // || value == "ClCompile") + { + if (element->Parent() != NULL) + { + return element; // ->Parent()->ToElement(); + } + } + + if (element->FirstChildElement() != NULL) + { + element = element->FirstChildElement(); + } + else if (element->NextSiblingElement() != NULL) + { + element = element->NextSiblingElement(); + } + else + { + while (element->Parent()->ToElement() != NULL && element->Parent()->NextSiblingElement() == NULL) + { + TiXmlElement* newElement = element->Parent()->ToElement(); + + element = newElement; + } + if (element->Parent() != NULL && element->Parent()->NextSiblingElement() != NULL) + { + element = element->Parent()->NextSiblingElement(); + } + else + { + return NULL; + } + } + } + + return NULL; +} + +std::vector SolutionParserUtility::getAllTagsByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute) +{ + std::vector nodes; + + TiXmlElement* element = root; + + while (element) + { + std::string value = element->Value(); + + bool hasAttribute = false; + if (element->Attribute(attribute.c_str()) != NULL) + { + hasAttribute = true; + } + + if (value == tag && hasAttribute) + { + nodes.push_back(element); + } + + if (element->FirstChildElement() != NULL) + { + element = element->FirstChildElement(); + } + else if (element->NextSiblingElement() != NULL) + { + element = element->NextSiblingElement(); + } + else + { + while (element->Parent()->ToElement() != NULL && element->Parent()->NextSiblingElement() == NULL) + { + TiXmlElement* newElement = element->Parent()->ToElement(); + + element = newElement; + } + if (element->Parent() != NULL && element->Parent()->NextSiblingElement() != NULL) + { + element = element->Parent()->NextSiblingElement(); + } + else + { + break; + } + } + } + + return nodes; +} + +bool SolutionParserUtility::checkValidFileExtension(const std::string& file, const std::vector& validExtensions) +{ + for (unsigned int i = 0; i < validExtensions.size(); i++) + { + size_t pos = file.find(validExtensions[i]); + + if (pos != std::string::npos) + { + return true; + } + } + + return false; +} + +std::vector SolutionParserUtility::resolveEnvironmentVariables(const std::vector& paths) +{ + std::vector resolvedPaths; + + for (unsigned int i = 0; i < paths.size(); i++) + { + resolvedPaths.push_back(findAndResolveEnvironmentVariable(paths[i])); + } + + return resolvedPaths; +} + +std::string SolutionParserUtility::findAndResolveEnvironmentVariable(const std::string& path) +{ + std::string resolvedPath; + + size_t pos = path.find("$("); + + if (pos != std::string::npos) + { + size_t endPos = path.substr(pos).find(")"); + + std::string envVariable = path.substr(pos + 2, (endPos - 2) - pos); + std::string envPath = getenv(envVariable.c_str()); + + std::string prePath = path.substr(0, pos); + std::string postPath = path.substr(endPos + 1); + + resolvedPath = prePath + envPath + postPath; + } + else + { + resolvedPath = path; + } + + return resolvedPath; +} + +std::vector SolutionParserUtility::makePathsCanonical(const std::vector& paths) +{ + std::vector canonicalPaths; + + int errorCount = 0; + + for (unsigned int i = 0; i < paths.size(); i++) + { + try + { + boost::filesystem::path canonicalPath = boost::filesystem::canonical(boost::filesystem::path(paths[i])); + canonicalPaths.push_back(canonicalPath.string()); + } + catch (std::exception& e) + { + std::string what = e.what(); + LOG_WARNING_STREAM(<< e.what()); + errorCount++; + } + } + + if (errorCount > 0) + { + std::stringstream errorMessage; + errorMessage << "Detected " << errorCount << " invalid include file paths. Check if the include paths of your VS project exist."; + MessageStatus(errorMessage.str(), true).dispatch(); + } + + return canonicalPaths; +} diff --git a/src/lib/utility/solution/SolutionParserUtility.h b/src/lib/utility/solution/SolutionParserUtility.h new file mode 100644 index 00000000..2b2e2811 --- /dev/null +++ b/src/lib/utility/solution/SolutionParserUtility.h @@ -0,0 +1,25 @@ +#ifndef SOLUTION_PARSER_UTILITY_H +#define SOLUTION_PARSER_UTILITY_H + +#include +#include + +#include "tinyxml/tinyxml.h" + +class SolutionParserUtility +{ +public: + static TiXmlElement* getFirstTagByName(TiXmlElement* root, const std::string& tag); + static std::vector getAllTagsByName(TiXmlElement* root, const std::string& tag); + + static TiXmlElement* getFirstTagByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute); + static std::vector getAllTagsByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute); + + static bool checkValidFileExtension(const std::string& file, const std::vector& validExtensions); + + static std::vector resolveEnvironmentVariables(const std::vector& paths); + static std::string findAndResolveEnvironmentVariable(const std::string& path); + static std::vector makePathsCanonical(const std::vector& paths); +}; + +#endif // SOLUTION_PARSER_UTILITY_H diff --git a/src/lib/utility/solution/SolutionParserVisualStudio.cpp b/src/lib/utility/solution/SolutionParserVisualStudio.cpp index d099be7a..16f64dcf 100644 --- a/src/lib/utility/solution/SolutionParserVisualStudio.cpp +++ b/src/lib/utility/solution/SolutionParserVisualStudio.cpp @@ -7,6 +7,8 @@ #include "boost/filesystem/path.hpp" #include "boost/filesystem.hpp" +#include "SolutionParserUtility.h" + #include "utility/logging/logging.h" SolutionParserVisualStudio::SolutionParserVisualStudio() @@ -19,6 +21,11 @@ SolutionParserVisualStudio::~SolutionParserVisualStudio() } +std::string SolutionParserVisualStudio::getToolID() const +{ + return "vs"; +} + std::string SolutionParserVisualStudio::getSolutionName() { std::string result = ""; @@ -86,7 +93,7 @@ std::vector SolutionParserVisualStudio::getProjectItems() { std::vector projectItems = findProjectItems(); - projectItems = makePathsCanonical(projectItems); + projectItems = SolutionParserUtility::makePathsCanonical(projectItems); return projectItems; } @@ -95,11 +102,61 @@ std::vector SolutionParserVisualStudio::getIncludePaths() { std::vector includePaths = findIncludePaths(); - includePaths = makePathsCanonical(includePaths); + includePaths = SolutionParserUtility::makePathsCanonical(includePaths); return includePaths; } +ProjectSettings SolutionParserVisualStudio::getProjectSettings(const std::string& solutionFilePath) +{ + openSolutionFile(solutionFilePath); + + ProjectSettings settings; + settings.setProjectName(getSolutionName()); + settings.setProjectFileLocation(getSolutionPath()); + settings.setVisualStudioSolutionPath(solutionFilePath); + + std::vector sourceFiles = getProjectItems(); + std::vector sourcePaths; + for (const std::string& p : sourceFiles) + { + sourcePaths.push_back(FilePath(p)); + } + + std::vector includePaths = getIncludePaths(); + + std::vector headerPaths; + for (const std::string& p : includePaths) + { + headerPaths.push_back(FilePath(p)); + } + + settings.setSourcePaths(sourcePaths); + settings.setHeaderSearchPaths(headerPaths); + + return settings; +} + +std::string SolutionParserVisualStudio::getIdeName() const +{ + return "Visual Studio"; +} + +std::string SolutionParserVisualStudio::getDescription() const +{ + return "Create a new project from an existing Visual Studio Solution file."; +} + +std::string SolutionParserVisualStudio::getIconPath() const +{ + return "icon/project_vs_256_256.png"; +} + +std::string SolutionParserVisualStudio::getFileExtension() const +{ + return ".sln"; +} + std::vector SolutionParserVisualStudio::getProjectItemsNonCanonical() { return findProjectItems(); @@ -156,8 +213,8 @@ std::vector SolutionParserVisualStudio::findProjectItems() continue; } - TiXmlElement* root = getFirstTagByNameWithAttribute(doc.RootElement(), "ClCompile", "Include"); - TiXmlElement* headerRoot = getFirstTagByNameWithAttribute(doc.RootElement(), "ClInclude", "Include"); + TiXmlElement* root = SolutionParserUtility::getFirstTagByNameWithAttribute(doc.RootElement(), "ClCompile", "Include"); + TiXmlElement* headerRoot = SolutionParserUtility::getFirstTagByNameWithAttribute(doc.RootElement(), "ClInclude", "Include"); if (root != NULL) { // std::string text(root->GetText()); @@ -218,7 +275,7 @@ std::vector SolutionParserVisualStudio::findProjectItems() { std::string filePath = child->Attribute("Include"); - if (boost::filesystem::exists(filePath) && checkValidFileExtension(filePath, validFileExtensions)) + if (boost::filesystem::exists(filePath) && SolutionParserUtility::checkValidFileExtension(filePath, validFileExtensions)) { projectItems.push_back(filePath); continue; @@ -229,7 +286,7 @@ std::vector SolutionParserVisualStudio::findProjectItems() filePath = relativeProjectPaths[i] + "/" + filePath; } - if (checkValidFileExtension(filePath, validFileExtensions)) + if (SolutionParserUtility::checkValidFileExtension(filePath, validFileExtensions)) { projectItems.push_back(filePath); } @@ -242,7 +299,7 @@ std::vector SolutionParserVisualStudio::findProjectItems() { std::string filePath = child->Attribute("Include"); - if (boost::filesystem::exists(filePath) && checkValidFileExtension(filePath, validFileExtensions)) + if (boost::filesystem::exists(filePath) && SolutionParserUtility::checkValidFileExtension(filePath, validFileExtensions)) { projectItems.push_back(filePath); continue; @@ -253,7 +310,7 @@ std::vector SolutionParserVisualStudio::findProjectItems() filePath = relativeProjectPaths[i] + "/" + filePath; } - if (checkValidFileExtension(filePath, validFileExtensions)) + if (SolutionParserUtility::checkValidFileExtension(filePath, validFileExtensions)) { projectItems.push_back(filePath); } @@ -264,7 +321,7 @@ std::vector SolutionParserVisualStudio::findProjectItems() std::set s(projectItems.begin(), projectItems.end()); projectItems.assign(s.begin(), s.end()); - projectItems = resolveEnvironmentVariables(projectItems); + projectItems = SolutionParserUtility::resolveEnvironmentVariables(projectItems); projectItems = makePathsAbsolute(projectItems); return projectItems; @@ -295,7 +352,7 @@ std::vector SolutionParserVisualStudio::findIncludePaths() continue; } - std::vector nodes = getAllTagsByName(doc.RootElement(), "AdditionalIncludeDirectories"); + std::vector nodes = SolutionParserUtility::getAllTagsByName(doc.RootElement(), "AdditionalIncludeDirectories"); for (unsigned int j = 0; j < nodes.size(); j++) { @@ -310,27 +367,12 @@ std::vector SolutionParserVisualStudio::findIncludePaths() std::set s(includePaths.begin(), includePaths.end()); includePaths.assign(s.begin(), s.end()); - includePaths = resolveEnvironmentVariables(includePaths); + includePaths = SolutionParserUtility::resolveEnvironmentVariables(includePaths); includePaths = makePathsAbsolute(includePaths); return includePaths; } -bool SolutionParserVisualStudio::checkValidFileExtension(const std::string& file, const std::vector& validExtensions) -{ - for (unsigned int i = 0; i < validExtensions.size(); i++) - { - size_t pos = file.find(validExtensions[i]); - - if (pos != std::string::npos) - { - return true; - } - } - - return false; -} - std::vector SolutionParserVisualStudio::getProjectBlocks(const std::string& solution) const { std::vector blocks; @@ -420,300 +462,3 @@ std::vector SolutionParserVisualStudio::seperateIncludePaths(const return seperatedPaths; } - -TiXmlElement* SolutionParserVisualStudio::getFirstTagByName(TiXmlElement* root, const std::string& tag) -{ - TiXmlElement* element = root; - - while (element) - { - if (element == NULL) - { - } - - std::string value = element->Value(); - - if (value == tag) // "ClInclude") // || value == "ClCompile") - { - if (element->Parent() != NULL) - { - return element; // ->Parent()->ToElement(); - } - } - - if (element->FirstChildElement() != NULL) - { - element = element->FirstChildElement(); - } - else if (element->NextSiblingElement() != NULL) - { - element = element->NextSiblingElement(); - } - else - { - if (element == NULL) - { - } - - while (element->Parent()->ToElement() != NULL && element->Parent()->NextSiblingElement() == NULL) - { - TiXmlElement* newElement = element->Parent()->ToElement(); - - if (newElement == NULL) - { - } - - element = newElement; - } - if (element->Parent() != NULL && element->Parent()->NextSiblingElement() != NULL) - { - element = element->Parent()->NextSiblingElement(); - } - else - { - return NULL; - } - } - } - - return NULL; -} - -std::vector SolutionParserVisualStudio::getAllTagsByName(TiXmlElement* root, const std::string& tag) -{ - std::vector nodes; - - TiXmlElement* element = root; - - while (element) - { - std::string value = element->Value(); - - if (value == tag) - { - nodes.push_back(element); - } - - if (element->FirstChildElement() != NULL) - { - element = element->FirstChildElement(); - } - else if (element->NextSiblingElement() != NULL) - { - element = element->NextSiblingElement(); - } - else - { - if (element == NULL) - { - } - - while (element->Parent()->ToElement() != NULL && element->Parent()->NextSiblingElement() == NULL) - { - TiXmlElement* newElement = element->Parent()->ToElement(); - - if (newElement == NULL) - { - } - - element = newElement; - } - if (element->Parent() != NULL && element->Parent()->NextSiblingElement() != NULL) - { - element = element->Parent()->NextSiblingElement(); - } - else - { - break; - } - } - } - - return nodes; -} - -TiXmlElement* SolutionParserVisualStudio::getFirstTagByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute) -{ - TiXmlElement* element = root; - - while (element) - { - if (element == NULL) - { - } - - std::string value = element->Value(); - - bool hasAttribute = false; - if (element->Attribute(attribute.c_str()) != NULL) - { - hasAttribute = true; - } - - if (value == tag && hasAttribute) // "ClInclude") // || value == "ClCompile") - { - if (element->Parent() != NULL) - { - return element; // ->Parent()->ToElement(); - } - } - - if (element->FirstChildElement() != NULL) - { - element = element->FirstChildElement(); - } - else if (element->NextSiblingElement() != NULL) - { - element = element->NextSiblingElement(); - } - else - { - while (element->Parent()->ToElement() != NULL && element->Parent()->NextSiblingElement() == NULL) - { - TiXmlElement* newElement = element->Parent()->ToElement(); - - element = newElement; - } - if (element->Parent() != NULL && element->Parent()->NextSiblingElement() != NULL) - { - element = element->Parent()->NextSiblingElement(); - } - else - { - return NULL; - } - } - } - - return NULL; -} - -std::vector SolutionParserVisualStudio::getAllTagsByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute) -{ - std::vector nodes; - - TiXmlElement* element = root; - - while (element) - { - std::string value = element->Value(); - - bool hasAttribute = false; - if (element->Attribute(attribute.c_str()) != NULL) - { - hasAttribute = true; - } - - if (value == tag && hasAttribute) - { - nodes.push_back(element); - } - - if (element->FirstChildElement() != NULL) - { - element = element->FirstChildElement(); - } - else if (element->NextSiblingElement() != NULL) - { - element = element->NextSiblingElement(); - } - else - { - while (element->Parent()->ToElement() != NULL && element->Parent()->NextSiblingElement() == NULL) - { - TiXmlElement* newElement = element->Parent()->ToElement(); - - element = newElement; - } - if (element->Parent() != NULL && element->Parent()->NextSiblingElement() != NULL) - { - element = element->Parent()->NextSiblingElement(); - } - else - { - break; - } - } - } - - return nodes; -} - -std::vector SolutionParserVisualStudio::resolveEnvironmentVariables(const std::vector& paths) -{ - std::vector resolvedPaths; - - for (unsigned int i = 0; i < paths.size(); i++) - { - resolvedPaths.push_back(findAndResolveEnvironmentVariable(paths[i])); - } - - return resolvedPaths; -} - -std::string SolutionParserVisualStudio::findAndResolveEnvironmentVariable(const std::string& path) -{ - std::string resolvedPath; - - size_t pos = path.find("$("); - - if (pos != std::string::npos) - { - size_t endPos = path.substr(pos).find(")"); - - std::string envVariable = path.substr(pos+2, (endPos-2) - pos); - std::string envPath = getenv(envVariable.c_str()); - - std::string prePath = path.substr(0, pos); - std::string postPath = path.substr(endPos + 1); - - resolvedPath = prePath + envPath + postPath; - } - else - { - resolvedPath = path; - } - - return resolvedPath; -} - -std::vector SolutionParserVisualStudio::makePathsAbsolute(const std::vector& paths) -{ - std::vector absolutePaths; - - for (unsigned int i = 0; i < paths.size(); i++) - { - std::string path = paths[i]; - - boost::filesystem::path boostPath(path); - if (boostPath.is_relative()) - { - path = m_solutionPath + path; - } - - absolutePaths.push_back(path); - } - - return absolutePaths; -} - -std::vector SolutionParserVisualStudio::makePathsCanonical(const std::vector& paths) -{ - std::vector canonicalPaths; - - for (unsigned int i = 0; i < paths.size(); i++) - { - try - { - boost::filesystem::path canonicalPath = boost::filesystem::canonical(boost::filesystem::path(paths[i])); - canonicalPaths.push_back(canonicalPath.string()); - } - catch (std::exception& e) - { - std::string what = e.what(); - LOG_WARNING_STREAM(<< e.what()); - } - } - - return canonicalPaths; -} diff --git a/src/lib/utility/solution/SolutionParserVisualStudio.h b/src/lib/utility/solution/SolutionParserVisualStudio.h index 028a9a45..4e8644a7 100644 --- a/src/lib/utility/solution/SolutionParserVisualStudio.h +++ b/src/lib/utility/solution/SolutionParserVisualStudio.h @@ -11,6 +11,8 @@ public: SolutionParserVisualStudio(); virtual ~SolutionParserVisualStudio(); + virtual std::string getToolID() const; + virtual std::string getSolutionName(); virtual std::vector getProjects(); @@ -18,6 +20,13 @@ public: virtual std::vector getProjectItems(); virtual std::vector getIncludePaths(); + virtual ProjectSettings getProjectSettings(const std::string& solutionFilePath); + + virtual std::string getIdeName() const; + virtual std::string getDescription() const; + virtual std::string getIconPath() const; + virtual std::string getFileExtension() const; + std::vector getProjectItemsNonCanonical(); // for testing purposes, paths returned are non canonical, don't use if you don't know what that means std::vector getIncludePathsNonCanonical(); // for testing purposes, paths returned are non canonical, don't use if you don't know what that means @@ -25,24 +34,11 @@ private: std::vector findProjectItems(); std::vector findIncludePaths(); - bool checkValidFileExtension(const std::string& file, const std::vector& validExtensions); - std::vector getProjectBlocks(const std::string& solution) const; std::string getProjectFilePath(const std::string& projectBlock) const; std::vector seperateIncludePaths(const std::vector& includePaths) const; std::vector seperateIncludePaths(const std::string& includePaths) const; - - TiXmlElement* getFirstTagByName(TiXmlElement* root, const std::string& tag); - std::vector getAllTagsByName(TiXmlElement* root, const std::string& tag); - - TiXmlElement* getFirstTagByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute); - std::vector getAllTagsByNameWithAttribute(TiXmlElement* root, const std::string& tag, const std::string& attribute); - - std::vector resolveEnvironmentVariables(const std::vector& paths); - std::string findAndResolveEnvironmentVariable(const std::string& path); - std::vector makePathsAbsolute(const std::vector& paths); - std::vector makePathsCanonical(const std::vector& paths); }; #endif // SOLUTION_PARSER_VISUAL_STUDIO_H diff --git a/src/lib_gui/qt/graphics/QtGraphicsView.h b/src/lib_gui/qt/graphics/QtGraphicsView.h index 1a7a8c6e..1fc6482b 100644 --- a/src/lib_gui/qt/graphics/QtGraphicsView.h +++ b/src/lib_gui/qt/graphics/QtGraphicsView.h @@ -5,6 +5,8 @@ #include +#include + class QTimer; class QtGraphicsView diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index b13834e1..75edcf6c 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -566,9 +566,9 @@ void QtMainWindow::doCreateNewProject(MessageProjectNew message) { QtProjectWizzard* wizzard = createWindow(); - if (message.fromVisualStudioSolution()) + if (message.fromSolution()) { - wizzard->newProjectFromVisualStudioSolution(message.visualStudioSolutionPath); + wizzard->newProjectFromSolution(message.ideId ,message.solutionPath); } else { diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp index c625bb70..6611f8e4 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp @@ -1,5 +1,7 @@ #include "qt/window/project_wizzard/QtProjectWizzard.h" +#include + #include #include #include @@ -16,7 +18,14 @@ #include "qt/window/project_wizzard/QtProjectWizzardContentSummary.h" #include "qt/window/project_wizzard/QtProjectWizzardWindow.h" #include "utility/messaging/type/MessageLoadProject.h" + +// #include "utility/solution/SolutionParserCompilationDatabase.h" #include "utility/solution/SolutionParserVisualStudio.h" +#include "utility/solution/SolutionParserCodeBlocks.h" + +#include "utility/messaging/type/MessageStatus.h" + +#include "utility/logging/logging.h" QtProjectWizzard::QtProjectWizzard(QWidget* parent) : QtWindowStackElement(parent) @@ -24,6 +33,12 @@ QtProjectWizzard::QtProjectWizzard(QWidget* parent) { connect(&m_windowStack, SIGNAL(push()), this, SLOT(windowStackChanged())); connect(&m_windowStack, SIGNAL(pop()), this, SLOT(windowStackChanged())); + + m_parserManager = std::make_shared(); + + // wip + /*m_parserManager->pushSolutionParser(std::make_shared()); + m_parserManager->pushSolutionParser(std::make_shared());*/ } void QtProjectWizzard::showWindow() @@ -60,41 +75,63 @@ void QtProjectWizzard::newProject() window->setPreviousEnabled(false); } -void QtProjectWizzard::newProjectFromVisualStudioSolution(const std::string& visualStudioSolutionPath) +void QtProjectWizzard::newProjectFromSolution(const std::string& ideId, const std::string& visualStudioSolutionPath) { - ProjectSettings settings = getSettingsForVisualStudioSolution(visualStudioSolutionPath); - - editProject(settings); - - QWidget* widget = m_windowStack.getTopWindow(); - - if (widget) + if (m_parserManager->canParseSolution(ideId)) { - QtProjectWizzardWindow* window = dynamic_cast(widget); + ProjectSettings settings = m_parserManager->getProjectSettings(ideId, visualStudioSolutionPath); - window->updateTitle("NEW PROJECT FROM VS SOLUTION"); - window->updateNextButton("Create"); - window->setPreviousVisible(m_windowStack.getWindowCount() > 0); + editProject(settings); + + QWidget* widget = m_windowStack.getTopWindow(); + + if (widget) + { + QtProjectWizzardWindow* window = dynamic_cast(widget); + + std::string title = "NEW PROJECT FROM "; + title += ideId; + title += " SOLUTION"; + + boost::algorithm::to_upper(title); + + window->updateTitle(QString(title.c_str())); + window->updateNextButton("Create"); + window->setPreviousVisible(m_windowStack.getWindowCount() > 0); + } + } + else + { + LOG_ERROR_STREAM(<< "Unknown solution type"); + MessageStatus("Unable to parse given solution", true).dispatch(); } } -void QtProjectWizzard::refreshProjectFromVisualStudioSolution(const std::string& visualStudioSolutionPath) +void QtProjectWizzard::refreshProjectFromSolution(const std::string& ideId, const std::string& visualStudioSolutionPath) { - QtProjectWizzardWindow* window = dynamic_cast(m_windowStack.getTopWindow()); - if (window) + if (m_parserManager->canParseSolution(ideId)) { - window->content()->save(); + QtProjectWizzardWindow* window = dynamic_cast(m_windowStack.getTopWindow()); + if (window) + { + window->content()->save(); + } + + ProjectSettings settings = m_parserManager->getProjectSettings(ideId, visualStudioSolutionPath); + + m_settings.setSourcePaths(settings.getSourcePaths()); + m_settings.setHeaderSearchPaths(settings.getHeaderSearchPaths()); + m_settings.setVisualStudioSolutionPath(FilePath(visualStudioSolutionPath)); + + if (window) + { + window->content()->load(); + } } - - ProjectSettings settings = getSettingsForVisualStudioSolution(visualStudioSolutionPath); - - m_settings.setSourcePaths(settings.getSourcePaths()); - m_settings.setHeaderSearchPaths(settings.getHeaderSearchPaths()); - m_settings.setVisualStudioSolutionPath(FilePath(visualStudioSolutionPath)); - - if (window) + else { - window->content()->load(); + LOG_ERROR_STREAM(<< "Unknown solution type"); + MessageStatus("Unable to parse given solution", true).dispatch(); } } @@ -186,6 +223,26 @@ QtProjectWizzardWindow* QtProjectWizzard::createWindowWithContent() return window; } +template<> +QtProjectWizzardWindow* QtProjectWizzard::createWindowWithContent() +{ + QtProjectWizzardWindow* window = new QtProjectWizzardWindow(parentWidget()); + + connect(window, SIGNAL(previous()), &m_windowStack, SLOT(popWindow())); + connect(window, SIGNAL(canceled()), this, SLOT(cancelWizzard())); + + QtProjectWizzardContentSelect* content = new QtProjectWizzardContentSelect(&m_settings, window, m_parserManager); + + + + window->setContent(content); + window->setup(); + + m_windowStack.pushWindow(window); + + return window; +} + QtProjectWizzardWindow* QtProjectWizzard::createWindowWithSummary( std::function func ){ @@ -228,44 +285,6 @@ QtProjectWizzardWindow* QtProjectWizzard::createPopupWithContent() return window; } -ProjectSettings QtProjectWizzard::getSettingsForVisualStudioSolution(const std::string& visualStudioSolutionPath) const -{ - SolutionParserVisualStudio parser; - parser.openSolutionFile(visualStudioSolutionPath); - - ProjectSettings settings; - settings.setProjectName(parser.getSolutionName()); - settings.setProjectFileLocation(parser.getSolutionPath()); - settings.setVisualStudioSolutionPath(FilePath(visualStudioSolutionPath)); - - std::vector sourceFiles = parser.getProjectItems(); - std::vector sourcePaths; - for (const std::string& p : sourceFiles) - { - sourcePaths.push_back(FilePath(p)); - } - - std::vector includePaths = parser.getIncludePaths(); - std::vector headerPaths; - for (const std::string& p : includePaths) - { - headerPaths.push_back(FilePath(p)); - } - - settings.setSourcePaths(sourcePaths); - settings.setHeaderSearchPaths(headerPaths); - - // For testing - - // ProjectSettings settings; - // settings.setProjectName("hallo"); - // settings.setProjectFileLocation("~/Desktop"); - // settings.setVisualStudioSolutionPath(FilePath(visualStudioSolutionPath)); - // settings.setSourcePaths(std::vector(1, visualStudioSolutionPath)); - - return settings; -} - ProjectSettings QtProjectWizzard::getSettingsForCompilationDatabase(const std::string& compilationDatabasePath) const { ProjectSettings settings; @@ -315,13 +334,26 @@ void QtProjectWizzard::selectedProjectType(QtProjectWizzardContentSelect::Projec case QtProjectWizzardContentSelect::PROJECT_VS: { + std::string fileEndings = "("; + for (unsigned int i = 0; i < m_parserManager->getParserCount(); i++) + { + fileEndings += " *" + m_parserManager->getParserFileEnding(i); + } + fileEndings += ")"; + QString fileName = QFileDialog::getOpenFileName( - this, tr("Open Visual Studio Solution"), "", "Visual Studio Solution (*.sln)" + this, tr("Open Solution"), "", fileEndings.c_str() ); if (!fileName.isNull()) { - newProjectFromVisualStudioSolution(fileName.toStdString()); + for (unsigned int i = 0; i < m_parserManager->getParserCount(); i++) + { + if (fileName.contains(m_parserManager->getParserFileEnding(i).c_str())) + { + newProjectFromSolution(m_parserManager->getParserIdeId(i), fileName.toStdString()); + } + } } break; } @@ -508,8 +540,8 @@ void QtProjectWizzard::showSummary() summary->addContent(buildFile, false, true); connect(dynamic_cast(buildFile), - SIGNAL(refreshVisualStudioSolution(const std::string&)), - this, SLOT(refreshProjectFromVisualStudioSolution(const std::string&))); + SIGNAL(refreshVisualStudioSolution(const std::string&, const std::string&)), + this, SLOT(refreshProjectFromSolution(const std::string&, const std::string&))); } if (buildFile->getType() != QtProjectWizzardContentSelect::PROJECT_CDB) diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h index 094bc5d0..702f53fa 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h @@ -6,6 +6,8 @@ #include "qt/window/project_wizzard/QtProjectWizzardContentSelect.h" #include "qt/window/QtWindowStack.h" +#include "utility/solution/SolutionParserManager.h" + class ProjectSettings; class QtProjectWizzardContentSummary; class QtProjectWizzardWindow; @@ -28,8 +30,11 @@ public: public slots: void newProject(); - void newProjectFromVisualStudioSolution(const std::string& visualStudioSolutionPath); - void refreshProjectFromVisualStudioSolution(const std::string& visualStudioSolutionPath); + + void newProjectFromSolution(const std::string& ideId, const std::string& visualStudioSolutionPath); + + void refreshProjectFromSolution(const std::string& ideId, const std::string& visualStudioSolutionPath); + void newProjectFromCompilationDatabase(const std::string& compilationDatabasePath); void refreshProjectFromCompilationDatabase(const std::string& compilationDatabasePath); void editProject(const ProjectSettings& settings); @@ -38,12 +43,15 @@ public slots: private: template QtProjectWizzardWindow* createWindowWithContent(); + + template<> + QtProjectWizzardWindow* createWindowWithContent(); + QtProjectWizzardWindow* createWindowWithSummary( std::function func); template QtProjectWizzardWindow* createPopupWithContent(); - ProjectSettings getSettingsForVisualStudioSolution(const std::string& visualStudioSolutionPath) const; ProjectSettings getSettingsForCompilationDatabase(const std::string& compilationDatabasePath) const; void connectShowFiles(QtProjectWizzardContent* content); @@ -52,6 +60,8 @@ private: std::shared_ptr m_popup; ProjectSettings m_settings; + std::shared_ptr m_parserManager; + private slots: void cancelWizzard(); void windowStackChanged(); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp index f07ca2b4..5041c80d 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp @@ -160,7 +160,7 @@ void QtProjectWizzardContentBuildFile::refreshClicked() case QtProjectWizzardContentSelect::PROJECT_CDB: break; case QtProjectWizzardContentSelect::PROJECT_VS: - emit refreshVisualStudioSolution(path.str()); + emit refreshVisualStudioSolution("vs", path.str()); break; } } diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h index d2767727..384e8be2 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h @@ -13,7 +13,7 @@ class QtProjectWizzardContentBuildFile Q_OBJECT signals: - void refreshVisualStudioSolution(const std::string&); + void refreshVisualStudioSolution(const std::string& ideId, const std::string& solutionPath); public: QtProjectWizzardContentBuildFile(ProjectSettings* settings, QtProjectWizzardWindow* window); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp index d6cc9eba..54c4b43c 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp @@ -8,8 +8,11 @@ #include "qt/window/project_wizzard/QtProjectWizzardWindow.h" #include "utility/ResourcePaths.h" -QtProjectWizzardContentSelect::QtProjectWizzardContentSelect(ProjectSettings* settings, QtProjectWizzardWindow* window) +#include "utility/solution/SolutionParserManager.h" + +QtProjectWizzardContentSelect::QtProjectWizzardContentSelect(ProjectSettings* settings, QtProjectWizzardWindow* window, std::weak_ptr solutionParserManager) : QtProjectWizzardContent(settings, window) + , m_solutionParserManager(solutionParserManager) { } @@ -67,6 +70,14 @@ void QtProjectWizzardContentSelect::populateWindow(QGridLayout* layout) QToolButton* c = createProjectButton( "from Compilation\nDatabase", (ResourcePaths::getGuiPath() + "icon/project_cdb_256_256.png").c_str()); + + m_solutionDescription.push_back("Create a new Coati project by defining what files will be analyzed and header search paths."); + m_solutionDescription.push_back("Create a new project from an existing Visual Studio Solution file."); + m_solutionDescription.push_back("Create a project from an existing Compilation Database. Compilation Databases can be created from " + "cmake projects. Have a look at the " + "" + "documentation to find out more."); + m_buttons = new QButtonGroup(this); m_buttons->addButton(a); m_buttons->addButton(b); @@ -76,10 +87,39 @@ void QtProjectWizzardContentSelect::populateWindow(QGridLayout* layout) m_buttons->setId(b, PROJECT_VS); m_buttons->setId(c, PROJECT_CDB); + QHBoxLayout* hlayout = new QHBoxLayout(); + + hlayout->addWidget(a); + hlayout->addWidget(b); + hlayout->addWidget(c); + + unsigned int runningId = 3; + std::shared_ptr manager = m_solutionParserManager.lock(); + if (manager != NULL) + { + for (unsigned int i = 0; i < manager->getParserCount(); i++) + { + std::string name = manager->getParserName(i); + + QToolButton* button = createProjectButton(name.c_str(), + (ResourcePaths::getGuiPath() + "icon/project_vs_256_256.png").c_str()); + + m_buttons->addButton(button); + + m_solutionDescription.push_back(manager->getParserDescription(i)); + + hlayout->addWidget(button); + + m_buttons->setId(button, runningId); + + runningId++; + } + } + connect(m_buttons, static_cast(&QButtonGroup::buttonClicked), [this](int id) { - switch (id) + /*switch (id) { case 0: m_description->setText( "Create a new Coati project by defining what files will be analyzed and header search paths." @@ -93,17 +133,15 @@ void QtProjectWizzardContentSelect::populateWindow(QGridLayout* layout) "" "documentation to find out more." ); break; - } + }*/ + + m_description->setText(m_solutionDescription[id].c_str()); m_window->setNextEnabled(true); } ); - QHBoxLayout* hlayout = new QHBoxLayout(); - - hlayout->addWidget(a); - hlayout->addWidget(b); - hlayout->addWidget(c); + QFrame* container = new QFrame(); container->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); @@ -141,9 +179,12 @@ void QtProjectWizzardContentSelect::save() case 0: type = PROJECT_EMPTY; break; case 1: type = PROJECT_VS; break; case 2: type = PROJECT_CDB; break; + default: type = PROJECT_VS; break; // use vs for "standard" solutions TODO: change name of enum to reflect this is the default type } emit selected(type); + + // emit selected(m_buttons->checkedId()); } bool QtProjectWizzardContentSelect::check() diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.h index fdfd8f46..5fcc4f14 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.h @@ -4,6 +4,7 @@ #include "qt/window/project_wizzard/QtProjectWizzardContent.h" class QButtonGroup; +class SolutionParserManager; class QtProjectWizzardContentSelect : public QtProjectWizzardContent @@ -18,7 +19,7 @@ public: PROJECT_CDB = 2 }; - QtProjectWizzardContentSelect(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentSelect(ProjectSettings* settings, QtProjectWizzardWindow* window, std::weak_ptr solutionParserManager); // QtProjectWizzardContent implementation virtual void populateWindow(QGridLayout* layout) override; @@ -31,12 +32,21 @@ public: signals: void selected(QtProjectWizzardContentSelect::ProjectType); + // void selected(unsigned int type); + private: QButtonGroup* m_languages; QButtonGroup* m_buttons; QLabel* m_title; QLabel* m_description; + + std::vector m_projectTypeNames; + std::vector m_projectTypeDescriptions; + std::vector m_projectTypeIconPaths; + + std::weak_ptr m_solutionParserManager; + std::vector m_solutionDescription; }; #endif // QT_PROJECT_WIZZARD_CONTENT_SELECT_H