logic: Ask user before reparsing the project
While the message box with the question is visible the ui is blocked. A message appears when: * when project was edited * when preferences were edited * when project file has more recent changes than db * when db has a different version than Coati
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
#include "qt/view/QtMainView.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
#include "qt/window/QtMainWindow.h"
|
||||
@@ -12,6 +17,7 @@ QtMainView::QtMainView()
|
||||
, m_activateWindowFunctor(std::bind(&QtMainView::doActivateWindow, this))
|
||||
, m_updateRecentProjectMenuFunctor(std::bind(&QtMainView::doUpdateRecentProjectMenu, this))
|
||||
, m_forceLicenseScreenFunctor(std::bind(&QtMainView::doForceLicenseScreen, this, std::placeholders::_1))
|
||||
, m_confirmFunctor(std::bind(&QtMainView::doConfirm, this, std::placeholders::_1, std::placeholders::_2))
|
||||
{
|
||||
m_window = std::make_shared<QtMainWindow>();
|
||||
m_window->show();
|
||||
@@ -89,6 +95,30 @@ void QtMainView::updateRecentProjectMenu()
|
||||
m_updateRecentProjectMenuFunctor();
|
||||
}
|
||||
|
||||
int QtMainView::confirm(const std::string& message, const std::vector<std::string>& options)
|
||||
{
|
||||
m_confirmDone = false;
|
||||
|
||||
m_confirmFunctor(message, options);
|
||||
|
||||
while (true)
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_confirmMutex);
|
||||
|
||||
if (m_confirmDone)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const int SLEEP_TIME_MS = 25;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS));
|
||||
}
|
||||
|
||||
return m_confirmResult;
|
||||
}
|
||||
|
||||
void QtMainView::handleMessage(MessageForceEnterLicense* message)
|
||||
{
|
||||
m_forceLicenseScreenFunctor(message->licenseExpired);
|
||||
@@ -144,3 +174,30 @@ void QtMainView::doForceLicenseScreen(bool expired)
|
||||
{
|
||||
m_window->forceEnterLicense(expired);
|
||||
}
|
||||
|
||||
void QtMainView::doConfirm(const std::string& message, const std::vector<std::string>& options)
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(message.c_str());
|
||||
|
||||
for (const std::string& option : options)
|
||||
{
|
||||
msgBox.addButton(option.c_str(), QMessageBox::AcceptRole);
|
||||
}
|
||||
|
||||
msgBox.exec();
|
||||
|
||||
m_confirmResult = -1;
|
||||
|
||||
for (int i = 0; i < msgBox.buttons().size(); i++)
|
||||
{
|
||||
if (msgBox.clickedButton() == msgBox.buttons().at(i))
|
||||
{
|
||||
m_confirmResult = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_confirmMutex);
|
||||
m_confirmDone = true;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ public:
|
||||
virtual void activateWindow();
|
||||
virtual void updateRecentProjectMenu();
|
||||
|
||||
virtual int confirm(const std::string& message, const std::vector<std::string>& options);
|
||||
|
||||
private:
|
||||
void handleMessage(MessageForceEnterLicense* message);
|
||||
void handleMessage(MessageProjectNew* message);
|
||||
@@ -59,6 +61,8 @@ private:
|
||||
void doUpdateRecentProjectMenu();
|
||||
void doForceLicenseScreen(bool expired);
|
||||
|
||||
void doConfirm(const std::string& message, const std::vector<std::string>& options);
|
||||
|
||||
std::shared_ptr<QtMainWindow> m_window;
|
||||
std::vector<View*> m_views;
|
||||
|
||||
@@ -69,6 +73,11 @@ private:
|
||||
QtThreadedFunctor<> m_activateWindowFunctor;
|
||||
QtThreadedFunctor<> m_updateRecentProjectMenuFunctor;
|
||||
QtThreadedFunctor<bool> m_forceLicenseScreenFunctor;
|
||||
|
||||
QtThreadedFunctor<const std::string&, const std::vector<std::string>&> m_confirmFunctor;
|
||||
std::mutex m_confirmMutex;
|
||||
bool m_confirmDone;
|
||||
int m_confirmResult;
|
||||
};
|
||||
|
||||
#endif // QT_MAIN_VIEW_H
|
||||
|
||||
@@ -30,10 +30,15 @@
|
||||
QtProjectWizzard::QtProjectWizzard(QWidget* parent)
|
||||
: QtWindowStackElement(parent)
|
||||
, m_windowStack(this)
|
||||
, m_editing(false)
|
||||
{
|
||||
connect(&m_windowStack, SIGNAL(push()), this, SLOT(windowStackChanged()));
|
||||
connect(&m_windowStack, SIGNAL(pop()), this, SLOT(windowStackChanged()));
|
||||
|
||||
ApplicationSettings* appSettings = ApplicationSettings::getInstance().get();
|
||||
m_appSettings.setHeaderSearchPaths(appSettings->getHeaderSearchPaths());
|
||||
m_appSettings.setFrameworkSearchPaths(appSettings->getFrameworkSearchPaths());
|
||||
|
||||
m_parserManager = std::make_shared<SolutionParserManager>();
|
||||
|
||||
// wip
|
||||
@@ -166,6 +171,7 @@ void QtProjectWizzard::refreshProjectFromCompilationDatabase(const std::string&
|
||||
void QtProjectWizzard::editProject(const ProjectSettings& settings)
|
||||
{
|
||||
m_settings = settings;
|
||||
m_editing = true;
|
||||
|
||||
showSummary();
|
||||
|
||||
@@ -204,7 +210,7 @@ void QtProjectWizzard::showPreferences()
|
||||
}
|
||||
);
|
||||
|
||||
connect(window, SIGNAL(next()), this, SLOT(cancelWizzard()));
|
||||
connect(window, SIGNAL(next()), this, SLOT(savePreferences()));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -304,6 +310,12 @@ void QtProjectWizzard::cancelWizzard()
|
||||
emit canceled();
|
||||
}
|
||||
|
||||
void QtProjectWizzard::finishWizzard()
|
||||
{
|
||||
m_windowStack.clearWindows();
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void QtProjectWizzard::windowStackChanged()
|
||||
{
|
||||
QWidget* window = m_windowStack.getTopWindow();
|
||||
@@ -602,12 +614,35 @@ void QtProjectWizzard::createProject()
|
||||
|
||||
m_settings.save(path);
|
||||
|
||||
bool forceRefresh = !(m_settings == *ProjectSettings::getInstance().get());
|
||||
bool edited = false;
|
||||
if (m_editing)
|
||||
{
|
||||
bool settingsChanged = !(m_settings == *ProjectSettings::getInstance().get());
|
||||
bool appSettingsChanged = !(m_appSettings == *ApplicationSettings::getInstance().get());
|
||||
|
||||
if (settingsChanged || appSettingsChanged)
|
||||
{
|
||||
edited = true;
|
||||
}
|
||||
}
|
||||
|
||||
MessageDispatchWhenLicenseValid(
|
||||
std::make_shared<MessageLoadProject>(path, forceRefresh)
|
||||
std::make_shared<MessageLoadProject>(path, edited)
|
||||
).dispatch();
|
||||
|
||||
m_windowStack.clearWindows();
|
||||
emit finished();
|
||||
finishWizzard();
|
||||
}
|
||||
|
||||
void QtProjectWizzard::savePreferences()
|
||||
{
|
||||
bool appSettingsChanged = !(m_appSettings == *ApplicationSettings::getInstance().get());
|
||||
|
||||
if (appSettingsChanged)
|
||||
{
|
||||
MessageDispatchWhenLicenseValid(
|
||||
std::make_shared<MessageLoadProject>("", true)
|
||||
).dispatch();
|
||||
}
|
||||
|
||||
cancelWizzard();
|
||||
}
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
#include "qt/window/project_wizzard/QtProjectWizzardContentSelect.h"
|
||||
#include "qt/window/QtWindowStack.h"
|
||||
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "settings/ProjectSettings.h"
|
||||
|
||||
#include "utility/solution/SolutionParserManager.h"
|
||||
|
||||
class ProjectSettings;
|
||||
class QtProjectWizzardContentSummary;
|
||||
class QtProjectWizzardWindow;
|
||||
|
||||
@@ -55,12 +57,18 @@ private:
|
||||
|
||||
QtWindowStack m_windowStack;
|
||||
std::shared_ptr<QtProjectWizzardWindow> m_popup;
|
||||
|
||||
ProjectSettings m_settings;
|
||||
ApplicationSettings m_appSettings;
|
||||
|
||||
bool m_editing;
|
||||
|
||||
std::shared_ptr<SolutionParserManager> m_parserManager;
|
||||
|
||||
private slots:
|
||||
void cancelWizzard();
|
||||
void finishWizzard();
|
||||
|
||||
void windowStackChanged();
|
||||
void popupClosed();
|
||||
|
||||
@@ -87,6 +95,7 @@ private slots:
|
||||
void showSummary();
|
||||
|
||||
void createProject();
|
||||
void savePreferences();
|
||||
};
|
||||
|
||||
template<>
|
||||
|
||||
Reference in New Issue
Block a user