* @brief Renames a workspace. No-op if id not found. */
| 900 | * @brief Renames a workspace. No-op if id not found. |
| 901 | */ |
| 902 | API::CommandResponse API::Handlers::WorkspacesHandler::rename(const QString& id, |
| 903 | const QJsonObject& params) |
| 904 | { |
| 905 | if (!inProjectFileMode()) |
| 906 | return CommandResponse::makeError( |
| 907 | id, ErrorCode::InvalidParam, QStringLiteral("Workspace mutations require ProjectFile mode")); |
| 908 | |
| 909 | if (!params.contains(QStringLiteral("id"))) |
| 910 | return CommandResponse::makeError( |
| 911 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: id")); |
| 912 | |
| 913 | if (!params.contains(QStringLiteral("title"))) |
| 914 | return CommandResponse::makeError( |
| 915 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: title")); |
| 916 | |
| 917 | auto& pm = DataModel::ProjectModel::instance(); |
| 918 | if (!pm.customizeWorkspaces()) |
| 919 | return CommandResponse::makeError( |
| 920 | id, |
| 921 | ErrorCode::InvalidParam, |
| 922 | QStringLiteral("customizeWorkspaces is off; call project.workspaces.customize.set first")); |
| 923 | |
| 924 | const int wid = params.value(QStringLiteral("id")).toInt(); |
| 925 | const QString newTitle = params.value(QStringLiteral("title")).toString(); |
| 926 | if (newTitle.trimmed().isEmpty()) |
| 927 | return CommandResponse::makeError( |
| 928 | id, ErrorCode::InvalidParam, QStringLiteral("Workspace title cannot be empty")); |
| 929 | |
| 930 | pm.renameWorkspace(wid, newTitle); |
| 931 | |
| 932 | QJsonObject result; |
| 933 | result[QStringLiteral("id")] = wid; |
| 934 | result[QStringLiteral("title")] = newTitle; |
| 935 | result[QStringLiteral("renamed")] = true; |
| 936 | return CommandResponse::makeSuccess(id, result); |
| 937 | } |
| 938 | |
| 939 | /** |
| 940 | * @brief Patches workspace title and/or icon by id. |
nothing calls this directly
no test coverage detected