diff --git a/GUI/View/Main/ActionManager.cpp b/GUI/View/Main/ActionManager.cpp index d5a5b35dacad1cf98be2e9f90d6bcc2a76c2a728..47ec0c495ad20b64a78f85577e4f3f57e6236dc1 100644 --- a/GUI/View/Main/ActionManager.cpp +++ b/GUI/View/Main/ActionManager.cpp @@ -192,8 +192,9 @@ void ActionManager::onAboutToShowSettingsMenu() action->setToolTip("Project will be saved periodically in project's autosave directory.\n" "When opening project, recover option will be suggested, if possible."); action->setCheckable(true); - checkBox->setChecked(m_project_manager->isAutosaveEnabled()); - connect(checkBox, &QCheckBox::toggled, m_project_manager, &ProjectManager::setAutosaveEnabled); + checkBox->setChecked(gApp->autosave_enabled); + connect(checkBox, &QCheckBox::toggled, + [] { gApp->autosave_enabled = !gApp->autosave_enabled; }); m_settings_menu->addAction(action); } diff --git a/GUI/View/Main/ProjectManager.cpp b/GUI/View/Main/ProjectManager.cpp index 1696cd7a64b1936b98a220b8f59d974ee319b8a6..28c0cde38f5ed6176d0fbfffc75f2b8ee8040980 100644 --- a/GUI/View/Main/ProjectManager.cpp +++ b/GUI/View/Main/ProjectManager.cpp @@ -38,6 +38,7 @@ const QString S_LASTUSEDIMPORTDIR = "LastUsedImportDir"; ProjectManager::ProjectManager(QObject* parent) : QObject(parent) + , m_autosaver(std::make_unique<AutosaveController>()) { } @@ -108,19 +109,6 @@ bool ProjectManager::saveOnQuit() return true; } -bool ProjectManager::isAutosaveEnabled() const -{ - return static_cast<bool>(m_autosave); -} - -void ProjectManager::setAutosaveEnabled(bool value) -{ - if (value) - m_autosave = std::make_unique<AutosaveController>(); - else - m_autosave.reset(); -} - //! Clears list of recent projects. void ProjectManager::clearRecentProjects() @@ -206,8 +194,8 @@ void ProjectManager::createNewProject() { gDoc->clear(); - if (m_autosave) - m_autosave->setDocument(gDoc.get()); + if (gApp->autosave_enabled) + m_autosaver->setDocument(gDoc.get()); } //! Load project data from file name. If autosave info exists, opens dialog for project restore. diff --git a/GUI/View/Main/ProjectManager.h b/GUI/View/Main/ProjectManager.h index 1088a1767509e18bff28f55dc074d97a95044a60..44a5da6dd663a30819001f90f87fb3ad42de45c9 100644 --- a/GUI/View/Main/ProjectManager.h +++ b/GUI/View/Main/ProjectManager.h @@ -36,14 +36,11 @@ public: QStringList recentProjects(); - bool isAutosaveEnabled() const; - signals: void documentOpenedOrClosed(bool opened); void recentListModified(); public slots: - void setAutosaveEnabled(bool value); void clearRecentProjects(); void newProject(); bool saveProject(QString projectPullPath = ""); @@ -63,7 +60,7 @@ private: QString m_working_directory; QStringList m_recent_projects; - std::unique_ptr<AutosaveController> m_autosave; + std::unique_ptr<AutosaveController> m_autosaver; }; #endif // BORNAGAIN_GUI_VIEW_MAIN_PROJECTMANAGER_H