(this: Field, name: string)
| 203 | * @returns The accepted name. |
| 204 | */ |
| 205 | export function rename(this: Field, name: string): string { |
| 206 | const block = this.getSourceBlock(); |
| 207 | if (!block) { |
| 208 | throw new UnattachedFieldError(); |
| 209 | } |
| 210 | |
| 211 | // Strip leading and trailing whitespace. Beyond this, all names are legal. |
| 212 | name = name.trim(); |
| 213 | |
| 214 | const legalName = findLegalName(name, block); |
| 215 | if (isProcedureBlock(block) && !block.isInsertionMarker()) { |
| 216 | block.getProcedureModel().setName(legalName); |
| 217 | } |
| 218 | const oldName = this.getValue(); |
| 219 | if (oldName !== name && oldName !== legalName) { |
| 220 | // Rename any callers. |
| 221 | const blocks = block.workspace.getAllBlocks(false); |
| 222 | for (let i = 0; i < blocks.length; i++) { |
| 223 | // Assume it is a procedure so we can check. |
| 224 | const procedureBlock = blocks[i] as unknown as ProcedureBlock; |
| 225 | if (procedureBlock.renameProcedure) { |
| 226 | procedureBlock.renameProcedure(oldName as string, legalName); |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | return legalName; |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Construct the blocks required by the flyout for the procedure category. |
no test coverage detected