diff --git a/MantidPlot/src/ApplicationWindow.cpp b/MantidPlot/src/ApplicationWindow.cpp index 563e82ebe6aa8b5399288d5741d531670a4a473d..9ae8be7325fdcfc55efd1055a2fa71fdbbce174e 100644 --- a/MantidPlot/src/ApplicationWindow.cpp +++ b/MantidPlot/src/ApplicationWindow.cpp @@ -16839,3 +16839,7 @@ void ApplicationWindow::checkForProjectRecovery() { m_projectRecovery.startProjectSaving(); } } + +void ApplicationWindow::saveRecoveryCheckpoint() { + m_projectRecovery.saveAll(false); +} \ No newline at end of file diff --git a/MantidPlot/src/ApplicationWindow.h b/MantidPlot/src/ApplicationWindow.h index d859cdeb5180611c58e3f74c68f8df1c821c1214..e9592562040047376a4b47d14c3ab19be5b742f9 100644 --- a/MantidPlot/src/ApplicationWindow.h +++ b/MantidPlot/src/ApplicationWindow.h @@ -1133,6 +1133,10 @@ public slots: /// Checks for and attempts project recovery if required void checkForProjectRecovery(); + /// Make a Recovery checkpoint so you don't have to wait for it to happen + /// normally + void saveRecoveryCheckpoint(); + signals: void modified(); void shutting_down(); diff --git a/MantidPlot/src/ProjectRecovery.cpp b/MantidPlot/src/ProjectRecovery.cpp index 6cfdbc0506241b2ca7381826c5223d5736c8d642..d6bfdc130383242dc545390158f9e86106226eff 100644 --- a/MantidPlot/src/ProjectRecovery.cpp +++ b/MantidPlot/src/ProjectRecovery.cpp @@ -434,43 +434,29 @@ void ProjectRecovery::projectSavingThread() { return; } } - - // "Timeout" - Save out again - const auto &ads = Mantid::API::AnalysisDataService::Instance(); - if (ads.size() == 0) { - g_log.debug("Nothing to save"); - continue; - } - - g_log.debug("Project Recovery: Saving started"); - const auto basePath = getOutputPath(); - - Poco::File(basePath).createDirectories(); - auto projectFile = Poco::Path(basePath).append(OUTPUT_PROJ_NAME); - - saveWsHistories(basePath); - saveOpenWindows(projectFile.toString()); - - // Purge any excessive folders - deleteExistingCheckpoints(NO_OF_CHECKPOINTS); - g_log.debug("Project Recovery: Saving finished"); + this->saveAll(); } } - /** * Saves open all open windows using the main GUI thread * * @param projectDestFile :: The full path to write to * @throws If saving fails in the main GUI thread */ -void ProjectRecovery::saveOpenWindows(const std::string &projectDestFile) { +void ProjectRecovery::saveOpenWindows(const std::string &projectDestFile, + bool autoSave) { bool saveCompleted = false; - if (!QMetaObject::invokeMethod(m_windowPtr, "saveProjectRecovery", - Qt::BlockingQueuedConnection, - Q_RETURN_ARG(bool, saveCompleted), - Q_ARG(const std::string, projectDestFile))) { - throw std::runtime_error("Project Recovery: Failed to save project " - "windows - Qt binding failed"); + if (autoSave) { + if (!QMetaObject::invokeMethod(m_windowPtr, "saveProjectRecovery", + Qt::BlockingQueuedConnection, + Q_RETURN_ARG(bool, saveCompleted), + Q_ARG(const std::string, projectDestFile))) { + throw std::runtime_error("Project Recovery: Failed to save project " + "windows - Qt binding failed"); + } + } else { + // Only use this if it is called from the python interface/error reporter + saveCompleted = m_windowPtr->saveProjectRecovery(projectDestFile); } if (!saveCompleted) { @@ -523,4 +509,31 @@ void ProjectRecovery::saveWsHistories(const Poco::Path &historyDestFolder) { } } +/** + * @brief A function that brings the two seperate save methods together + * This won't run if it is locked by the background thread but then it saving + * Anyway so thats no issue. + */ +void ProjectRecovery::saveAll(bool autoSave) { + // "Timeout" - Save out again + const auto &ads = Mantid::API::AnalysisDataService::Instance(); + if (ads.size() == 0) { + g_log.debug("Nothing to save"); + return; + } + + g_log.debug("Project Recovery: Saving started"); + + const auto basePath = getOutputPath(); + Poco::File(basePath).createDirectories(); + + saveWsHistories(basePath); + auto projectFile = Poco::Path(basePath).append(OUTPUT_PROJ_NAME); + saveOpenWindows(projectFile.toString(), autoSave); + + // Purge any excessive folders + deleteExistingCheckpoints(NO_OF_CHECKPOINTS); + g_log.debug("Project Recovery: Saving finished"); +} + } // namespace MantidQt diff --git a/MantidPlot/src/ProjectRecovery.h b/MantidPlot/src/ProjectRecovery.h index 307f52dc11eb5fd6c8d087e770ed470f66f72eee..2f6ef3f8f186e6197c8c62119c45e55502af7d7c 100644 --- a/MantidPlot/src/ProjectRecovery.h +++ b/MantidPlot/src/ProjectRecovery.h @@ -67,6 +67,9 @@ public: /// Stops the background thread void stopProjectSaving(); + /// Saves a project recovery checkpoint + void saveAll(bool autoSave = true); + private: /// Captures the current object in the background thread std::thread createBackgroundThread(); @@ -95,7 +98,8 @@ private: void projectSavingThread(); /// Saves a project recovery file in Mantid - void saveOpenWindows(const std::string &projectDestFolder); + void saveOpenWindows(const std::string &projectDestFolder, + bool autoSave = true); /// Saves the current workspace's histories from Mantid void saveWsHistories(const Poco::Path &projectDestFile); diff --git a/MantidPlot/src/qti.sip b/MantidPlot/src/qti.sip index 679cf688fb15308704c0ee85321019cf3b5de161..9942964ee97ac8efc0e59ee78079bc9330abc2de 100644 --- a/MantidPlot/src/qti.sip +++ b/MantidPlot/src/qti.sip @@ -1240,6 +1240,8 @@ public: QString stemPlot(Table *t, const QString& colName, int power = 1001, int startRow = 0, int endRow = -1); + void saveRecoveryCheckpoint(); + //---- Mantid MantidUI* mantidUI; void addUserMenu(const QString &); diff --git a/docs/source/release/v3.14.0/ui.rst b/docs/source/release/v3.14.0/ui.rst index 60f605b9b215bbc1be5846ea294ca0aa3fef2801..4227197eb84bed3c879645ebfb4ca9068209f287 100644 --- a/docs/source/release/v3.14.0/ui.rst +++ b/docs/source/release/v3.14.0/ui.rst @@ -13,6 +13,9 @@ UI & Usability Changes Project Recovery ---------------- +New +### +-Project recovery can now make a recovery checkpoint on command using mantidplot.app.saveRecoveryCheckpoint() in either the interpreter or script windows in python Changes #######