2 extends DialogicVisualEditorField
4 ## Event block field for selecting a file or directory.
7 ################################################################################
9 @export var file_filter := ""
10 @export var placeholder := ""
11 @export var file_mode: EditorFileDialog.FileMode = EditorFileDialog.FILE_MODE_OPEN_FILE
12 var resource_icon: Texture:
16 resource_icon = new_icon
17 %Icon.texture = new_icon
19 %Field.theme_type_variation = ""
21 %Field.theme_type_variation = "LineEditWithIcon"
24 var current_value: String
25 var hide_reset := false
31 ################################################################################
33 func _ready() -> void:
34 $FocusStyle.add_theme_stylebox_override('panel', get_theme_stylebox('focus', 'DialogicEventEdit'))
36 %OpenButton.icon = get_theme_icon("Folder", "EditorIcons")
37 %OpenButton.button_down.connect(_on_OpenButton_pressed)
39 %ClearButton.icon = get_theme_icon("Reload", "EditorIcons")
40 %ClearButton.button_up.connect(clear_path)
41 %ClearButton.visible = !hide_reset
43 %Field.set_drag_forwarding(Callable(), self._can_drop_data_fw, self._drop_data_fw)
44 %Field.placeholder_text = placeholder
47 func _load_display_info(info:Dictionary) -> void:
48 file_filter = info.get('file_filter', '')
49 placeholder = info.get('placeholder', '')
50 resource_icon = info.get('icon', null)
53 if resource_icon == null and info.has('editor_icon'):
54 resource_icon = callv('get_theme_icon', info.editor_icon)
57 func _set_value(value: Variant) -> void:
59 var text: String = value
61 if file_mode != EditorFileDialog.FILE_MODE_OPEN_DIR:
62 text = value.get_file()
63 %Field.tooltip_text = value
65 if %Field.get_theme_font('font').get_string_size(
67 %Field.get_theme_font_size('font_size')).x > max_width:
68 %Field.expand_to_text_length = false
69 %Field.custom_minimum_size.x = max_width
72 %Field.custom_minimum_size.x = 0
73 %Field.expand_to_text_length = true
75 if not %Field.text == text:
76 value_changed.emit(property_name, current_value)
79 %ClearButton.visible = not value.is_empty() and not hide_reset
86 ################################################################################
88 func _on_OpenButton_pressed() -> void:
89 find_parent('EditorView').godot_file_dialog(_on_file_dialog_selected, file_filter, file_mode, "Open "+ property_name)
92 func _on_file_dialog_selected(path:String) -> void:
94 value_changed.emit(property_name, path)
97 func clear_path() -> void:
99 value_changed.emit(property_name, "")
104 #region DRAG AND DROP
105 ################################################################################
107 func _can_drop_data_fw(_at_position: Vector2, data: Variant) -> bool:
108 if typeof(data) == TYPE_DICTIONARY and data.has('files') and len(data.files) == 1:
112 if '*.'+data.files[0].get_extension() in file_filter:
120 func _drop_data_fw(_at_position: Vector2, data: Variant) -> void:
121 var file: String = data.files[0]
122 _on_file_dialog_selected(file)
127 #region VISUALS FOR FOCUS
128 ################################################################################
130 func _on_field_focus_entered() -> void:
134 func _on_field_focus_exited() -> void:
136 var field_text: String = %Field.text
137 if current_value == field_text or (file_mode != EditorFileDialog.FILE_MODE_OPEN_DIR and current_value.get_file() == field_text):
139 _on_file_dialog_selected(field_text)