* @brief Prompts to save changes, returning false only on cancel. */
| 1777 | * @brief Prompts to save changes, returning false only on cancel. |
| 1778 | */ |
| 1779 | bool DataModel::ProjectModel::askSave() |
| 1780 | { |
| 1781 | if (!modified()) |
| 1782 | return true; |
| 1783 | |
| 1784 | const auto opMode = AppState::instance().operationMode(); |
| 1785 | if (opMode != SerialStudio::ProjectFile && m_filePath.isEmpty()) |
| 1786 | return true; |
| 1787 | |
| 1788 | if (m_suppressMessageBoxes) { |
| 1789 | qWarning() << "[ProjectModel] Discarding unsaved changes (API mode)"; |
| 1790 | if (jsonFilePath().isEmpty()) |
| 1791 | newJsonFile(); |
| 1792 | else { |
| 1793 | const auto path = m_filePath; |
| 1794 | m_silentReload = true; |
| 1795 | m_filePath.clear(); |
| 1796 | openJsonFile(path); |
| 1797 | m_silentReload = false; |
| 1798 | if (opMode != SerialStudio::ProjectFile) |
| 1799 | AppState::instance().setOperationMode(opMode); |
| 1800 | } |
| 1801 | |
| 1802 | return true; |
| 1803 | } |
| 1804 | |
| 1805 | auto ret = |
| 1806 | Misc::Utilities::showMessageBox(tr("Do you want to save your changes?"), |
| 1807 | tr("You have unsaved modifications in this project!"), |
| 1808 | QMessageBox::Question, |
| 1809 | APP_NAME, |
| 1810 | QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); |
| 1811 | |
| 1812 | if (ret == QMessageBox::Cancel) |
| 1813 | return false; |
| 1814 | |
| 1815 | if (ret == QMessageBox::Discard) { |
| 1816 | if (jsonFilePath().isEmpty()) |
| 1817 | newJsonFile(); |
| 1818 | else { |
| 1819 | const auto path = m_filePath; |
| 1820 | m_silentReload = true; |
| 1821 | m_filePath.clear(); |
| 1822 | openJsonFile(path); |
| 1823 | m_silentReload = false; |
| 1824 | if (opMode != SerialStudio::ProjectFile) |
| 1825 | AppState::instance().setOperationMode(opMode); |
| 1826 | } |
| 1827 | |
| 1828 | return true; |
| 1829 | } |
| 1830 | |
| 1831 | return saveJsonFile(false); |
| 1832 | } |
| 1833 | |
| 1834 | /** |
| 1835 | * @brief Validates and saves the project, optionally prompting for a path; the |
nothing calls this directly
no test coverage detected