From 842bce8b3221c25e27b8900a677042a384ccc679 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Wed, 17 Oct 2018 01:30:33 +0200 Subject: [PATCH] logic: Show hidden indexing dialog on refresh * Fixed refresh restarted when refreshing while processing files --- src/lib/component/view/DialogView.cpp | 4 +-- src/lib/component/view/DialogView.h | 4 +-- src/lib/project/Project.cpp | 33 +++++++++---------- src/lib/project/Project.h | 9 ++++- .../type/indexing/MessageIndexingShowDialog.h | 5 +-- src/lib_gui/qt/element/QtStatusBar.cpp | 2 +- src/lib_gui/qt/view/QtDialogView.cpp | 19 +++++++---- src/lib_gui/qt/view/QtDialogView.h | 4 +-- src/lib_gui/qt/view/QtRefreshView.cpp | 11 +++++-- src/lib_gui/qt/window/QtIndexingDialog.cpp | 8 ++++- src/lib_gui/qt/window/QtIndexingDialog.h | 2 +- src/lib_gui/qt/window/QtMainWindow.cpp | 3 ++ 12 files changed, 64 insertions(+), 40 deletions(-) diff --git a/src/lib/component/view/DialogView.cpp b/src/lib/component/view/DialogView.cpp index 5964ad73..ea718f3f 100644 --- a/src/lib/component/view/DialogView.cpp +++ b/src/lib/component/view/DialogView.cpp @@ -42,8 +42,8 @@ void DialogView::hideProgressDialog() } void DialogView::startIndexingDialog( - Project* project, const std::vector& enabledModes, const RefreshInfo& info, - std::function onStartIndexing) + Project* project, const std::vector& enabledModes, const RefreshMode initialMode, + std::function onStartIndexing, std::function onCancelIndexing) { } diff --git a/src/lib/component/view/DialogView.h b/src/lib/component/view/DialogView.h index eafe89c3..2cd500c2 100644 --- a/src/lib/component/view/DialogView.h +++ b/src/lib/component/view/DialogView.h @@ -45,8 +45,8 @@ public: virtual void hideProgressDialog(); virtual void startIndexingDialog( - Project* project, const std::vector& enabledModes, const RefreshInfo& info, - std::function onStartIndexing); + Project* project, const std::vector& enabledModes, const RefreshMode initialMode, + std::function onStartIndexing, std::function onCancelIndexing); virtual void updateIndexingDialog( size_t startedFileCount, size_t finishedFileCount, size_t totalFileCount, const std::vector& sourcePaths); virtual DatabasePolicy finishedIndexingDialog( diff --git a/src/lib/project/Project.cpp b/src/lib/project/Project.cpp index 393f4217..74cb0c79 100644 --- a/src/lib/project/Project.cpp +++ b/src/lib/project/Project.cpp @@ -36,7 +36,6 @@ #include "TaskLambda.h" #include "TaskReturnSuccessIf.h" #include "TaskSetValue.h" -#include "ScopedFunctor.h" #include "TextAccess.h" #include "utility.h" #include "utilityApp.h" @@ -52,7 +51,7 @@ Project::Project(std::shared_ptr settings, StorageCache* storag : m_settings(settings) , m_storageCache(storageCache) , m_state(PROJECT_STATE_NOT_LOADED) - , m_isIndexing(false) + , m_refreshStage(RefreshStageType::NONE) , m_appUUID(appUUID) , m_hasGUI(hasGUI) { @@ -74,7 +73,7 @@ std::string Project::getDescription() const bool Project::isIndexing() const { - return m_isIndexing; + return m_refreshStage == RefreshStageType::INDEXING; } bool Project::settingsEqualExceptNameAndLocation(const ProjectSettings& otherSettings) const @@ -92,7 +91,7 @@ void Project::setStateOutdated() void Project::load(std::shared_ptr dialogView) { - if (m_isIndexing) + if (m_refreshStage != RefreshStageType::NONE) { MessageStatus(L"Cannot load another project while indexing.", true, false).dispatch(); return; @@ -234,12 +233,13 @@ void Project::load(std::shared_ptr dialogView) void Project::refresh(RefreshMode refreshMode, std::shared_ptr dialogView) { - if (m_isIndexing) + if (m_refreshStage != RefreshStageType::NONE) { - MessageStatus(L"Cannot refresh the project while indexing.", true, false).dispatch(); return; } + m_refreshStage = RefreshStageType::REFRESHING; + if (m_state == PROJECT_STATE_NOT_LOADED) { return; @@ -312,11 +312,6 @@ void Project::refresh(RefreshMode refreshMode, std::shared_ptr dialo } } - dialogView->showUnknownProgressDialog(L"Preparing Project", L"Processing Files"); - ScopedFunctor dialogHider([&dialogView](){ - dialogView->hideUnknownProgressDialog(); - }); - if (m_state == PROJECT_STATE_NEEDS_MIGRATION) { m_settings->migrate(); @@ -342,8 +337,6 @@ void Project::refresh(RefreshMode refreshMode, std::shared_ptr dialo refreshMode = REFRESH_UPDATED_FILES; } - RefreshInfo info = getRefreshInfo(refreshMode); - if (m_hasGUI) { std::vector enabledModes = { REFRESH_ALL_FILES }; @@ -352,16 +345,20 @@ 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, + dialogView->startIndexingDialog(this, enabledModes, refreshMode, [this, dialogView](const RefreshInfo& info) { buildIndex(info, dialogView); + }, + [this]() + { + m_refreshStage = RefreshStageType::NONE; } ); } else { - buildIndex(info, dialogView); + buildIndex(getRefreshInfo(refreshMode), dialogView); } } @@ -385,7 +382,7 @@ RefreshInfo Project::getRefreshInfo(RefreshMode mode) const void Project::buildIndex(const RefreshInfo& info, std::shared_ptr dialogView) { - if (m_isIndexing) + if (m_refreshStage == RefreshStageType::INDEXING) { MessageStatus(L"Cannot refresh project while indexing.", true, false).dispatch(); return; @@ -572,14 +569,14 @@ void Project::buildIndex(const RefreshInfo& info, std::shared_ptr di )); taskSequential->addTask(std::make_shared([dialogView, this]() { - m_isIndexing = false; + m_refreshStage = RefreshStageType::NONE; MessageIndexingFinished().dispatch(); })); taskSequential->setIsBackgroundTask(true); Task::dispatch(taskSequential); - m_isIndexing = true; + m_refreshStage = RefreshStageType::INDEXING; MessageIndexingStarted().dispatch(); } diff --git a/src/lib/project/Project.h b/src/lib/project/Project.h index be98ff90..bb9f7330 100644 --- a/src/lib/project/Project.h +++ b/src/lib/project/Project.h @@ -55,6 +55,13 @@ private: PROJECT_STATE_DB_CORRUPTED }; + enum class RefreshStageType + { + REFRESHING, + INDEXING, + NONE + }; + Project(const Project&); void swapToTempStorage(std::shared_ptr dialogView); @@ -67,7 +74,7 @@ private: StorageCache* const m_storageCache; ProjectStateType m_state; - bool m_isIndexing = false; + RefreshStageType m_refreshStage; std::shared_ptr m_storage; std::vector> m_sourceGroups; diff --git a/src/lib/utility/messaging/type/indexing/MessageIndexingShowDialog.h b/src/lib/utility/messaging/type/indexing/MessageIndexingShowDialog.h index 7cd2b8ee..4e50ecc6 100644 --- a/src/lib/utility/messaging/type/indexing/MessageIndexingShowDialog.h +++ b/src/lib/utility/messaging/type/indexing/MessageIndexingShowDialog.h @@ -12,13 +12,10 @@ public: return "MessageIndexingShowDialog"; } - MessageIndexingShowDialog(bool showDialog) - : showDialog(showDialog) + MessageIndexingShowDialog() { setSendAsTask(false); } - - const bool showDialog; }; #endif // MESSAGE_INDEXING_SHOW_DIALOG_H diff --git a/src/lib_gui/qt/element/QtStatusBar.cpp b/src/lib_gui/qt/element/QtStatusBar.cpp index a22dfa7b..0e09b8d1 100644 --- a/src/lib_gui/qt/element/QtStatusBar.cpp +++ b/src/lib_gui/qt/element/QtStatusBar.cpp @@ -190,7 +190,7 @@ void QtStatusBar::showErrors() void QtStatusBar::clickedIndexingProgress() { - MessageIndexingShowDialog(true).dispatch(); + MessageIndexingShowDialog().dispatch(); } QWidget* QtStatusBar::addPermanentVLine() diff --git a/src/lib_gui/qt/view/QtDialogView.cpp b/src/lib_gui/qt/view/QtDialogView.cpp index 3aeb4dec..82d510fc 100644 --- a/src/lib_gui/qt/view/QtDialogView.cpp +++ b/src/lib_gui/qt/view/QtDialogView.cpp @@ -134,8 +134,8 @@ void QtDialogView::hideProgressDialog() } void QtDialogView::startIndexingDialog( - Project* project, const std::vector& enabledModes, const RefreshInfo& info, - std::function onStartIndexing) + Project* project, const std::vector& enabledModes, const RefreshMode initialMode, + std::function onStartIndexing, std::function onCancelIndexing) { m_refreshInfos.clear(); @@ -146,9 +146,6 @@ void QtDialogView::startIndexingDialog( m_windowStack.clearWindows(); QtIndexingDialog* window = createWindow(); - window->setupStart(enabledModes); - - m_refreshInfos.emplace(info.mode, info); connect(window, &QtIndexingDialog::setMode, [=](RefreshMode refreshMode) @@ -157,6 +154,7 @@ void QtDialogView::startIndexingDialog( if (it != m_refreshInfos.end()) { window->updateRefreshInfo(it->second); + window->show(); return; } @@ -184,6 +182,7 @@ void QtDialogView::startIndexingDialog( timer->stop(); hideUnknownProgress(); + window->show(); } ); } @@ -209,11 +208,19 @@ void QtDialogView::startIndexingDialog( connect(window, &QtWindow::canceled, [=]() { + Task::dispatch(std::make_shared( + [=]() + { + onCancelIndexing(); + } + )); + setUIBlocked(false); } ); - window->updateRefreshInfo(info); + window->setupStart(enabledModes, initialMode); + window->hide(); setUIBlocked(true); } ); diff --git a/src/lib_gui/qt/view/QtDialogView.h b/src/lib_gui/qt/view/QtDialogView.h index 132fcea1..2bf12c05 100644 --- a/src/lib_gui/qt/view/QtDialogView.h +++ b/src/lib_gui/qt/view/QtDialogView.h @@ -40,8 +40,8 @@ public: void hideProgressDialog() override; void startIndexingDialog( - Project* project, const std::vector& enabledModes, const RefreshInfo& info, - std::function onStartIndexing) override; + Project* project, const std::vector& enabledModes, const RefreshMode initialMode, + std::function onStartIndexing, std::function onCancelIndexing) override; void updateIndexingDialog( size_t startedFileCount, size_t finishedFileCount, size_t totalFileCount, const std::vector& sourcePaths) override; DatabasePolicy finishedIndexingDialog( diff --git a/src/lib_gui/qt/view/QtRefreshView.cpp b/src/lib_gui/qt/view/QtRefreshView.cpp index 78ea5875..f6ccdcc5 100644 --- a/src/lib_gui/qt/view/QtRefreshView.cpp +++ b/src/lib_gui/qt/view/QtRefreshView.cpp @@ -3,12 +3,13 @@ #include #include +#include "MessageIndexingShowDialog.h" #include "MessageRefresh.h" #include "ResourcePaths.h" #include "QtSearchBarButton.h" -#include "utilityQt.h" #include "QtViewWidgetWrapper.h" +#include "utilityQt.h" QtRefreshView::QtRefreshView(ViewLayout* viewLayout) : RefreshView(viewLayout) @@ -25,7 +26,13 @@ QtRefreshView::QtRefreshView(ViewLayout* viewLayout) new QtSearchBarButton(ResourcePaths::getGuiPath().concatenate(L"refresh_view/images/refresh.png")); refreshButton->setObjectName("refresh_button"); refreshButton->setToolTip("refresh"); - m_widget->connect(refreshButton, &QPushButton::clicked, [](){ MessageRefresh().dispatch(); }); + m_widget->connect(refreshButton, &QPushButton::clicked, + []() + { + MessageIndexingShowDialog().dispatch(); + MessageRefresh().dispatch(); + } + ); layout->addWidget(refreshButton); m_widget->setLayout(layout); diff --git a/src/lib_gui/qt/window/QtIndexingDialog.cpp b/src/lib_gui/qt/window/QtIndexingDialog.cpp index 51dfd199..9df2877a 100644 --- a/src/lib_gui/qt/window/QtIndexingDialog.cpp +++ b/src/lib_gui/qt/window/QtIndexingDialog.cpp @@ -38,7 +38,7 @@ QtIndexingDialog::DialogType QtIndexingDialog::getType() const return m_type; } -void QtIndexingDialog::setupStart(const std::vector& enabledModes) +void QtIndexingDialog::setupStart(const std::vector& enabledModes, const RefreshMode initialMode) { setType(DIALOG_START_INDEXING); @@ -111,6 +111,10 @@ void QtIndexingDialog::setupStart(const std::vector& enabledModes) QRadioButton* button = p.second; button->setObjectName("option"); button->setEnabled(false); + if (p.first == initialMode) + { + button->setChecked(true); + } modeLayout->addWidget(button); connect(button, &QRadioButton::toggled, func); } @@ -132,6 +136,8 @@ void QtIndexingDialog::setupStart(const std::vector& enabledModes) m_sizeHint = QSize(350, 310); finishSetup(); + + emit setMode(initialMode); } void QtIndexingDialog::updateRefreshInfo(const RefreshInfo& info) diff --git a/src/lib_gui/qt/window/QtIndexingDialog.h b/src/lib_gui/qt/window/QtIndexingDialog.h index 1447c544..77d2261d 100644 --- a/src/lib_gui/qt/window/QtIndexingDialog.h +++ b/src/lib_gui/qt/window/QtIndexingDialog.h @@ -37,7 +37,7 @@ public: DialogType getType() const; - void setupStart(const std::vector& enabledModes); + void setupStart(const std::vector& enabledModes, const RefreshMode initialMode); void updateRefreshInfo(const RefreshInfo& info); void setupIndexing(bool hideable); diff --git a/src/lib_gui/qt/window/QtMainWindow.cpp b/src/lib_gui/qt/window/QtMainWindow.cpp index aa9941d9..7f36e5f4 100644 --- a/src/lib_gui/qt/window/QtMainWindow.cpp +++ b/src/lib_gui/qt/window/QtMainWindow.cpp @@ -39,6 +39,7 @@ #include "MessageDisplayBookmarks.h" #include "MessageEnteredLicense.h" #include "MessageFind.h" +#include "MessageIndexingShowDialog.h" #include "MessageInterruptTasks.h" #include "MessageLoadProject.h" #include "MessageRefresh.h" @@ -660,11 +661,13 @@ void QtMainWindow::closeWindow() void QtMainWindow::refresh() { + MessageIndexingShowDialog().dispatch(); MessageRefresh().dispatch(); } void QtMainWindow::forceRefresh() { + MessageIndexingShowDialog().dispatch(); MessageRefresh().refreshAll().dispatch(); }