@@ -175,6 +175,7 @@ void EditorFileDialog::_update_theme_item_cache() {
175
175
theme_cache.back_folder = get_editor_theme_icon (SNAME (" Back" ));
176
176
theme_cache.reload = get_editor_theme_icon (SNAME (" Reload" ));
177
177
theme_cache.toggle_hidden = get_editor_theme_icon (SNAME (" GuiVisibilityVisible" ));
178
+ theme_cache.toggle_filename_filter = get_editor_theme_icon (SNAME (" FilenameFilter" ));
178
179
theme_cache.favorite = get_editor_theme_icon (SNAME (" Favorites" ));
179
180
theme_cache.mode_thumbnails = get_editor_theme_icon (SNAME (" FileThumbnail" ));
180
181
theme_cache.mode_list = get_editor_theme_icon (SNAME (" FileList" ));
@@ -329,8 +330,10 @@ void EditorFileDialog::shortcut_input(const Ref<InputEvent> &p_event) {
329
330
handled = true ;
330
331
}
331
332
if (ED_IS_SHORTCUT (" file_dialog/focus_filter" , p_event)) {
333
+ show_search_filter_button->set_pressed (!show_search_filter_button->is_pressed ());
332
334
_focus_filter_box ();
333
335
handled = true ;
336
+ handled = true ;
334
337
}
335
338
if (ED_IS_SHORTCUT (" file_dialog/move_favorite_up" , p_event)) {
336
339
_favorite_move_up ();
@@ -1146,6 +1149,15 @@ void EditorFileDialog::_filter_selected(int) {
1146
1149
update_file_list ();
1147
1150
}
1148
1151
1152
+ void EditorFileDialog::_search_filter_selected () {
1153
+ Vector items = item_list->get_selected_items ();
1154
+ if (!items.is_empty ()) {
1155
+ int index = items[0 ];
1156
+ file->set_text (item_list->get_item_text (index ));
1157
+ file->emit_signal (" text_submitted" , file->get_text ());
1158
+ }
1159
+ }
1160
+
1149
1161
void EditorFileDialog::update_filters () {
1150
1162
filter->clear ();
1151
1163
@@ -1187,6 +1199,23 @@ void EditorFileDialog::clear_filters() {
1187
1199
invalidate ();
1188
1200
}
1189
1201
1202
+ void EditorFileDialog::clear_search_filter () {
1203
+ set_search_filter (" " );
1204
+ update_search_filter_gui ();
1205
+ invalidate ();
1206
+ }
1207
+
1208
+ void EditorFileDialog::update_search_filter_gui () {
1209
+ filter_hb->set_visible (show_search_filter);
1210
+ if (!show_search_filter) {
1211
+ search_string.clear ();
1212
+ }
1213
+ if (filter_box->get_text () == search_string) {
1214
+ return ;
1215
+ }
1216
+ filter_box->set_text (search_string);
1217
+ }
1218
+
1190
1219
void EditorFileDialog::add_filter (const String &p_filter, const String &p_description) {
1191
1220
if (p_description.is_empty ()) {
1192
1221
filters.push_back (p_filter);
@@ -1206,10 +1235,24 @@ void EditorFileDialog::set_filters(const Vector<String> &p_filters) {
1206
1235
invalidate ();
1207
1236
}
1208
1237
1238
+ void EditorFileDialog::set_search_filter (const String &p_search_filter) {
1239
+ if (search_string == p_search_filter) {
1240
+ return ;
1241
+ }
1242
+ search_string = p_search_filter;
1243
+ update_search_filter_gui ();
1244
+ emit_signal (SNAME (" filename_filter_changed" ), filter);
1245
+ invalidate ();
1246
+ }
1247
+
1209
1248
Vector<String> EditorFileDialog::get_filters () const {
1210
1249
return filters;
1211
1250
}
1212
1251
1252
+ String EditorFileDialog::get_search_filter () const {
1253
+ return search_string;
1254
+ }
1255
+
1213
1256
String EditorFileDialog::get_current_dir () const {
1214
1257
return dir_access->get_current_dir ();
1215
1258
}
@@ -1392,6 +1435,11 @@ void EditorFileDialog::_focus_filter_box() {
1392
1435
void EditorFileDialog::_filter_changed (const String &p_text) {
1393
1436
search_string = p_text;
1394
1437
invalidate ();
1438
+
1439
+ item_list->deselect_all ();
1440
+ if (item_list->get_item_count () > 0 ) {
1441
+ item_list->call_deferred (" select" , 0 );
1442
+ }
1395
1443
}
1396
1444
1397
1445
void EditorFileDialog::_file_sort_popup (int p_id) {
@@ -1492,6 +1540,7 @@ void EditorFileDialog::_update_icons() {
1492
1540
favorite->set_icon (theme_cache.favorite );
1493
1541
show_hidden->set_icon (theme_cache.toggle_hidden );
1494
1542
makedir->set_icon (theme_cache.create_folder );
1543
+ show_search_filter_button->set_icon (theme_cache.toggle_filename_filter );
1495
1544
1496
1545
filter_box->set_right_icon (theme_cache.filter_box );
1497
1546
file_sort_button->set_icon (theme_cache.file_sort_button );
@@ -1972,6 +2021,9 @@ void EditorFileDialog::_bind_methods() {
1972
2021
ClassDB::bind_method (D_METHOD (" get_option_count" ), &EditorFileDialog::get_option_count);
1973
2022
ClassDB::bind_method (D_METHOD (" add_option" , " name" , " values" , " default_value_index" ), &EditorFileDialog::add_option);
1974
2023
ClassDB::bind_method (D_METHOD (" get_selected_options" ), &EditorFileDialog::get_selected_options);
2024
+ ClassDB::bind_method (D_METHOD (" clear_filename_filter" ), &EditorFileDialog::clear_search_filter);
2025
+ ClassDB::bind_method (D_METHOD (" set_filename_filter" , " filter" ), &EditorFileDialog::set_search_filter);
2026
+ ClassDB::bind_method (D_METHOD (" get_filename_filter" ), &EditorFileDialog::get_search_filter);
1975
2027
ClassDB::bind_method (D_METHOD (" get_current_dir" ), &EditorFileDialog::get_current_dir);
1976
2028
ClassDB::bind_method (D_METHOD (" get_current_file" ), &EditorFileDialog::get_current_file);
1977
2029
ClassDB::bind_method (D_METHOD (" get_current_path" ), &EditorFileDialog::get_current_path);
@@ -2000,6 +2052,7 @@ void EditorFileDialog::_bind_methods() {
2000
2052
ADD_SIGNAL (MethodInfo (" file_selected" , PropertyInfo (Variant::STRING, " path" )));
2001
2053
ADD_SIGNAL (MethodInfo (" files_selected" , PropertyInfo (Variant::PACKED_STRING_ARRAY, " paths" )));
2002
2054
ADD_SIGNAL (MethodInfo (" dir_selected" , PropertyInfo (Variant::STRING, " dir" )));
2055
+ ADD_SIGNAL (MethodInfo (" filename_filter_changed" , PropertyInfo (Variant::STRING, " filter" )));
2003
2056
2004
2057
ADD_PROPERTY (PropertyInfo (Variant::INT, " access" , PROPERTY_HINT_ENUM, " Resources,User data,File system" ), " set_access" , " get_access" );
2005
2058
ADD_PROPERTY (PropertyInfo (Variant::INT, " display_mode" , PROPERTY_HINT_ENUM, " Thumbnails,List" ), " set_display_mode" , " get_display_mode" );
@@ -2046,6 +2099,24 @@ void EditorFileDialog::set_show_hidden_files(bool p_show) {
2046
2099
invalidate ();
2047
2100
}
2048
2101
2102
+ void EditorFileDialog::set_show_search_filter (bool p_show) {
2103
+ if (p_show == show_search_filter) {
2104
+ return ;
2105
+ }
2106
+ if (p_show) {
2107
+ filter_box->grab_focus ();
2108
+ } else {
2109
+ search_string.clear ();
2110
+ filter_box->clear ();
2111
+ if (filter_box->has_focus ()) {
2112
+ item_list->call_deferred (" grab_focus" );
2113
+ }
2114
+ }
2115
+ show_search_filter = p_show;
2116
+ update_search_filter_gui ();
2117
+ invalidate ();
2118
+ }
2119
+
2049
2120
bool EditorFileDialog::is_showing_hidden_files () const {
2050
2121
return show_hidden_files;
2051
2122
}
@@ -2189,7 +2260,6 @@ EditorFileDialog::EditorFileDialog() {
2189
2260
dir = memnew (LineEdit);
2190
2261
dir->set_structured_text_bidi_override (TextServer::STRUCTURED_TEXT_FILE);
2191
2262
pathhb->add_child (dir);
2192
- dir->set_h_size_flags (Control::SIZE_EXPAND_FILL);
2193
2263
2194
2264
refresh = memnew (Button );
2195
2265
refresh->set_theme_type_variation (" FlatButton" );
@@ -2204,37 +2274,6 @@ EditorFileDialog::EditorFileDialog() {
2204
2274
favorite->connect (SceneStringName (pressed), callable_mp (this , &EditorFileDialog::_favorite_pressed));
2205
2275
pathhb->add_child (favorite);
2206
2276
2207
- show_hidden = memnew (Button );
2208
- show_hidden->set_theme_type_variation (" FlatButton" );
2209
- show_hidden->set_toggle_mode (true );
2210
- show_hidden->set_pressed (is_showing_hidden_files ());
2211
- show_hidden->set_tooltip_text (TTR (" Toggle the visibility of hidden files." ));
2212
- show_hidden->connect (SceneStringName (toggled), callable_mp (this , &EditorFileDialog::set_show_hidden_files));
2213
- pathhb->add_child (show_hidden);
2214
-
2215
- pathhb->add_child (memnew (VSeparator));
2216
-
2217
- Ref<ButtonGroup> view_mode_group;
2218
- view_mode_group.instantiate ();
2219
-
2220
- mode_thumbnails = memnew (Button );
2221
- mode_thumbnails->set_theme_type_variation (" FlatButton" );
2222
- mode_thumbnails->connect (SceneStringName (pressed), callable_mp (this , &EditorFileDialog::set_display_mode).bind (DISPLAY_THUMBNAILS));
2223
- mode_thumbnails->set_toggle_mode (true );
2224
- mode_thumbnails->set_pressed (display_mode == DISPLAY_THUMBNAILS);
2225
- mode_thumbnails->set_button_group (view_mode_group);
2226
- mode_thumbnails->set_tooltip_text (TTR (" View items as a grid of thumbnails." ));
2227
- pathhb->add_child (mode_thumbnails);
2228
-
2229
- mode_list = memnew (Button );
2230
- mode_list->set_theme_type_variation (" FlatButton" );
2231
- mode_list->connect (SceneStringName (pressed), callable_mp (this , &EditorFileDialog::set_display_mode).bind (DISPLAY_LIST));
2232
- mode_list->set_toggle_mode (true );
2233
- mode_list->set_pressed (display_mode == DISPLAY_LIST);
2234
- mode_list->set_button_group (view_mode_group);
2235
- mode_list->set_tooltip_text (TTR (" View items as a list." ));
2236
- pathhb->add_child (mode_list);
2237
-
2238
2277
shortcuts_container = memnew (HBoxContainer);
2239
2278
pathhb->add_child (shortcuts_container);
2240
2279
@@ -2250,6 +2289,8 @@ EditorFileDialog::EditorFileDialog() {
2250
2289
makedir->connect (SceneStringName (pressed), callable_mp (this , &EditorFileDialog::_make_dir));
2251
2290
pathhb->add_child (makedir);
2252
2291
2292
+ dir->set_h_size_flags (Control::SIZE_EXPAND_FILL);
2293
+
2253
2294
body_hsplit = memnew (HSplitContainer);
2254
2295
body_hsplit->set_v_size_flags (Control::SIZE_EXPAND_FILL);
2255
2296
vbc->add_child (body_hsplit);
@@ -2319,21 +2360,55 @@ EditorFileDialog::EditorFileDialog() {
2319
2360
2320
2361
l = memnew (Label (TTR (" Directories & Files:" )));
2321
2362
l->set_theme_type_variation (" HeaderSmall" );
2363
+ l->set_h_size_flags (Control::SIZE_EXPAND_FILL);
2364
+
2322
2365
lower_hb->add_child (l);
2323
2366
2324
- list_vb->add_child (lower_hb);
2325
- preview_hb->add_child (list_vb);
2367
+ show_hidden = memnew (Button );
2368
+ show_hidden->set_theme_type_variation (" FlatButton" );
2369
+ show_hidden->set_toggle_mode (true );
2370
+ show_hidden->set_pressed (is_showing_hidden_files ());
2371
+ show_hidden->set_tooltip_text (TTR (" Toggle the visibility of hidden files." ));
2372
+ show_hidden->connect (SceneStringName (toggled), callable_mp (this , &EditorFileDialog::set_show_hidden_files));
2373
+ lower_hb->add_child (show_hidden);
2326
2374
2327
- filter_box = memnew (LineEdit);
2328
- filter_box->set_h_size_flags (Control::SIZE_EXPAND_FILL);
2329
- filter_box->set_placeholder (TTR (" Filter" ));
2330
- filter_box->connect (SceneStringName (text_changed), callable_mp (this , &EditorFileDialog::_filter_changed));
2331
- lower_hb->add_child (filter_box);
2375
+ lower_hb->add_child (memnew (VSeparator));
2376
+
2377
+ Ref<ButtonGroup> view_mode_group;
2378
+ view_mode_group.instantiate ();
2379
+
2380
+ mode_thumbnails = memnew (Button );
2381
+ mode_thumbnails->set_theme_type_variation (" FlatButton" );
2382
+ mode_thumbnails->connect (SceneStringName (pressed), callable_mp (this , &EditorFileDialog::set_display_mode).bind (DISPLAY_THUMBNAILS));
2383
+ mode_thumbnails->set_toggle_mode (true );
2384
+ mode_thumbnails->set_pressed (display_mode == DISPLAY_THUMBNAILS);
2385
+ mode_thumbnails->set_button_group (view_mode_group);
2386
+ mode_thumbnails->set_tooltip_text (TTR (" View items as a grid of thumbnails." ));
2387
+ lower_hb->add_child (mode_thumbnails);
2388
+
2389
+ mode_list = memnew (Button );
2390
+ mode_list->set_theme_type_variation (" FlatButton" );
2391
+ mode_list->connect (SceneStringName (pressed), callable_mp (this , &EditorFileDialog::set_display_mode).bind (DISPLAY_LIST));
2392
+ mode_list->set_toggle_mode (true );
2393
+ mode_list->set_pressed (display_mode == DISPLAY_LIST);
2394
+ mode_list->set_button_group (view_mode_group);
2395
+ mode_list->set_tooltip_text (TTR (" View items as a list." ));
2396
+ lower_hb->add_child (mode_list);
2397
+
2398
+ lower_hb->add_child (memnew (VSeparator));
2332
2399
2333
2400
file_sort_button = memnew (MenuButton);
2334
2401
file_sort_button->set_flat (true );
2335
2402
file_sort_button->set_tooltip_text (TTR (" Sort files" ));
2336
2403
2404
+ show_search_filter_button = memnew (Button );
2405
+ show_search_filter_button->set_theme_type_variation (" FlatButton" );
2406
+ show_search_filter_button->set_toggle_mode (true );
2407
+ show_search_filter_button->set_pressed (false );
2408
+ show_search_filter_button->set_tooltip_text (TTR (" Toggle the visibility of the filter for file names." ));
2409
+ show_search_filter_button->connect (" toggled" , callable_mp (this , &EditorFileDialog::set_show_search_filter));
2410
+ lower_hb->add_child (show_search_filter_button);
2411
+
2337
2412
PopupMenu *p = file_sort_button->get_popup ();
2338
2413
p->connect (SceneStringName (id_pressed), callable_mp (this , &EditorFileDialog::_file_sort_popup));
2339
2414
p->add_radio_check_item (TTR (" Sort by Name (Ascending)" ), static_cast <int >(FileSortOption::FILE_SORT_NAME));
@@ -2345,6 +2420,9 @@ EditorFileDialog::EditorFileDialog() {
2345
2420
p->set_item_checked (0 , true );
2346
2421
lower_hb->add_child (file_sort_button);
2347
2422
2423
+ list_vb->add_child (lower_hb);
2424
+ preview_hb->add_child (list_vb);
2425
+
2348
2426
// Item (files and folders) list with context menu.
2349
2427
2350
2428
item_list = memnew (ItemList);
@@ -2370,6 +2448,15 @@ EditorFileDialog::EditorFileDialog() {
2370
2448
prev_cc->add_child (preview);
2371
2449
preview_vb->hide ();
2372
2450
2451
+ filter_hb = memnew (HBoxContainer);
2452
+ filter_hb->add_child (memnew (Label (RTR (" Filter:" ))));
2453
+ filter_box = memnew (LineEdit);
2454
+ filter_box->set_h_size_flags (Control::SIZE_EXPAND_FILL);
2455
+ filter_box->set_placeholder (TTR (" Filter" ));
2456
+ filter_hb->add_child (filter_box);
2457
+ filter_hb->set_visible (false );
2458
+ item_vb->add_child (filter_hb);
2459
+
2373
2460
file_box = memnew (HBoxContainer);
2374
2461
2375
2462
l = memnew (Label (TTR (" File:" )));
@@ -2398,6 +2485,8 @@ EditorFileDialog::EditorFileDialog() {
2398
2485
item_list->connect (" item_activated" , callable_mp (this , &EditorFileDialog::_item_dc_selected).bind ());
2399
2486
item_list->connect (" empty_clicked" , callable_mp (this , &EditorFileDialog::_items_clear_selection));
2400
2487
dir->connect (" text_submitted" , callable_mp (this , &EditorFileDialog::_dir_submitted));
2488
+ filter_box->connect (SceneStringName (text_changed), callable_mp (this , &EditorFileDialog::_filter_changed));
2489
+ filter_box->connect (SceneStringName (text_submitted), callable_mp (this , &EditorFileDialog::_search_filter_selected).unbind (1 ));
2401
2490
file->connect (" text_submitted" , callable_mp (this , &EditorFileDialog::_file_submitted));
2402
2491
filter->connect (SceneStringName (item_selected), callable_mp (this , &EditorFileDialog::_filter_selected));
2403
2492
0 commit comments