diff --git a/doc/classes/ItemList.xml b/doc/classes/ItemList.xml index bc95472ea83..b94a06f1702 100644 --- a/doc/classes/ItemList.xml +++ b/doc/classes/ItemList.xml @@ -308,7 +308,11 @@ + + If [code]true[/code] the currently selected item may be selected again. + + If [code]true[/code] a right mouse button click can select items. @@ -327,6 +331,7 @@ + Allow single or multiple selection. See the [code]SELECT_*[/code] constants. diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index d7331d4f770..bd8c502a804 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -148,8 +148,6 @@ public: } }; -#define SORT_SCRIPT_LIST - void ScriptEditorQuickOpen::popup(const Vector &p_functions, bool p_dontclear) { popup_centered_ratio(0.6); @@ -2608,11 +2606,13 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { members_overview = memnew(ItemList); list_split->add_child(members_overview); + members_overview->set_allow_reselect(true); members_overview->set_custom_minimum_size(Size2(0, 90)); //need to give a bit of limit to avoid it from disappearing members_overview->set_v_size_flags(SIZE_EXPAND_FILL); help_overview = memnew(ItemList); list_split->add_child(help_overview); + help_overview->set_allow_reselect(true); help_overview->set_custom_minimum_size(Size2(0, 90)); //need to give a bit of limit to avoid it from disappearing help_overview->set_v_size_flags(SIZE_EXPAND_FILL); diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 73ac99bfee6..fe85d04003f 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -517,11 +517,11 @@ void ItemList::_gui_input(const Ref &p_event) { emit_signal("item_rmb_selected", i, get_local_mouse_position()); } else { - bool selected = !items[i].selected; + bool selected = items[i].selected; select(i, select_mode == SELECT_SINGLE || !mb->get_command()); - if (selected) { + if (!selected || allow_reselect) { if (select_mode == SELECT_SINGLE) { emit_signal("item_selected", i); } else @@ -1241,6 +1241,7 @@ int ItemList::find_metadata(const Variant &p_metadata) const { } void ItemList::set_allow_rmb_select(bool p_allow) { + allow_rmb_select = p_allow; } @@ -1249,6 +1250,16 @@ bool ItemList::get_allow_rmb_select() const { return allow_rmb_select; } +void ItemList::set_allow_reselect(bool p_allow) { + + allow_reselect = p_allow; +} + +bool ItemList::get_allow_reselect() const { + + return allow_reselect; +} + void ItemList::set_icon_scale(real_t p_scale) { icon_scale = p_scale; } @@ -1404,6 +1415,9 @@ void ItemList::_bind_methods() { ClassDB::bind_method(D_METHOD("set_allow_rmb_select", "allow"), &ItemList::set_allow_rmb_select); ClassDB::bind_method(D_METHOD("get_allow_rmb_select"), &ItemList::get_allow_rmb_select); + 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_auto_height", "enable"), &ItemList::set_auto_height); ClassDB::bind_method(D_METHOD("has_auto_height"), &ItemList::has_auto_height); @@ -1422,6 +1436,7 @@ void ItemList::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items"); 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_PROPERTYNZ(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select"); ADD_PROPERTYNO(PropertyInfo(Variant::INT, "max_text_lines"), "set_max_text_lines", "get_max_text_lines"); ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "auto_height"), "set_auto_height", "has_auto_height"); @@ -1476,6 +1491,7 @@ ItemList::ItemList() { ensure_selected_visible = false; defer_select_single = -1; allow_rmb_select = false; + allow_reselect = false; do_autoscroll_to_bottom = false; icon_scale = 1.0f; diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index 24e94980447..7f34a250bdb 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -106,6 +106,8 @@ private: bool allow_rmb_select; + bool allow_reselect; + real_t icon_scale; bool do_autoscroll_to_bottom; @@ -198,6 +200,9 @@ public: void set_allow_rmb_select(bool p_allow); bool get_allow_rmb_select() const; + void set_allow_reselect(bool p_allow); + bool get_allow_reselect() const; + void ensure_current_is_visible(); void sort_items_by_text();