diff --git a/src/app/main.cpp b/src/app/main.cpp index bec59b4e..b917a09a 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -4,6 +4,7 @@ #include "utility/logging/FileLogger.h" #include "utility/logging/LogManager.h" #include "utility/ResourcePaths.h" +#include "utility/ScopedFunctor.h" #include "utility/UserPaths.h" #include "utility/Version.h" @@ -58,7 +59,10 @@ int main(int argc, char *argv[]) setupApp(argc, argv); init(); - std::shared_ptr app = Application::create(version); + Application::createInstance(version, nullptr, nullptr); + ScopedFunctor f([](){ + Application::destroyInstance(); + }); std::shared_ptr checker = LicenseChecker::getInstance(); @@ -92,7 +96,10 @@ int main(int argc, char *argv[]) QtNetworkFactory networkFactory; utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf"); - std::shared_ptr app = Application::create(version, &viewFactory, &networkFactory); + Application::createInstance(version, &viewFactory, &networkFactory); + ScopedFunctor f([](){ + Application::destroyInstance(); + }); commandLineParser.projectLoad(); diff --git a/src/app/utility/commandline/CommandLineParser.cpp b/src/app/utility/commandline/CommandLineParser.cpp index d373ab52..a669382d 100644 --- a/src/app/utility/commandline/CommandLineParser.cpp +++ b/src/app/utility/commandline/CommandLineParser.cpp @@ -176,10 +176,11 @@ void CommandLineParser::processProjectfile(const std::string& file) void CommandLineParser::projectLoad() { - if (!m_projectFile.empty()) + FilePath path(m_projectFile); // todo: use filepath as datatype for m_projectFile + if (path.exists() && path.extension() == ".coatiproject") { MessageDispatchWhenLicenseValid( - std::make_shared(m_projectFile, m_force) + std::make_shared(path.str(), m_force) ).dispatch(); } } diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 214baff5..c09e5230 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -23,55 +23,56 @@ #include "settings/ColorScheme.h" #include "settings/ProjectSettings.h" -std::shared_ptr Application::create( +void Application::createInstance( const Version& version, ViewFactory* viewFactory, NetworkFactory* networkFactory ){ Version::setApplicationVersion(version); loadSettings(); - std::shared_ptr ptr(new Application()); + TaskScheduler::getInstance(); + MessageQueue::getInstance(); - ptr->m_storageCache = std::make_shared(); + bool hasGui = (viewFactory != nullptr); + s_instance = std::shared_ptr(new Application(hasGui)); - ptr->m_componentManager = ComponentManager::create(viewFactory, ptr->m_storageCache.get()); + s_instance->m_storageCache = std::make_shared(); - ptr->m_mainView = viewFactory->createMainView(); - ptr->m_mainView->setTitle("Coati"); + if (viewFactory != nullptr) + { + s_instance->m_componentManager = ComponentManager::create(viewFactory, s_instance->m_storageCache.get()); - MessageDispatchWhenLicenseValid(std::make_shared()).dispatch(); + s_instance->m_mainView = viewFactory->createMainView(); + s_instance->m_mainView->setTitle("Coati"); - ptr->m_componentManager->setup(ptr->m_mainView.get()); - ptr->m_mainView->loadLayout(); + MessageDispatchWhenLicenseValid(std::make_shared()).dispatch(); - ptr->m_project = Project::create(ptr->m_storageCache.get()); + s_instance->m_componentManager->setup(s_instance->m_mainView.get()); + s_instance->m_mainView->loadLayout(); + } - ptr->m_ideCommunicationController = networkFactory->createIDECommunicationController(ptr->m_storageCache.get()); + if (networkFactory != nullptr) + { + s_instance->m_ideCommunicationController = networkFactory->createIDECommunicationController(s_instance->m_storageCache.get()); + } - ptr->startMessagingAndScheduling(); - - return ptr; + s_instance->startMessagingAndScheduling(); } -std::shared_ptr Application::create(const Version& version) +std::shared_ptr Application::getInstance() { - Version::setApplicationVersion(version); - loadSettings(); + return s_instance; +} - std::shared_ptr ptr(new Application(false)); - - ptr->m_storageCache = std::make_shared(); - ptr->m_project = Project::create(ptr->m_storageCache.get()); - - ptr->startMessagingAndScheduling(); - - return ptr; +void Application::destroyInstance() +{ + s_instance.reset(); } void Application::loadSettings() { - ApplicationSettings::getInstance()->load(FilePath(UserPaths::getAppSettingsPath())); - - loadStyle(ApplicationSettings::getInstance()->getColorSchemePath()); + std::shared_ptr settings = ApplicationSettings::getInstance(); + settings->load(FilePath(UserPaths::getAppSettingsPath())); + loadStyle(settings->getColorSchemePath()); } void Application::loadStyle(const FilePath& colorSchemePath) @@ -80,6 +81,8 @@ void Application::loadStyle(const FilePath& colorSchemePath) GraphViewStyle::loadStyleSettings(); } +std::shared_ptr Application::s_instance; + Application::Application(bool withGUI) : m_hasGUI(withGUI) { @@ -96,29 +99,55 @@ Application::~Application() } } +const std::shared_ptr Application::getCurrentProject() +{ + return m_project; +} + bool Application::hasGUI() { return m_hasGUI; } +int Application::handleDialog(const std::string& message) +{ + return m_mainView->confirm(message); +} + +int Application::handleDialog(const std::string& message, const std::vector& options) +{ + return m_mainView->confirm(message, options); +} + +void Application::setTitle(const std::string& title) +{ + m_mainView->setTitle(title); +} + void Application::createAndLoadProject(const FilePath& projectSettingsFilePath) { MessageStatus("Loading Project: " + projectSettingsFilePath.str(), false, true).dispatch(); - - loadSettings(); - updateRecentProjects(projectSettingsFilePath); - - m_storageCache->clear(); - - m_project = Project::create(m_storageCache.get()); - loadProject(projectSettingsFilePath); - - if (m_hasGUI) + try { - m_mainView->setTitle("Coati - " + projectSettingsFilePath.fileName()); - m_mainView->hideStartScreen(); + updateRecentProjects(projectSettingsFilePath); - m_componentManager->refreshViews(); + m_storageCache->clear(); + + m_project = Project::create(projectSettingsFilePath, m_storageCache.get()); + loadProject(projectSettingsFilePath); + + if (m_hasGUI) + { + setTitle("Coati - " + projectSettingsFilePath.fileName()); + m_mainView->hideStartScreen(); + + m_componentManager->refreshViews(); + } + } + catch (...) + { + LOG_ERROR_STREAM(<< "Failed to load project."); + MessageStatus("Failed to load project.", true).dispatch(); } } @@ -128,82 +157,25 @@ void Application::loadProject(const FilePath& projectSettingsFilePath) { m_componentManager->clearComponents(); } - - bool reparse = false; - - Project::ProjectState state = m_project->load(projectSettingsFilePath); - if (state == Project::PROJECT_OUTDATED) - { - if (m_hasGUI && !isTrial()) - { - std::vector options; - options.push_back("Yes"); - options.push_back("No"); - int result = m_mainView->confirm( - "The project file was changed after the last indexing. The project needs to get fully reindexed to " - "reflect the current project state. Do you want to reindex the project?", options); - - reparse = (result == 0); - } - } - else if (state == Project::PROJECT_OUTVERSIONED) - { - MessageStatus("Can't load project").dispatch(); - - reparse = true; - - if (m_hasGUI) - { - std::vector options; - options.push_back("Yes"); - options.push_back("No"); - int result = m_mainView->confirm( - "This project was indexed with a different version of Coati. It needs to be fully reindexed to be used " - "with this version of Coati. Do you want to reindex the project?", options); - - reparse = (result == 0); - } - } - - if (reparse) - { - m_project->clearStorage(); - m_project->load(projectSettingsFilePath); - } } -void Application::refreshProject() +void Application::refreshProject(bool force) { MessageStatus("Refreshing Project").dispatch(); - FilePath cdbPath = ProjectSettings::getInstance()->getCompilationDatabasePath(); - if (!cdbPath.empty() && !cdbPath.exists()) - { - MessageStatus("Can't refresh project").dispatch(); - - if (m_hasGUI) - { - std::vector options; - options.push_back("Ok"); - m_mainView->confirm( - "Can't refresh. The compilation database of the project does not exist anymore: " + cdbPath.str(), - options); - } - - return; - } - m_storageCache->clear(); if (m_hasGUI) { m_componentManager->refreshViews(); } - Project::ProjectState state = m_project->reload(); - if (state != Project::PROJECT_LOADED) + if (force) { - MessageStatus("Can't refresh project").dispatch(); - loadProject(m_project->getProjectSettingsFilePath()); + m_project->forceRefresh(); + } + else + { + m_project->refresh(); } } @@ -228,83 +200,41 @@ void Application::handleMessage(MessageLoadProject* message) { TRACE("app load project"); + loadSettings(); + FilePath projectSettingsFilePath(message->projectSettingsFilePath); if (projectSettingsFilePath.empty()) { - projectSettingsFilePath = m_project->getProjectSettingsFilePath(); - if (projectSettingsFilePath.empty()) - { - return; - } + return; } if (message->forceRefresh && !isTrial()) { if (m_hasGUI) { - FilePath path = projectSettingsFilePath; - FilePath oldPath = m_project->getProjectSettingsFilePath(); + std::vector options; + options.push_back("Yes"); + options.push_back("No"); + int result = m_mainView->confirm( + "Some settings were changed, the project needs to be fully reindexed. " + "Do you want to reindex the project?", options); - if (oldPath.exists() && oldPath != path) + if (result == 1) { - std::vector options; - options.push_back("Yes"); - options.push_back("No"); - int result = m_mainView->confirm( - "You changed the project location. The project file (.coatiproject) and the database file (.coatidb) will " - "be moved to the new location. Do you want to keep a copy of the files in the previous location?" - , options); - - FilePath dbPath = FilePath(path).replaceExtension("coatidb"); - FilePath olddbPath = FilePath(oldPath).replaceExtension("coatidb"); - - m_project = Project::create(m_storageCache.get()); - - if (result == 0) + if (!m_project || projectSettingsFilePath != m_project->getProjectSettingsFilePath()) { - FileSystem::copyFile(olddbPath, dbPath); - } - else - { - FileSystem::remove(oldPath); - FileSystem::rename(olddbPath, dbPath); - } - } - else - { - std::vector options; - options.push_back("Yes"); - options.push_back("No"); - int result = m_mainView->confirm( - "Some settings were changed, the project needs to be fully reindexed. " - "Do you want to reindex the project?", options); - - if (result == 1) - { - m_project->load(projectSettingsFilePath); - updateRecentProjects(projectSettingsFilePath); - m_mainView->setTitle("Coati - " + projectSettingsFilePath.fileName()); + createAndLoadProject(projectSettingsFilePath); return; } } } - m_project->clearStorage(); + refreshProject(true); } - else if (projectSettingsFilePath == m_project->getProjectSettingsFilePath()) - { - return; - } - - try + else if (!m_project || projectSettingsFilePath != m_project->getProjectSettingsFilePath()) { createAndLoadProject(projectSettingsFilePath); } - catch (...) - { - LOG_ERROR_STREAM(<< "Failed to load project."); - MessageStatus("Failed to load project.", true).dispatch(); - } } void Application::handleMessage(MessageRefresh* message) @@ -318,16 +248,14 @@ void Application::handleMessage(MessageRefresh* message) if (message->uiOnly) { - m_componentManager->refreshViews(); - } - else if (message->all) - { - m_project->clearStorage(); - refreshProject(); + if (m_hasGUI) + { + m_componentManager->refreshViews(); + } } else { - refreshProject(); + refreshProject(message->all); } } diff --git a/src/lib/Application.h b/src/lib/Application.h index 6ba99bf1..b2192952 100644 --- a/src/lib/Application.h +++ b/src/lib/Application.h @@ -27,19 +27,30 @@ class Application , public MessageListener { public: - static std::shared_ptr create(const Version& version, ViewFactory* viewFactory, NetworkFactory* networkFactory); - static std::shared_ptr create(const Version& version); + static void createInstance(const Version& version, ViewFactory* viewFactory, NetworkFactory* networkFactory); + static std::shared_ptr getInstance(); + static void destroyInstance(); + static void loadSettings(); static void loadStyle(const FilePath& colorSchemePath); ~Application(); + const std::shared_ptr getCurrentProject(); + void createAndLoadProject(const FilePath& projectSettingsFilePath); void loadProject(const FilePath& projectSettingsFilePath); - void refreshProject(); + void refreshProject(bool force); bool hasGUI(); + int handleDialog(const std::string& message); + int handleDialog(const std::string& message, const std::vector& options); + + void setTitle(const std::string& title); + private: + static std::shared_ptr s_instance; + Application(bool withGUI=true); virtual void handleMessage(MessageActivateWindow* message); @@ -52,7 +63,7 @@ private: void updateRecentProjects(const FilePath& projectSettingsFilePath); - bool m_hasGUI; + const bool m_hasGUI; std::shared_ptr m_project; std::shared_ptr m_storageCache; diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index aded41e6..c6fac5ff 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -195,6 +195,12 @@ add_files( settings/ApplicationSettings.h settings/ColorScheme.cpp settings/ColorScheme.h + settings/CxxProjectSettings.cpp + settings/CxxProjectSettings.h + settings/JavaProjectSettings.cpp + settings/JavaProjectSettings.h + settings/LanguageType.cpp + settings/LanguageType.h settings/ProjectSettings.cpp settings/ProjectSettings.h settings/Settings.cpp @@ -329,6 +335,8 @@ add_files( utility/Property.h utility/ResourcePaths.cpp utility/ResourcePaths.h + utility/ScopedFunctor.cpp + utility/ScopedFunctor.h utility/ScopedSwitcher.h utility/TimePoint.cpp utility/TimePoint.h @@ -346,7 +354,11 @@ add_files( Application.cpp Application.h + CxxProject.cpp + CxxProject.h isTrial.h + JavaProject.cpp + JavaProject.h LicenseChecker.cpp LicenseChecker.h Project.cpp diff --git a/src/lib/CxxProject.cpp b/src/lib/CxxProject.cpp new file mode 100644 index 00000000..a347fc0c --- /dev/null +++ b/src/lib/CxxProject.cpp @@ -0,0 +1,132 @@ +#include "CxxProject.h" + + +#include "settings/ApplicationSettings.h" + +#include "utility/messaging/type/MessageStatus.h" +#include "utility/utility.h" + +#include "Application.h" + +#include "utility/file/FileRegister.h" +#include "utility/file/FileSystem.h" + + +#include "data/parser/cxx/TaskParseCxx.h" + + + +CxxProject::~CxxProject() +{ +} + +std::shared_ptr CxxProject::getProjectSettings() +{ + return m_projectSettings; +} + +const std::shared_ptr CxxProject::getProjectSettings() const +{ + return m_projectSettings; +} + +CxxProject::CxxProject(std::shared_ptr projectSettings, StorageAccessProxy* storageAccessProxy) + : Project(storageAccessProxy) + , m_projectSettings(projectSettings) +{ +} + +bool CxxProject::allowsRefresh() +{ + FilePath cdbPath = m_projectSettings->getCompilationDatabasePath(); + if (!cdbPath.empty() && !cdbPath.exists()) + { + MessageStatus("Can't refresh project").dispatch(); + + if (Application::getInstance()->hasGUI()) + { + std::vector options; + options.push_back("Ok"); + Application::getInstance()->handleDialog( + "Can't refresh. The compilation database of the project does not exist anymore: " + cdbPath.str(), + options + ); + } + return false; + } + return true; +} + +std::shared_ptr CxxProject::createIndexerTask( + PersistentStorage* storage, + std::shared_ptr storageMutex, + std::shared_ptr fileRegister) +{ + return std::make_shared( + storage, + storageMutex, + fileRegister, + getParserArguments() + ); +} + +void CxxProject::updateFileManager(FileManager& fileManager) +{ + std::vector sourcePaths = m_projectSettings->getAbsoluteSourcePaths(); + std::vector headerPaths = sourcePaths; + + std::vector sourceExtensions; + + if (m_projectSettings->getCompilationDatabasePath().exists()) + { + sourcePaths = TaskParseCxx::getSourceFilesFromCDB(m_projectSettings->getCompilationDatabasePath()); + } + else + { + sourceExtensions = m_projectSettings->getSourceExtensions(); + } + + std::vector excludePaths = m_projectSettings->getAbsoluteExcludePaths(); + + fileManager.setPaths(sourcePaths, headerPaths, excludePaths, sourceExtensions); +} + +Parser::Arguments CxxProject::getParserArguments() const +{ + std::shared_ptr appSettings = ApplicationSettings::getInstance(); + + Parser::Arguments args; + + utility::append(args.compilerFlags, m_projectSettings->getCompilerFlags()); + + // MAYBE DO THIS IN PARSER! AND ONLY ADD THE PATH OF THE CURRENT FILE!! + // Add the source paths as HeaderSearchPaths as well, so clang will also look here when searching include files. + //utility::append(args.systemHeaderSearchPaths, m_fileManager.getSourcePaths()); + + utility::append(args.systemHeaderSearchPaths, m_projectSettings->getAbsoluteHeaderSearchPaths()); + + utility::append(args.systemHeaderSearchPaths, appSettings->getHeaderSearchPathsExpanded()); + + // Add all subdirectories of the header search paths + if (m_projectSettings->getUseSourcePathsForHeaderSearch()) + { + std::vector headerSearchSubPaths; + for (FilePath p : m_projectSettings->getSourcePaths()) + { + utility::append(headerSearchSubPaths, FileSystem::getSubDirectories(p)); + } + + utility::append(args.systemHeaderSearchPaths, utility::unique(headerSearchSubPaths)); + } + + utility::append(args.frameworkSearchPaths, m_projectSettings->getAbsoluteFrameworkSearchPaths()); + utility::append(args.frameworkSearchPaths, appSettings->getFrameworkSearchPathsExpanded()); + + args.language = m_projectSettings->getLanguage(); + args.languageStandard = m_projectSettings->getStandard(); + args.compilationDatabasePath = m_projectSettings->getCompilationDatabasePath(); + + return args; +} + + diff --git a/src/lib/CxxProject.h b/src/lib/CxxProject.h new file mode 100644 index 00000000..deafe6b9 --- /dev/null +++ b/src/lib/CxxProject.h @@ -0,0 +1,39 @@ +#ifndef CXX_PROJECT_H +#define CXX_PROJECT_H + +#include + +#include "settings/CxxProjectSettings.h" +#include "Project.h" + +class CxxProject: public Project +{ +public: + virtual ~CxxProject(); + +protected: + virtual std::shared_ptr getProjectSettings(); + virtual const std::shared_ptr getProjectSettings() const; + +private: + CxxProject(std::shared_ptr projectSettings, StorageAccessProxy* storageAccessProxy); + CxxProject(const CxxProject&); + + virtual bool allowsRefresh(); + + virtual std::shared_ptr createIndexerTask( + PersistentStorage* storage, + std::shared_ptr storageMutex, + std::shared_ptr fileRegister); + + virtual void updateFileManager(FileManager& fileManager); + + Parser::Arguments getParserArguments() const; + + std::shared_ptr m_projectSettings; + + + friend Project; +}; + +#endif // CXX_PROJECT_H diff --git a/src/lib/JavaProject.cpp b/src/lib/JavaProject.cpp new file mode 100644 index 00000000..f89d54b6 --- /dev/null +++ b/src/lib/JavaProject.cpp @@ -0,0 +1,80 @@ +#include "JavaProject.h" + +#include "data/parser/java/JavaEnvironmentFactory.h" +#include "data/parser/java/TaskParseJava.h" + +JavaProject::~JavaProject() +{ +} + +std::shared_ptr JavaProject::getProjectSettings() +{ + return m_projectSettings; +} + +const std::shared_ptr JavaProject::getProjectSettings() const +{ + return m_projectSettings; +} + +JavaProject::JavaProject(std::shared_ptr projectSettings, StorageAccessProxy* storageAccessProxy) + : Project(storageAccessProxy) + , m_projectSettings(projectSettings) +{ + if (!JavaEnvironmentFactory::getInstance()) + { + JavaEnvironmentFactory::createInstance( + "data/java/asm-5.0.3.jar;" + "data/java/cglib-3.1.jar;" + "data/java/easymock-3.3.1.jar;" + "data/java/guava-18.0.jar;" + "data/java/hamcrest-core-1.3.jar;" + "data/java/java-indexer.jar;" + "data/java/javaparser-core-2.4.1-SNAPSHOT.jar;" + "data/java/javaslang-2.0.0-beta.jar;" + "data/java/javassist-3.19.0-GA.jar;" + "data/java/java-symbol-solver-core-0.2.0-SNAPSHOT.jar;" + "data/java/java-symbol-solver-logic-0.2.0-SNAPSHOT.jar;" + "data/java/java-symbol-solver-model-0.2.0-SNAPSHOT.jar;" + "data/java/objenesis-2.1.jar;" + ); + } +} + +std::shared_ptr JavaProject::createIndexerTask( + PersistentStorage* storage, + std::shared_ptr storageMutex, + std::shared_ptr fileRegister) +{ + Parser::Arguments arguments; + + for (FilePath classpath: m_projectSettings->getAbsoluteClasspaths()) + { + arguments.javaClassPaths.push_back(classpath.str()); + } + + for (FilePath sourcePath: m_projectSettings->getAbsoluteSourcePaths()) + { + if (sourcePath.extension().empty()) + { + arguments.javaClassPaths.push_back(sourcePath.str()); + } + } + + return std::make_shared( + storage, + storageMutex, + fileRegister, + arguments + ); +} + +void JavaProject::updateFileManager(FileManager& fileManager) +{ + std::vector sourcePaths = m_projectSettings->getAbsoluteSourcePaths(); + std::vector headerPaths = sourcePaths; + std::vector sourceExtensions = m_projectSettings->getSourceExtensions(); + std::vector excludePaths = m_projectSettings->getAbsoluteExcludePaths(); + + fileManager.setPaths(sourcePaths, headerPaths, excludePaths, sourceExtensions); +} diff --git a/src/lib/JavaProject.h b/src/lib/JavaProject.h new file mode 100644 index 00000000..d41a1a3f --- /dev/null +++ b/src/lib/JavaProject.h @@ -0,0 +1,34 @@ +#ifndef JAVA_PROJECT_H +#define JAVA_PROJECT_H + +#include + +#include "settings/JavaProjectSettings.h" +#include "Project.h" + +class JavaProject: public Project +{ +public: + virtual ~JavaProject(); + +protected: + virtual std::shared_ptr getProjectSettings(); + virtual const std::shared_ptr getProjectSettings() const; + +private: + JavaProject(std::shared_ptr projectSettings, StorageAccessProxy* storageAccessProxy); + JavaProject(const JavaProject&); + + virtual std::shared_ptr createIndexerTask( + PersistentStorage* storage, + std::shared_ptr storageMutex, + std::shared_ptr fileRegister); + + virtual void updateFileManager(FileManager& fileManager); + + std::shared_ptr m_projectSettings; + + friend Project; +}; + +#endif // JAVA_PROJECT_H diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index 22ce11bc..95ebce43 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -2,12 +2,11 @@ #include "data/access/StorageAccessProxy.h" #include "data/graph/Token.h" -#include "data/parser/cxx/TaskParseCxx.h" #include "data/parser/cxx/TaskParseWrapper.h" -#include "data/parser/java/JavaEnvironmentFactory.h" #include "data/parser/java/TaskParseJava.h" #include "data/PersistentStorage.h" #include "data/TaskCleanStorage.h" + #include "settings/ApplicationSettings.h" #include "settings/ProjectSettings.h" @@ -17,103 +16,201 @@ #include "utility/messaging/type/MessageFinishedParsing.h" #include "utility/scheduling/TaskGroupSequential.h" #include "utility/scheduling/TaskGroupParallel.h" +#include "utility/text/TextAccess.h" #include "utility/utility.h" #include "utility/utilityString.h" #include "utility/Version.h" -std::shared_ptr Project::create(StorageAccessProxy* storageAccessProxy) +#include "Application.h" +#include "CxxProject.h" +#include "JavaProject.h" +#include "isTrial.h" + +std::shared_ptr Project::create(const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy) { - std::shared_ptr ptr(new Project(storageAccessProxy)); - return ptr; + std::shared_ptr project; + + switch (ProjectSettings::getLanguageOfProject(projectSettingsFile)) + { + case LANGUAGE_C: + case LANGUAGE_CPP: + { + project = std::shared_ptr(new CxxProject( + std::make_shared(projectSettingsFile), storageAccessProxy + )); + } + break; + case LANGUAGE_JAVA: + { + project = std::shared_ptr(new JavaProject( + std::make_shared(projectSettingsFile), storageAccessProxy + )); + } + break; + } + + if (project) + { + project->load(); + } + return project; } Project::~Project() { } -const FilePath& Project::getProjectSettingsFilePath() const +void Project::refresh() { - return m_projectSettingsFilepath; + if (allowsRefresh()) + { + bool loadedSettings = getProjectSettings()->load(); + + updateFileManager(m_fileManager); + + buildIndex(); + + m_state = PROJECT_STATE_LOADED; + } } -Project::ProjectState Project::load(const FilePath& projectSettingsFile) +void Project::forceRefresh() { - m_state = PROJECT_NONE; - - bool success = true; - if (!projectSettingsFile.empty()) + if (allowsRefresh()) { - success = ProjectSettings::getInstance()->load(projectSettingsFile); + clearStorage(); } + refresh(); +} - if (success) +FilePath Project::getProjectSettingsFilePath() const +{ + return getProjectSettings()->getFilePath(); +} + +std::string Project::getDescription() const +{ + return getProjectSettings()->getDescription(); +} + +bool Project::settingsEqualExceptNameAndLocation(const ProjectSettings& otherSettings) const +{ + return getProjectSettings()->equalsExceptNameAndLocation(otherSettings); +} + +void Project::logStats() const +{ + m_storage->logStats(); +} + +Project::Project(StorageAccessProxy* storageAccessProxy) + : m_storageAccessProxy(storageAccessProxy) + , m_state(PROJECT_STATE_NOT_LOADED) +{ +} + +void Project::load() +{ + const std::shared_ptr projectSettings = getProjectSettings(); + bool loadedSettings = projectSettings->load(); + if (loadedSettings) { - setProjectSettingsFilePath(projectSettingsFile); - updateFileManager(); + const FilePath projectSettingsPath = projectSettings->getFilePath(); + const FilePath dbPath = FilePath(projectSettingsPath).replaceExtension("coatidb"); + m_storage = std::make_shared(dbPath); + m_storageAccessProxy->setSubject(m_storage.get()); + + if (m_storage->isEmpty()) + { + m_state = PROJECT_STATE_EMPTY; + m_storage->setup(); + } + else if (m_storage->isIncompatible()) + { + m_state = PROJECT_STATE_OUTVERSIONED; + } + else if (TextAccess::createFromFile(projectSettingsPath.str())->getText() != m_storage->getProjectSettingsText()) + { + m_state = PROJECT_STATE_OUTDATED; + } + else + { + m_state = PROJECT_STATE_LOADED; + } + + updateFileManager(m_fileManager); + + bool reparse = false; switch (m_state) { - case PROJECT_NONE: - break; + case PROJECT_STATE_EMPTY: + buildIndex(); + m_state = PROJECT_STATE_LOADED; + break; + case PROJECT_STATE_OUTDATED: + if (Application::getInstance()->hasGUI() && !isTrial()) + { + std::vector options; + options.push_back("Yes"); + options.push_back("No"); + int result = Application::getInstance()->handleDialog( + "The project file was changed after the last indexing. The project needs to get fully reindexed to " + "reflect the current project state. Do you want to reindex the project?", options); - case PROJECT_EMPTY: - parseCode(); - break; + reparse = (result == 0); + } + // dont break here. + case PROJECT_STATE_LOADED: + m_storage->finishParsing(); + MessageFinishedParsing(0, 0, 0, true).dispatch(); + break; + case PROJECT_STATE_OUTVERSIONED: + MessageStatus("Can't load project").dispatch(); - case PROJECT_LOADED: - case PROJECT_OUTDATED: - m_storage->finishParsing(); - MessageFinishedParsing(0, 0, 0, true).dispatch(); - break; + reparse = true; - case PROJECT_OUTVERSIONED: - m_storage.reset(); - break; + if (Application::getInstance()->hasGUI() && !isTrial()) + { + std::vector options; + options.push_back("Yes"); + options.push_back("No"); + int result = Application::getInstance()->handleDialog( + "This project was indexed with a different version of Coati. It needs to be fully reindexed to be used " + "with this version of Coati. Do you want to reindex the project?", options); + + reparse = (result == 0); + } + m_storage.reset(); + break; + } + + if (reparse) + { + forceRefresh(); } } - - return m_state; -} - -Project::ProjectState Project::reload() -{ - if (m_state == PROJECT_LOADED && - FileSystem::getFileInfoForPath(m_projectSettingsFilepath).lastWriteTime > - FileSystem::getFileInfoForPath(m_storage->getDbFilePath()).lastWriteTime) - { - m_state = PROJECT_OUTDATED; - } - else if (!m_projectSettingsFilepath.empty() && (m_state == PROJECT_EMPTY || m_state == PROJECT_LOADED)) - { - ProjectSettings::getInstance()->load(m_projectSettingsFilepath); - updateFileManager(); - - parseCode(); - } - - return m_state; } void Project::clearStorage() { - if (m_state == PROJECT_OUTVERSIONED) + if (!m_storage) { - loadStorage(m_projectSettingsFilepath); + const FilePath projectSettingsPath = getProjectSettings()->getFilePath(); + const FilePath dbPath = FilePath(projectSettingsPath).replaceExtension("coatidb"); + m_storage = std::make_shared(dbPath); } if (m_storage) { m_storage->clear(); - m_state = PROJECT_EMPTY; + m_state = PROJECT_STATE_EMPTY; } } -void Project::parseCode() +void Project::buildIndex() { - if (m_projectSettingsFilepath.empty()) - { - return; - } + m_storage->setProjectSettingsText(TextAccess::createFromFile(getProjectSettingsFilePath().str())->getText()); m_fileManager.fetchFilePaths(m_storage->getInfoOnAllFiles()); std::set addedFilePaths = m_fileManager.getAddedFilePaths(); @@ -131,7 +228,6 @@ void Project::parseCode() filesToParse.insert(filesToParse.end(), addedFilePaths.begin(), addedFilePaths.end()); filesToParse.insert(filesToParse.end(), updatedFilePaths.begin(), updatedFilePaths.end()); - m_state = PROJECT_LOADED; if (!filesToClean.size() && !filesToParse.size()) { @@ -147,28 +243,6 @@ void Project::parseCode() std::shared_ptr fileRegister = std::make_shared(&m_fileManager, indexerThreadCount > 1); fileRegister->setFilePaths(filesToParse); - if (ProjectSettings::getInstance()->getLanguage() == "Java") - { - if (!JavaEnvironmentFactory::getInstance()) - { - JavaEnvironmentFactory::createInstance( - "data/java/asm-5.0.3.jar;" - "data/java/cglib-3.1.jar;" - "data/java/easymock-3.3.1.jar;" - "data/java/guava-18.0.jar;" - "data/java/hamcrest-core-1.3.jar;" - "data/java/java-indexer.jar;" - "data/java/javaparser-core-2.4.1-SNAPSHOT.jar;" - "data/java/javaslang-2.0.0-beta.jar;" - "data/java/javassist-3.19.0-GA.jar;" - "data/java/java-symbol-solver-core-0.2.0-SNAPSHOT.jar;" - "data/java/java-symbol-solver-logic-0.2.0-SNAPSHOT.jar;" - "data/java/java-symbol-solver-model-0.2.0-SNAPSHOT.jar;" - "data/java/objenesis-2.1.jar;" - ); - } - } - std::shared_ptr taskParserWrapper = std::make_shared( m_storage.get(), fileRegister @@ -182,160 +256,15 @@ void Project::parseCode() for (int i = 0; i < indexerThreadCount; i++) { - if (ProjectSettings::getInstance()->getLanguage() == "Java") - { - std::shared_ptr projSettings = ProjectSettings::getInstance(); - - Parser::Arguments arguments; - - for (FilePath classpath: projSettings->getAbsoluteJavaClasspaths()) - { - arguments.javaClassPaths.push_back(classpath.str()); - } - - for (FilePath sourcePath: projSettings->getAbsoluteSourcePaths()) - { - if (sourcePath.extension().empty()) - { - arguments.javaClassPaths.push_back(sourcePath.str()); - } - } - - taskParallelIndexing->addTask( - std::make_shared( - m_storage.get(), - storageMutex, - fileRegister, - arguments - ) - ); - } - else // c or cxx - { - taskParallelIndexing->addTask(std::make_shared( - m_storage.get(), - storageMutex, - fileRegister, - getParserArguments() - )); - } + taskParallelIndexing->addTask(createIndexerTask(m_storage.get(), storageMutex, fileRegister)); } Task::dispatch(taskSequential); } -void Project::logStats() const +bool Project::allowsRefresh() { - m_storage->logStats(); + return true; } -void Project::setProjectSettingsFilePath(const FilePath& path) -{ - if (path.empty()) - { - m_storage.reset(); - m_state = PROJECT_NONE; - } - else - { - loadStorage(path); - if (m_storage->isEmpty()) - { - m_state = PROJECT_EMPTY; - m_storage->setup(); - } - else if (m_storage->isIncompatible()) - { - m_state = PROJECT_OUTVERSIONED; - m_storage.reset(); - } - else if (FileSystem::getFileInfoForPath(path).lastWriteTime > FileSystem::getFileInfoForPath(m_storage->getDbFilePath()).lastWriteTime) - { - m_state = PROJECT_OUTDATED; - } - else - { - m_state = PROJECT_LOADED; - } - } - - m_storageAccessProxy->setSubject(m_storage.get()); - m_projectSettingsFilepath = path; -} - -void Project::loadStorage(const FilePath& path) -{ - FilePath dbPath = FilePath(path).replaceExtension("coatidb"); - if (!m_storage || path != m_projectSettingsFilepath || !dbPath.exists()) - { - m_storage = std::make_shared(dbPath); - } -} - -void Project::updateFileManager() -{ - std::shared_ptr projSettings = ProjectSettings::getInstance(); - - std::vector sourcePaths = projSettings->getAbsoluteSourcePaths(); - std::vector headerPaths = sourcePaths; - - std::vector sourceExtensions; - - if (projSettings->getCompilationDatabasePath().exists()) - { - sourcePaths = TaskParseCxx::getSourceFilesFromCDB(projSettings->getCompilationDatabasePath()); - } - else - { - sourceExtensions = projSettings->getSourceExtensions(); - } - - std::vector excludePaths = projSettings->getAbsoluteExcludePaths(); - - m_fileManager.setPaths(sourcePaths, headerPaths, excludePaths, sourceExtensions); -} - -Parser::Arguments Project::getParserArguments() const -{ - std::shared_ptr projSettings = ProjectSettings::getInstance(); - std::shared_ptr appSettings = ApplicationSettings::getInstance(); - - Parser::Arguments args; - - utility::append(args.compilerFlags, projSettings->getCompilerFlags()); - - // Add the source paths as HeaderSearchPaths as well, so clang will also look here when searching include files. - utility::append(args.systemHeaderSearchPaths, m_fileManager.getSourcePaths()); - - utility::append(args.systemHeaderSearchPaths, projSettings->getAbsoluteHeaderSearchPaths()); - - utility::append(args.systemHeaderSearchPaths, appSettings->getHeaderSearchPathsExpanded()); - - // Add all subdirectories of the header search paths - if (projSettings->getUseSourcePathsForHeaderSearch()) - { - std::vector headerSearchSubPaths; - for (FilePath p : projSettings->getSourcePaths()) - { - utility::append(headerSearchSubPaths, FileSystem::getSubDirectories(p)); - } - - utility::append(args.systemHeaderSearchPaths, utility::unique(headerSearchSubPaths)); - } - - utility::append(args.frameworkSearchPaths, projSettings->getAbsoluteFrameworkSearchPaths()); - utility::append(args.frameworkSearchPaths, appSettings->getFrameworkSearchPathsExpanded()); - - args.language = projSettings->getLanguage(); - args.languageStandard = projSettings->getStandard(); - args.compilationDatabasePath = projSettings->getCompilationDatabasePath(); - - return args; -} - -Project::Project(StorageAccessProxy* storageAccessProxy) - : m_storageAccessProxy(storageAccessProxy) - , m_state(PROJECT_NONE) -{ -} diff --git a/src/lib/Project.h b/src/lib/Project.h index 40769044..34f8187a 100644 --- a/src/lib/Project.h +++ b/src/lib/Project.h @@ -2,57 +2,65 @@ #define PROJECT_H #include +#include #include "utility/file/FileManager.h" #include "data/parser/Parser.h" +#include "settings/ProjectSettings.h" // todo: use forward declaration here +#include "utility/scheduling/Task.h" class PersistentStorage; class StorageAccessProxy; +class FileRegister; class Project { public: - enum ProjectState - { - PROJECT_NONE, - PROJECT_EMPTY, - PROJECT_LOADED, - PROJECT_OUTDATED, - PROJECT_OUTVERSIONED - }; + static std::shared_ptr create(const FilePath& projectSettingsFile, StorageAccessProxy* storageAccessProxy); - static std::shared_ptr create(StorageAccessProxy* storageAccessProxy); + virtual ~Project(); - ~Project(); - - const FilePath& getProjectSettingsFilePath() const; - - ProjectState load(const FilePath& projectSettingsFile); - ProjectState reload(); - - void clearStorage(); + void refresh(); + void forceRefresh(); + FilePath getProjectSettingsFilePath() const; + std::string getDescription() const; + bool settingsEqualExceptNameAndLocation(const ProjectSettings& otherSettings) const; void logStats() const; -private: +protected: Project(StorageAccessProxy* storageAccessProxy); + + virtual std::shared_ptr getProjectSettings() = 0; + virtual const std::shared_ptr getProjectSettings() const = 0; + +private: + enum ProjectStateType + { + PROJECT_STATE_NOT_LOADED, + PROJECT_STATE_EMPTY, + PROJECT_STATE_LOADED, + PROJECT_STATE_OUTDATED, + PROJECT_STATE_OUTVERSIONED + }; + Project(const Project&); - Project operator=(const Project&); - void parseCode(); + void load(); + void clearStorage(); + void buildIndex(); - void setProjectSettingsFilePath(const FilePath& path); - void loadStorage(const FilePath& path); - void updateFileManager(); - - Parser::Arguments getParserArguments() const; + virtual bool allowsRefresh(); + virtual std::shared_ptr createIndexerTask( + PersistentStorage* storage, + std::shared_ptr storageMutex, + std::shared_ptr fileRegister) = 0; + virtual void updateFileManager(FileManager& fileManager) = 0; StorageAccessProxy* const m_storageAccessProxy; - ProjectState m_state; - - FilePath m_projectSettingsFilepath; + ProjectStateType m_state; FileManager m_fileManager; std::shared_ptr m_storage; diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index 0c8538f1..42b5c4d5 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -14,7 +14,7 @@ #include "data/location/TokenLocationFile.h" #include "data/location/TokenLocationLine.h" #include "settings/ApplicationSettings.h" -#include "settings/ProjectSettings.h" +#include "Application.h" CodeController::CodeController(StorageAccess* storageAccess) : m_storageAccess(storageAccess) @@ -47,7 +47,7 @@ void CodeController::handleMessage(MessageActivateAll* message) statsSnippet.locationFile = std::make_shared(FilePath()); statsSnippet.locationFile->isWholeCopy = true; - statsSnippet.title = ProjectSettings::getInstance()->getFilePath().withoutExtension().fileName(); + statsSnippet.title = Application::getInstance()->getCurrentProject()->getProjectSettingsFilePath().withoutExtension().fileName(); std::vector description = getProjectDescription(statsSnippet.locationFile.get()); @@ -662,7 +662,7 @@ std::shared_ptr CodeController::getTokenLocationOfParentScope std::vector CodeController::getProjectDescription(TokenLocationFile* locationFile) const { - std::string description = ProjectSettings::getInstance()->getDescription(); + std::string description = Application::getInstance()->getCurrentProject()->getDescription(); if (!description.size()) { diff --git a/src/lib/data/PersistentStorage.cpp b/src/lib/data/PersistentStorage.cpp index 6bfe144f..619dfdda 100644 --- a/src/lib/data/PersistentStorage.cpp +++ b/src/lib/data/PersistentStorage.cpp @@ -248,6 +248,16 @@ bool PersistentStorage::isIncompatible() const return m_sqliteStorage.isIncompatible(); } +std::string PersistentStorage::getProjectSettingsText() const +{ + return m_sqliteStorage.getProjectSettingsText(); +} + +void PersistentStorage::setProjectSettingsText(std::string text) +{ + m_sqliteStorage.setProjectSettingsText(text); +} + void PersistentStorage::setup() { m_sqliteStorage.setup(); diff --git a/src/lib/data/PersistentStorage.h b/src/lib/data/PersistentStorage.h index 07525ddb..02bba738 100644 --- a/src/lib/data/PersistentStorage.h +++ b/src/lib/data/PersistentStorage.h @@ -52,6 +52,8 @@ public: bool isEmpty() const; bool isIncompatible() const; + std::string getProjectSettingsText() const; + void setProjectSettingsText(std::string text); void setup(); void clear(); diff --git a/src/lib/data/SqliteStorage.cpp b/src/lib/data/SqliteStorage.cpp index 1d92a90f..8137155d 100644 --- a/src/lib/data/SqliteStorage.cpp +++ b/src/lib/data/SqliteStorage.cpp @@ -11,7 +11,7 @@ #include "utility/utilityString.h" #include "utility/Version.h" -const size_t SqliteStorage::STORAGE_VERSION = 2; +const size_t SqliteStorage::STORAGE_VERSION = 3; SqliteStorage::SqliteStorage(const FilePath& dbFilePath) : m_dbFilePath(dbFilePath) @@ -90,6 +90,16 @@ bool SqliteStorage::isIncompatible() const return false; } +std::string SqliteStorage::getProjectSettingsText() const +{ + return getMetaValue("project_settings"); +} + +void SqliteStorage::setProjectSettingsText(std::string text) +{ + insertOrUpdateMetaValue("project_settings", text); +} + void SqliteStorage::setVersion() { setStorageVersion(); diff --git a/src/lib/data/SqliteStorage.h b/src/lib/data/SqliteStorage.h index 234c2529..c5175a83 100644 --- a/src/lib/data/SqliteStorage.h +++ b/src/lib/data/SqliteStorage.h @@ -35,6 +35,8 @@ public: bool isEmpty() const; bool isIncompatible() const; + std::string getProjectSettingsText() const; + void setProjectSettingsText(std::string text); void setVersion(); diff --git a/src/lib/settings/CxxProjectSettings.cpp b/src/lib/settings/CxxProjectSettings.cpp new file mode 100644 index 00000000..6d6183e0 --- /dev/null +++ b/src/lib/settings/CxxProjectSettings.cpp @@ -0,0 +1,124 @@ +#include "settings/CxxProjectSettings.h" + +#include "utility/utility.h" + +CxxProjectSettings::CxxProjectSettings() +{ + // setlanguage... +} + +CxxProjectSettings::CxxProjectSettings(const FilePath& projectFilePath) + : ProjectSettings(projectFilePath) +{ + // setlanguage... +} + +CxxProjectSettings::CxxProjectSettings(std::string projectName, const FilePath& projectFileLocation) + : ProjectSettings(projectName, projectFileLocation) +{ + // setlanguage... +} + +CxxProjectSettings::~CxxProjectSettings() +{ +} + +bool CxxProjectSettings::equalsExceptNameAndLocation(const ProjectSettings& other) const +{ + if (other.getLanguage() == getLanguage()) + { + const CxxProjectSettings* typedOther = dynamic_cast(&other); + return( + ProjectSettings::equalsExceptNameAndLocation(other)// && + // utility::isPermutation(getClasspaths(), typedOther->getClasspaths()) + ); + } + return false; +} + +std::vector CxxProjectSettings::getHeaderSearchPaths() const +{ + return getPathValues("source/header_search_paths/header_search_path"); +} + +std::vector CxxProjectSettings::getAbsoluteHeaderSearchPaths() const +{ + std::vector paths = getHeaderSearchPaths(); + expandPaths(paths); + makePathsAbsolute(paths); + return paths; +} + +bool CxxProjectSettings::setHeaderSearchPaths(const std::vector& headerSearchPaths) +{ + return setPathValues("source/header_search_paths/header_search_path", headerSearchPaths); +} + +std::vector CxxProjectSettings::getFrameworkSearchPaths() const +{ + return getPathValues("source/framework_search_paths/framework_search_path"); +} + +std::vector CxxProjectSettings::getAbsoluteFrameworkSearchPaths() const +{ + std::vector paths = getFrameworkSearchPaths(); + expandPaths(paths); + makePathsAbsolute(paths); + return paths; +} + +bool CxxProjectSettings::setFrameworkSearchPaths(const std::vector& frameworkSearchPaths) +{ + return setPathValues("source/framework_search_paths/framework_search_path", frameworkSearchPaths); +} + +std::vector CxxProjectSettings::getCompilerFlags() const +{ + std::vector defaultValues; + return getValues("source/compiler_flags/compiler_flag", defaultValues); +} + +bool CxxProjectSettings::setCompilerFlags(const std::vector& compilerFlags) +{ + return setValues("source/compiler_flags/compiler_flag", compilerFlags); +} + +bool CxxProjectSettings::getUseSourcePathsForHeaderSearch() const +{ + return getValue("source/use_source_paths_for_header_search", false); +} + +bool CxxProjectSettings::setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch) +{ + return setValue("source/use_source_paths_for_header_search", useSourcePathsForHeaderSearch); +} + +FilePath CxxProjectSettings::getVisualStudioSolutionPath() const +{ + return FilePath(getValue("source/build_file_path/vs_solution_path", "")); +} + +bool CxxProjectSettings::setVisualStudioSolutionPath(const FilePath& visualStudioSolutionPath) +{ + return setValue("source/build_file_path/vs_solution_path", visualStudioSolutionPath.str()); +} + +FilePath CxxProjectSettings::getCompilationDatabasePath() const +{ + return FilePath(getValue("source/build_file_path/compilation_db_path", "")); +} + +bool CxxProjectSettings::setCompilationDatabasePath(const FilePath& compilationDatabasePath) +{ + return setValue("source/build_file_path/compilation_db_path", compilationDatabasePath.str()); +} + +std::vector CxxProjectSettings::getDefaultSourceExtensions() const +{ + std::vector defaultValues; + defaultValues.push_back(".c"); + defaultValues.push_back(".cpp"); + defaultValues.push_back(".cxx"); + defaultValues.push_back(".cc"); + return defaultValues; +} diff --git a/src/lib/settings/CxxProjectSettings.h b/src/lib/settings/CxxProjectSettings.h new file mode 100644 index 00000000..1a5d718f --- /dev/null +++ b/src/lib/settings/CxxProjectSettings.h @@ -0,0 +1,40 @@ +#ifndef CXX_PROJECT_SETTINGS_H +#define CXX_PROJECT_SETTINGS_H + +#include "settings/ProjectSettings.h" + +class CxxProjectSettings: public ProjectSettings +{ +public: + CxxProjectSettings(); + CxxProjectSettings(const FilePath& projectFilePath); + CxxProjectSettings(std::string projectName, const FilePath& projectFileLocation); + virtual ~CxxProjectSettings(); + + virtual bool equalsExceptNameAndLocation(const ProjectSettings& other) const; + + std::vector getHeaderSearchPaths() const; + std::vector getAbsoluteHeaderSearchPaths() const; + bool setHeaderSearchPaths(const std::vector& headerSearchPaths); + + std::vector getFrameworkSearchPaths() const; + std::vector getAbsoluteFrameworkSearchPaths() const; + bool setFrameworkSearchPaths(const std::vector& frameworkSearchPaths); + + std::vector getCompilerFlags() const; + bool setCompilerFlags(const std::vector& compilerFlags); + + bool getUseSourcePathsForHeaderSearch() const; + bool setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch); + + FilePath getVisualStudioSolutionPath() const; + bool setVisualStudioSolutionPath(const FilePath& visualStudioSolutionPath); + + FilePath getCompilationDatabasePath() const; + bool setCompilationDatabasePath(const FilePath& compilationDatabasePath); + +private: + virtual std::vector getDefaultSourceExtensions() const; +}; + +#endif // CXX_PROJECT_SETTINGS_H diff --git a/src/lib/settings/JavaProjectSettings.cpp b/src/lib/settings/JavaProjectSettings.cpp new file mode 100644 index 00000000..1a90cd6d --- /dev/null +++ b/src/lib/settings/JavaProjectSettings.cpp @@ -0,0 +1,62 @@ +#include "settings/JavaProjectSettings.h" + +#include "utility/utility.h" + +JavaProjectSettings::JavaProjectSettings() +{ + // setlanguage... +} + +JavaProjectSettings::JavaProjectSettings(const FilePath& projectFilePath) + : ProjectSettings(projectFilePath) +{ + // setlanguage... +} + +JavaProjectSettings::JavaProjectSettings(std::string projectName, const FilePath& projectFileLocation) + : ProjectSettings(projectName, projectFileLocation) +{ + // setlanguage... +} + +JavaProjectSettings::~JavaProjectSettings() +{ +} + +bool JavaProjectSettings::equalsExceptNameAndLocation(const ProjectSettings& other) const +{ + if (other.getLanguage() == getLanguage()) + { + const JavaProjectSettings* typedOther = dynamic_cast(&other); + return( + ProjectSettings::equalsExceptNameAndLocation(other) && + utility::isPermutation(getClasspaths(), typedOther->getClasspaths()) + ); + } + return false; +} + +std::vector JavaProjectSettings::getClasspaths() const +{ + return getPathValues("source/class_paths/class_path"); +} + +std::vector JavaProjectSettings::getAbsoluteClasspaths() const +{ + std::vector paths = getClasspaths(); + expandPaths(paths); + makePathsAbsolute(paths); + return paths; +} + +bool JavaProjectSettings::setClasspaths(const std::vector& paths) +{ + return setPathValues("source/class_paths/class_path", paths); +} + +std::vector JavaProjectSettings::getDefaultSourceExtensions() const +{ + std::vector defaultValues; + defaultValues.push_back(".java"); + return defaultValues; +} diff --git a/src/lib/settings/JavaProjectSettings.h b/src/lib/settings/JavaProjectSettings.h new file mode 100644 index 00000000..d1fca82d --- /dev/null +++ b/src/lib/settings/JavaProjectSettings.h @@ -0,0 +1,24 @@ +#ifndef JAVA_PROJECT_SETTINGS_H +#define JAVA_PROJECT_SETTINGS_H + +#include "settings/ProjectSettings.h" + +class JavaProjectSettings: public ProjectSettings +{ +public: + JavaProjectSettings(); + JavaProjectSettings(const FilePath& projectFilePath); + JavaProjectSettings(std::string projectName, const FilePath& projectFileLocation); + virtual ~JavaProjectSettings(); + + virtual bool equalsExceptNameAndLocation(const ProjectSettings& other) const; + + std::vector getClasspaths() const; + std::vector getAbsoluteClasspaths() const; + bool setClasspaths(const std::vector& headerSearchPaths); + +private: + virtual std::vector getDefaultSourceExtensions() const; +}; + +#endif // JAVA_PROJECT_SETTINGS_H diff --git a/src/lib/settings/LanguageType.cpp b/src/lib/settings/LanguageType.cpp new file mode 100644 index 00000000..bc365a87 --- /dev/null +++ b/src/lib/settings/LanguageType.cpp @@ -0,0 +1,32 @@ +#include "settings/LanguageType.h" + +std::string languageTypeToString(LanguageType t) +{ + switch (t) + { + case LANGUAGE_C: + return "C"; + case LANGUAGE_CPP: + return "C++"; + case LANGUAGE_JAVA: + return "Java"; + } + return "unknown"; +} + +LanguageType stringToLanguageType(std::string s) +{ + if (s == "C") + { + return LANGUAGE_C; + } + else if (s == "C++") + { + return LANGUAGE_CPP; + } + else if (s == "Java") + { + return LANGUAGE_JAVA; + } + return LANGUAGE_UNKNOWN; +} diff --git a/src/lib/settings/LanguageType.h b/src/lib/settings/LanguageType.h new file mode 100644 index 00000000..3847c93a --- /dev/null +++ b/src/lib/settings/LanguageType.h @@ -0,0 +1,17 @@ +#ifndef LANGUAGE_TYPE_H +#define LANGUAGE_TYPE_H + +#include + +enum LanguageType +{ + LANGUAGE_C, + LANGUAGE_CPP, + LANGUAGE_JAVA, + LANGUAGE_UNKNOWN +}; + +std::string languageTypeToString(LanguageType t); +LanguageType stringToLanguageType(std::string s); + +#endif // LANGUAGE_TYPE_H diff --git a/src/lib/settings/ProjectSettings.cpp b/src/lib/settings/ProjectSettings.cpp index a17f0050..31816522 100644 --- a/src/lib/settings/ProjectSettings.cpp +++ b/src/lib/settings/ProjectSettings.cpp @@ -1,75 +1,83 @@ #include "settings/ProjectSettings.h" +#include "settings/CxxProjectSettings.h" +#include "settings/JavaProjectSettings.h" #include "utility/utility.h" -std::vector ProjectSettings::getDefaultSourceExtensions() +LanguageType ProjectSettings::getLanguageOfProject(FilePath projectFilePath) { - std::vector defaultValues; - defaultValues.push_back(".c"); - defaultValues.push_back(".cpp"); - defaultValues.push_back(".cxx"); - defaultValues.push_back(".cc"); - return defaultValues; -} - -std::shared_ptr ProjectSettings::s_instance; - -std::shared_ptr ProjectSettings::getInstance() -{ - if (!s_instance) - { - s_instance = std::shared_ptr(new ProjectSettings()); - } - - return s_instance; + ProjectSettings tempSettings(projectFilePath); + tempSettings.load(); + return tempSettings.getLanguage(); } ProjectSettings::ProjectSettings() { } +ProjectSettings::ProjectSettings(const FilePath& projectFilePath) +{ + setFilePath(projectFilePath); +} + +ProjectSettings::ProjectSettings(std::string projectName, const FilePath& projectFileLocation) +{ + setFilePath(FilePath(projectFileLocation.str() + "/" + projectName + ".coatiproject")); +} + ProjectSettings::~ProjectSettings() { } -bool ProjectSettings::operator==(const ProjectSettings& other) const +bool ProjectSettings::equalsExceptNameAndLocation(const ProjectSettings& other) const { - return - getFilePath() == other.getFilePath() && + return ( getLanguage() == other.getLanguage() && getStandard() == other.getStandard() && - getVisualStudioSolutionPath() == other.getVisualStudioSolutionPath() && - getCompilationDatabasePath() == other.getCompilationDatabasePath() && - getUseSourcePathsForHeaderSearch() == other.getUseSourcePathsForHeaderSearch() && utility::isPermutation(getSourcePaths(), other.getSourcePaths()) && - utility::isPermutation(getHeaderSearchPaths(), other.getHeaderSearchPaths()) && - utility::isPermutation(getFrameworkSearchPaths(), other.getFrameworkSearchPaths()) && utility::isPermutation(getExcludePaths(), other.getExcludePaths()) && - utility::isPermutation(getCompilerFlags(), other.getCompilerFlags()) && - utility::isPermutation(getSourceExtensions(), other.getSourceExtensions()); + utility::isPermutation(getSourceExtensions(), other.getSourceExtensions()) + ); } -bool ProjectSettings::operator!=(const ProjectSettings& other) const +bool ProjectSettings::load() { - return !(*this == other); + return Settings::load(getFilePath()); } -void ProjectSettings::save(const FilePath& filePath) +std::string ProjectSettings::getProjectName() const { - m_projectName = ""; - m_projectFileLocation = ""; - - Settings::save(filePath); + return getFilePath().withoutExtension().fileName(); } -std::string ProjectSettings::getLanguage() const +void ProjectSettings::setProjectName(const std::string& name) { - return getValue("language_settings/language", "C++"); + setFilePath(FilePath(getProjectFileLocation().str() + "/" + name + ".coatiproject")); } -bool ProjectSettings::setLanguage(const std::string& language) +FilePath ProjectSettings::getProjectFileLocation() const { - return setValue("language_settings/language", language); + return getFilePath().parentDirectory(); +} + +void ProjectSettings::setProjectFileLocation(const FilePath& location) +{ + setFilePath(FilePath(location.str() + "/" + getProjectName() + ".coatiproject")); +} + +std::string ProjectSettings::getDescription() const +{ + return getValue("info/description", ""); +} + +LanguageType ProjectSettings::getLanguage() const +{ + return stringToLanguageType(getValue("language_settings/language", languageTypeToString(LANGUAGE_UNKNOWN))); +} + +bool ProjectSettings::setLanguage(LanguageType language) +{ + return setValue("language_settings/language", languageTypeToString(language)); } std::string ProjectSettings::getStandard() const @@ -82,19 +90,6 @@ bool ProjectSettings::setStandard(const std::string& standard) return setValue("language_settings/standard", standard); } -std::vector ProjectSettings::getJavaClasspaths() const -{ - return getPathValues("source/class_paths/class_path"); -} - -std::vector ProjectSettings::getAbsoluteJavaClasspaths() const -{ - std::vector paths = getJavaClasspaths(); - expandPaths(paths); - makePathsAbsolute(paths); - return paths; -} - std::vector ProjectSettings::getSourcePaths() const { return getPathValues("source/source_paths/source_path"); @@ -113,73 +108,6 @@ bool ProjectSettings::setSourcePaths(const std::vector& sourcePaths) return setPathValues("source/source_paths/source_path", sourcePaths); } -std::vector ProjectSettings::getHeaderSearchPaths() const -{ - return getPathValues("source/header_search_paths/header_search_path"); -} - -std::vector ProjectSettings::getAbsoluteHeaderSearchPaths() const -{ - std::vector paths = getHeaderSearchPaths(); - expandPaths(paths); - makePathsAbsolute(paths); - return paths; -} - -bool ProjectSettings::setHeaderSearchPaths(const std::vector& headerSearchPaths) -{ - return setPathValues("source/header_search_paths/header_search_path", headerSearchPaths); -} - -std::vector ProjectSettings::getFrameworkSearchPaths() const -{ - return getPathValues("source/framework_search_paths/framework_search_path"); -} - -std::vector ProjectSettings::getAbsoluteFrameworkSearchPaths() const -{ - std::vector paths = getFrameworkSearchPaths(); - expandPaths(paths); - makePathsAbsolute(paths); - return paths; -} - -bool ProjectSettings::setFrameworkSearchPaths(const std::vector& frameworkSearchPaths) -{ - return setPathValues("source/framework_search_paths/framework_search_path", frameworkSearchPaths); -} - -std::vector ProjectSettings::getCompilerFlags() const -{ - std::vector defaultValues; - return getValues("source/compiler_flags/compiler_flag", defaultValues); -} - -bool ProjectSettings::setCompilerFlags(const std::vector& compilerFlags) -{ - return setValues("source/compiler_flags/compiler_flag", compilerFlags); -} - -std::vector ProjectSettings::getSourceExtensions() const -{ - return getValues("source/extensions/source_extensions", getDefaultSourceExtensions()); -} - -bool ProjectSettings::setSourceExtensions(const std::vector &sourceExtensions) -{ - return setValues("source/extensions/source_extensions", sourceExtensions); -} - -bool ProjectSettings::getUseSourcePathsForHeaderSearch() const -{ - return getValue("source/use_source_paths_for_header_search", false); -} - -bool ProjectSettings::setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch) -{ - return setValue("source/use_source_paths_for_header_search", useSourcePathsForHeaderSearch); -} - std::vector ProjectSettings::getExcludePaths() const { return getPathValues("source/exclude_paths/exclude_path"); @@ -198,59 +126,14 @@ bool ProjectSettings::setExcludePaths(const std::vector& excludePaths) return setPathValues("source/exclude_paths/exclude_path", excludePaths); } -FilePath ProjectSettings::getVisualStudioSolutionPath() const +std::vector ProjectSettings::getSourceExtensions() const { - return FilePath(getValue("source/build_file_path/vs_solution_path", "")); + return getValues("source/extensions/source_extensions", getDefaultSourceExtensions()); } -bool ProjectSettings::setVisualStudioSolutionPath(const FilePath& visualStudioSolutionPath) +bool ProjectSettings::setSourceExtensions(const std::vector &sourceExtensions) { - return setValue("source/build_file_path/vs_solution_path", visualStudioSolutionPath.str()); -} - -FilePath ProjectSettings::getCompilationDatabasePath() const -{ - return FilePath(getValue("source/build_file_path/compilation_db_path", "")); -} - -bool ProjectSettings::setCompilationDatabasePath(const FilePath& compilationDatabasePath) -{ - return setValue("source/build_file_path/compilation_db_path", compilationDatabasePath.str()); -} - -std::string ProjectSettings::getDescription() const -{ - return getValue("info/description", ""); -} - -std::string ProjectSettings::getProjectName() const -{ - if (m_projectName.size()) - { - return m_projectName; - } - - return getFilePath().withoutExtension().fileName(); -} - -void ProjectSettings::setProjectName(const std::string& name) -{ - m_projectName = name; -} - -FilePath ProjectSettings::getProjectFileLocation() const -{ - if (!m_projectFileLocation.empty()) - { - return m_projectFileLocation; - } - - return getFilePath().parentDirectory(); -} - -void ProjectSettings::setProjectFileLocation(const FilePath& location) -{ - m_projectFileLocation = location; + return setValues("source/extensions/source_extensions", sourceExtensions); } void ProjectSettings::makePathsAbsolute(std::vector& paths) const @@ -264,3 +147,8 @@ void ProjectSettings::makePathsAbsolute(std::vector& paths) const } } } + +std::vector ProjectSettings::getDefaultSourceExtensions() const +{ + return std::vector(); +} diff --git a/src/lib/settings/ProjectSettings.h b/src/lib/settings/ProjectSettings.h index d4074fd8..c00b12c3 100644 --- a/src/lib/settings/ProjectSettings.h +++ b/src/lib/settings/ProjectSettings.h @@ -5,82 +5,53 @@ #include #include "settings/Settings.h" +#include "settings/LanguageType.h" class ProjectSettings : public Settings { public: - static std::vector getDefaultSourceExtensions(); + static LanguageType getLanguageOfProject(FilePath projectFilePath); - static std::shared_ptr getInstance(); ProjectSettings(); - ~ProjectSettings(); + ProjectSettings(const FilePath& projectFilePath); + ProjectSettings(std::string projectName, const FilePath& projectFileLocation); + virtual ~ProjectSettings(); - bool operator==(const ProjectSettings& other) const; - bool operator!=(const ProjectSettings& other) const; + virtual bool equalsExceptNameAndLocation(const ProjectSettings& other) const; - virtual void save(const FilePath& filePath); + virtual bool load(); - // language settings - std::string getLanguage() const; - bool setLanguage(const std::string& language); - - std::string getStandard() const; - bool setStandard(const std::string& standard); - - // java... todo: move this - std::vector getJavaClasspaths() const; - std::vector getAbsoluteJavaClasspaths() const; - - // source - std::vector getSourcePaths() const; - std::vector getAbsoluteSourcePaths() const; - bool setSourcePaths(const std::vector& sourcePaths); - - std::vector getHeaderSearchPaths() const; - std::vector getAbsoluteHeaderSearchPaths() const; - bool setHeaderSearchPaths(const std::vector& headerSearchPaths); - - std::vector getFrameworkSearchPaths() const; - std::vector getAbsoluteFrameworkSearchPaths() const; - bool setFrameworkSearchPaths(const std::vector& frameworkSearchPaths); - - std::vector getCompilerFlags() const; - bool setCompilerFlags(const std::vector& compilerFlags); - - std::vector getSourceExtensions() const; - bool setSourceExtensions(const std::vector& sourceExtensions); - - bool getUseSourcePathsForHeaderSearch() const; - bool setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch); - - std::vector getExcludePaths() const; - std::vector getAbsoluteExcludePaths() const; - bool setExcludePaths(const std::vector& excludePaths); - - FilePath getVisualStudioSolutionPath() const; - bool setVisualStudioSolutionPath(const FilePath& visualStudioSolutionPath); - - FilePath getCompilationDatabasePath() const; - bool setCompilationDatabasePath(const FilePath& compilationDatabasePath); - - // info - std::string getDescription() const; - - // used in project wizzard std::string getProjectName() const; void setProjectName(const std::string& name); FilePath getProjectFileLocation() const; void setProjectFileLocation(const FilePath& location); -private: + std::string getDescription() const; + + LanguageType getLanguage() const; + bool setLanguage(LanguageType language); + + std::string getStandard() const; + bool setStandard(const std::string& standard); + + std::vector getSourcePaths() const; + std::vector getAbsoluteSourcePaths() const; + bool setSourcePaths(const std::vector& sourcePaths); + + std::vector getExcludePaths() const; + std::vector getAbsoluteExcludePaths() const; + bool setExcludePaths(const std::vector& excludePaths); + + std::vector getSourceExtensions() const; + bool setSourceExtensions(const std::vector& sourceExtensions); + +protected: void makePathsAbsolute(std::vector& paths) const; - std::string m_projectName; - FilePath m_projectFileLocation; - - static std::shared_ptr s_instance; +private: + virtual std::vector getDefaultSourceExtensions() const; }; #endif // PROJECT_SETTINGS_H diff --git a/src/lib/settings/Settings.h b/src/lib/settings/Settings.h index 68290339..df05bc8c 100644 --- a/src/lib/settings/Settings.h +++ b/src/lib/settings/Settings.h @@ -15,12 +15,13 @@ public: Settings& operator=(const Settings& other); virtual ~Settings(); - bool load(const FilePath& filePath); - void save(); + virtual bool load(const FilePath& filePath); + virtual void save(); virtual void save(const FilePath& filePath); + void clear(); - const FilePath& getFilePath() const; + virtual const FilePath& getFilePath() const; protected: Settings(); diff --git a/src/lib/utility/ScopedFunctor.cpp b/src/lib/utility/ScopedFunctor.cpp new file mode 100644 index 00000000..b51c2170 --- /dev/null +++ b/src/lib/utility/ScopedFunctor.cpp @@ -0,0 +1,11 @@ +#include "utility/ScopedFunctor.h" + +ScopedFunctor::ScopedFunctor(std::function onDestroy) + : m_onDestroy(onDestroy) +{ +} + +ScopedFunctor::~ScopedFunctor() +{ + m_onDestroy(); +} diff --git a/src/lib/utility/ScopedFunctor.h b/src/lib/utility/ScopedFunctor.h new file mode 100644 index 00000000..1df94cf1 --- /dev/null +++ b/src/lib/utility/ScopedFunctor.h @@ -0,0 +1,16 @@ +#ifndef SCOPED_FUNCTOR_H +#define SCOPED_FUNCTOR_H + +#include + +class ScopedFunctor +{ +public: + ScopedFunctor(std::function onDestroy); + ~ScopedFunctor(); + +private: + std::function m_onDestroy; +}; + +#endif // SCOPED_FUNCTOR_H diff --git a/src/lib/utility/solution/ISolutionParser.h b/src/lib/utility/solution/ISolutionParser.h index 2e056e49..916202ed 100644 --- a/src/lib/utility/solution/ISolutionParser.h +++ b/src/lib/utility/solution/ISolutionParser.h @@ -28,7 +28,7 @@ public: virtual std::vector getProjectItems() = 0; virtual std::vector getCompileFlags() = 0; - virtual ProjectSettings getProjectSettings(const std::string& solutionFilePath) = 0; + virtual std::shared_ptr getProjectSettings(const std::string& solutionFilePath) = 0; virtual std::string getIdeName() const = 0; virtual std::string getButtonText() const = 0; diff --git a/src/lib/utility/solution/SolutionParserCodeBlocks.cpp b/src/lib/utility/solution/SolutionParserCodeBlocks.cpp index feddc344..443c5a68 100644 --- a/src/lib/utility/solution/SolutionParserCodeBlocks.cpp +++ b/src/lib/utility/solution/SolutionParserCodeBlocks.cpp @@ -4,6 +4,7 @@ #include "SolutionParserUtility.h" +#include "settings/CxxProjectSettings.h" #include "utility/logging/logging.h" SolutionParserCodeBlocks::SolutionParserCodeBlocks() @@ -174,14 +175,12 @@ std::vector SolutionParserCodeBlocks::getCompileFlags() return compilerFlags; } -ProjectSettings SolutionParserCodeBlocks::getProjectSettings(const std::string& solutionFilePath) +std::shared_ptr SolutionParserCodeBlocks::getProjectSettings(const std::string& solutionFilePath) { openSolutionFile(solutionFilePath); - ProjectSettings settings; - settings.setProjectName(getSolutionName()); - settings.setProjectFileLocation(getSolutionPath()); - settings.setVisualStudioSolutionPath(solutionFilePath); + std::shared_ptr settings = std::make_shared(getSolutionName(), getSolutionPath()); + settings->setVisualStudioSolutionPath(solutionFilePath); // why is it called vs solution if it is used for codeblocks as well? std::vector sourceFiles = getProjectItems(); std::vector sourcePaths; @@ -197,8 +196,8 @@ ProjectSettings SolutionParserCodeBlocks::getProjectSettings(const std::string& headerPaths.push_back(FilePath(p)); } - settings.setSourcePaths(sourcePaths); - settings.setHeaderSearchPaths(headerPaths); + settings->setSourcePaths(sourcePaths); + settings->setHeaderSearchPaths(headerPaths); return settings; } diff --git a/src/lib/utility/solution/SolutionParserCodeBlocks.h b/src/lib/utility/solution/SolutionParserCodeBlocks.h index 2df10afa..827c28fd 100644 --- a/src/lib/utility/solution/SolutionParserCodeBlocks.h +++ b/src/lib/utility/solution/SolutionParserCodeBlocks.h @@ -21,7 +21,7 @@ public: virtual std::vector getIncludePaths(); virtual std::vector getCompileFlags(); - virtual ProjectSettings getProjectSettings(const std::string& solutionFilePath); + virtual std::shared_ptr getProjectSettings(const std::string& solutionFilePath); virtual std::string getIdeName() const; virtual std::string getButtonText() const; diff --git a/src/lib/utility/solution/SolutionParserManager.cpp b/src/lib/utility/solution/SolutionParserManager.cpp index 53c0d881..e0f6c4ff 100644 --- a/src/lib/utility/solution/SolutionParserManager.cpp +++ b/src/lib/utility/solution/SolutionParserManager.cpp @@ -39,7 +39,7 @@ bool SolutionParserManager::canParseSolution(const std::string& ideId) const return false; } -ProjectSettings SolutionParserManager::getProjectSettings(const std::string& ideId, const std::string& solutionFilePath) const +std::shared_ptr SolutionParserManager::getProjectSettings(const std::string& ideId, const std::string& solutionFilePath) const { std::string lIdeId = ideId; boost::algorithm::to_lower(lIdeId); @@ -57,7 +57,7 @@ ProjectSettings SolutionParserManager::getProjectSettings(const std::string& ide LOG_ERROR_STREAM(<< "Solution type is unknown"); - return ProjectSettings(); + return std::shared_ptr(); } unsigned int SolutionParserManager::getParserCount() const diff --git a/src/lib/utility/solution/SolutionParserManager.h b/src/lib/utility/solution/SolutionParserManager.h index c7fa1d38..a0f70d7d 100644 --- a/src/lib/utility/solution/SolutionParserManager.h +++ b/src/lib/utility/solution/SolutionParserManager.h @@ -15,7 +15,7 @@ public: bool canParseSolution(const std::string& ideId) const; - ProjectSettings getProjectSettings(const std::string& ideId, const std::string& solutionFilePath) const; + std::shared_ptr getProjectSettings(const std::string& ideId, const std::string& solutionFilePath) const; unsigned int getParserCount() const; diff --git a/src/lib/utility/solution/SolutionParserVisualStudio.cpp b/src/lib/utility/solution/SolutionParserVisualStudio.cpp index d6621e71..0d7b2b7a 100644 --- a/src/lib/utility/solution/SolutionParserVisualStudio.cpp +++ b/src/lib/utility/solution/SolutionParserVisualStudio.cpp @@ -9,6 +9,7 @@ #include "SolutionParserUtility.h" +#include "settings/CxxProjectSettings.h" #include "utility/logging/logging.h" SolutionParserVisualStudio::SolutionParserVisualStudio() @@ -202,7 +203,7 @@ std::vector SolutionParserVisualStudio::getCompileFlags() return compilerFlags; } -ProjectSettings SolutionParserVisualStudio::getProjectSettings(const std::string& solutionFilePath) +std::shared_ptr SolutionParserVisualStudio::getProjectSettings(const std::string& solutionFilePath) { LOG_INFO_STREAM(<< "Starting to parse VS solution"); @@ -218,10 +219,8 @@ ProjectSettings SolutionParserVisualStudio::getProjectSettings(const std::string LOG_INFO_STREAM(<< "Setting meta information"); - ProjectSettings settings; - settings.setProjectName(getSolutionName()); - settings.setProjectFileLocation(getSolutionPath()); - settings.setVisualStudioSolutionPath(solutionFilePath); + std::shared_ptr settings = std::make_shared(getSolutionName(), getSolutionPath()); + settings->setVisualStudioSolutionPath(solutionFilePath); LOG_INFO_STREAM(<< "Parsing project files"); @@ -247,10 +246,10 @@ ProjectSettings SolutionParserVisualStudio::getProjectSettings(const std::string LOG_INFO_STREAM(<< "Setting compile flags"); std::vector compilerFlags = getCompileFlags(); - settings.setCompilerFlags(compilerFlags); + settings->setCompilerFlags(compilerFlags); - settings.setSourcePaths(sourcePaths); - settings.setHeaderSearchPaths(headerPaths); + settings->setSourcePaths(sourcePaths); + settings->setHeaderSearchPaths(headerPaths); LOG_INFO_STREAM(<< "Done parsing VS solution"); diff --git a/src/lib/utility/solution/SolutionParserVisualStudio.h b/src/lib/utility/solution/SolutionParserVisualStudio.h index b65bfb66..0f8dcd20 100644 --- a/src/lib/utility/solution/SolutionParserVisualStudio.h +++ b/src/lib/utility/solution/SolutionParserVisualStudio.h @@ -21,7 +21,7 @@ public: virtual std::vector getIncludePaths(); virtual std::vector getCompileFlags(); - virtual ProjectSettings getProjectSettings(const std::string& solutionFilePath); + virtual std::shared_ptr getProjectSettings(const std::string& solutionFilePath); virtual std::string getIdeName() const; virtual std::string getButtonText() const; diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index d4f5fc2a..9332de5a 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -21,7 +21,7 @@ #include "qt/window/QtAbout.h" #include "qt/window/QtLicense.h" #include "settings/ApplicationSettings.h" -#include "settings/ProjectSettings.h" +#include "Application.h" #include "utility/file/FileSystem.h" #include "utility/logging/logging.h" #include "utility/messaging/type/MessageCodeReference.h" @@ -420,7 +420,7 @@ void QtMainWindow::openProject(const QString &path) void QtMainWindow::editProject() { QtProjectWizzard* wizzard = createWindow(); - wizzard->editProject(*ProjectSettings::getInstance().get()); + wizzard->editProject(Application::getInstance()->getCurrentProject()->getProjectSettingsFilePath()); } void QtMainWindow::find() diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp index 1cf36fb5..edf02a71 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp @@ -18,6 +18,9 @@ #include "qt/window/project_wizzard/QtProjectWizzardContentSourceList.h" #include "qt/window/project_wizzard/QtProjectWizzardContentSummary.h" #include "qt/window/project_wizzard/QtProjectWizzardWindow.h" +#include "settings/CxxProjectSettings.h" +#include "settings/JavaProjectSettings.h" +#include "utility/file/FileSystem.h" #include "utility/messaging/type/MessageDispatchWhenLicenseValid.h" #include "utility/messaging/type/MessageLoadProject.h" #include "utility/messaging/type/MessageRefresh.h" @@ -29,6 +32,8 @@ #include "utility/logging/logging.h" +#include "Application.h" + QtProjectWizzard::QtProjectWizzard(QWidget* parent) : QtWindowStackElement(parent) , m_windowStack(this) @@ -70,13 +75,11 @@ void QtProjectWizzard::hideWindow() void QtProjectWizzard::newProject() { - m_settings = ProjectSettings(); - QtProjectWizzardWindow* window = createWindowWithContent(); connect(dynamic_cast(window->content()), - SIGNAL(selected(QtProjectWizzardContentSelect::ProjectType)), - this, SLOT(selectedProjectType(QtProjectWizzardContentSelect::ProjectType))); + SIGNAL(selected(LanguageType, QtProjectWizzardContentSelect::ProjectType)), + this, SLOT(selectedProjectType(LanguageType, QtProjectWizzardContentSelect::ProjectType))); window->setNextEnabled(false); window->setPreviousEnabled(false); @@ -86,8 +89,9 @@ void QtProjectWizzard::newProjectFromSolution(const std::string& ideId, const st { if (m_parserManager->canParseSolution(ideId)) { - ProjectSettings settings = m_parserManager->getProjectSettings(ideId, visualStudioSolutionPath); + std::shared_ptr settings = m_parserManager->getProjectSettings(ideId, visualStudioSolutionPath); + // this looks rather hacky.. calling the edit project and then setting the title. editProject(settings); QWidget* widget = m_windowStack.getTopWindow(); @@ -124,12 +128,16 @@ void QtProjectWizzard::refreshProjectFromSolution(const std::string& ideId, cons 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)); + std::shared_ptr settings = m_parserManager->getProjectSettings(ideId, visualStudioSolutionPath); + std::shared_ptr otherCxxSettings = std::dynamic_pointer_cast(settings); + std::shared_ptr ownCxxSettings = std::dynamic_pointer_cast(m_settings); + if (otherCxxSettings && ownCxxSettings) + { + ownCxxSettings->setSourcePaths(otherCxxSettings->getSourcePaths()); + ownCxxSettings->setHeaderSearchPaths(otherCxxSettings->getHeaderSearchPaths()); + ownCxxSettings->setVisualStudioSolutionPath(FilePath(visualStudioSolutionPath)); + } if (window) { window->content()->load(); @@ -142,7 +150,28 @@ void QtProjectWizzard::refreshProjectFromSolution(const std::string& ideId, cons } } -void QtProjectWizzard::editProject(const ProjectSettings& settings) +void QtProjectWizzard::editProject(const FilePath& settingsPath) +{ + std::shared_ptr settings; + switch (ProjectSettings::getLanguageOfProject(settingsPath)) + { + case LANGUAGE_C: + case LANGUAGE_CPP: + settings = std::make_shared(settingsPath); + break; + case LANGUAGE_JAVA: + settings = std::make_shared(settingsPath); + break; + } + + if (settings) + { + settings->load(); + editProject(settings); + } +} + +void QtProjectWizzard::editProject(std::shared_ptr settings) { m_settings = settings; m_editing = true; @@ -167,14 +196,12 @@ void QtProjectWizzard::showPreferences() { summary->setIsForm(true); - ProjectSettings* settings = &m_settings; + summary->addContent(new QtProjectWizzardContentPreferences(m_settings, window), false, false); - summary->addContent(new QtProjectWizzardContentPreferences(settings, window), false, false); - - summary->addContent(new QtProjectWizzardContentPathsHeaderSearchGlobal(settings, window), false, false); + summary->addContent(new QtProjectWizzardContentPathsHeaderSearchGlobal(m_settings, window), false, false); if (QSysInfo::macVersion() != QSysInfo::MV_None) { - summary->addContent(new QtProjectWizzardContentPathsFrameworkSearchGlobal(settings, window), false, false); + summary->addContent(new QtProjectWizzardContentPathsFrameworkSearchGlobal(m_settings, window), false, false); } window->setup(); @@ -196,7 +223,7 @@ QtProjectWizzardWindow* QtProjectWizzard::createWindowWithContent() connect(window, SIGNAL(previous()), &m_windowStack, SLOT(popWindow())); connect(window, SIGNAL(canceled()), this, SLOT(cancelWizzard())); - window->setContent(new T(&m_settings, window)); + window->setContent(new T(m_settings, window)); window->setup(); m_windowStack.pushWindow(window); @@ -212,9 +239,7 @@ QtProjectWizzardWindow* QtProjectWizzard::createWindowWithContentsetContent(content); window->setup(); @@ -232,7 +257,7 @@ QtProjectWizzardWindow* QtProjectWizzard::createWindowWithSummary( connect(window, SIGNAL(previous()), &m_windowStack, SLOT(popWindow())); connect(window, SIGNAL(canceled()), this, SLOT(cancelWizzard())); - QtProjectWizzardContentSummary* summary = new QtProjectWizzardContentSummary(&m_settings, window); + QtProjectWizzardContentSummary* summary = new QtProjectWizzardContentSummary(m_settings, window); window->setContent(summary); func(window, summary); @@ -248,7 +273,7 @@ QtProjectWizzardWindow* QtProjectWizzard::createPopupWithContent() QtProjectWizzardWindow* window = new QtProjectWizzardWindow(parentWidget()); window->setShowAsPopup(true); - window->setContent(new T(&m_settings, window)); + window->setContent(new T(m_settings, window)); window->setup(); window->move(window->pos() + QPoint(50, 50)); @@ -266,13 +291,6 @@ QtProjectWizzardWindow* QtProjectWizzard::createPopupWithContent() return window; } -ProjectSettings QtProjectWizzard::getSettingsForCompilationDatabase(const std::string& compilationDatabasePath) const -{ - ProjectSettings settings; - settings.setCompilationDatabasePath(FilePath(compilationDatabasePath)); - return settings; -} - void QtProjectWizzard::connectShowFiles(QtProjectWizzardContent* content) { connect(content, SIGNAL(filesButtonClicked(QtProjectWizzardContent*)), @@ -311,11 +329,13 @@ void QtProjectWizzard::popupClosed() } } -void QtProjectWizzard::selectedProjectType(QtProjectWizzardContentSelect::ProjectType type) +void QtProjectWizzard::selectedProjectType(LanguageType languageType, QtProjectWizzardContentSelect::ProjectType type) { switch (type) { case QtProjectWizzardContentSelect::PROJECT_EMPTY: + m_settings = std::make_shared(); + m_settings->setLanguage(languageType); emptyProject(); break; @@ -346,6 +366,8 @@ void QtProjectWizzard::selectedProjectType(QtProjectWizzardContentSelect::Projec } case QtProjectWizzardContentSelect::PROJECT_CDB: + m_settings = std::make_shared(); + m_settings->setLanguage(languageType); emptyProjectCDB(); break; } @@ -362,13 +384,12 @@ void QtProjectWizzard::sourcePaths() QtProjectWizzardWindow* window = createWindowWithSummary( [this](QtProjectWizzardWindow* window, QtProjectWizzardContentSummary* summary) { - ProjectSettings* settings = &m_settings; - QtProjectWizzardContent* source = new QtProjectWizzardContentPathsSource(settings, window); + QtProjectWizzardContent* source = new QtProjectWizzardContentPathsSource(m_settings, window); summary->addContent(source, false, false); connectShowFiles(source); - summary->addContent(new QtProjectWizzardContentExtensions(settings, window), false, false); + summary->addContent(new QtProjectWizzardContentExtensions(m_settings, window), false, false); window->setup(); } @@ -382,11 +403,9 @@ void QtProjectWizzard::headerSearchPaths() QtProjectWizzardWindow* window = createWindowWithSummary( [this](QtProjectWizzardWindow* window, QtProjectWizzardContentSummary* summary) { - ProjectSettings* settings = &m_settings; - - summary->addContent(new QtProjectWizzardContentPathsHeaderSearch(settings, window), false, false); - summary->addContent(new QtProjectWizzardContentSimple(settings, window), false, false); - summary->addContent(new QtProjectWizzardContentPathsHeaderSearchGlobal(settings, window), false, true); + summary->addContent(new QtProjectWizzardContentPathsHeaderSearch(m_settings, window), false, false); + summary->addContent(new QtProjectWizzardContentSimple(m_settings, window), false, false); + summary->addContent(new QtProjectWizzardContentPathsHeaderSearchGlobal(m_settings, window), false, true); window->setup(); } @@ -412,10 +431,8 @@ void QtProjectWizzard::frameworkSearchPaths() QtProjectWizzardWindow* window = createWindowWithSummary( [this](QtProjectWizzardWindow* window, QtProjectWizzardContentSummary* summary) { - ProjectSettings* settings = &m_settings; - - summary->addContent(new QtProjectWizzardContentPathsFrameworkSearch(settings, window), false, false); - summary->addContent(new QtProjectWizzardContentPathsFrameworkSearchGlobal(settings, window), false, false); + summary->addContent(new QtProjectWizzardContentPathsFrameworkSearch(m_settings, window), false, false); + summary->addContent(new QtProjectWizzardContentPathsFrameworkSearchGlobal(m_settings, window), false, false); window->setup(); } @@ -438,13 +455,11 @@ void QtProjectWizzard::headerPathsCDB() QtProjectWizzardWindow* window = createWindowWithSummary( [this](QtProjectWizzardWindow* window, QtProjectWizzardContentSummary* summary) { - ProjectSettings* settings = &m_settings; - - QtProjectWizzardContent* source = new QtProjectWizzardContentCDBSource(settings, window); + QtProjectWizzardContent* source = new QtProjectWizzardContentCDBSource(m_settings, window); summary->addContent(source, false, false); connectShowFiles(source); - QtProjectWizzardContent* header = new QtProjectWizzardContentPathsCDBHeader(settings, window); + QtProjectWizzardContent* header = new QtProjectWizzardContentPathsCDBHeader(m_settings, window); summary->addContent(header, false, false); window->setup(); @@ -492,13 +507,11 @@ void QtProjectWizzard::showSummary() { summary->setIsForm(true); - ProjectSettings* settings = &m_settings; - - QtProjectWizzardContentBuildFile* buildFile = new QtProjectWizzardContentBuildFile(settings, window); + QtProjectWizzardContentBuildFile* buildFile = new QtProjectWizzardContentBuildFile(m_settings, window); if (buildFile->getType() != QtProjectWizzardContentSelect::PROJECT_CDB) { - summary->addContent(new QtProjectWizzardContentData(settings, window), false, false); + summary->addContent(new QtProjectWizzardContentData(m_settings, window), false, false); if (buildFile->getType() == QtProjectWizzardContentSelect::PROJECT_MANAGED) { @@ -509,39 +522,39 @@ void QtProjectWizzard::showSummary() this, SLOT(refreshProjectFromSolution(const std::string&, const std::string&))); } - QtProjectWizzardContentPathsSource* source = new QtProjectWizzardContentPathsSource(settings, window); + QtProjectWizzardContentPathsSource* source = new QtProjectWizzardContentPathsSource(m_settings, window); summary->addContent(source, false, true); connectShowFiles(source); - summary->addContent(new QtProjectWizzardContentPathsHeaderSearch(settings, window), false, true); - summary->addContent(new QtProjectWizzardContentSimple(settings, window), false, false); - summary->addContent(new QtProjectWizzardContentPathsHeaderSearchGlobal(settings, window), false, false); + summary->addContent(new QtProjectWizzardContentPathsHeaderSearch(m_settings, window), false, true); + summary->addContent(new QtProjectWizzardContentSimple(m_settings, window), false, false); + summary->addContent(new QtProjectWizzardContentPathsHeaderSearchGlobal(m_settings, window), false, false); if (QSysInfo::macVersion() != QSysInfo::MV_None) { - summary->addContent(new QtProjectWizzardContentPathsFrameworkSearch(settings, window), false, true); - summary->addContent(new QtProjectWizzardContentPathsFrameworkSearchGlobal(settings, window), false, false); + summary->addContent(new QtProjectWizzardContentPathsFrameworkSearch(m_settings, window), false, true); + summary->addContent(new QtProjectWizzardContentPathsFrameworkSearchGlobal(m_settings, window), false, false); } } else { - summary->addContent(new QtProjectWizzardContentDataCDB(settings, window), false, false); + summary->addContent(new QtProjectWizzardContentDataCDB(m_settings, window), false, false); - QtProjectWizzardContent* headers = new QtProjectWizzardContentPathsCDBHeader(settings, window); + QtProjectWizzardContent* headers = new QtProjectWizzardContentPathsCDBHeader(m_settings, window); summary->addContent(headers, false, true); - summary->addContent(new QtProjectWizzardContentPathsHeaderSearch(settings, window), true, false); - summary->addContent(new QtProjectWizzardContentPathsHeaderSearchGlobal(settings, window), false, true); + summary->addContent(new QtProjectWizzardContentPathsHeaderSearch(m_settings, window), true, false); + summary->addContent(new QtProjectWizzardContentPathsHeaderSearchGlobal(m_settings, window), false, true); if (QSysInfo::macVersion() != QSysInfo::MV_None) { - summary->addContent(new QtProjectWizzardContentPathsFrameworkSearch(settings, window), true, false); - summary->addContent(new QtProjectWizzardContentPathsFrameworkSearchGlobal(settings, window), false, false); + summary->addContent(new QtProjectWizzardContentPathsFrameworkSearch(m_settings, window), true, false); + summary->addContent(new QtProjectWizzardContentPathsFrameworkSearchGlobal(m_settings, window), false, false); } } - summary->addContent(new QtProjectWizzardContentFlags(settings, window), true, true); - summary->addContent(new QtProjectWizzardContentPathsExclude(settings, window), true, true); + summary->addContent(new QtProjectWizzardContentFlags(m_settings, window), true, true); + summary->addContent(new QtProjectWizzardContentPathsExclude(m_settings, window), true, true); window->setup(); @@ -555,23 +568,52 @@ void QtProjectWizzard::showSummary() void QtProjectWizzard::createProject() { - FilePath path(m_settings.getProjectFileLocation().str() + "/" + m_settings.getProjectName() + ".coatiproject"); - m_settings.save(path); + FilePath path = m_settings->getFilePath(); - bool edited = false; + m_settings->save(path); + + bool foreceRefreshProject = false; if (m_editing) { - bool settingsChanged = !(m_settings == *ProjectSettings::getInstance().get()); + std::shared_ptr application = Application::getInstance(); + FilePath oldPath = application->getCurrentProject()->getProjectSettingsFilePath(); + + if (oldPath.exists() && oldPath != path) + { + std::vector options; + options.push_back("Yes"); + options.push_back("No"); + int result = application->handleDialog( + "You changed the project location. The project file (.coatiproject) and the database file (.coatidb) will " + "be moved to the new location. Do you want to keep a copy of the files in the previous location?" + , options + ); + + FilePath dbPath = FilePath(path).replaceExtension("coatidb"); + FilePath oldDbPath = FilePath(oldPath).replaceExtension("coatidb"); + + if (result == 0) + { + FileSystem::copyFile(oldDbPath, dbPath); + } + else + { + FileSystem::remove(oldPath); + FileSystem::rename(oldDbPath, dbPath); + } + } + + bool settingsChanged = !(application->getCurrentProject()->settingsEqualExceptNameAndLocation(*(m_settings.get()))); bool appSettingsChanged = !(m_appSettings == *ApplicationSettings::getInstance().get()); if (settingsChanged || appSettingsChanged) { - edited = true; + foreceRefreshProject = true; } } MessageDispatchWhenLicenseValid( - std::make_shared(path, edited) + std::make_shared(path, foreceRefreshProject) ).dispatch(); finishWizzard(); @@ -584,7 +626,9 @@ void QtProjectWizzard::savePreferences() if (appSettingsChanged) { MessageDispatchWhenLicenseValid( - std::make_shared("", true) + std::make_shared( + Application::getInstance()->getCurrentProject()->getProjectSettingsFilePath(), true + ) ).dispatch(); } else diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h index e29757d1..a90c0ca6 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.h @@ -36,7 +36,8 @@ public slots: void newProjectFromSolution(const std::string& ideId, const std::string& visualStudioSolutionPath); void refreshProjectFromSolution(const std::string& ideId, const std::string& visualStudioSolutionPath); - void editProject(const ProjectSettings& settings); + void editProject(const FilePath& settingsPath); + void editProject(std::shared_ptr settings); void showPreferences(); private: @@ -48,14 +49,12 @@ private: template QtProjectWizzardWindow* createPopupWithContent(); - ProjectSettings getSettingsForCompilationDatabase(const std::string& compilationDatabasePath) const; - void connectShowFiles(QtProjectWizzardContent* content); QtWindowStack m_windowStack; std::shared_ptr m_popup; - ProjectSettings m_settings; + std::shared_ptr m_settings; ApplicationSettings m_appSettings; bool m_editing; @@ -69,7 +68,7 @@ private slots: void windowStackChanged(); void popupClosed(); - void selectedProjectType(QtProjectWizzardContentSelect::ProjectType type); + void selectedProjectType(LanguageType languageType, QtProjectWizzardContentSelect::ProjectType type); void emptyProject(); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp index cd4bbc62..60bcbfcc 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp @@ -24,7 +24,7 @@ void QtHelpButton::handleHelpPress() } -QtProjectWizzardContent::QtProjectWizzardContent(ProjectSettings* settings, QtProjectWizzardWindow* window) +QtProjectWizzardContent::QtProjectWizzardContent(std::shared_ptr settings, QtProjectWizzardWindow* window) : QWidget(window) , m_settings(settings) , m_window(window) diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h index a1a7f7ea..85532195 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h @@ -33,7 +33,7 @@ class QtProjectWizzardContent Q_OBJECT public: - QtProjectWizzardContent(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContent(std::shared_ptr settings, QtProjectWizzardWindow* window); virtual void populateWindow(QWidget* widget); virtual void populateWindow(QGridLayout* layout); @@ -64,7 +64,7 @@ protected: QtHelpButton* addHelpButton(QString helpString, QGridLayout* layout, int row) const; QPushButton* addFilesButton(QString name, QGridLayout* layout, int row) const; - ProjectSettings* m_settings; + std::shared_ptr m_settings; QtProjectWizzardWindow* m_window; private slots: diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp index f3c303f8..177c42f0 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp @@ -4,20 +4,25 @@ #include #include "qt/element/QtLocationPicker.h" +#include "settings/CxxProjectSettings.h" QtProjectWizzardContentBuildFile::QtProjectWizzardContentBuildFile( - ProjectSettings* settings, QtProjectWizzardWindow* window + std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContent(settings, window) , m_type(QtProjectWizzardContentSelect::PROJECT_EMPTY) { - if (!m_settings->getVisualStudioSolutionPath().empty()) + std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); + if (cxxSettings) { - m_type = QtProjectWizzardContentSelect::PROJECT_MANAGED; - } - else if (!m_settings->getCompilationDatabasePath().empty()) - { - m_type = QtProjectWizzardContentSelect::PROJECT_CDB; + if (!cxxSettings->getVisualStudioSolutionPath().empty()) + { + m_type = QtProjectWizzardContentSelect::PROJECT_MANAGED; + } + else if (!cxxSettings->getCompilationDatabasePath().empty()) + { + m_type = QtProjectWizzardContentSelect::PROJECT_CDB; + } } } @@ -73,35 +78,43 @@ void QtProjectWizzardContentBuildFile::populateForm(QGridLayout* layout, int& ro void QtProjectWizzardContentBuildFile::load() { - switch (m_type) + std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); + if (cxxSettings) { - case QtProjectWizzardContentSelect::PROJECT_EMPTY: - return; - case QtProjectWizzardContentSelect::PROJECT_MANAGED: - m_picker->setText(QString::fromStdString(m_settings->getVisualStudioSolutionPath().str())); - break; - case QtProjectWizzardContentSelect::PROJECT_CDB: - m_picker->setText(QString::fromStdString(m_settings->getCompilationDatabasePath().str())); - break; + switch (m_type) + { + case QtProjectWizzardContentSelect::PROJECT_EMPTY: + return; + case QtProjectWizzardContentSelect::PROJECT_MANAGED: + m_picker->setText(QString::fromStdString(cxxSettings->getVisualStudioSolutionPath().str())); + break; + case QtProjectWizzardContentSelect::PROJECT_CDB: + m_picker->setText(QString::fromStdString(cxxSettings->getCompilationDatabasePath().str())); + break; + } } } void QtProjectWizzardContentBuildFile::save() { - switch (m_type) + std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); + if (cxxSettings) { - case QtProjectWizzardContentSelect::PROJECT_EMPTY: - case QtProjectWizzardContentSelect::PROJECT_MANAGED: - break; - case QtProjectWizzardContentSelect::PROJECT_CDB: + switch (m_type) { - FilePath path = m_picker->getText().toStdString(); - if (!path.exists() || path.extension() != ".json") + case QtProjectWizzardContentSelect::PROJECT_EMPTY: + case QtProjectWizzardContentSelect::PROJECT_MANAGED: + break; + case QtProjectWizzardContentSelect::PROJECT_CDB: { - return; + FilePath path = m_picker->getText().toStdString(); + if (!path.exists() || path.extension() != ".json") + { + return; + } + cxxSettings->setCompilationDatabasePath(m_picker->getText().toStdString()); + break; } - m_settings->setCompilationDatabasePath(m_picker->getText().toStdString()); - break; } } } diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h index 384e8be2..5a816e39 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.h @@ -16,7 +16,7 @@ signals: void refreshVisualStudioSolution(const std::string& ideId, const std::string& solutionPath); public: - QtProjectWizzardContentBuildFile(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentBuildFile(std::shared_ptr settings, QtProjectWizzardWindow* window); QtProjectWizzardContentSelect::ProjectType getType() const; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp index 12f6ffe2..b8855622 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.cpp @@ -1,9 +1,10 @@ #include "qt/window/project_wizzard/QtProjectWizzardContentCDBSource.h" #include "data/parser/cxx/TaskParseCxx.h" +#include "settings/CxxProjectSettings.h" QtProjectWizzardContentCDBSource::QtProjectWizzardContentCDBSource( - ProjectSettings* settings, QtProjectWizzardWindow* window + std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContent(settings, window) , m_text(nullptr) @@ -38,32 +39,35 @@ void QtProjectWizzardContentCDBSource::load() FilePath projectPath = m_settings->getProjectFileLocation(); std::vector excludePaths = m_settings->getAbsoluteExcludePaths(); - std::vector filePaths = TaskParseCxx::getSourceFilesFromCDB(m_settings->getCompilationDatabasePath()); - for (FilePath path : filePaths) + std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); + if (cxxSettings) { - bool excluded = false; - for (FilePath p : excludePaths) + std::vector filePaths = TaskParseCxx::getSourceFilesFromCDB(cxxSettings->getCompilationDatabasePath()); + for (FilePath path : filePaths) { - if (p == path || p.contains(path)) + bool excluded = false; + for (FilePath p : excludePaths) { - excluded = true; - break; + if (p == path || p.contains(path)) + { + excluded = true; + break; + } } - } - if (excluded) - { - continue; - } + if (excluded) + { + continue; + } - if (projectPath.exists()) - { - path = path.relativeTo(projectPath); - } + if (projectPath.exists()) + { + path = path.relativeTo(projectPath); + } - m_fileNames << QString::fromStdString(path.str()); + m_fileNames << QString::fromStdString(path.str()); + } } - if (m_text) { m_text->setText(QString::number(m_fileNames.size()) + " source files were found in the compilation database."); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.h index 52c2b4f5..0d56c427 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentCDBSource.h @@ -9,7 +9,7 @@ class QtProjectWizzardContentCDBSource Q_OBJECT public: - QtProjectWizzardContentCDBSource(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentCDBSource(std::shared_ptr settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation virtual void populateWindow(QGridLayout* layout, int& row) override; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.cpp index 926b42fe..1ce42ed6 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.cpp @@ -3,7 +3,9 @@ #include #include -QtProjectWizzardContentData::QtProjectWizzardContentData(ProjectSettings* settings, QtProjectWizzardWindow* window) +#include "settings/CxxProjectSettings.h" + +QtProjectWizzardContentData::QtProjectWizzardContentData(std::shared_ptr settings, QtProjectWizzardWindow* window) : QtProjectWizzardContent(settings, window) , m_projectName(nullptr) , m_projectFileLocation(nullptr) @@ -45,9 +47,9 @@ void QtProjectWizzardContentData::load() if (m_language) { - if (m_settings->getLanguage().length() > 0) + if (m_settings->getLanguage() != LANGUAGE_UNKNOWN) { - m_language->setCurrentText(QString::fromStdString(m_settings->getLanguage())); + m_language->setCurrentText(QString::fromStdString(languageTypeToString(m_settings->getLanguage()))); } if (m_settings->getStandard().length() > 0) @@ -76,7 +78,7 @@ void QtProjectWizzardContentData::save() if (m_language) { - m_settings->setLanguage(m_language->currentText().toStdString()); + m_settings->setLanguage(stringToLanguageType(m_language->currentText().toStdString())); if (m_cppStandard->isVisible()) { @@ -239,7 +241,7 @@ void QtProjectWizzardContentData::handleSelectionChanged(int index) QtProjectWizzardContentDataCDB::QtProjectWizzardContentDataCDB( - ProjectSettings* settings, QtProjectWizzardWindow* window) + std::shared_ptr settings, QtProjectWizzardWindow* window) : QtProjectWizzardContentData(settings, window) { } @@ -259,8 +261,11 @@ void QtProjectWizzardContentDataCDB::populateForm(QGridLayout* layout, int& row) void QtProjectWizzardContentDataCDB::load() { QtProjectWizzardContentData::load(); - - m_buildFilePicker->setText(QString::fromStdString(m_settings->getCompilationDatabasePath().str())); + std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); + if (cxxSettings) + { + m_buildFilePicker->setText(QString::fromStdString(cxxSettings->getCompilationDatabasePath().str())); + } } void QtProjectWizzardContentDataCDB::save() @@ -272,7 +277,12 @@ void QtProjectWizzardContentDataCDB::save() { return; } - m_settings->setCompilationDatabasePath(path); + + std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); + if (cxxSettings) + { + cxxSettings->setCompilationDatabasePath(path); + } } bool QtProjectWizzardContentDataCDB::check() diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.h index b47e06de..c0b915f8 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentData.h @@ -13,7 +13,7 @@ class QtProjectWizzardContentData Q_OBJECT public: - QtProjectWizzardContentData(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentData(std::shared_ptr settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation virtual void populateWindow(QGridLayout* layout) override; @@ -50,7 +50,7 @@ class QtProjectWizzardContentDataCDB Q_OBJECT public: - QtProjectWizzardContentDataCDB(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentDataCDB(std::shared_ptr settings, QtProjectWizzardWindow* window); virtual void populateForm(QGridLayout* layout, int& row) override; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.cpp index 07b8773f..8bf49547 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.cpp @@ -5,7 +5,7 @@ #include "qt/element/QtDirectoryListBox.h" QtProjectWizzardContentExtensions::QtProjectWizzardContentExtensions( - ProjectSettings* settings, QtProjectWizzardWindow* window + std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContent(settings, window) { diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.h index af6b04ee..e8905dad 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentExtensions.h @@ -11,7 +11,7 @@ class QtProjectWizzardContentExtensions Q_OBJECT public: - QtProjectWizzardContentExtensions(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentExtensions(std::shared_ptr settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation virtual void populateWindow(QGridLayout* layout, int& row) override; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentFlags.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentFlags.cpp index a6171d8d..d7da2e80 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentFlags.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentFlags.cpp @@ -3,8 +3,9 @@ #include #include "qt/element/QtDirectoryListBox.h" +#include "settings/CxxProjectSettings.h" -QtProjectWizzardContentFlags::QtProjectWizzardContentFlags(ProjectSettings* settings, QtProjectWizzardWindow* window) +QtProjectWizzardContentFlags::QtProjectWizzardContentFlags(std::shared_ptr settings, QtProjectWizzardWindow* window) : QtProjectWizzardContent(settings, window) { } @@ -24,10 +25,18 @@ void QtProjectWizzardContentFlags::populateForm(QGridLayout* layout, int& row) void QtProjectWizzardContentFlags::load() { - m_list->setStringList(m_settings->getCompilerFlags()); + std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); + if (cxxSettings) + { + m_list->setStringList(cxxSettings->getCompilerFlags()); + } } void QtProjectWizzardContentFlags::save() { - m_settings->setCompilerFlags(m_list->getStringList()); + std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); + if (cxxSettings) + { + cxxSettings->setCompilerFlags(m_list->getStringList()); + } } diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentFlags.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentFlags.h index 79a7df09..0a78d210 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentFlags.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentFlags.h @@ -11,7 +11,7 @@ class QtProjectWizzardContentFlags Q_OBJECT public: - QtProjectWizzardContentFlags(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentFlags(std::shared_ptr settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation virtual void populateForm(QGridLayout* layout, int& row) override; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp index b23dcba3..2b6056af 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.cpp @@ -5,13 +5,14 @@ #include #include "qt/element/QtDirectoryListBox.h" +#include "settings/CxxProjectSettings.h" #include "settings/ApplicationSettings.h" #include "utility/file/FileManager.h" #include "utility/file/FileSystem.h" #include "utility/headerSearch/StandardHeaderDetection.h" #include "utility/utility.h" -QtProjectWizzardContentPaths::QtProjectWizzardContentPaths(ProjectSettings* settings, QtProjectWizzardWindow* window) +QtProjectWizzardContentPaths::QtProjectWizzardContentPaths(std::shared_ptr settings, QtProjectWizzardWindow* window) : QtProjectWizzardContent(settings, window) { } @@ -197,7 +198,7 @@ void QtProjectWizzardContentPaths::detectionClicked() QtProjectWizzardContentPathsSource::QtProjectWizzardContentPathsSource( - ProjectSettings* settings, QtProjectWizzardWindow* window + std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContentPaths(settings, window) { @@ -278,7 +279,7 @@ QString QtProjectWizzardContentPathsSource::getFileNamesDescription() const } QtProjectWizzardContentPathsCDBHeader::QtProjectWizzardContentPathsCDBHeader( - ProjectSettings* settings, QtProjectWizzardWindow* window + std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContentPathsSource(settings, window) { @@ -297,7 +298,7 @@ QtProjectWizzardContentPathsCDBHeader::QtProjectWizzardContentPathsCDBHeader( QtProjectWizzardContentPathsExclude::QtProjectWizzardContentPathsExclude( - ProjectSettings* settings, QtProjectWizzardWindow* window + std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContentPaths(settings, window) { @@ -320,7 +321,7 @@ void QtProjectWizzardContentPathsExclude::save() QtProjectWizzardContentPathsHeaderSearch::QtProjectWizzardContentPathsHeaderSearch( - ProjectSettings* settings, QtProjectWizzardWindow* window + std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContentPaths(settings, window) { @@ -335,12 +336,20 @@ QtProjectWizzardContentPathsHeaderSearch::QtProjectWizzardContentPathsHeaderSear void QtProjectWizzardContentPathsHeaderSearch::load() { - m_list->setList(m_settings->getHeaderSearchPaths()); + std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); + if (cxxSettings) + { + m_list->setList(cxxSettings->getHeaderSearchPaths()); + } } void QtProjectWizzardContentPathsHeaderSearch::save() { - m_settings->setHeaderSearchPaths(m_list->getList()); + std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); + if (cxxSettings) + { + cxxSettings->setHeaderSearchPaths(m_list->getList()); + } } bool QtProjectWizzardContentPathsHeaderSearch::isScrollAble() const @@ -349,7 +358,7 @@ bool QtProjectWizzardContentPathsHeaderSearch::isScrollAble() const } QtProjectWizzardContentPathsHeaderSearchGlobal::QtProjectWizzardContentPathsHeaderSearchGlobal( - ProjectSettings* settings, QtProjectWizzardWindow* window + std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContentPaths(settings, window) { @@ -380,7 +389,7 @@ void QtProjectWizzardContentPathsHeaderSearchGlobal::save() QtProjectWizzardContentPathsFrameworkSearch::QtProjectWizzardContentPathsFrameworkSearch( - ProjectSettings* settings, QtProjectWizzardWindow* window + std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContentPaths(settings, window) { @@ -394,12 +403,20 @@ QtProjectWizzardContentPathsFrameworkSearch::QtProjectWizzardContentPathsFramewo void QtProjectWizzardContentPathsFrameworkSearch::load() { - m_list->setList(m_settings->getFrameworkSearchPaths()); + std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); + if (cxxSettings) + { + m_list->setList(cxxSettings->getFrameworkSearchPaths()); + } } void QtProjectWizzardContentPathsFrameworkSearch::save() { - m_settings->setFrameworkSearchPaths(m_list->getList()); + std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); + if (cxxSettings) + { + cxxSettings->setFrameworkSearchPaths(m_list->getList()); + } } bool QtProjectWizzardContentPathsFrameworkSearch::isScrollAble() const @@ -408,7 +425,7 @@ bool QtProjectWizzardContentPathsFrameworkSearch::isScrollAble() const } QtProjectWizzardContentPathsFrameworkSearchGlobal::QtProjectWizzardContentPathsFrameworkSearchGlobal( - ProjectSettings* settings, QtProjectWizzardWindow* window + std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContentPaths(settings, window) { diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h index a422e0c1..17ef535e 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPaths.h @@ -17,7 +17,7 @@ signals: void showSourceFiles(); public: - QtProjectWizzardContentPaths(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentPaths(std::shared_ptr settings, QtProjectWizzardWindow* window); // QtSettingsWindow implementation virtual void populateWindow(QGridLayout* layout) override; @@ -57,7 +57,7 @@ class QtProjectWizzardContentPathsSource : public QtProjectWizzardContentPaths { public: - QtProjectWizzardContentPathsSource(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentPathsSource(std::shared_ptr settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation virtual QSize preferredWindowSize() const override; @@ -74,7 +74,7 @@ class QtProjectWizzardContentPathsCDBHeader : public QtProjectWizzardContentPathsSource { public: - QtProjectWizzardContentPathsCDBHeader(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentPathsCDBHeader(std::shared_ptr settings, QtProjectWizzardWindow* window); }; @@ -82,7 +82,7 @@ class QtProjectWizzardContentPathsExclude : public QtProjectWizzardContentPaths { public: - QtProjectWizzardContentPathsExclude(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentPathsExclude(std::shared_ptr settings, QtProjectWizzardWindow* window); virtual void load() override; virtual void save() override; @@ -93,7 +93,7 @@ class QtProjectWizzardContentPathsHeaderSearch : public QtProjectWizzardContentPaths { public: - QtProjectWizzardContentPathsHeaderSearch(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentPathsHeaderSearch(std::shared_ptr settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation virtual void load() override; @@ -106,7 +106,7 @@ class QtProjectWizzardContentPathsHeaderSearchGlobal : public QtProjectWizzardContentPaths { public: - QtProjectWizzardContentPathsHeaderSearchGlobal(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentPathsHeaderSearchGlobal(std::shared_ptr settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation virtual void load() override; @@ -118,7 +118,7 @@ class QtProjectWizzardContentPathsFrameworkSearch : public QtProjectWizzardContentPaths { public: - QtProjectWizzardContentPathsFrameworkSearch(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentPathsFrameworkSearch(std::shared_ptr settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation virtual void load() override; @@ -131,7 +131,7 @@ class QtProjectWizzardContentPathsFrameworkSearchGlobal : public QtProjectWizzardContentPaths { public: - QtProjectWizzardContentPathsFrameworkSearchGlobal(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentPathsFrameworkSearchGlobal(std::shared_ptr settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation virtual void load() override; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp index 896564f7..47f24355 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.cpp @@ -6,7 +6,7 @@ #include "utility/ResourcePaths.h" QtProjectWizzardContentPreferences::QtProjectWizzardContentPreferences( - ProjectSettings* settings, QtProjectWizzardWindow* window + std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContent(settings, window) , m_oldColorSchemeIndex(-1) diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h index d62e76ec..e64c4a68 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentPreferences.h @@ -13,7 +13,7 @@ class QtProjectWizzardContentPreferences Q_OBJECT public: - QtProjectWizzardContentPreferences(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentPreferences(std::shared_ptr settings, QtProjectWizzardWindow* window); ~QtProjectWizzardContentPreferences(); // QtProjectWizzardContent implementation diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp index 9e81c926..27a7e78b 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.cpp @@ -10,7 +10,7 @@ #include "utility/solution/SolutionParserManager.h" -QtProjectWizzardContentSelect::QtProjectWizzardContentSelect(ProjectSettings* settings, QtProjectWizzardWindow* window, std::weak_ptr solutionParserManager) +QtProjectWizzardContentSelect::QtProjectWizzardContentSelect(std::shared_ptr settings, QtProjectWizzardWindow* window, std::weak_ptr solutionParserManager) : QtProjectWizzardContent(settings, window) , m_solutionParserManager(solutionParserManager) { @@ -145,8 +145,6 @@ void QtProjectWizzardContentSelect::populateWindow(QGridLayout* layout) void QtProjectWizzardContentSelect::save() { - m_settings->setLanguage(m_languages->checkedButton()->text().toStdString()); - ProjectType type; switch (m_buttons->checkedId()) @@ -157,7 +155,7 @@ void QtProjectWizzardContentSelect::save() default: type = PROJECT_MANAGED; break; } - emit selected(type); + emit selected(stringToLanguageType(m_languages->checkedButton()->text().toStdString()), type); } 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 fa933464..3dd6cc73 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSelect.h @@ -19,7 +19,7 @@ public: PROJECT_MANAGED = 2 // use this type for all standard parser (parsers that are handled by the parser manager) }; - QtProjectWizzardContentSelect(ProjectSettings* settings, QtProjectWizzardWindow* window, std::weak_ptr solutionParserManager); + QtProjectWizzardContentSelect(std::shared_ptr settings, QtProjectWizzardWindow* window, std::weak_ptr solutionParserManager); // QtProjectWizzardContent implementation virtual void populateWindow(QGridLayout* layout) override; @@ -30,7 +30,7 @@ public: virtual QSize preferredWindowSize() const override; signals: - void selected(QtProjectWizzardContentSelect::ProjectType); + void selected(LanguageType, QtProjectWizzardContentSelect::ProjectType); // void selected(unsigned int type); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSimple.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSimple.cpp index 8c1cbd47..72fff43d 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSimple.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSimple.cpp @@ -3,7 +3,9 @@ #include #include -QtProjectWizzardContentSimple::QtProjectWizzardContentSimple(ProjectSettings* settings, QtProjectWizzardWindow* window) +#include "settings/CxxProjectSettings.h" + +QtProjectWizzardContentSimple::QtProjectWizzardContentSimple(std::shared_ptr settings, QtProjectWizzardWindow* window) : QtProjectWizzardContent(settings, window) , m_checkBox(nullptr) { @@ -52,10 +54,18 @@ void QtProjectWizzardContentSimple::populateForm(QGridLayout* layout, int& row) void QtProjectWizzardContentSimple::load() { - m_checkBox->setChecked(m_settings->getUseSourcePathsForHeaderSearch()); + std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); + if (cxxSettings) + { + m_checkBox->setChecked(cxxSettings->getUseSourcePathsForHeaderSearch()); + } } void QtProjectWizzardContentSimple::save() { - m_settings->setUseSourcePathsForHeaderSearch(m_checkBox->isChecked()); + std::shared_ptr cxxSettings = std::dynamic_pointer_cast(m_settings); + if (cxxSettings) + { + cxxSettings->setUseSourcePathsForHeaderSearch(m_checkBox->isChecked()); + } } diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSimple.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSimple.h index 1ab2fc09..636637d7 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSimple.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSimple.h @@ -12,7 +12,7 @@ class QtProjectWizzardContentSimple Q_OBJECT public: - QtProjectWizzardContentSimple(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentSimple(std::shared_ptr settings, QtProjectWizzardWindow* window); // QtProjectWizzardContent implementation virtual void populateWindow(QGridLayout* layout) override; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.cpp index eb0116dd..62ece988 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.cpp @@ -4,7 +4,7 @@ #include QtProjectWizzardContentSourceList::QtProjectWizzardContentSourceList( - ProjectSettings* settings, QtProjectWizzardWindow* window + std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContent(settings, window) { diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.h index b612b55a..3d0f9f68 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSourceList.h @@ -10,7 +10,7 @@ class QtProjectWizzardContentSourceList : public QtProjectWizzardContent { public: - QtProjectWizzardContentSourceList(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentSourceList(std::shared_ptr settings, QtProjectWizzardWindow* window); // QtSettingsWindow implementation virtual void populateWindow(QWidget* widget) override; diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.cpp index af5ee7ce..896b8780 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.cpp @@ -3,7 +3,7 @@ #include QtProjectWizzardContentSummary::QtProjectWizzardContentSummary( - ProjectSettings* settings, QtProjectWizzardWindow* window + std::shared_ptr settings, QtProjectWizzardWindow* window ) : QtProjectWizzardContent(settings, window) , m_layout(nullptr) diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.h index 5d6709f0..5256abc9 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentSummary.h @@ -19,7 +19,7 @@ private: }; public: - QtProjectWizzardContentSummary(ProjectSettings* settings, QtProjectWizzardWindow* window); + QtProjectWizzardContentSummary(std::shared_ptr settings, QtProjectWizzardWindow* window); void addContent(QtProjectWizzardContent* content, bool advanced, bool gapBefore); void setIsForm(bool isForm); diff --git a/src/test/SettingsTestSuite.h b/src/test/SettingsTestSuite.h index 567cb9b9..d1469e01 100644 --- a/src/test/SettingsTestSuite.h +++ b/src/test/SettingsTestSuite.h @@ -1,6 +1,7 @@ #include #include "settings/ProjectSettings.h" +#include "settings/CxxProjectSettings.h" #include "settings/Settings.h" class SettingsTestSuite : public CxxTest::TestSuite @@ -108,13 +109,15 @@ public: void test_load_project_settings_from_file() { - TS_ASSERT(ProjectSettings::getInstance()->load("data/SettingsTestSuite/settings.xml")); + ProjectSettings settings(FilePath("data/SettingsTestSuite/settings.xml")); + TS_ASSERT(settings.load()); } void test_load_source_path_from_file() { - ProjectSettings::getInstance()->load("data/SettingsTestSuite/settings.xml"); - std::vector paths = ProjectSettings::getInstance()->getSourcePaths(); + ProjectSettings settings(FilePath("data/SettingsTestSuite/settings.xml")); + settings.load(); + std::vector paths = settings.getSourcePaths(); TS_ASSERT_EQUALS(paths.size(), 1); TS_ASSERT_EQUALS(paths[0].str(), "data"); @@ -122,8 +125,9 @@ public: void test_load_header_search_paths_from_file() { - ProjectSettings::getInstance()->load("data/SettingsTestSuite/settings.xml"); - std::vector paths = ProjectSettings::getInstance()->getHeaderSearchPaths(); + CxxProjectSettings settings(FilePath("data/SettingsTestSuite/settings.xml")); + settings.load(); + std::vector paths = settings.getHeaderSearchPaths(); TS_ASSERT_EQUALS(paths.size(), 2); TS_ASSERT_EQUALS(paths[0].str(), "data/"); diff --git a/src/trial/main.cpp b/src/trial/main.cpp index c93ffb46..8bc9fd2b 100644 --- a/src/trial/main.cpp +++ b/src/trial/main.cpp @@ -3,6 +3,7 @@ #include "utility/logging/FileLogger.h" #include "utility/logging/LogManager.h" #include "utility/ResourcePaths.h" +#include "utility/ScopedFunctor.h" #include "utility/UserPaths.h" #include "utility/Version.h" @@ -53,7 +54,10 @@ int main(int argc, char *argv[]) utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf"); - std::shared_ptr app = Application::create(version, &viewFactory, &networkFactory); + Application::createInstance(version, &viewFactory, &networkFactory); + ScopedFunctor f([](){ + Application::destroyInstance(); + }); return qtApp.exec(); }