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