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

EditorFileDialog's current_path/current_file does not select files for FILE_MODE_OPEN_FILE/OPEN_FILES/OPEN_ANY, but FileDialog works as expected. #86819

Open
nathanfranke opened this issue Jan 5, 2024 · 0 comments

Comments

@nathanfranke
Copy link
Contributor

nathanfranke commented Jan 5, 2024

Tested versions

Not reproducible in Godot 3.5.3.stable
Reproducible in Godot 4.2.1.stable

System information

Linux 6.6.7-arch1-1

Issue description

Setting current_path/current_file does not select a file in EditorFileDialog for _OPEN_FILE, _OPEN_FILES, _OPEN_ANY, but _SAVE_FILE works.

In contrast, FileDialog's current_path/current_file works as expected.

Findings

This is caused by calling file->set_text("") in EditorFileDialog::update_dir. Line was introduced here: #51478, and brought up again here #81226

This change "resolves" the issue, but you must also move current_path = ... after popup_centered() unlike the MRP. Because _post_popup also calls update_dir, current_file is reset on popup_centered().

diff --git a/editor/gui/editor_file_dialog.cpp b/editor/gui/editor_file_dialog.cpp
index fad7e29..8f3b1ee 100644
--- a/editor/gui/editor_file_dialog.cpp
+++ b/editor/gui/editor_file_dialog.cpp
@@ -1085,7 +1085,6 @@ void EditorFileDialog::set_current_dir(const String &p_dir) {
 
 void EditorFileDialog::set_current_file(const String &p_file) {
 	file->set_text(p_file);
-	update_dir();
 	invalidate();
 	_focus_file_text();
 

Removing file->set_text("") is not a good option because now switching directories doesn't clear the file name line edit.

4.2.1 Editor plugin:

@tool
extends EditorPlugin

# CTRL+G    EditorFileDialog; FILE_MODE_OPEN_FILE    Fail - `current_path` does not select "project.godot".
# CTRL+H    EditorFileDialog; FILE_MODE_SAVE_FILE    Working.
# CTRL+J    FileDialog;       FILE_MODE_OPEN_FILE    Working.

func _input(event: InputEvent) -> void:
	if event is InputEventKey:
		if event.keycode == KEY_G:
			if event.ctrl_pressed:
				if event.pressed:
					var file := EditorFileDialog.new()
					add_child(file)
					
					file.file_mode = EditorFileDialog.FILE_MODE_OPEN_FILE
					#file.file_mode = EditorFileDialog.FILE_MODE_OPEN_FILES
					#file.file_mode = EditorFileDialog.FILE_MODE_OPEN_ANY
					
					# "project.godot" is never selected.
					file.current_path = "res://project.godot"
					
					file.popup_centered()
		if event.keycode == KEY_H:
			if event.ctrl_pressed:
				if event.pressed:
					var file := EditorFileDialog.new()
					add_child(file)
					
					file.file_mode = EditorFileDialog.FILE_MODE_SAVE_FILE
					
					# Working as expected.
					file.current_path = "res://project.godot"
					
					file.popup_centered()
		if event.keycode == KEY_J:
			if event.ctrl_pressed:
				if event.pressed:
					var file := FileDialog.new()
					add_child(file)
					file.min_size = Vector2(500.0, 400.0)
					
					file.file_mode = FileDialog.FILE_MODE_OPEN_FILE
					#file.file_mode = FileDialog.FILE_MODE_OPEN_ANY
					#file.file_mode = FileDialog.FILE_MODE_SAVE_FILE
					
					# Working as expected.
					file.current_path = "res://project.godot"
					
					file.popup_centered()

This issue doesn't really apply to FILE_MODE_OPEN_DIR as much as other enum variants.


Steps to reproduce

  1. Open MRP in editor (there are no scenes)
  2. Hotkey CTRL+G is the bug, project.godot is not selected, despite current_path = "res://project.godot".
  3. Hotkey CTRL+H shows a working EditorFileDialog with FILE_MODE_SAVE_FILE, project.godot is selected.
  4. Hotkey CTRL+J shows a working FileDialog with FILE_MODE_OPEN_FILE, project.godot is selected.

Minimal reproduction project (MRP)

Not reproducible but 3.5.3 test project godot3_file_dialogs.zip

4.2.1 file_dialogs.zip

@nathanfranke nathanfranke changed the title EditorFileDialog's current_path/current_file does not work for FILE_MODE_OPEN_FILE/OPEN_FILES/OPEN_ANY, but FileDialog works as expected. EditorFileDialog's current_path/current_file does not select files for FILE_MODE_OPEN_FILE/OPEN_FILES/OPEN_ANY, but FileDialog works as expected. Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants