From 8ca54f20917498e4036c2e3e3587e9eae504fbb4 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Tue, 28 Jun 2016 15:59:22 +0200 Subject: [PATCH] ui: removed 'Save Project' and 'Save Project As' actions * removed save actions from menu in QtMainWindow * removed MessageSaveProject and all Listeners * updated project loading to ask whether old project and db file should be kept at old location * fixed crash for missing include files * fixed simple header search within source paths was broken --- src/lib/Application.cpp | 69 +++++++----- src/lib/Application.h | 4 - src/lib/CMakeLists.txt | 1 - src/lib/Project.cpp | 38 +------ src/lib/Project.h | 2 - src/lib/settings/ProjectSettings.cpp | 5 - src/lib/settings/ProjectSettings.h | 1 - src/lib/utility/file/FileSystem.cpp | 101 +++++++++++------- src/lib/utility/file/FileSystem.h | 11 +- .../messaging/type/MessageLoadProject.h | 10 +- .../messaging/type/MessageSaveProject.h | 27 ----- src/lib_gui/qt/window/QtMainWindow.cpp | 22 ---- src/lib_gui/qt/window/QtMainWindow.h | 3 - .../project_wizzard/QtProjectWizzard.cpp | 3 +- .../data/parser/cxx/PreprocessorCallbacks.cpp | 2 +- web/documentation/index.html | 26 ----- 16 files changed, 123 insertions(+), 202 deletions(-) delete mode 100644 src/lib/utility/messaging/type/MessageSaveProject.h diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index e804637b..12769c38 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -1,5 +1,6 @@ #include "Application.h" +#include "utility/file/FileSystem.h" #include "utility/logging/logging.h" #include "utility/messaging/MessageQueue.h" #include "utility/messaging/type/MessageActivateNodes.h" @@ -201,18 +202,6 @@ void Application::refreshProject() } } -void Application::saveProject(const FilePath& projectSettingsFilePath) -{ - if (!m_project->save(projectSettingsFilePath)) - { - LOG_ERROR("No Project Settings File defined"); - } - else - { - MessageStatus("Project saved").dispatch(); - } -} - void Application::handleMessage(MessageActivateWindow* message) { if (m_hasGUI) @@ -248,17 +237,50 @@ void Application::handleMessage(MessageLoadProject* message) { if (m_hasGUI) { - 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); + FilePath path = projectSettingsFilePath; + FilePath oldPath = m_project->getProjectSettingsFilePath(); - if (result == 1) + if (oldPath.exists() && oldPath != path) { - m_project->load(projectSettingsFilePath); - return; + 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) + { + 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()); + return; + } } } @@ -301,11 +323,6 @@ void Application::handleMessage(MessageRefresh* message) } } -void Application::handleMessage(MessageSaveProject* message) -{ - saveProject(message->projectSettingsFilePath); -} - void Application::startMessagingAndScheduling() { TaskScheduler::getInstance()->startSchedulerLoopThreaded(); diff --git a/src/lib/Application.h b/src/lib/Application.h index 135812ea..36956d28 100644 --- a/src/lib/Application.h +++ b/src/lib/Application.h @@ -10,7 +10,6 @@ #include "utility/messaging/type/MessageFinishedParsing.h" #include "utility/messaging/type/MessageLoadProject.h" #include "utility/messaging/type/MessageRefresh.h" -#include "utility/messaging/type/MessageSaveProject.h" class IDECommunicationController; class NetworkFactory; @@ -24,7 +23,6 @@ class Application , public MessageListener , public MessageListener , public MessageListener - , public MessageListener { public: static std::shared_ptr create(const Version& version, ViewFactory* viewFactory, NetworkFactory* networkFactory); @@ -36,7 +34,6 @@ public: void createAndLoadProject(const FilePath& projectSettingsFilePath); void loadProject(const FilePath& projectSettingsFilePath); void refreshProject(); - void saveProject(const FilePath& projectSettingsFilePath); bool hasGUI(); private: @@ -46,7 +43,6 @@ private: virtual void handleMessage(MessageFinishedParsing* message); virtual void handleMessage(MessageLoadProject* message); virtual void handleMessage(MessageRefresh* message); - virtual void handleMessage(MessageSaveProject* message); void startMessagingAndScheduling(); diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 64d78085..1bfcd86e 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -255,7 +255,6 @@ add_files( utility/messaging/type/MessageRedo.h utility/messaging/type/MessageRefresh.h utility/messaging/type/MessageResetZoom.h - utility/messaging/type/MessageSaveProject.h utility/messaging/type/MessageScrollCode.h utility/messaging/type/MessageSearch.h utility/messaging/type/MessageSearchAutocomplete.h diff --git a/src/lib/Project.cpp b/src/lib/Project.cpp index f56376d2..9054b6eb 100644 --- a/src/lib/Project.cpp +++ b/src/lib/Project.cpp @@ -91,36 +91,6 @@ Project::ProjectState Project::reload() return m_state; } -bool Project::save(const FilePath& projectSettingsFile) -{ - bool differentLocation = (projectSettingsFile != m_projectSettingsFilepath); - if (!projectSettingsFile.empty()) - { - setProjectSettingsFilePath(projectSettingsFile); - } - else - { - differentLocation = false; - } - - if (m_projectSettingsFilepath.empty()) - { - return false; - } - - ProjectSettings settings; - settings.load(m_projectSettingsFilepath); - - if (differentLocation || settings != *ProjectSettings::getInstance().get()) - { - ProjectSettings::getInstance()->save(m_projectSettingsFilepath); - - LOG_INFO_STREAM(<< "ProjectSettings saved to file: " << m_projectSettingsFilepath.str()); - } - - return true; -} - void Project::clearStorage() { if (m_state == PROJECT_OUTVERSIONED) @@ -291,14 +261,12 @@ Parser::Arguments Project::getParserArguments() const if (projSettings->getUseSourcePathsForHeaderSearch()) { std::vector headerSearchSubPaths; - for (FilePath p : projSettings->getAbsoluteHeaderSearchPaths()) + for (FilePath p : projSettings->getSourcePaths()) { - std::vector tempPaths = FileSystem::getSubDirectories(p); - headerSearchSubPaths.insert( headerSearchSubPaths.end(), tempPaths.begin(), tempPaths.end() ); + utility::append(headerSearchSubPaths, FileSystem::getSubDirectories(p)); } - std::unique(headerSearchSubPaths.begin(),headerSearchSubPaths.end()); - utility::append(args.systemHeaderSearchPaths, headerSearchSubPaths); + utility::append(args.systemHeaderSearchPaths, utility::unique(headerSearchSubPaths)); } utility::append(args.frameworkSearchPaths, projSettings->getAbsoluteFrameworkSearchPaths()); diff --git a/src/lib/Project.h b/src/lib/Project.h index e6fa400b..40769044 100644 --- a/src/lib/Project.h +++ b/src/lib/Project.h @@ -31,8 +31,6 @@ public: ProjectState load(const FilePath& projectSettingsFile); ProjectState reload(); - bool save(const FilePath& projectSettingsFile); - void clearStorage(); void logStats() const; diff --git a/src/lib/settings/ProjectSettings.cpp b/src/lib/settings/ProjectSettings.cpp index 474e584f..627e05d0 100644 --- a/src/lib/settings/ProjectSettings.cpp +++ b/src/lib/settings/ProjectSettings.cpp @@ -157,11 +157,6 @@ bool ProjectSettings::setSourceExtensions(const std::vector &source return setValues("source/extensions/source_extensions", sourceExtensions); } -bool ProjectSettings::isUseSourcePathsForHeaderSearchDefined() const -{ - return isValueDefined("source/use_source_paths_for_header_search"); -} - bool ProjectSettings::getUseSourcePathsForHeaderSearch() const { return getValue("source/use_source_paths_for_header_search", false); diff --git a/src/lib/settings/ProjectSettings.h b/src/lib/settings/ProjectSettings.h index 121950e4..f041b02e 100644 --- a/src/lib/settings/ProjectSettings.h +++ b/src/lib/settings/ProjectSettings.h @@ -47,7 +47,6 @@ public: std::vector getSourceExtensions() const; bool setSourceExtensions(const std::vector& sourceExtensions); - bool isUseSourcePathsForHeaderSearchDefined() const; bool getUseSourcePathsForHeaderSearch() const; bool setUseSourcePathsForHeaderSearch(bool useSourcePathsForHeaderSearch); diff --git a/src/lib/utility/file/FileSystem.cpp b/src/lib/utility/file/FileSystem.cpp index bd3a5d79..ed8ca782 100644 --- a/src/lib/utility/file/FileSystem.cpp +++ b/src/lib/utility/file/FileSystem.cpp @@ -116,14 +116,72 @@ std::string FileSystem::getTimeStringNow() // TODO: move to utility return boost::posix_time::to_iso_string(boost::posix_time::second_clock::universal_time()); } -bool FileSystem::exists(const std::string& path) +bool FileSystem::exists(const FilePath& path) { - return boost::filesystem::exists(boost::filesystem::path(path)); + return boost::filesystem::exists(path.path()); } -bool FileSystem::remove(const std::string& path) +bool FileSystem::remove(const FilePath& path) { - return boost::filesystem::remove(path); + return boost::filesystem::remove(path.path()); +} + +bool FileSystem::rename(const FilePath& from, const FilePath& to) +{ + if (!from.exists() || to.exists()) + { + return false; + } + + boost::filesystem::rename(from.path(), to.path()); + return true; +} + +bool FileSystem::copyFile(const FilePath& from, const FilePath& to) +{ + if (!from.exists() || to.exists()) + { + return false; + } + + boost::filesystem::copy_file(boost::filesystem::path(from.path()), boost::filesystem::path(to.path())); + return true; +} + +bool FileSystem::copy_directory(const FilePath& from, const FilePath& to) +{ + if (!from.exists() || to.exists()) + { + return false; + } + + boost::filesystem::copy_directory(boost::filesystem::path(from.path()),boost::filesystem::path(to.path())); + return true; +} + +void FileSystem::createDirectory(const FilePath& path) +{ + boost::filesystem::create_directories(path.str()); +} + +std::vector FileSystem::getSubDirectories(const FilePath &path) +{ + std::vector v; + + if (!path.exists()) + { + return v; + } + + for (boost::filesystem::recursive_directory_iterator end, dir(path.str()); dir != end; dir++) + { + if (boost::filesystem::is_directory(dir->path())) + { + v.push_back(FilePath(dir->path())); + } + } + + return v; } std::string FileSystem::fileName(const std::string& path) @@ -169,38 +227,3 @@ bool FileSystem::equivalent(const std::string& pathA, const std::string& pathB) return boost::filesystem::path(pathA).compare(boost::filesystem::path(pathB)) == 0; } - -void FileSystem::createDirectory(const FilePath& path) -{ - boost::filesystem::create_directories(path.str()); -} - -bool FileSystem::copy_directory(const FilePath& from, const FilePath& to) -{ - if(!from.exists() || to.exists()) - { - return false; - } - boost::filesystem::copy_directory(boost::filesystem::path(from.str()),boost::filesystem::path(to.str())); - return true; -} - -std::vector FileSystem::getSubDirectories(const FilePath &path) -{ - std::vector v; - - if (!path.exists()) - { - return v; - } - - for (boost::filesystem::recursive_directory_iterator end, dir(path.str()); dir != end; dir++) - { - if (boost::filesystem::is_directory(dir->path())) - { - v.push_back(FilePath(dir->path())); - } - } - - return v; -} diff --git a/src/lib/utility/file/FileSystem.h b/src/lib/utility/file/FileSystem.h index 273f498e..29bdf217 100644 --- a/src/lib/utility/file/FileSystem.h +++ b/src/lib/utility/file/FileSystem.h @@ -23,15 +23,18 @@ public: static TimePoint getLastWriteTime(const FilePath& filePath); static std::string getTimeStringNow(); + static bool exists(const FilePath& path); + static bool remove(const FilePath& path); + static bool rename(const FilePath& from, const FilePath& to); + + static bool copyFile(const FilePath& from, const FilePath& to); + static bool copy_directory(const FilePath& from, const FilePath& to); + static void createDirectory(const FilePath& path); static std::vector getSubDirectories(const FilePath& path); - static bool exists(const std::string& path); static std::string fileName(const std::string& path); static std::string absoluteFilePath(const std::string& path); - static bool remove(const std::string& path); - - static bool copy_directory(const FilePath& from, const FilePath& to); static std::string extension(const std::string& path); static std::string filePathWithoutExtension(const std::string& path); diff --git a/src/lib/utility/messaging/type/MessageLoadProject.h b/src/lib/utility/messaging/type/MessageLoadProject.h index 8c9e4acb..9b881ed2 100644 --- a/src/lib/utility/messaging/type/MessageLoadProject.h +++ b/src/lib/utility/messaging/type/MessageLoadProject.h @@ -1,12 +1,14 @@ #ifndef MESSAGE_LOAD_PROJECT_H #define MESSAGE_LOAD_PROJECT_H +#include "utility/file/FilePath.h" #include "utility/messaging/Message.h" -class MessageLoadProject: public Message +class MessageLoadProject + : public Message { public: - MessageLoadProject(const std::string& filePath, bool forceRefresh) + MessageLoadProject(const FilePath& filePath, bool forceRefresh) : projectSettingsFilePath(filePath) , forceRefresh(forceRefresh) { @@ -19,10 +21,10 @@ public: virtual void print(std::ostream& os) const { - os << projectSettingsFilePath << ", forceRefresh: " << std::boolalpha << forceRefresh; + os << projectSettingsFilePath.str() << ", forceRefresh: " << std::boolalpha << forceRefresh; } - const std::string projectSettingsFilePath; + const FilePath projectSettingsFilePath; const bool forceRefresh; }; diff --git a/src/lib/utility/messaging/type/MessageSaveProject.h b/src/lib/utility/messaging/type/MessageSaveProject.h deleted file mode 100644 index 36957ed2..00000000 --- a/src/lib/utility/messaging/type/MessageSaveProject.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef MESSAGE_SAVE_PROJECT_H -#define MESSAGE_SAVE_PROJECT_H - -#include "utility/messaging/Message.h" - -class MessageSaveProject: public Message -{ -public: - MessageSaveProject(const std::string& filePath) - : projectSettingsFilePath(filePath) - { - } - - static const std::string getStaticType() - { - return "MessageSaveProject"; - } - - virtual void print(std::ostream& os) const - { - os << projectSettingsFilePath; - } - - const std::string projectSettingsFilePath; -}; - -#endif // MESSAGE_SAVE_PROJECT_H diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index f357c27a..029dd24c 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -30,7 +30,6 @@ #include "utility/messaging/type/MessageRedo.h" #include "utility/messaging/type/MessageRefresh.h" #include "utility/messaging/type/MessageResetZoom.h" -#include "utility/messaging/type/MessageSaveProject.h" #include "utility/messaging/type/MessageSearch.h" #include "utility/messaging/type/MessageSwitchColorScheme.h" #include "utility/messaging/type/MessageUndo.h" @@ -446,22 +445,6 @@ void QtMainWindow::forceRefresh() MessageRefresh().refreshAll().dispatch(); } -void QtMainWindow::saveProject() -{ - MessageSaveProject("").dispatch(); -} - -void QtMainWindow::saveAsProject() -{ - QString filename = ""; - filename = QFileDialog::getSaveFileName(this, "Save File as", "", "Coati Project Files (*.coatiproject)"); - - if(!filename.isEmpty()) - { - MessageSaveProject(filename.toStdString()).dispatch(); - } -} - void QtMainWindow::undo() { MessageUndo().dispatch(); @@ -544,11 +527,6 @@ void QtMainWindow::setupProjectMenu() menu->addAction(tr("&Edit Project..."), this, SLOT(editProject())); menu->addSeparator(); - - menu->addAction(tr("&Save Project"), this, SLOT(saveProject()), QKeySequence::Save); - menu->addAction(tr("Save Project as..."), this, SLOT(saveAsProject()), QKeySequence::SaveAs); - - menu->addSeparator(); } menu->addAction(tr("E&xit"), QCoreApplication::instance(), SLOT(quit()), QKeySequence::Quit); diff --git a/src/lib_gui/qt/window/QtMainWindow.h b/src/lib_gui/qt/window/QtMainWindow.h index e87a669f..0230dc6e 100644 --- a/src/lib_gui/qt/window/QtMainWindow.h +++ b/src/lib_gui/qt/window/QtMainWindow.h @@ -117,9 +117,6 @@ public slots: void refresh(); void forceRefresh(); - void saveProject(); - void saveAsProject(); - void undo(); void redo(); void zoomIn(); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp index ee1fcc6e..1cf36fb5 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzard.cpp @@ -555,8 +555,7 @@ void QtProjectWizzard::showSummary() void QtProjectWizzard::createProject() { - std::string path = m_settings.getProjectFileLocation().str() + "/" + m_settings.getProjectName() + ".coatiproject"; - + FilePath path(m_settings.getProjectFileLocation().str() + "/" + m_settings.getProjectName() + ".coatiproject"); m_settings.save(path); bool edited = false; diff --git a/src/lib_parser/data/parser/cxx/PreprocessorCallbacks.cpp b/src/lib_parser/data/parser/cxx/PreprocessorCallbacks.cpp index 0f608d56..278512f4 100644 --- a/src/lib_parser/data/parser/cxx/PreprocessorCallbacks.cpp +++ b/src/lib_parser/data/parser/cxx/PreprocessorCallbacks.cpp @@ -50,7 +50,7 @@ void PreprocessorCallbacks::InclusionDirective( clang::CharSourceRange fileNameRange, const clang::FileEntry* fileEntry, llvm::StringRef searchPath, llvm::StringRef relativePath, const clang::Module* imported ){ - if (!m_currentPath.empty()) + if (!m_currentPath.empty() && fileEntry) { FilePath includedFilePath = FilePath(fileEntry->getName()).canonical(); if (m_fileRegister->hasFilePath(includedFilePath)) diff --git a/web/documentation/index.html b/web/documentation/index.html index 32d78c7c..d6982498 100644 --- a/web/documentation/index.html +++ b/web/documentation/index.html @@ -878,20 +878,6 @@
  • Opens the Edit Project Window prefilled with your project settings and allows for changing them.
  • -
  • - Save Project - -
  • -
  • - Save Project As -
      -
    • Shortcut: Save Project As
    • -
    • Save the project file to another location. The project file will be duplicated.
    • -
    -
  • Exit
      @@ -1074,18 +1060,6 @@ Cmd + O Ctrl + O - - Save Project - Ctrl + S - Cmd + S - Ctrl + S - - - Save Project As - Ctrl + Shift + S - Cmd + Shift + S - Ctrl + Shift + S - Close Window Alt + F4