* @brief Wipes every workspace in one shot. Leaves customize mode on with an empty list. */
| 850 | * @brief Wipes every workspace in one shot. Leaves customize mode on with an empty list. |
| 851 | */ |
| 852 | API::CommandResponse API::Handlers::WorkspacesHandler::clearAll(const QString& id, |
| 853 | const QJsonObject& params) |
| 854 | { |
| 855 | if (!inProjectFileMode()) |
| 856 | return CommandResponse::makeError( |
| 857 | id, ErrorCode::InvalidParam, QStringLiteral("Workspace mutations require ProjectFile mode")); |
| 858 | |
| 859 | const bool isDryRun = params.value(QStringLiteral("dryRun")).toBool(false); |
| 860 | |
| 861 | auto& pm = DataModel::ProjectModel::instance(); |
| 862 | |
| 863 | const auto& active = pm.activeWorkspaces(); |
| 864 | QJsonArray wouldDelete; |
| 865 | for (const auto& ws : active) { |
| 866 | QJsonObject row; |
| 867 | row[QStringLiteral("id")] = ws.workspaceId; |
| 868 | row[QStringLiteral("title")] = ws.title; |
| 869 | row[QStringLiteral("widgetCount")] = static_cast<int>(ws.widgetRefs.size()); |
| 870 | wouldDelete.append(row); |
| 871 | } |
| 872 | |
| 873 | const int previousCount = static_cast<int>(pm.editorWorkspaces().size()); |
| 874 | if (!isDryRun) |
| 875 | pm.clearAllWorkspaces(); |
| 876 | |
| 877 | QJsonObject result; |
| 878 | if (isDryRun) { |
| 879 | result[QStringLiteral("dryRun")] = true; |
| 880 | result[QStringLiteral("warning")] = |
| 881 | QStringLiteral("DRY RUN: nothing was cleared. Re-call without dryRun:true to commit. " |
| 882 | "wouldDelete[] enumerates every workspace that would be removed."); |
| 883 | result[QStringLiteral("wouldDelete")] = wouldDelete; |
| 884 | result[QStringLiteral("cleared")] = 0; |
| 885 | result[QStringLiteral("remaining")] = previousCount; |
| 886 | } else { |
| 887 | result[QStringLiteral("cleared")] = previousCount; |
| 888 | result[QStringLiteral("remaining")] = static_cast<int>(pm.editorWorkspaces().size()); |
| 889 | result[QStringLiteral("deleted")] = wouldDelete; |
| 890 | } |
| 891 | |
| 892 | result[QStringLiteral("hint")] = QStringLiteral( |
| 893 | "All workspaces removed; customize mode is on. Call project.workspace.autoGenerate " |
| 894 | "to recreate the default Overview/AllData/per-group layout, or build a custom layout " |
| 895 | "with project.workspace.add + project.workspace.addWidget."); |
| 896 | return CommandResponse::makeSuccess(id, result); |
| 897 | } |
| 898 | |
| 899 | /** |
| 900 | * @brief Renames a workspace. No-op if id not found. |
nothing calls this directly
no test coverage detected