* @brief Reset the active project to a blank slate. */
| 1480 | * @brief Reset the active project to a blank slate. |
| 1481 | */ |
| 1482 | API::CommandResponse API::Handlers::ProjectHandler::fileNew(const QString& id, |
| 1483 | const QJsonObject& params) |
| 1484 | { |
| 1485 | const bool isDryRun = params.value(QStringLiteral("dryRun")).toBool(false); |
| 1486 | |
| 1487 | if (isDryRun) { |
| 1488 | QJsonObject wouldCreate; |
| 1489 | wouldCreate[QStringLiteral("title")] = QStringLiteral("Untitled Project"); |
| 1490 | wouldCreate[QStringLiteral("groupCount")] = 0; |
| 1491 | wouldCreate[QStringLiteral("datasetCount")] = 0; |
| 1492 | wouldCreate[QStringLiteral("sourceCount")] = 1; |
| 1493 | |
| 1494 | QJsonObject result; |
| 1495 | result[QStringLiteral("dryRun")] = true; |
| 1496 | result[QStringLiteral("wouldDiscard")] = summarizeCurrentProject(); |
| 1497 | result[QStringLiteral("wouldCreate")] = wouldCreate; |
| 1498 | result[QStringLiteral("warning")] = |
| 1499 | QStringLiteral("DRY RUN: no project was reset. The current project (wouldDiscard) " |
| 1500 | "would be replaced by a blank one. Confirm before re-issuing without " |
| 1501 | "dryRun:true."); |
| 1502 | return CommandResponse::makeSuccess(id, result); |
| 1503 | } |
| 1504 | |
| 1505 | DataModel::ProjectModel::instance().setSuppressMessageBoxes(true); |
| 1506 | DataModel::ProjectModel::instance().newJsonFile(); |
| 1507 | DataModel::ProjectModel::instance().setSuppressMessageBoxes(false); |
| 1508 | |
| 1509 | AppState::instance().setOperationMode(SerialStudio::ProjectFile); |
| 1510 | |
| 1511 | QJsonObject result; |
| 1512 | result[QStringLiteral("created")] = true; |
| 1513 | result[QStringLiteral("title")] = DataModel::ProjectModel::instance().title(); |
| 1514 | return CommandResponse::makeSuccess(id, result); |
| 1515 | } |
| 1516 | |
| 1517 | /** |
| 1518 | * @brief Set project title |
nothing calls this directly
no test coverage detected