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

Method remove

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

* @brief Deletes a workspace. No-op if id not found. */

Source from the content-addressed store, hash-verified

798 * @brief Deletes a workspace. No-op if id not found.
799 */
800API::CommandResponse API::Handlers::WorkspacesHandler::remove(const QString& id,
801 const QJsonObject& params)
802{
803 if (!inProjectFileMode())
804 return CommandResponse::makeError(
805 id, ErrorCode::InvalidParam, QStringLiteral("Workspace mutations require ProjectFile mode"));
806
807 if (!params.contains(QStringLiteral("id")))
808 return CommandResponse::makeError(
809 id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: id"));
810
811 const bool isDryRun = params.value(QStringLiteral("dryRun")).toBool(false);
812
813 auto& pm = DataModel::ProjectModel::instance();
814 if (!pm.customizeWorkspaces())
815 return CommandResponse::makeError(
816 id,
817 ErrorCode::InvalidParam,
818 QStringLiteral("customizeWorkspaces is off; call project.workspaces.customize.set first"));
819
820 const int wid = params.value(QStringLiteral("id")).toInt();
821
822 const auto& workspaces = pm.activeWorkspaces();
823 const auto it = findWorkspace(workspaces, wid);
824 if (it == workspaces.end())
825 return CommandResponse::makeError(
826 id, ErrorCode::InvalidParam, QStringLiteral("Workspace not found: %1").arg(wid));
827
828 QJsonObject deleted;
829 deleted[QStringLiteral("id")] = it->workspaceId;
830 deleted[QStringLiteral("title")] = it->title;
831 deleted[QStringLiteral("widgetCount")] = static_cast<int>(it->widgetRefs.size());
832
833 if (!isDryRun)
834 pm.deleteWorkspace(wid);
835
836 QJsonObject result;
837 if (isDryRun) {
838 result[QStringLiteral("dryRun")] = true;
839 result[QStringLiteral("warning")] =
840 QStringLiteral("DRY RUN: workspace not deleted. Re-call without dryRun:true to commit.");
841 }
842
843 result[QStringLiteral("id")] = wid;
844 result[QStringLiteral("deleted")] = !isDryRun;
845 result[QStringLiteral("workspace")] = deleted;
846 return CommandResponse::makeSuccess(id, result);
847}
848
849/**
850 * @brief Wipes every workspace in one shot. Leaves customize mode on with an empty list.

Callers 7

clearSessionMethod · 0.45
handleAuthHandshakeMethod · 0.45
onDataReceivedMethod · 0.45
onSocketDisconnectedMethod · 0.45
dryRunDelimiterFunction · 0.45
scriptDryRunMethod · 0.45
scriptApplyMethod · 0.45

Calls 7

inProjectFileModeFunction · 0.85
findWorkspaceFunction · 0.85
customizeWorkspacesMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45
deleteWorkspaceMethod · 0.45

Tested by

no test coverage detected