3333#include " editor/editor_settings.h"
3434#include " editor/editor_string_names.h"
3535#include " editor/event_listener_line_edit.h"
36+ #include " editor/gui/editor_event_search_bar.h"
3637#include " editor/input_event_configuration_dialog.h"
3738#include " editor/themes/editor_scale.h"
3839#include " scene/gui/check_button.h"
@@ -223,9 +224,8 @@ void ActionMapEditor::_tree_item_activated() {
223224 _tree_button_pressed (item, 2 , BUTTON_EDIT_EVENT , MouseButton::LEFT );
224225}
225226
226- void ActionMapEditor::set_show_builtin_actions (bool p_show) {
227+ void ActionMapEditor::_set_show_builtin_actions (bool p_show) {
227228 show_builtin_actions = p_show;
228- show_builtin_actions_checkbutton->set_pressed (p_show);
229229 EditorSettings::get_singleton ()->set_project_metadata (" project_settings" , " show_builtin_actions" , show_builtin_actions);
230230
231231 // Prevent unnecessary updates of action list when cache is empty.
@@ -234,14 +234,17 @@ void ActionMapEditor::set_show_builtin_actions(bool p_show) {
234234 }
235235}
236236
237- void ActionMapEditor::_search_term_updated (const String &) {
238- update_action_list ();
239- }
240-
241- void ActionMapEditor::_search_by_event (const Ref<InputEvent> &p_event) {
242- if (p_event.is_null () || (p_event->is_pressed () && !p_event->is_echo ())) {
243- update_action_list ();
237+ void ActionMapEditor::_on_search_bar_value_changed () {
238+ if (action_list_search_bar->is_searching ()) {
239+ show_builtin_actions_checkbutton->set_pressed_no_signal (true );
240+ show_builtin_actions_checkbutton->set_disabled (true );
241+ show_builtin_actions_checkbutton->set_tooltip_text (TTRC (" Built-in actions are always shown when searching." ));
242+ } else {
243+ show_builtin_actions_checkbutton->set_pressed_no_signal (show_builtin_actions);
244+ show_builtin_actions_checkbutton->set_disabled (false );
245+ show_builtin_actions_checkbutton->set_tooltip_text (String ());
244246 }
247+ update_action_list ();
245248}
246249
247250Variant ActionMapEditor::get_drag_data_fw (const Point2 &p_point, Control *p_from) {
@@ -371,7 +374,6 @@ void ActionMapEditor::_notification(int p_what) {
371374 } break ;
372375
373376 case NOTIFICATION_THEME_CHANGED : {
374- action_list_search->set_right_icon (get_editor_theme_icon (SNAME (" Search" )));
375377 add_button->set_button_icon (get_editor_theme_icon (SNAME (" Add" )));
376378 if (!actions_cache.is_empty ()) {
377379 update_action_list ();
@@ -386,12 +388,10 @@ void ActionMapEditor::_bind_methods() {
386388 ADD_SIGNAL (MethodInfo (" action_removed" , PropertyInfo (Variant::STRING , " name" )));
387389 ADD_SIGNAL (MethodInfo (" action_renamed" , PropertyInfo (Variant::STRING , " old_name" ), PropertyInfo (Variant::STRING , " new_name" )));
388390 ADD_SIGNAL (MethodInfo (" action_reordered" , PropertyInfo (Variant::STRING , " action_name" ), PropertyInfo (Variant::STRING , " relative_to" ), PropertyInfo (Variant::BOOL , " before" )));
389- ADD_SIGNAL (MethodInfo (SNAME (" filter_focused" )));
390- ADD_SIGNAL (MethodInfo (SNAME (" filter_unfocused" )));
391391}
392392
393393LineEdit *ActionMapEditor::get_search_box () const {
394- return action_list_search ;
394+ return action_list_search_bar-> get_name_search_box () ;
395395}
396396
397397LineEdit *ActionMapEditor::get_path_box () const {
@@ -403,7 +403,7 @@ InputEventConfigurationDialog *ActionMapEditor::get_configuration_dialog() {
403403}
404404
405405bool ActionMapEditor::_should_display_action (const String &p_name, const Array &p_events) const {
406- const Ref<InputEvent> search_ev = action_list_search_by_event ->get_event ();
406+ const Ref<InputEvent> search_ev = action_list_search_bar ->get_event ();
407407 bool event_match = true ;
408408 if (search_ev.is_valid ()) {
409409 event_match = false ;
@@ -415,7 +415,7 @@ bool ActionMapEditor::_should_display_action(const String &p_name, const Array &
415415 }
416416 }
417417
418- return event_match && action_list_search-> get_text ().is_subsequence_ofn (p_name);
418+ return event_match && action_list_search_bar-> get_name ().is_subsequence_ofn (p_name);
419419}
420420
421421void ActionMapEditor::update_action_list (const Vector<ActionInfo> &p_action_infos) {
@@ -426,15 +426,13 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
426426 action_tree->clear ();
427427 TreeItem *root = action_tree->create_item ();
428428
429- for (int i = 0 ; i < actions_cache.size (); i++) {
430- ActionInfo action_info = actions_cache[i];
431-
429+ for (const ActionInfo &action_info : actions_cache) {
432430 const Array events = action_info.action [" events" ];
433431 if (!_should_display_action (action_info.name , events)) {
434432 continue ;
435433 }
436434
437- if (!action_info.editable && !show_builtin_actions) {
435+ if (!action_info.editable && !action_list_search_bar-> is_searching () && ! show_builtin_actions) {
438436 continue ;
439437 }
440438
@@ -448,6 +446,7 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
448446 action_item->set_meta (" __name" , action_info.name );
449447
450448 // First Column - Action Name
449+ action_item->set_auto_translate_mode (0 , AUTO_TRANSLATE_MODE_DISABLED );
451450 action_item->set_text (0 , action_info.name );
452451 action_item->set_editable (0 , action_info.editable );
453452 action_item->set_icon (0 , action_info.icon );
@@ -464,13 +463,13 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
464463 bool events_eq = Shortcut::is_event_array_equal (action_info.action_initial [" events" ], action_info.action [" events" ]);
465464 bool action_eq = deadzone_eq && events_eq;
466465 action_item->set_meta (" __action_initial" , action_info.action_initial );
467- action_item->add_button (2 , action_tree-> get_editor_theme_icon (SNAME (" ReloadSmall" )), BUTTON_REVERT_ACTION , action_eq, action_eq ? TTRC (" Cannot Revert - Action is same as initial" ) : TTRC (" Revert Action" ));
466+ action_item->add_button (2 , get_editor_theme_icon (SNAME (" ReloadSmall" )), BUTTON_REVERT_ACTION , action_eq, action_eq ? TTRC (" Cannot Revert - Action is same as initial" ) : TTRC (" Revert Action" ));
468467 }
469- action_item->add_button (2 , action_tree-> get_editor_theme_icon (SNAME (" Add" )), BUTTON_ADD_EVENT , false , TTRC (" Add Event" ));
470- action_item->add_button (2 , action_tree-> get_editor_theme_icon (SNAME (" Remove" )), BUTTON_REMOVE_ACTION , !action_info.editable , action_info.editable ? TTRC (" Remove Action" ) : TTRC (" Cannot Remove Action" ));
468+ action_item->add_button (2 , get_editor_theme_icon (SNAME (" Add" )), BUTTON_ADD_EVENT , false , TTRC (" Add Event" ));
469+ action_item->add_button (2 , get_editor_theme_icon (SNAME (" Remove" )), BUTTON_REMOVE_ACTION , !action_info.editable , action_info.editable ? TTRC (" Remove Action" ) : TTRC (" Cannot Remove Action" ));
471470
472- action_item->set_custom_bg_color (0 , action_tree-> get_theme_color (SNAME (" prop_subsection" ), EditorStringName (Editor)));
473- action_item->set_custom_bg_color (1 , action_tree-> get_theme_color (SNAME (" prop_subsection" ), EditorStringName (Editor)));
471+ action_item->set_custom_bg_color (0 , get_theme_color (SNAME (" prop_subsection" ), EditorStringName (Editor)));
472+ action_item->set_custom_bg_color (1 , get_theme_color (SNAME (" prop_subsection" ), EditorStringName (Editor)));
474473
475474 for (int evnt_idx = 0 ; evnt_idx < events.size (); evnt_idx++) {
476475 Ref<InputEvent> event = events[evnt_idx];
@@ -481,6 +480,7 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
481480 TreeItem *event_item = action_tree->create_item (action_item);
482481
483482 // First Column - Text
483+ event_item->set_auto_translate_mode (0 , AUTO_TRANSLATE_MODE_DISABLED );
484484 event_item->set_text (0 , EventListenerLineEdit::get_event_text (event, true ));
485485 event_item->set_meta (" __event" , event);
486486 event_item->set_meta (" __index" , evnt_idx);
@@ -489,94 +489,54 @@ void ActionMapEditor::update_action_list(const Vector<ActionInfo> &p_action_info
489489 Ref<InputEventKey> k = event;
490490 if (k.is_valid ()) {
491491 if (k->get_physical_keycode () == Key::NONE && k->get_keycode () == Key::NONE && k->get_key_label () != Key::NONE ) {
492- event_item->set_icon (0 , action_tree-> get_editor_theme_icon (SNAME (" KeyboardLabel" )));
492+ event_item->set_icon (0 , get_editor_theme_icon (SNAME (" KeyboardLabel" )));
493493 } else if (k->get_keycode () != Key::NONE ) {
494- event_item->set_icon (0 , action_tree-> get_editor_theme_icon (SNAME (" Keyboard" )));
494+ event_item->set_icon (0 , get_editor_theme_icon (SNAME (" Keyboard" )));
495495 } else if (k->get_physical_keycode () != Key::NONE ) {
496- event_item->set_icon (0 , action_tree-> get_editor_theme_icon (SNAME (" KeyboardPhysical" )));
496+ event_item->set_icon (0 , get_editor_theme_icon (SNAME (" KeyboardPhysical" )));
497497 } else {
498- event_item->set_icon (0 , action_tree-> get_editor_theme_icon (SNAME (" KeyboardError" )));
498+ event_item->set_icon (0 , get_editor_theme_icon (SNAME (" KeyboardError" )));
499499 }
500500 }
501501
502502 Ref<InputEventMouseButton> mb = event;
503503 if (mb.is_valid ()) {
504- event_item->set_icon (0 , action_tree-> get_editor_theme_icon (SNAME (" Mouse" )));
504+ event_item->set_icon (0 , get_editor_theme_icon (SNAME (" Mouse" )));
505505 }
506506
507507 Ref<InputEventJoypadButton> jb = event;
508508 if (jb.is_valid ()) {
509- event_item->set_icon (0 , action_tree-> get_editor_theme_icon (SNAME (" JoyButton" )));
509+ event_item->set_icon (0 , get_editor_theme_icon (SNAME (" JoyButton" )));
510510 }
511511
512512 Ref<InputEventJoypadMotion> jm = event;
513513 if (jm.is_valid ()) {
514- event_item->set_icon (0 , action_tree-> get_editor_theme_icon (SNAME (" JoyAxis" )));
514+ event_item->set_icon (0 , get_editor_theme_icon (SNAME (" JoyAxis" )));
515515 }
516516
517517 // Third Column - Buttons
518- event_item->add_button (2 , action_tree-> get_editor_theme_icon (SNAME (" Edit" )), BUTTON_EDIT_EVENT , false , TTRC (" Edit Event" ), TTRC (" Edit Event" ));
519- event_item->add_button (2 , action_tree-> get_editor_theme_icon (SNAME (" Remove" )), BUTTON_REMOVE_EVENT , false , TTRC (" Remove Event" ), TTRC (" Remove Event" ));
518+ event_item->add_button (2 , get_editor_theme_icon (SNAME (" Edit" )), BUTTON_EDIT_EVENT , false , TTRC (" Edit Event" ), TTRC (" Edit Event" ));
519+ event_item->add_button (2 , get_editor_theme_icon (SNAME (" Remove" )), BUTTON_REMOVE_EVENT , false , TTRC (" Remove Event" ), TTRC (" Remove Event" ));
520520 event_item->set_button_color (2 , 0 , Color (1 , 1 , 1 , 0.75 ));
521521 event_item->set_button_color (2 , 1 , Color (1 , 1 , 1 , 0.75 ));
522522 }
523523 }
524-
525- // Update UI.
526- clear_all_search->set_disabled (action_list_search->get_text ().is_empty () && action_list_search_by_event->get_event ().is_null ());
527524}
528525
529526void ActionMapEditor::show_message (const String &p_message) {
530527 message->set_text (p_message);
531528 message->popup_centered ();
532529}
533530
534- void ActionMapEditor::use_external_search_box (LineEdit *p_searchbox) {
535- memdelete (action_list_search);
536- action_list_search = p_searchbox;
537- action_list_search->connect (SceneStringName (text_changed), callable_mp (this , &ActionMapEditor::_search_term_updated));
538- }
539-
540- void ActionMapEditor::_on_filter_focused () {
541- emit_signal (SNAME (" filter_focused" ));
542- }
543-
544- void ActionMapEditor::_on_filter_unfocused () {
545- emit_signal (SNAME (" filter_unfocused" ));
546- }
547-
548531ActionMapEditor::ActionMapEditor () {
549532 // Main Vbox Container
550533 VBoxContainer *main_vbox = memnew (VBoxContainer);
551534 main_vbox->set_anchors_and_offsets_preset (PRESET_FULL_RECT );
552535 add_child (main_vbox);
553536
554- HBoxContainer *top_hbox = memnew (HBoxContainer);
555- main_vbox->add_child (top_hbox);
556-
557- action_list_search = memnew (LineEdit);
558- action_list_search->set_h_size_flags (Control::SIZE_EXPAND_FILL );
559- action_list_search->set_placeholder (TTRC (" Filter by Name" ));
560- action_list_search->set_accessibility_name (TTRC (" Filter by Name" ));
561- action_list_search->set_clear_button_enabled (true );
562- action_list_search->connect (SceneStringName (text_changed), callable_mp (this , &ActionMapEditor::_search_term_updated));
563- top_hbox->add_child (action_list_search);
564-
565- action_list_search_by_event = memnew (EventListenerLineEdit);
566- action_list_search_by_event->set_h_size_flags (Control::SIZE_EXPAND_FILL );
567- action_list_search_by_event->set_stretch_ratio (0.75 );
568- action_list_search_by_event->set_accessibility_name (TTRC (" Action Event" ));
569- action_list_search_by_event->connect (" event_changed" , callable_mp (this , &ActionMapEditor::_search_by_event));
570- action_list_search_by_event->connect (SceneStringName (focus_entered), callable_mp (this , &ActionMapEditor::_on_filter_focused));
571- action_list_search_by_event->connect (SceneStringName (focus_exited), callable_mp (this , &ActionMapEditor::_on_filter_unfocused));
572- top_hbox->add_child (action_list_search_by_event);
573-
574- clear_all_search = memnew (Button);
575- clear_all_search->set_text (TTRC (" Clear All" ));
576- clear_all_search->set_tooltip_text (TTRC (" Clear all search filters." ));
577- clear_all_search->connect (SceneStringName (pressed), callable_mp (action_list_search_by_event, &EventListenerLineEdit::clear_event));
578- clear_all_search->connect (SceneStringName (pressed), callable_mp (action_list_search, &LineEdit::clear));
579- top_hbox->add_child (clear_all_search);
537+ action_list_search_bar = memnew (EditorEventSearchBar);
538+ action_list_search_bar->connect (SceneStringName (value_changed), callable_mp (this , &ActionMapEditor::_on_search_bar_value_changed));
539+ main_vbox->add_child (action_list_search_bar);
580540
581541 // Adding Action line edit + button
582542 add_hbox = memnew (HBoxContainer);
@@ -603,7 +563,7 @@ ActionMapEditor::ActionMapEditor() {
603563
604564 show_builtin_actions_checkbutton = memnew (CheckButton);
605565 show_builtin_actions_checkbutton->set_text (TTRC (" Show Built-in Actions" ));
606- show_builtin_actions_checkbutton->connect (SceneStringName (toggled), callable_mp (this , &ActionMapEditor::set_show_builtin_actions ));
566+ show_builtin_actions_checkbutton->connect (SceneStringName (toggled), callable_mp (this , &ActionMapEditor::_set_show_builtin_actions ));
607567 add_hbox->add_child (show_builtin_actions_checkbutton);
608568
609569 show_builtin_actions = EditorSettings::get_singleton ()->get_project_metadata (" project_settings" , " show_builtin_actions" , false );
0 commit comments