diff --git a/doc/classes/ItemList.xml b/doc/classes/ItemList.xml
index f5da4553d0b..2da5ad3cac0 100644
--- a/doc/classes/ItemList.xml
+++ b/doc/classes/ItemList.xml
@@ -341,6 +341,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 1e4282cd0b3..2a3cba3a444 100644
--- a/doc/classes/Tree.xml
+++ b/doc/classes/Tree.xml
@@ -335,6 +335,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 c23232c9742..30f161d27a8 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -897,7 +897,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_GET("gui/timers/incremental_search_max_interval_msec"));
@@ -1586,6 +1586,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_finite(p_scale));
icon_scale = p_scale;
@@ -1828,6 +1836,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);
@@ -1845,6 +1856,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_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis,Word Ellipsis"), "set_text_overrun_behavior", "get_text_overrun_behavior");
diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h
index d050f4a9d0d..cd91f97410f 100644
--- a/scene/gui/item_list.h
+++ b/scene/gui/item_list.h
@@ -90,6 +90,7 @@ private:
bool ensure_selected_visible = false;
bool same_column_width = false;
+ bool allow_search = true;
bool auto_height = false;
float auto_height_value = 0.0;
@@ -258,6 +259,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 e22890562f6..434daa484f6 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -3395,7 +3395,7 @@ void Tree::gui_input(const Ref &p_event) {
accept_event();
}
- if (k.is_valid()) { // Incremental search
+ if (allow_search && k.is_valid()) { // Incremental search
if (!k->is_pressed()) {
return;
@@ -5246,6 +5246,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("clear"), &Tree::clear);
ClassDB::bind_method(D_METHOD("create_item", "parent", "index"), &Tree::create_item, DEFVAL(Variant()), DEFVAL(-1));
@@ -5326,10 +5334,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, "enable_recursive_folding"), "set_enable_recursive_folding", "is_recursive_folding_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_root"), "set_hide_root", "is_root_hidden");
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 42fc719f462..fcfeb26f957 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -625,6 +625,7 @@ private:
bool scrolling = false;
bool allow_reselect = false;
+ bool allow_search = true;
bool force_edit_checkbox_only_on_checkbox = false;
@@ -753,6 +754,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;
+
Size2 get_minimum_size() const override;
Tree();