Skip to content
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

Implements "Batch Rename" editor tool. #15928

Merged
merged 1 commit into from
May 8, 2018

Conversation

bfloch
Copy link
Contributor

@bfloch bfloch commented Jan 21, 2018

Adds a very flexible way to rename multiple nodes at once. I badly needed this in the past. Hope you like it, too.

batch_rename_ui

This is too late for 3.0 so maybe for 3.1? It should be feature complete but please test and read the TODO items at the bottom. I wanted to have this here for discussion before polishing the minimal remaining items.

Long Demo

https://www.dropbox.com/s/wxvhhobk4cc6h9v/batch_rename_overview.mp4?dl=0

(If the mp4 does not work let me know and I try to make a smaller gif)

Features

  • Full undo support
  • Search / Replace
  • Adding of Prefix and Suffix
  • Hidden advanced options for simplicity
  • Substitution (optional):
    • Node Name
    • Node Parent Name
    • Node Type
    • Scene Name
    • Root Name
    • Counter
      • Per level (each children have their own counter)
      • Start, Step and 0-Padding
  • Regular Expressions (optional)
  • Post-Processing (optional)
    • CamelCase to under_lined and reveresed
    • to lowercase / UPPERCASE
  • Live Preview with RegExp Error display
  • Reset options

For discussion / TODO

  • Possibly restore selection after rename.
  • Missing documentation (if this gets accepted)
  • Not using translation strings yet
  • Missing Tool tips (especially for the substitutions)
  • Fix build (compare comment below)
  • Currently lives in editor. Could/Should this be an EditorPlugin? Can I still integrate it with the shortcuts etc? Have not check. Input welcome.
  • Just noticed I called it under_lined but godot calls it underscored. Will fix this.
  • The dialog could be lazily loaded, however I did not want to make the code more complex
  • String offers a CamelCase to underscore (which does not normalize multiple __ btw.). I've implemented the reverese, might be something that can be added to the string itself.
  • RegEx behaves strange:
    • Search: .*
    • Replace: Test
    • Result: TestTest
    • Expected: Test
    • It is fixed if ^.* is used instead. This is clearly how RegEx is working. Is there an option I am missing or is this expected?
  • Needed to expose EditorSelection::get_selected_nodes as none of the other public methods would keep the order which is necessary for the counter. Hope that's ok.
  • Had to expose: LineEdit::seleciton_delete in order to be able to insert text at the cursor (delete selection if something is selected). I think this one is harmless and useful to be public.

In future when I have the time I would like to write a separate tool that sorts nodes based on attributes (E.g. X position, Z order, Name, Type etc.) which would work hand in hand with this tool.

Let me know what you think. Thanks.

@@ -2032,6 +2043,10 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
add_child(create_dialog);
create_dialog->connect("create", this, "_create");

rename_dialog = memnew(RenameDialog(scene_tree, &editor_data->get_undo_redo()));
add_child(rename_dialog);
//rename_dialog->connect("confirmed", this, "_barename");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will get rid of the comment. Sorry.

@bfloch
Copy link
Contributor Author

bfloch commented Jan 21, 2018

Will need to address this:
https://travis-ci.org/godotengine/godot/jobs/331387384#L1618

editor/rename_dialog.cpp:370:44: error: 'Control::FocusMode' is not a class or namespace
  but_insert_count->set_focus_mode(Control::FocusMode::FOCUS_NONE);

@groud
Copy link
Member

groud commented Jan 21, 2018

Hum why not, the tool seems obviously useful but in quite rare and specific cases.
IMHO, I think it would be better to make it a plugin than a part of the editor itself.

@Zephilinox
Copy link
Contributor

Does this also rename node paths in gdscript?

@blurymind
Copy link

looks very useful!!

@bfloch
Copy link
Contributor Author

bfloch commented Jan 21, 2018

Thanks for the feedback so far.
@Zephilinox No. But I am using the same renaming function as the regular rename. Meaning if in future someone contributes the work this tool will benefit, too. In my understanding it is not a trivial task to solve. I do believe the current code does take care of references in AnimationPlayer though.

@groud I will look into moving it. I hope that I can still use the shortcut/context menu entry with a PluginEditor.

@groud
Copy link
Member

groud commented Jan 21, 2018

I hope that I can still use the shortcut/context menu entry with a PluginEditor.

If it's a problem later on, we can make this possible :)

@bfloch bfloch force-pushed the feature_batch_rename branch 6 times, most recently from de00988 to d782424 Compare January 22, 2018 05:01
@bfloch
Copy link
Contributor Author

bfloch commented Jan 22, 2018

Cleaned up minor issues, added translation strings, tooltips, fixed the build.

I looked into the EditorPlugin. I think this mostly boils down to #6128
Wrapping the dialog into an editor plugin should be the easy part. I just wonder about the benefit until the context menu api exists, since the base-code pollution is pretty minimal as is. Are there other benefits I can not see?

I am not sure about the regex. I'll leave it as expected behaviour.

Not sure if under_score to CamelCase should be moved up to String class. Input welcome.

The only important one I see is restoring the selection (which probably gets lost by the renaming itself).
I hope that it can be fixed by a deferred call to restore the initial selection. Not sure what this implies.
If this does not work than I'll leave it for now. It is a minor defect.

@reduz
Copy link
Member

reduz commented May 7, 2018

This seems fine to me, if @akien-mga approves, should be able to merge

@bfloch
Copy link
Contributor Author

bfloch commented May 8, 2018

Thanks. I just checked it against the latest master. Seems to still work fine.

@akien-mga
Copy link
Member

Thanks, looks good! I also think it might be better eventually as an editor plugin, but there might indeed be some features missing from EditorPlugin to do it fully, and since it's a self contained class, it doesn't hurt to add it as is for now.

@akien-mga akien-mga merged commit 64cb616 into godotengine:master May 8, 2018
@bfloch
Copy link
Contributor Author

bfloch commented May 8, 2018

Agreed, @akien-mga
I will hook up to the EditorPlugin tickets and will migrate it once its possible.
Thanks for the feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants