Skip to content

Add file rename button to project explorer - #11664

Open
Dmitriy Antipov (THEb0nny) wants to merge 4 commits into
microsoft:masterfrom
THEb0nny:feature/rename-file-button
Open

Dmitriy Antipov (THEb0nny) wants to merge 4 commits into
microsoft:masterfrom
THEb0nny:feature/rename-file-button

Conversation

@THEb0nny

Copy link
Copy Markdown
Contributor

Summary

Adds the ability to rename user-created files directly from the file explorer (MakeCode project view), located right next to the delete button.
#11299

Problem / Motivation

Previously, users could create and delete custom files, but could not rename them. To rename a file, users were forced to create a new file with the desired name, copy-paste the code over, and delete the old file.

Changes

  1. Explorer UI (webapp/src/filelist.tsx):

    • Added an edit (pencil) icon button next to the delete button in FileTreeItem for editable top-level user files (excluding system/entry files like main.ts, pxt.json, main.blocks, etc.).
    • Added a rename modal dialog (renameFile) with full validation: checks for empty names, special characters (/, \, :), system/reserved names, language restrictions, and collision with existing files.
    • For custom .ts block files (like custom.ts), automatically re-extracts/updates the custom blocks display name header.
  2. Core Renaming Logic (webapp/src/package.ts & webapp/src/app.tsx):

    • Added EditorPackage.renameFileAsync: updates file mappings in memory and updates files / testFiles in pxt.json.
    • Added ProjectView.renameFile: updates fileHistory, disposes the old Monaco editor model, saves files to workspace, reloads the project header, and switches focus to the newly renamed file.
    • Updated IProjectView typings in localtypings/pxteditor.d.ts.
  3. Styling (theme/common.less):

    • Adjusted margin-left for buttons within .file-list-item so action buttons (rename and delete) sit neatly side-by-side with appropriate spacing.

Testing

  • Tested renaming custom files (custom.ts, other .ts and data files).
  • Verified validation for invalid filenames, reserved filenames, duplicates, and empty strings.
  • Verified that pxt.json is updated and saved.
  • Verified that the open Monaco tab seamlessly updates to the renamed file without errors.
  • Verified that system files (main.ts, pxt.json, etc.) do not show the rename button.

Screenshots

image image image image

Video

BrickCode.for.EV3.-.Google.Chrome.2026-10-21.01-35-02.mp4

Add a visible "Custom" label to the custom blocks namespace and capitalize the empty-filename validation message.
Capitalize the validation message shown when a filename is empty.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant