Added "allow_reselect" property to ItemList and enabled it for the method/help lists.

(cherry picked from commit 4dbf6ac1b8)
This commit is contained in:
Michael Alexsander Silva Dias 2018-02-14 01:24:57 -02:00 committed by Hein-Pieter van Braam
parent 4bdcee2b9d
commit 9fb843db06
4 changed files with 30 additions and 4 deletions

View file

@ -308,7 +308,11 @@
</method>
</methods>
<members>
<member name="allow_reselect" type="bool" setter="set_allow_reselect" getter="get_allow_reselect">
If [code]true[/code] the currently selected item may be selected again.
</member>
<member name="allow_rmb_select" type="bool" setter="set_allow_rmb_select" getter="get_allow_rmb_select">
If [code]true[/code] a right mouse button click can select items.
</member>
<member name="auto_height" type="bool" setter="set_auto_height" getter="has_auto_height">
</member>
@ -327,6 +331,7 @@
<member name="same_column_width" type="bool" setter="set_same_column_width" getter="is_same_column_width">
</member>
<member name="select_mode" type="int" setter="set_select_mode" getter="get_select_mode" enum="ItemList.SelectMode">
Allow single or multiple selection. See the [code]SELECT_*[/code] constants.
</member>
</members>
<signals>

View file

@ -148,8 +148,6 @@ public:
}
};
#define SORT_SCRIPT_LIST
void ScriptEditorQuickOpen::popup(const Vector<String> &p_functions, bool p_dontclear) {
popup_centered_ratio(0.6);
@ -2601,11 +2599,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);

View file

@ -517,11 +517,11 @@ void ItemList::_gui_input(const Ref<InputEvent> &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;

View file

@ -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();