-
Notifications
You must be signed in to change notification settings - Fork 7
Implement Templates system #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds a template system: new template actions (create, save, continue), Template Manager UI and scene, a regex-driven Replace popup for placeholder completion, constants and assets, menu entries, a Factory API rename (signle → single), and docs/tests updates. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant Main
participant TemplatesMenu as "Templates submenu"
participant Editor
participant ReplacePopup as "Replace Popup"
User->>Main: File → New With Template
Main->>TemplatesMenu: reload_templates()
User->>TemplatesMenu: select template
TemplatesMenu->>Main: load_template(name)
Main->>Editor: set editor text from template
Main->>ReplacePopup: start(pattern = S.PATTERN_PLACEHOLDER)
ReplacePopup->>Editor: find & highlight first placeholder
note right of ReplacePopup: User may Next/Previous, Replace, Insert, or Close
User->>ReplacePopup: Close
ReplacePopup->>Editor: deselect & hide
sequenceDiagram
autonumber
actor User
participant Action as "Continue Placeholder Action"
participant Main
participant ReplacePopup as "Replace Popup"
User->>Action: Format → Continue Placeholder Completion
Action->>Main: start_replace_action(S.PATTERN_PLACEHOLDER)
Main->>ReplacePopup: start(pattern)
alt matches found
ReplacePopup->>ReplacePopup: show popup near caret (highlight current match)
else no matches
ReplacePopup->>ReplacePopup: close popup (no matches)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (3)
action_scripts/scenes/template_manager.gd (2)
44-47: Guard against selecting guidance items.When the template list is empty, lines 15-16 add non-selectable guidance messages. If a user somehow selects one of these items (e.g., through keyboard navigation or a race condition), lines 46-47 would attempt to load a non-existent template file, causing an error.
Apply this diff:
func _on_templates_item_selected(index: int) -> void: + # Skip if this is a guidance message + if not templates.is_item_selectable(index): + return preview_panel.show() template_name.text = templates.get_item_text(index) preview.text = FileAccess.get_file_as_string(S.TEMPLATE_TEMPLATES.format([template_name.text]))
38-41: Handle trash failures and refactor list refresh.Line 39 doesn't check if
OS.move_to_trash()succeeds, which could fail silently. Line 41 calls_ready()to refresh the list, but_ready()is a lifecycle method and shouldn't be manually invoked.Apply this diff:
func _delete_template() -> void: - OS.move_to_trash(S.globalize_path(S.TEMPLATE_TEMPLATES.format([template_name.text]))) + var path := S.globalize_path(S.TEMPLATE_TEMPLATES.format([template_name.text])) + var err := OS.move_to_trash(path) + if err != OK: + Global.send_notification(Global.Notification.ERROR, "Failed to remove template!", "Error code: " + str(err)) + return preview_panel.hide() - _ready() + _reload_list() + +func _reload_list() -> void: + templates.clear() + if not DirAccess.dir_exists_absolute(S.globalize_path(S.FOLDER_TEMPLATES)): + DirAccess.make_dir_recursive_absolute(S.globalize_path(S.FOLDER_TEMPLATES)) + for t in DirAccess.get_files_at(S.FOLDER_TEMPLATES): + templates.add_item(t.get_basename()) + if templates.item_count == 0: + templates.add_item("There is no template to show!", null, false) + templates.add_item("Use Format > Save As Template to create one.", null, false)action_scripts/save_as_template.gd (1)
15-33: Remove unrelated file name mutation and add overwrite warning.Line 32 removes the unsaved indicator (
*) from the current file's name when saving a template. This is incorrect because saving as a template doesn't save the current file—it only creates a new template file. Additionally, there's no warning when overwriting an existing template.Apply this diff:
func _save_template(_name: String) -> void: _name = _name.strip_edges().validate_filename() if _name.is_empty(): Global.send_notification(Global.Notification.ERROR, "Invalid template name!", "Please use letters, numbers, space, dash or underscore.") return if not DirAccess.dir_exists_absolute(S.globalize_path(S.FOLDER_TEMPLATES)): DirAccess.make_dir_recursive_absolute(S.globalize_path(S.FOLDER_TEMPLATES)) var path := S.TEMPLATE_TEMPLATES.format([_name]) + if FileAccess.file_exists(path): + Global.send_notification(Global.Notification.WARNING, "Template exists", "Overwriting existing template: " + _name) var file_access := FileAccess.open(path, FileAccess.WRITE) var err := FileAccess.get_open_error() if err or not file_access: Global.send_notification(Global.Notification.ERROR, "Failed to save file as template!", "Error code: " + str(err)) return file_access.store_string(Global.get_editor_text()) file_access.close() Global.send_notification(Global.Notification.INFO, "File saved as template!") Global.get_core().reload_templates() - Global.set_file_name(Global.get_file_name().replace("*", "")) Signals.open_file.emit(path)
🧹 Nitpick comments (1)
core/main.gd (1)
48-51: Inconsistent comment formatting for method references.Line 48 references
_reload_recent_fileswhile line 50 references_reload_templates, but the actual method on line 416 isreload_templates(without underscore prefix). The comments should consistently reference the actual method names.Apply this diff:
-## Recent files [PopupMenu], see also [method _reload_recent_files]. +## Recent files [PopupMenu], see also [method _reload_recent_files()]. var recent_files_submenu: PopupMenu -## Templates [PopupMenu], see also [method _reload_templates]. +## Templates [PopupMenu], see also [method reload_templates()]. var templates_submenu: PopupMenu
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
CHANGELOG.md(1 hunks)action_scripts/new_with_template.gd(1 hunks)action_scripts/save_as_template.gd(1 hunks)action_scripts/scenes/template_manager.gd(1 hunks)action_scripts/scenes/template_manager.tscn(1 hunks)core/autoload/factory.gd(2 hunks)core/main.gd(3 hunks)core/scripts/editor_api.gd(1 hunks)core/scripts/replace_popup.gd(1 hunks)docs/menus.md(2 hunks)docs/templates.md(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- docs/templates.md
- core/scripts/editor_api.gd
- core/scripts/replace_popup.gd
🔇 Additional comments (3)
core/autoload/factory.gd (3)
5-6: LGTM! Typo fixed in class documentation.The typo has been corrected from "signle" to "single" in the class-level documentation.
48-49: Past review comment addressed - typo fixed.The typo "signle" has been corrected to "single" in the function-level comment, resolving the concern raised in the previous review.
50-71: All references tosignle_line_inputremoved
A full-code search returned no instances of the old name; the rename is complete.
Type of Change
Description
This pull request implements the template system as described in Issue #2. It introduces a reusable file templating mechanism to streamline file creation and reduce repetitive work. Key features include:
user://templates/directory for storing user-defined templates{{{...}}}syntax, including internal variables like{{{!date}}},{{{!file_name}}}, etc.Testing
Impact
Additional Information
Documentation added in
docs/templates.md, including usage examples and screenshots.All new UI strings localized via
translation.csv.Assets and scenes for Template Manager included.
Checklist
Summary by CodeRabbit