diff --git a/src/lib/Application.cpp b/src/lib/Application.cpp index 3d946350..6d55dcfd 100644 --- a/src/lib/Application.cpp +++ b/src/lib/Application.cpp @@ -273,11 +273,11 @@ void Application::handleMessage(MessageLoadProject* message) m_storageCache->setSubject(nullptr); m_project = std::make_shared( - std::make_shared(projectSettingsFilePath), m_storageCache.get(), hasGUI()); + std::make_shared(projectSettingsFilePath), m_storageCache.get(), getUUID(), hasGUI()); if (m_project) { - m_project->load(); + m_project->load(getDialogView(DialogView::UseCase::GENERAL)); } else { diff --git a/src/lib/component/ComponentManager.cpp b/src/lib/component/ComponentManager.cpp index 0382bbd5..f933e9a9 100644 --- a/src/lib/component/ComponentManager.cpp +++ b/src/lib/component/ComponentManager.cpp @@ -70,6 +70,8 @@ void ComponentManager::setup(ViewLayout* viewLayout) ); } + m_dialogViews[DialogView::UseCase::INDEXING]->setDialogsHideable(true); + std::shared_ptr tabbedView = m_componentFactory->getViewFactory()->createTabbedView(viewLayout, "Status"); m_tabbedViews.push_back(tabbedView); diff --git a/src/lib/component/controller/StatusBarController.cpp b/src/lib/component/controller/StatusBarController.cpp index 9e920983..a784ef0f 100644 --- a/src/lib/component/controller/StatusBarController.cpp +++ b/src/lib/component/controller/StatusBarController.cpp @@ -39,6 +39,11 @@ void StatusBarController::handleMessage(MessageIndexingFinished* message) getView()->hideIndexingProgress(); } +void StatusBarController::handleMessage(MessageIndexingStarted* message) +{ + getView()->showIndexingProgress(0); +} + void StatusBarController::handleMessage(MessageIndexingStatus* message) { if (message->showProgress) diff --git a/src/lib/component/controller/StatusBarController.h b/src/lib/component/controller/StatusBarController.h index 9473a96a..ccbe2eb4 100644 --- a/src/lib/component/controller/StatusBarController.h +++ b/src/lib/component/controller/StatusBarController.h @@ -9,6 +9,7 @@ #include "utility/messaging/type/error/MessageErrorCountClear.h" #include "utility/messaging/type/error/MessageErrorCountUpdate.h" #include "utility/messaging/type/indexing/MessageIndexingFinished.h" +#include "utility/messaging/type/indexing/MessageIndexingStarted.h" #include "utility/messaging/type/indexing/MessageIndexingStatus.h" #include "utility/messaging/type/MessagePingReceived.h" #include "utility/messaging/type/MessageRefresh.h" @@ -22,6 +23,7 @@ class StatusBarController , public MessageListener , public MessageListener , public MessageListener + , public MessageListener , public MessageListener , public MessageListener , public MessageListener @@ -39,6 +41,7 @@ private: virtual void handleMessage(MessageErrorCountClear* message); virtual void handleMessage(MessageErrorCountUpdate* message); virtual void handleMessage(MessageIndexingFinished* message); + virtual void handleMessage(MessageIndexingStarted* message); virtual void handleMessage(MessageIndexingStatus* message); virtual void handleMessage(MessagePingReceived* message); virtual void handleMessage(MessageRefresh* message); diff --git a/src/lib/data/TaskCleanStorage.cpp b/src/lib/data/TaskCleanStorage.cpp index c1b24b0c..89608677 100644 --- a/src/lib/data/TaskCleanStorage.cpp +++ b/src/lib/data/TaskCleanStorage.cpp @@ -8,9 +8,11 @@ #include "Application.h" TaskCleanStorage::TaskCleanStorage( - std::weak_ptr storage, const std::vector& filePaths, bool clearAllErrors + std::weak_ptr storage, std::shared_ptr dialogView, + const std::vector& filePaths, bool clearAllErrors ) : m_storage(storage) + , m_dialogView(dialogView) , m_filePaths(filePaths) , m_clearAllErrors(clearAllErrors) { @@ -18,8 +20,7 @@ TaskCleanStorage::TaskCleanStorage( void TaskCleanStorage::doEnter(std::shared_ptr blackboard) { - Application::getInstance()->getDialogView(DialogView::UseCase::INDEXING)->showUnknownProgressDialog( - L"Clearing Files", std::to_wstring(m_filePaths.size()) + L" Files"); + m_dialogView->showUnknownProgressDialog(L"Clearing Files", std::to_wstring(m_filePaths.size()) + L" Files"); m_start = utility::durationStart(); @@ -43,8 +44,7 @@ Task::TaskState TaskCleanStorage::doUpdate(std::shared_ptr blackboar storage->clearFileElements(m_filePaths, [=](int progress) { - Application::getInstance()->getDialogView(DialogView::UseCase::INDEXING)->showProgressDialog( - L"Clearing", std::to_wstring(m_filePaths.size()) + L" Files", progress); + m_dialogView->showProgressDialog(L"Clearing", std::to_wstring(m_filePaths.size()) + L" Files", progress); } ); } @@ -58,7 +58,7 @@ void TaskCleanStorage::doExit(std::shared_ptr blackboard) { blackboard->set("clear_time", utility::duration(m_start)); - Application::getInstance()->getDialogView(DialogView::UseCase::INDEXING)->hideProgressDialog(); + m_dialogView->hideProgressDialog(); } void TaskCleanStorage::doReset(std::shared_ptr blackboard) diff --git a/src/lib/data/TaskCleanStorage.h b/src/lib/data/TaskCleanStorage.h index a0ea5ac1..2e610423 100644 --- a/src/lib/data/TaskCleanStorage.h +++ b/src/lib/data/TaskCleanStorage.h @@ -16,6 +16,7 @@ class TaskCleanStorage public: TaskCleanStorage( std::weak_ptr storage, + std::shared_ptr dialogView, const std::vector& filePaths, bool clearAllErrors ); @@ -27,6 +28,7 @@ private: void doReset(std::shared_ptr blackboard) override; std::weak_ptr m_storage; + std::shared_ptr m_dialogView; std::vector m_filePaths; bool m_clearAllErrors; diff --git a/src/lib/data/TaskFinishParsing.cpp b/src/lib/data/TaskFinishParsing.cpp index ced4b55b..38dc657e 100644 --- a/src/lib/data/TaskFinishParsing.cpp +++ b/src/lib/data/TaskFinishParsing.cpp @@ -11,18 +11,15 @@ #include "utility/utilityString.h" #include "Application.h" -TaskFinishParsing::TaskFinishParsing(std::shared_ptr storage) +TaskFinishParsing::TaskFinishParsing(std::shared_ptr storage, std::shared_ptr dialogView) : m_storage(storage) + , m_dialogView(dialogView) { } void TaskFinishParsing::terminate() { - Application* app = Application::getInstance().get(); - if (app) - { - app->getDialogView(DialogView::UseCase::INDEXING)->clearDialogs(); - } + m_dialogView->clearDialogs(); MessageStatus(L"An unknown exception was thrown during indexing.", true, false).dispatch(); MessageIndexingFinished().dispatch(); @@ -37,11 +34,9 @@ Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr blackboa { TimeStamp start = utility::durationStart(); - std::shared_ptr dialogView = Application::getInstance()->getDialogView(DialogView::UseCase::INDEXING); - - dialogView->showUnknownProgressDialog(L"Finish Indexing", L"Optimizing database"); + m_dialogView->showUnknownProgressDialog(L"Finish Indexing", L"Optimizing database"); m_storage->optimizeMemory(); - dialogView->hideUnknownProgressDialog(); + m_dialogView->hideUnknownProgressDialog(); float time = utility::duration(start); @@ -82,7 +77,7 @@ Task::TaskState TaskFinishParsing::doUpdate(std::shared_ptr blackboa MessageStatus(status, false, false).dispatch(); StorageStats stats = m_storage->getStorageStats(); - DatabasePolicy policy = dialogView->finishedIndexingDialog( + DatabasePolicy policy = m_dialogView->finishedIndexingDialog( indexedSourceFileCount, sourceFileCount, stats.completedFileCount, diff --git a/src/lib/data/TaskFinishParsing.h b/src/lib/data/TaskFinishParsing.h index e3f2baf4..581b4de5 100644 --- a/src/lib/data/TaskFinishParsing.h +++ b/src/lib/data/TaskFinishParsing.h @@ -14,7 +14,7 @@ class TaskFinishParsing : public Task { public: - TaskFinishParsing(std::shared_ptr storage); + TaskFinishParsing(std::shared_ptr storage, std::shared_ptr dialogView); void terminate() override; @@ -25,6 +25,7 @@ private: void doReset(std::shared_ptr blackboard) override; std::shared_ptr m_storage; + std::shared_ptr m_dialogView; }; #endif // TASK_FINISH_PARSING_H diff --git a/src/lib/data/indexer/TaskBuildIndex.cpp b/src/lib/data/indexer/TaskBuildIndex.cpp index c992310c..e3fd5cdf 100644 --- a/src/lib/data/indexer/TaskBuildIndex.cpp +++ b/src/lib/data/indexer/TaskBuildIndex.cpp @@ -3,16 +3,16 @@ #include "utility/AppPath.h" #include "utility/logging/FileLogger.h" #include "utility/messaging/type/indexing/MessageIndexingStatus.h" +#include "utility/messaging/type/MessageStatus.h" #include "utility/scheduling/Blackboard.h" +#include "utility/TimeStamp.h" #include "utility/UserPaths.h" #include "utility/utilityApp.h" -#include "Application.h" #include "component/view/DialogView.h" #include "data/indexer/IndexerCommandList.h" #include "data/indexer/interprocess/InterprocessIndexer.h" #include "data/storage/StorageProvider.h" -#include "utility/messaging/type/MessageStatus.h" #if _WIN32 const std::wstring TaskBuildIndex::s_processName(L"sourcetrail_indexer.exe"); @@ -21,16 +21,20 @@ const std::wstring TaskBuildIndex::s_processName(L"sourcetrail_indexer"); #endif TaskBuildIndex::TaskBuildIndex( - unsigned int processCount, + size_t processCount, std::shared_ptr indexerCommandList, std::shared_ptr storageProvider, + std::shared_ptr dialogView, + const std::string& appUUID, bool multiProcessIndexing ) : m_indexerCommandList(indexerCommandList) , m_storageProvider(storageProvider) + , m_dialogView(dialogView) + , m_appUUID(appUUID) , m_multiProcessIndexing(multiProcessIndexing) - , m_interprocessIndexerCommandManager(Application::getUUID(), 0, true) - , m_interprocessIndexingStatusManager(Application::getUUID(), 0, true) + , m_interprocessIndexerCommandManager(appUUID, 0, true) + , m_interprocessIndexingStatusManager(appUUID, 0, true) , m_processCount(processCount) , m_interrupted(false) , m_lastCommandCount(0) @@ -66,7 +70,7 @@ void TaskBuildIndex::doEnter(std::shared_ptr blackboard) const int processId = i + 1; // 0 remains reserved for the main process m_interprocessIntermediateStorageManagers.push_back( - std::make_shared(Application::getUUID(), processId, true) + std::make_shared(m_appUUID, processId, true) ); if (m_multiProcessIndexing) @@ -168,7 +172,7 @@ void TaskBuildIndex::terminate() void TaskBuildIndex::handleMessage(MessageInterruptTasks* message) { - if (!Application::getInstance()->getDialogView(DialogView::UseCase::INDEXING)->dialogsHidden()) + if (!m_dialogView->dialogsHidden()) { m_interrupted = true; } @@ -192,7 +196,7 @@ void TaskBuildIndex::runIndexerProcess(int processId, const std::wstring& logFil const std::wstring commandPath = L"\"" + indexerProcessPath.wstr() + L"\""; std::vector commandArguments; commandArguments.push_back(std::to_wstring(processId)); - commandArguments.push_back(utility::decodeFromUtf8(Application::getUUID())); + commandArguments.push_back(utility::decodeFromUtf8(m_appUUID)); commandArguments.push_back(L"\"" + AppPath::getAppPath().getAbsolute().wstr() + L"\""); commandArguments.push_back(L"\"" + UserPaths::getUserDataPath().getAbsolute().wstr() + L"\""); @@ -222,7 +226,7 @@ void TaskBuildIndex::runIndexerThread(int processId) m_runningThreadCount++; } - InterprocessIndexer indexer(Application::getUUID(), processId); + InterprocessIndexer indexer(m_appUUID, processId); indexer.work(); { @@ -297,8 +301,7 @@ void TaskBuildIndex::updateIndexingDialog( m_indexingFileCount += sourcePaths.size(); - Application::getInstance()->getDialogView(DialogView::UseCase::INDEXING)->updateIndexingDialog( - m_indexingFileCount, indexedSourceFileCount, sourceFileCount, sourcePaths); + m_dialogView->updateIndexingDialog(m_indexingFileCount, indexedSourceFileCount, sourceFileCount, sourcePaths); int progress = 0; if (sourceFileCount) diff --git a/src/lib/data/indexer/TaskBuildIndex.h b/src/lib/data/indexer/TaskBuildIndex.h index 67d69d39..b2c5e601 100644 --- a/src/lib/data/indexer/TaskBuildIndex.h +++ b/src/lib/data/indexer/TaskBuildIndex.h @@ -21,9 +21,11 @@ class TaskBuildIndex { public: TaskBuildIndex( - unsigned int processCount, + size_t processCount, std::shared_ptr indexerCommandList, std::shared_ptr storageProvider, + std::shared_ptr dialogView, + const std::string& appUUID, bool multiProcessIndexing ); @@ -45,12 +47,14 @@ protected: std::shared_ptr m_indexerCommandList; std::shared_ptr m_storageProvider; + std::shared_ptr m_dialogView; + const std::string m_appUUID; bool m_multiProcessIndexing; InterprocessIndexerCommandManager m_interprocessIndexerCommandManager; InterprocessIndexingStatusManager m_interprocessIndexingStatusManager; - unsigned int m_processCount; + size_t m_processCount; bool m_interrupted; size_t m_lastCommandCount; size_t m_indexingFileCount; diff --git a/src/lib/data/parser/TaskParseWrapper.cpp b/src/lib/data/parser/TaskParseWrapper.cpp index 8b18d103..3bf04964 100644 --- a/src/lib/data/parser/TaskParseWrapper.cpp +++ b/src/lib/data/parser/TaskParseWrapper.cpp @@ -2,13 +2,12 @@ #include "component/view/DialogView.h" #include "data/storage/PersistentStorage.h" -#include "utility/messaging/type/indexing/MessageIndexingStatus.h" #include "utility/scheduling/Blackboard.h" #include "utility/utility.h" -#include "Application.h" -TaskParseWrapper::TaskParseWrapper(std::weak_ptr storage) +TaskParseWrapper::TaskParseWrapper(std::weak_ptr storage, std::shared_ptr dialogView) : m_storage(storage) + , m_dialogView(dialogView) { } @@ -17,13 +16,8 @@ void TaskParseWrapper::doEnter(std::shared_ptr blackboard) int sourceFileCount = 0; blackboard->get("source_file_count", sourceFileCount); - if (std::shared_ptr dialogView = Application::getInstance()->getDialogView(DialogView::UseCase::INDEXING)) - { - dialogView->clearDialogs(); - dialogView->updateIndexingDialog(0, 0, sourceFileCount, { }); - - MessageIndexingStatus(true, 0).dispatch(); - } + m_dialogView->clearDialogs(); + m_dialogView->updateIndexingDialog(0, 0, sourceFileCount, { }); m_start = utility::durationStart(); diff --git a/src/lib/data/parser/TaskParseWrapper.h b/src/lib/data/parser/TaskParseWrapper.h index 9526a1ed..295f1ae0 100644 --- a/src/lib/data/parser/TaskParseWrapper.h +++ b/src/lib/data/parser/TaskParseWrapper.h @@ -16,7 +16,7 @@ class TaskParseWrapper : public TaskDecorator { public: - TaskParseWrapper(std::weak_ptr storage); + TaskParseWrapper(std::weak_ptr storage, std::shared_ptr dialogView); private: virtual void doEnter(std::shared_ptr blackboard); @@ -25,6 +25,7 @@ private: virtual void doReset(std::shared_ptr blackboard); std::weak_ptr m_storage; + std::shared_ptr m_dialogView; TimeStamp m_start; }; diff --git a/src/lib/project/Project.cpp b/src/lib/project/Project.cpp index f1d3d3a8..b3962edb 100644 --- a/src/lib/project/Project.cpp +++ b/src/lib/project/Project.cpp @@ -41,18 +41,18 @@ #include "utility/utilityApp.h" #include "utility/utilityFile.h" #include "utility/utilityString.h" -#include "Application.h" const std::wstring Project::PROJECT_FILE_EXTENSION = L".srctrlprj"; const std::wstring Project::BOOKMARK_DB_FILE_EXTENSION = L".srctrlbm"; const std::wstring Project::INDEX_DB_FILE_EXTENSION = L".srctrldb"; const std::wstring Project::TEMP_INDEX_DB_FILE_EXTENSION = L".srctrldb_tmp"; -Project::Project(std::shared_ptr settings, StorageCache* storageCache, bool hasGUI) +Project::Project(std::shared_ptr settings, StorageCache* storageCache, const std::string& appUUID, bool hasGUI) : m_settings(settings) , m_storageCache(storageCache) , m_state(PROJECT_STATE_NOT_LOADED) , m_isIndexing(false) + , m_appUUID(appUUID) , m_hasGUI(hasGUI) { } @@ -89,7 +89,7 @@ void Project::setStateOutdated() } } -void Project::load() +void Project::load(std::shared_ptr dialogView) { if (m_isIndexing) { @@ -114,9 +114,10 @@ void Project::load() { if (dbPath.exists()) { - if (Application::getInstance()->getDialogView(DialogView::UseCase::GENERAL)->confirm( - "Sourcetrail has been closed unexpectedly while indexing this project. You can either choose to keep the data that has " - "already been indexed or discard that data and restore the state of your project before indexing?", + if (dialogView->confirm( + "Sourcetrail has been closed unexpectedly while indexing this project. You can either choose to keep " + "the data that has already been indexed or discard that data and restore the state of your project " + "before indexing?", { "Keep and Continue", "Discard and Restore" }) == 0) { LOG_INFO("Switching to temporary indexing data on user's decision"); @@ -346,7 +347,12 @@ void Project::refresh(RefreshMode refreshMode, std::shared_ptr dialo enabledModes.insert(enabledModes.end(), { REFRESH_UPDATED_FILES, REFRESH_UPDATED_AND_INCOMPLETE_FILES }); } - dialogView->startIndexingDialog(this, enabledModes, info, [this, dialogView](const RefreshInfo& info) { buildIndex(info, dialogView); }); + dialogView->startIndexingDialog(this, enabledModes, info, + [this, dialogView](const RefreshInfo& info) + { + buildIndex(info, dialogView); + } + ); } else { @@ -412,18 +418,17 @@ void Project::buildIndex(const RefreshInfo& info, std::shared_ptr di FileSystem::copyFile(indexDbFilePath, tempIndexDbFilePath); } - std::shared_ptr tempStorage = std::make_shared(tempIndexDbFilePath, m_storage->getBookmarkDbFilePath()); + std::shared_ptr tempStorage = + std::make_shared(tempIndexDbFilePath, m_storage->getBookmarkDbFilePath()); tempStorage->setup(); std::shared_ptr taskSequential = std::make_shared(); - bool hideable = m_state == PROJECT_STATE_LOADED || m_state == PROJECT_STATE_OUTDATED; - dialogView->setDialogsHideable(hideable); - if (info.mode != REFRESH_ALL_FILES && (info.filesToClear.size() || info.nonIndexedFilesToClear.size())) { taskSequential->addTask(std::make_shared( tempStorage, + dialogView, utility::toVector(utility::concat(info.filesToClear, info.nonIndexedFilesToClear)), info.mode == REFRESH_UPDATED_AND_INCOMPLETE_FILES )); @@ -468,11 +473,12 @@ void Project::buildIndex(const RefreshInfo& info, std::shared_ptr di taskSequential->addTask(std::make_shared>("indexed_source_file_count", 0)); taskSequential->addTask(std::make_shared>("indexer_count", 0)); - std::shared_ptr taskParserWrapper = std::make_shared(tempStorage); - + std::shared_ptr taskParserWrapper = std::make_shared(tempStorage, dialogView); taskSequential->addTask(taskParserWrapper); + std::shared_ptr taskParallelIndexing = std::make_shared(); taskParserWrapper->setTask(taskParallelIndexing); + // add task for indexing if (indexerThreadCount > 0) { @@ -480,7 +486,7 @@ void Project::buildIndex(const RefreshInfo& info, std::shared_ptr di taskParallelIndexing->addChildTasks( std::make_shared(TaskDecoratorRepeat::CONDITION_WHILE_SUCCESS, Task::STATE_SUCCESS)->addChildTask( - std::make_shared(indexerThreadCount, indexerCommandList, storageProvider, multiProcess) + std::make_shared(indexerThreadCount, indexerCommandList, storageProvider, dialogView, m_appUUID, multiProcess) ) ); } @@ -536,7 +542,7 @@ void Project::buildIndex(const RefreshInfo& info, std::shared_ptr di dialogView->hideUnknownProgressDialog(); } - taskSequential->addTask(std::make_shared(tempStorage)); + taskSequential->addTask(std::make_shared(tempStorage, dialogView)); taskSequential->addTask(std::make_shared()->addChildTasks( std::make_shared()->addChildTasks( @@ -560,7 +566,6 @@ void Project::buildIndex(const RefreshInfo& info, std::shared_ptr di taskSequential->addTask(std::make_shared([dialogView, this]() { m_isIndexing = false; - dialogView->setDialogsHideable(false); MessageIndexingFinished().dispatch(); })); diff --git a/src/lib/project/Project.h b/src/lib/project/Project.h index 24514236..46d043ce 100644 --- a/src/lib/project/Project.h +++ b/src/lib/project/Project.h @@ -24,7 +24,7 @@ public: static const std::wstring INDEX_DB_FILE_EXTENSION; static const std::wstring TEMP_INDEX_DB_FILE_EXTENSION; - Project(std::shared_ptr settings, StorageCache* storageCache, bool hasGUI); + Project(std::shared_ptr settings, StorageCache* storageCache, const std::string& appUUID, bool hasGUI); virtual ~Project(); FilePath getProjectSettingsFilePath() const; @@ -35,7 +35,7 @@ public: bool settingsEqualExceptNameAndLocation(const ProjectSettings& otherSettings) const; void setStateOutdated(); - void load(); + void load(std::shared_ptr dialogView); void refresh(RefreshMode refreshMode, std::shared_ptr dialogView); @@ -71,6 +71,7 @@ private: std::shared_ptr m_storage; std::vector> m_sourceGroups; + std::string m_appUUID; bool m_hasGUI; }; diff --git a/src/lib/utility/messaging/type/indexing/MessageIndexingShowDialog.h b/src/lib/utility/messaging/type/indexing/MessageIndexingShowDialog.h index 5a046adc..fad70f63 100644 --- a/src/lib/utility/messaging/type/indexing/MessageIndexingShowDialog.h +++ b/src/lib/utility/messaging/type/indexing/MessageIndexingShowDialog.h @@ -15,6 +15,7 @@ public: MessageIndexingShowDialog(bool showDialog) : showDialog(showDialog) { + setSendAsTask(false); } const bool showDialog; diff --git a/src/lib_gui/qt/view/QtDialogView.cpp b/src/lib_gui/qt/view/QtDialogView.cpp index 363138a7..a715f53a 100644 --- a/src/lib_gui/qt/view/QtDialogView.cpp +++ b/src/lib_gui/qt/view/QtDialogView.cpp @@ -142,6 +142,7 @@ void QtDialogView::startIndexingDialog( m_onQtThread( [=]() { + m_dialogsVisible = true; m_windowStack.clearWindows(); QtIndexingDialog* window = createWindow(); @@ -177,6 +178,7 @@ void QtDialogView::startIndexingDialog( m_onQtThread2( [=]() { + m_dialogsVisible = true; m_refreshInfos.emplace(info.mode, info); window->updateRefreshInfo(info); @@ -464,7 +466,7 @@ void QtDialogView::setUIBlocked(bool blocked) void QtDialogView::dialogVisibilityChanged(bool visible) { - QtIndexingDialog* window = dynamic_cast(m_windowStack.getTopWindow()); + QtWindowStackElement* window = m_windowStack.getTopWindow(); if (!window) { return; @@ -474,7 +476,7 @@ void QtDialogView::dialogVisibilityChanged(bool visible) m_dialogsVisible = visible; setUIBlocked(visible); - if (!visible) + if (!visible && dynamic_cast(window)) { MessageStatus(L"", false, false).dispatch(); }