godot
godot copied to clipboard
FileSystem Tab: Inline renaming of files and folders
The current SceneTree allows for direct inline edit of node names while the FileSystem docker does not. In fact, it still uses a popup text dialog. The pull request is a simple proposal to enable inline editing in the FileSystem docker while maintaining feature parity.
Effectively, it replaces the first image by the second.
The addition of the void set_editor_selection(int start, int end);
is maybe not the definite best solution, however there are no other means of accessing the LineEdit in thew Tree class (other than making it public or adding a getter). Additionally, I'm not sure why TreeItems have the editable property set to "not".
This is my first pull request for Godot so please let me know if there's anything I missed. This seemed like a rather simple change.
Bugsquad edit: Closes https://github.com/godotengine/godot-proposals/issues/4933
Thanks for your contribution. You need to squash the commits as required by our pipeline (see https://docs.godotengine.org/en/latest/community/contributing/pr_workflow.html).
Just squashed the commits as required.
Fixed some style errors.
Moved the set_editable in the _create_tree() and _update_tree(). For some reasons, the favorites creation is done within the _update_tree(). That way, the Favourite: and "res://" can't be edited.
Wrong names are not reverted and display incorrectly:
I fixed the wrong names not being reverted. I considered two options:
- Simply calling update_tree() which is the simple way; or
- Restoring old_name from to_rename with some string magic which needs to handle file vs folders
i.e. String old_name = to_rename.path.is_file ? to_rename.path.get_file() : to_rename.path.substr(0, to_rename.path.length() - 1).get_file();
And simply go with selected_item->set_text(old_name); // approximation
My understanding is that update_tree() will be eventually called on a successful rename so it shouldn't be a performance problem to call is for a rename call.
I also noticed that accidentally renaming files such as ".tscn" or ".svg" seemed an undesired behavior. I added a guard in the error checks since the file would be lost for the editor and hidden in the filesystem.
I haven't touched the rest of the rename_operation method since I frankly have no idea what the rest of thecode does.
Restoring old_name from to_rename with some string magic which needs to handle file vs folders
I think this would be preferred. There are no performance considerations here, but if the tree update is not necessary it should be avoided. Although the current solution is ok too, of improving it turns out too difficult for whatever reason. You could use my suggestion above.
I also noticed that accidentally renaming files such as ".tscn" or ".svg" seemed an undesired behavior. I added a guard in the error checks since the file would be lost for the editor and hidden in the filesystem.
Not sure what do you mean by this.
If a file named "scene.tscn" is renamed to ".tscn" by accident or voluntarily, the rename will pass because the file length check includes the extension. On my linux machine, this also means that the file is hidden from godot as its now starting with a dot.
I made the changes, I used the suggestion as it makes sense.
However, I have to figure whether my changes have done anything because double clicks currently edit the item instead of opening them.
The code in tree.cpp at lines 3563 is causing some weird behaviors.
Specifically, if the cell is set as "editable", a double click will automatically enable the "inline edit" mode and not send a double click signal.
if (rect.has_point(mpos)) {
if (!edit_selected()) {
emit_signal(SNAME("item_double_clicked"));
}
} else {
emit_signal(SNAME("item_double_clicked"));
}
AND
if (!edit_selected()) {
emit_signal(SNAME("item_activated"));
incr_search.clear();
}
Option 1. Optional argument to edit_selected() to bypass the selectable check and do the inline edit anyway. Option 2. Add a flag to Tree class to allow for selection of default double click behavior. (probably the best one)
I fixed the wrong names not being reverted.
Seems to be still happening. Tested on folders with duplicate names.
Alright, I have made changes, but also a huge mistake with git I believe.
I created a new pull request instead
https://github.com/godotengine/godot/pull/76794