Repository: godot
Issue: `EditorFileDialog`'s `current_path`/`current_file` does not select files for `FILE_MODE_OPEN_FILE`/`OPEN_FILES`/`OPEN_ANY`, but `FileDialog` works as expected.
Labels: bug,topic:editor

### 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: https://github.com/godotengine/godot/pull/51478, and brought up again here https://github.com/godotengine/godot/pull/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
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:

```gdscript
@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.
3. 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](https://github.com/godotengine/godot/files/13839002/godot3_file_dialogs.zip)

4.2.1 [file_dialogs.zip](https://github.com/godotengine/godot/files/13838332/file_dialogs.zip)