MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / clearAll

Method clearAll

app/src/API/Handlers/WorkspacesHandler.cpp:852–897  ·  view source on GitHub ↗

* @brief Wipes every workspace in one shot. Leaves customize mode on with an empty list. */

Source from the content-addressed store, hash-verified

850 * @brief Wipes every workspace in one shot. Leaves customize mode on with an empty list.
851 */
852API::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.

Callers

nothing calls this directly

Calls 5

inProjectFileModeFunction · 0.85
clearAllWorkspacesMethod · 0.80
valueMethod · 0.45
sizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected