editor_event_search_bar.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**************************************************************************/
  2. /* editor_event_search_bar.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "editor_event_search_bar.h"
  31. #include "editor/settings/event_listener_line_edit.h"
  32. #include "scene/gui/button.h"
  33. #include "scene/gui/dialogs.h"
  34. #include "scene/gui/line_edit.h"
  35. void EditorEventSearchBar::_on_event_changed(const Ref<InputEvent> &p_event) {
  36. if (p_event.is_valid() && (!p_event->is_pressed() || p_event->is_echo())) {
  37. return;
  38. }
  39. _value_changed();
  40. }
  41. void EditorEventSearchBar::_on_clear_all() {
  42. search_by_name->set_block_signals(true);
  43. search_by_name->clear();
  44. search_by_name->set_block_signals(false);
  45. search_by_event->set_block_signals(true);
  46. search_by_event->clear_event();
  47. search_by_event->set_block_signals(false);
  48. _value_changed();
  49. }
  50. void EditorEventSearchBar::_value_changed() {
  51. clear_all->set_disabled(!is_searching());
  52. emit_signal(SceneStringName(value_changed));
  53. }
  54. bool EditorEventSearchBar::is_searching() const {
  55. return !get_name().is_empty() || get_event().is_valid();
  56. }
  57. String EditorEventSearchBar::get_name() const {
  58. return search_by_name->get_text().strip_edges();
  59. }
  60. Ref<InputEvent> EditorEventSearchBar::get_event() const {
  61. return search_by_event->get_event();
  62. }
  63. void EditorEventSearchBar::_notification(int p_what) {
  64. switch (p_what) {
  65. case NOTIFICATION_THEME_CHANGED: {
  66. search_by_name->set_right_icon(get_editor_theme_icon(SNAME("Search")));
  67. } break;
  68. }
  69. }
  70. void EditorEventSearchBar::_bind_methods() {
  71. ADD_SIGNAL(MethodInfo("value_changed"));
  72. }
  73. EditorEventSearchBar::EditorEventSearchBar() {
  74. set_h_size_flags(Control::SIZE_EXPAND_FILL);
  75. search_by_name = memnew(LineEdit);
  76. search_by_name->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  77. search_by_name->set_placeholder(TTRC("Filter by Name"));
  78. search_by_name->set_accessibility_name(TTRC("Filter by Name"));
  79. search_by_name->set_clear_button_enabled(true);
  80. search_by_name->connect(SceneStringName(text_changed), callable_mp(this, &EditorEventSearchBar::_value_changed).unbind(1));
  81. add_child(search_by_name);
  82. search_by_event = memnew(EventListenerLineEdit);
  83. search_by_event->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  84. search_by_event->set_stretch_ratio(0.75);
  85. search_by_event->set_accessibility_name(TTRC("Action Event"));
  86. search_by_event->connect("event_changed", callable_mp(this, &EditorEventSearchBar::_on_event_changed));
  87. add_child(search_by_event);
  88. clear_all = memnew(Button(TTRC("Clear All")));
  89. clear_all->set_tooltip_text(TTRC("Clear all search filters."));
  90. clear_all->connect(SceneStringName(pressed), callable_mp(this, &EditorEventSearchBar::_on_clear_all));
  91. clear_all->set_disabled(true);
  92. add_child(clear_all);
  93. }