diff --git a/doc/classes/ItemList.xml b/doc/classes/ItemList.xml
index b0730ee0705..cdffc8d9e0d 100644
--- a/doc/classes/ItemList.xml
+++ b/doc/classes/ItemList.xml
@@ -315,6 +315,9 @@
If [code]true[/code], right mouse button click can select items.
+
+ If [code]true[/code], allows navigating the [ItemList] with letter keys through incremental search.
+
If [code]true[/code], the control will automatically resize the height to fit its content.
diff --git a/doc/classes/Tree.xml b/doc/classes/Tree.xml
index 1b1b335bc0a..00b732725a2 100644
--- a/doc/classes/Tree.xml
+++ b/doc/classes/Tree.xml
@@ -218,6 +218,9 @@
If [code]true[/code], a right mouse button click can select items.
+
+ If [code]true[/code], allows navigating the [Tree] with letter keys through incremental search.
+
If [code]true[/code], column titles are visible.
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 93c0200887b..55916243ed4 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -667,7 +667,7 @@ void ItemList::_gui_input(const Ref &p_event) {
} else {
Ref k = p_event;
- if (k.is_valid() && k->get_unicode()) {
+ if (allow_search && k.is_valid() && k->get_unicode()) {
uint64_t now = OS::get_singleton()->get_ticks_msec();
uint64_t diff = now - search_time_msec;
uint64_t max_interval = uint64_t(GLOBAL_DEF("gui/timers/incremental_search_max_interval_msec", 2000));
@@ -1273,6 +1273,14 @@ bool ItemList::get_allow_reselect() const {
return allow_reselect;
}
+void ItemList::set_allow_search(bool p_allow) {
+ allow_search = p_allow;
+}
+
+bool ItemList::get_allow_search() const {
+ return allow_search;
+}
+
void ItemList::set_icon_scale(real_t p_scale) {
ERR_FAIL_COND(Math::is_nan(p_scale) || Math::is_inf(p_scale));
icon_scale = p_scale;
@@ -1437,6 +1445,9 @@ void ItemList::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_allow_reselect", "allow"), &ItemList::set_allow_reselect);
ClassDB::bind_method(D_METHOD("get_allow_reselect"), &ItemList::get_allow_reselect);
+ ClassDB::bind_method(D_METHOD("set_allow_search", "allow"), &ItemList::set_allow_search);
+ ClassDB::bind_method(D_METHOD("get_allow_search"), &ItemList::get_allow_search);
+
ClassDB::bind_method(D_METHOD("set_auto_height", "enable"), &ItemList::set_auto_height);
ClassDB::bind_method(D_METHOD("has_auto_height"), &ItemList::has_auto_height);
@@ -1459,6 +1470,7 @@ void ItemList::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Multi"), "set_select_mode", "get_select_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_reselect"), "set_allow_reselect", "get_allow_reselect");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_search"), "set_allow_search", "get_allow_search");
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_text_lines", PROPERTY_HINT_RANGE, "1,10,1,or_greater"), "set_max_text_lines", "get_max_text_lines");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_height"), "set_auto_height", "has_auto_height");
ADD_GROUP("Columns", "");
@@ -1495,6 +1507,7 @@ ItemList::ItemList() {
fixed_column_width = 0;
same_column_width = false;
+ allow_search = true;
max_text_lines = 1;
max_columns = 1;
auto_height = false;
diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h
index b6d35650c85..7690146c41a 100644
--- a/scene/gui/item_list.h
+++ b/scene/gui/item_list.h
@@ -79,6 +79,7 @@ private:
bool ensure_selected_visible;
bool same_column_width;
+ bool allow_search;
bool auto_height;
float auto_height_value;
@@ -209,6 +210,9 @@ public:
void set_allow_reselect(bool p_allow);
bool get_allow_reselect() const;
+ void set_allow_search(bool p_allow);
+ bool get_allow_search() const;
+
void ensure_current_is_visible();
void sort_items_by_text();
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 03429195462..10c5e26b5f6 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -2332,7 +2332,7 @@ void Tree::_gui_input(Ref p_event) {
accept_event();
}
- if (k.is_valid()) { // Incremental search
+ if (allow_search && k.is_valid()) { // Incremental search
if (!k->is_pressed()) {
return;
@@ -3817,6 +3817,14 @@ bool Tree::get_allow_reselect() const {
return allow_reselect;
}
+void Tree::set_allow_search(bool p_allow) {
+ allow_search = p_allow;
+}
+
+bool Tree::get_allow_search() const {
+ return allow_search;
+}
+
void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("_range_click_timeout"), &Tree::_range_click_timeout);
ClassDB::bind_method(D_METHOD("_gui_input"), &Tree::_gui_input);
@@ -3879,10 +3887,14 @@ void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_allow_reselect", "allow"), &Tree::set_allow_reselect);
ClassDB::bind_method(D_METHOD("get_allow_reselect"), &Tree::get_allow_reselect);
+ ClassDB::bind_method(D_METHOD("set_allow_search", "allow"), &Tree::set_allow_search);
+ ClassDB::bind_method(D_METHOD("get_allow_search"), &Tree::get_allow_search);
+
ADD_PROPERTY(PropertyInfo(Variant::INT, "columns"), "set_columns", "get_columns");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "column_titles_visible"), "set_column_titles_visible", "are_column_titles_visible");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_reselect"), "set_allow_reselect", "get_allow_reselect");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_search"), "set_allow_search", "get_allow_search");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_folding"), "set_hide_folding", "is_folding_hidden");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_root"), "set_hide_root", "is_root_hidden");
ADD_PROPERTY(PropertyInfo(Variant::INT, "drop_mode_flags", PROPERTY_HINT_FLAGS, "On Item,In between"), "set_drop_mode_flags", "get_drop_mode_flags");
@@ -4008,6 +4020,7 @@ Tree::Tree() {
cache.hover_cell = -1;
allow_reselect = false;
+ allow_search = true;
propagate_mouse_activated = false;
update_cache();
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 132b004ecdc..9868d2e363b 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -496,6 +496,7 @@ private:
bool scrolling;
bool allow_reselect;
+ bool allow_search;
bool force_edit_checkbox_only_on_checkbox;
@@ -609,6 +610,9 @@ public:
void set_allow_reselect(bool p_allow);
bool get_allow_reselect() const;
+ void set_allow_search(bool p_allow);
+ bool get_allow_search() const;
+
Tree();
~Tree();
};