godot icon indicating copy to clipboard operation
godot copied to clipboard

FileSystem Tab: Inline renaming of files and folders

Open Wiwip opened this issue 2 years ago • 4 comments

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. image

image

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

Wiwip avatar Nov 26 '22 15:11 Wiwip

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).

Chaosus avatar Nov 26 '22 15:11 Chaosus

Just squashed the commits as required.

Wiwip avatar Nov 26 '22 16:11 Wiwip

Fixed some style errors.

Wiwip avatar Nov 26 '22 16:11 Wiwip

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.

Wiwip avatar Nov 28 '22 16:11 Wiwip

Wrong names are not reverted and display incorrectly: image

KoBeWi avatar Dec 09 '22 14:12 KoBeWi

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.

Wiwip avatar Dec 26 '22 19:12 Wiwip

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.

KoBeWi avatar Dec 26 '22 22:12 KoBeWi

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.

Wiwip avatar Dec 30 '22 16:12 Wiwip

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)

Wiwip avatar Dec 30 '22 17:12 Wiwip

I fixed the wrong names not being reverted.

Seems to be still happening. Tested on folders with duplicate names.

KoBeWi avatar Apr 30 '23 16:04 KoBeWi

Alright, I have made changes, but also a huge mistake with git I believe.

Wiwip avatar May 06 '23 22:05 Wiwip

I created a new pull request instead

https://github.com/godotengine/godot/pull/76794

Wiwip avatar May 06 '23 22:05 Wiwip