From 6b692ff0e9eaf60a724359ef1b250b6ac08b758a Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Tue, 27 Aug 2019 16:06:28 +0200 Subject: [PATCH] ui: add menu entry to close the current project (issue #722) --- src/lib/CMakeLists.txt | 1 + src/lib/app/Application.cpp | 15 ++++++++++- src/lib/app/Application.h | 5 +++- .../component/controller/CodeController.cpp | 4 +-- .../component/controller/ErrorController.cpp | 2 +- .../controller/UndoRedoController.cpp | 4 +-- .../storage/sqlite/SqliteBookmarkStorage.cpp | 2 +- .../messaging/type/MessageCloseProject.h | 27 +++++++++++++++++++ .../qt/element/code/QtCodeFileTitleBar.cpp | 2 +- .../qt/project_wizard/QtProjectWizard.cpp | 6 ++--- src/lib_gui/qt/window/QtMainWindow.cpp | 13 ++++++++- src/lib_gui/qt/window/QtMainWindow.h | 1 + src/lib_gui/qt/window/QtPreferencesWindow.cpp | 2 +- 13 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 src/lib/utility/messaging/type/MessageCloseProject.h diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 338c03ff..55fcc0c2 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -527,6 +527,7 @@ add_files( utility/messaging/type/MessageChangeFileView.h utility/messaging/type/MessageClearLogView.h utility/messaging/type/MessageClearStatusView.h + utility/messaging/type/MessageCloseProject.h utility/messaging/type/MessageCodeReference.h utility/messaging/type/MessageDeactivateEdge.h utility/messaging/type/MessageFind.h diff --git a/src/lib/app/Application.cpp b/src/lib/app/Application.cpp index d7be30eb..b23869a7 100644 --- a/src/lib/app/Application.cpp +++ b/src/lib/app/Application.cpp @@ -146,7 +146,7 @@ Application::~Application() } } -const std::shared_ptr Application::getCurrentProject() const +std::shared_ptr Application::getCurrentProject() const { return m_project; } @@ -213,6 +213,19 @@ void Application::handleMessage(MessageActivateWindow* message) } } +void Application::handleMessage(MessageCloseProject* message) +{ + if (m_project && m_project->isIndexing()) + { + MessageStatus(L"Cannot close the project while indexing.", true, false).dispatch(); + return; + } + + m_project.reset(); + updateTitle(); + m_mainView->clear(); +} + void Application::handleMessage(MessageIndexingFinished* message) { logStorageStats(); diff --git a/src/lib/app/Application.h b/src/lib/app/Application.h index c9d61403..57352f93 100644 --- a/src/lib/app/Application.h +++ b/src/lib/app/Application.h @@ -7,6 +7,7 @@ #include "MessageListener.h" #include "MessageIndexingFinished.h" #include "MessageActivateWindow.h" +#include "MessageCloseProject.h" #include "MessageLoadProject.h" #include "MessageRefresh.h" #include "MessageRefreshUI.h" @@ -26,6 +27,7 @@ class ViewFactory; class Application : public MessageListener + , public MessageListener , public MessageListener , public MessageListener , public MessageListener @@ -48,7 +50,7 @@ public: ~Application(); - const std::shared_ptr getCurrentProject() const; + std::shared_ptr getCurrentProject() const; FilePath getCurrentProjectPath() const; bool isProjectLoaded() const; @@ -68,6 +70,7 @@ private: Application(bool withGUI = true); void handleMessage(MessageActivateWindow* message) override; + void handleMessage(MessageCloseProject* message) override; void handleMessage(MessageIndexingFinished* message) override; void handleMessage(MessageLoadProject* message) override; void handleMessage(MessageRefresh* message) override; diff --git a/src/lib/component/controller/CodeController.cpp b/src/lib/component/controller/CodeController.cpp index 8e67dc2a..c1fd4a78 100644 --- a/src/lib/component/controller/CodeController.cpp +++ b/src/lib/component/controller/CodeController.cpp @@ -33,7 +33,7 @@ void CodeController::handleMessage(MessageActivateAll* message) saveOrRestoreViewMode(message); - Project* currentProject = Application::getInstance()->getCurrentProject().get(); + std::shared_ptr currentProject = Application::getInstance()->getCurrentProject(); if (!currentProject || message->acceptedNodeTypes != NodeTypeSet::all()) { clear(); @@ -804,7 +804,7 @@ const SourceLocation* CodeController::getSourceLocationOfParentScope( std::vector CodeController::getProjectDescription(SourceLocationFile* locationFile) const { - Project* currentProject = Application::getInstance()->getCurrentProject().get(); + std::shared_ptr currentProject = Application::getInstance()->getCurrentProject(); if (!currentProject) { return std::vector(); diff --git a/src/lib/component/controller/ErrorController.cpp b/src/lib/component/controller/ErrorController.cpp index 9490554a..e1d48672 100644 --- a/src/lib/component/controller/ErrorController.cpp +++ b/src/lib/component/controller/ErrorController.cpp @@ -124,7 +124,7 @@ void ErrorController::handleMessage(MessageErrorsAll* message) void ErrorController::handleMessage(MessageErrorsForFile* message) { - Project* project = Application::getInstance()->getCurrentProject().get(); + std::shared_ptr project = Application::getInstance()->getCurrentProject(); if (project && project->isIndexing()) { Application::getInstance()->handleDialog( diff --git a/src/lib/component/controller/UndoRedoController.cpp b/src/lib/component/controller/UndoRedoController.cpp index acc2f033..f7cb61f8 100644 --- a/src/lib/component/controller/UndoRedoController.cpp +++ b/src/lib/component/controller/UndoRedoController.cpp @@ -524,8 +524,8 @@ void UndoRedoController::replayCommand(std::list::iterator it) } else if (m->getType() == MessageActivateErrors::getStaticType()) { - Project* project = Application::getInstance()->getCurrentProject().get(); - if (project && project->isIndexing()) + std::shared_ptr currentProject = Application::getInstance()->getCurrentProject(); + if (currentProject && currentProject->isIndexing()) { Application::getInstance()->handleDialog(L"Errors cannot be activated while indexing."); diff --git a/src/lib/data/storage/sqlite/SqliteBookmarkStorage.cpp b/src/lib/data/storage/sqlite/SqliteBookmarkStorage.cpp index d26226f0..2d7adbe2 100644 --- a/src/lib/data/storage/sqlite/SqliteBookmarkStorage.cpp +++ b/src/lib/data/storage/sqlite/SqliteBookmarkStorage.cpp @@ -27,7 +27,7 @@ void SqliteBookmarkStorage::migrateIfNecessary() std::string separator = "::"; if (Application::getInstance()) { - if (std::shared_ptr currentProject = Application::getInstance()->getCurrentProject()) + std::shared_ptr currentProject = Application::getInstance()->getCurrentProject(); { LanguageType currentLanguage = ProjectSettings::getLanguageOfProject(currentProject->getProjectSettingsFilePath()); if (currentLanguage == LANGUAGE_JAVA) diff --git a/src/lib/utility/messaging/type/MessageCloseProject.h b/src/lib/utility/messaging/type/MessageCloseProject.h new file mode 100644 index 00000000..8bff953f --- /dev/null +++ b/src/lib/utility/messaging/type/MessageCloseProject.h @@ -0,0 +1,27 @@ +#ifndef MESSAGE_CLOSE_PROJECT_H +#define MESSAGE_CLOSE_PROJECT_H + +#include "RefreshInfo.h" + +#include "FilePath.h" +#include "Message.h" + +class MessageCloseProject + : public Message +{ +public: + MessageCloseProject() + { + } + + static const std::string getStaticType() + { + return "MessageCloseProject"; + } + + virtual void print(std::wostream& os) const + { + } +}; + +#endif // MESSAGE_CLOSE_PROJECT_H diff --git a/src/lib_gui/qt/element/code/QtCodeFileTitleBar.cpp b/src/lib_gui/qt/element/code/QtCodeFileTitleBar.cpp index e6cf17d5..2ddc577d 100644 --- a/src/lib_gui/qt/element/code/QtCodeFileTitleBar.cpp +++ b/src/lib_gui/qt/element/code/QtCodeFileTitleBar.cpp @@ -125,7 +125,7 @@ void QtCodeFileTitleBar::setIsComplete(bool isComplete) m_titleButton->setIsComplete(isComplete); m_showErrorsButton->setVisible(!isComplete); - Project* project = Application::getInstance()->getCurrentProject().get(); + std::shared_ptr project = Application::getInstance()->getCurrentProject(); if (project && project->isIndexing()) { m_showErrorsButton->setVisible(false); diff --git a/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp b/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp index cc90fd1c..f385691e 100644 --- a/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp +++ b/src/lib_gui/qt/project_wizard/QtProjectWizard.cpp @@ -1186,10 +1186,10 @@ void QtProjectWizard::createProject() bool settingsChanged = false; if (m_editing) { - Application* application = Application::getInstance().get(); - if (application->getCurrentProject() != nullptr) + std::shared_ptr currentProject = Application::getInstance()->getCurrentProject(); + if (currentProject) { - settingsChanged = !(application->getCurrentProject()->settingsEqualExceptNameAndLocation(*(m_projectSettings.get()))); + settingsChanged = !(currentProject->settingsEqualExceptNameAndLocation(*(m_projectSettings.get()))); } settingsChanged |= !(m_appSettings == *ApplicationSettings::getInstance().get()); diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index aa28d57e..31af17fe 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -39,6 +39,7 @@ #include "MessageBookmarkActivate.h" #include "MessageBookmarkBrowse.h" #include "MessageBookmarkCreate.h" +#include "MessageCloseProject.h" #include "MessageCodeReference.h" #include "MessageCustomTrailShow.h" #include "MessageFind.h" @@ -712,7 +713,7 @@ void QtMainWindow::openProject() void QtMainWindow::editProject() { - Project* currentProject = Application::getInstance()->getCurrentProject().get(); + std::shared_ptr currentProject = Application::getInstance()->getCurrentProject(); if (currentProject) { QtProjectWizard* wizard = createWindow(); @@ -721,6 +722,15 @@ void QtMainWindow::editProject() } } +void QtMainWindow::closeProject() +{ + if (Application::getInstance()->getCurrentProject()) + { + MessageCloseProject().dispatch(); + showStartScreen(); + } +} + void QtMainWindow::find() { MessageFind().dispatch(); @@ -932,6 +942,7 @@ void QtMainWindow::setupProjectMenu() menu->addAction(tr("&Edit Project..."), this, &QtMainWindow::editProject); menu->addSeparator(); + menu->addAction(tr("Close Project"), this, &QtMainWindow::closeProject); menu->addAction(tr("E&xit"), QCoreApplication::instance(), &QCoreApplication::quit, QKeySequence::Quit); } diff --git a/src/lib_gui/qt/window/QtMainWindow.h b/src/lib_gui/qt/window/QtMainWindow.h index 052ecc28..9ef0da03 100644 --- a/src/lib_gui/qt/window/QtMainWindow.h +++ b/src/lib_gui/qt/window/QtMainWindow.h @@ -129,6 +129,7 @@ public slots: void newProjectFromCDB(const FilePath& filePath); void openProject(); void editProject(); + void closeProject(); void find(); void findFulltext(); diff --git a/src/lib_gui/qt/window/QtPreferencesWindow.cpp b/src/lib_gui/qt/window/QtPreferencesWindow.cpp index 2e874ee9..a32852e2 100644 --- a/src/lib_gui/qt/window/QtPreferencesWindow.cpp +++ b/src/lib_gui/qt/window/QtPreferencesWindow.cpp @@ -101,7 +101,7 @@ void QtPreferencesWindow::handleNext() if (appSettingsChanged) { - Project* currentProject = app->getCurrentProject().get(); + std::shared_ptr currentProject = Application::getInstance()->getCurrentProject(); if (currentProject) { MessageLoadProject(currentProject->getProjectSettingsFilePath(), true).dispatch();