Skip to content

Add "Expand All" and "Collapse All" options to resource context menus when contained within array/dictionary #106755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "editor/editor_main_screen.h"
#include "editor/editor_node.h"
#include "editor/editor_properties.h"
#include "editor/editor_properties_array_dict.h"
#include "editor/editor_property_name_processor.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
Expand Down
15 changes: 15 additions & 0 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3386,6 +3386,16 @@ void EditorPropertyResource::setup(Object *p_object, const String &p_path, const
resource_picker = memnew(EditorResourcePicker);
}

if (EditorPropertyArray *parent_array = Object::cast_to<EditorPropertyArray>(p_object)) {
parent_editor_property_container = parent_array;
} else if (EditorPropertyDictionary *parent_dic = Object::cast_to<EditorPropertyDictionary>(p_object)) {
parent_editor_property_container = parent_dic;
}

if (parent_editor_property_container && !parent_editor_property_container->is_connected("child_section_unfold", callable_mp(this, &EditorPropertyResource::_set_unfold))) {
parent_editor_property_container->connect("child_section_unfold", callable_mp(this, &EditorPropertyResource::_set_unfold));
}

resource_picker->set_base_type(p_base_type);
resource_picker->set_resource_owner(p_object);
resource_picker->set_editable(true);
Expand Down Expand Up @@ -3544,6 +3554,11 @@ void EditorPropertyResource::_notification(int p_what) {
}
}

void EditorPropertyResource::_set_unfold(bool p_unfold) {
get_edited_object()->editor_set_section_unfold(get_edited_property(), p_unfold);
update_property();
}

void EditorPropertyResource::_bind_methods() {
ClassDB::bind_method(D_METHOD("_should_stop_editing"), &EditorPropertyResource::_should_stop_editing);
}
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ class EditorPropertyResource : public EditorProperty {

EditorResourcePicker *resource_picker = nullptr;
SceneTreeDialog *scene_tree = nullptr;
EditorProperty *parent_editor_property_container = nullptr;

bool use_sub_inspector = false;
EditorInspector *sub_inspector = nullptr;
Expand All @@ -714,6 +715,7 @@ class EditorPropertyResource : public EditorProperty {
protected:
virtual void _set_read_only(bool p_read_only) override;
void _notification(int p_what);
virtual void _set_unfold(bool p_unfold);
static void _bind_methods();

public:
Expand Down
16 changes: 16 additions & 0 deletions editor/editor_properties_array_dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,10 @@ void EditorPropertyArray::drop_data_fw(const Point2 &p_point, const Variant &p_d
}
}

void EditorPropertyArray::_bind_methods() {
ADD_SIGNAL(MethodInfo("child_section_unfold", PropertyInfo(Variant::BOOL, "unfold")));
}

Node *EditorPropertyArray::get_base_node() {
Node *base_node = Object::cast_to<Node>(InspectorDock::get_inspector_singleton()->get_edited_object());

Expand Down Expand Up @@ -962,6 +966,10 @@ bool EditorPropertyArray::is_colored(ColorationMode p_mode) {
return p_mode == COLORATION_CONTAINER_RESOURCE;
}

void EditorPropertyArray::unfold_all_children(bool p_unfold) {
emit_signal(SNAME("child_section_unfold"), p_unfold);
}

EditorPropertyArray::EditorPropertyArray() {
object.instantiate();
page_length = int(EDITOR_GET("interface/inspector/max_array_dictionary_items_per_page"));
Expand Down Expand Up @@ -1486,6 +1494,10 @@ void EditorPropertyDictionary::_notification(int p_what) {
}
}

void EditorPropertyDictionary::_bind_methods() {
ADD_SIGNAL(MethodInfo("child_section_unfold", PropertyInfo(Variant::BOOL, "unfold")));
}

void EditorPropertyDictionary::_edit_pressed() {
Variant prop_val = get_edited_property_value();
if (prop_val.get_type() == Variant::NIL && edit->is_pressed()) {
Expand Down Expand Up @@ -1516,6 +1528,10 @@ bool EditorPropertyDictionary::is_colored(ColorationMode p_mode) {
return p_mode == COLORATION_CONTAINER_RESOURCE;
}

void EditorPropertyDictionary::unfold_all_children(bool p_unfold) {
emit_signal(SNAME("child_section_unfold"), p_unfold);
}

EditorPropertyDictionary::EditorPropertyDictionary() {
object.instantiate();
page_length = int(EDITOR_GET("interface/inspector/max_array_dictionary_items_per_page"));
Expand Down
6 changes: 6 additions & 0 deletions editor/editor_properties_array_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,14 @@ class EditorPropertyArray : public EditorProperty {
virtual bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
virtual void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);

static void _bind_methods();

public:
void setup(Variant::Type p_array_type, const String &p_hint_string = "");
void set_preview_value(bool p_preview_value);
virtual void update_property() override;
virtual bool is_colored(ColorationMode p_mode) override;
virtual void unfold_all_children(bool p_unfold);
EditorPropertyArray();
};

Expand Down Expand Up @@ -260,11 +263,14 @@ class EditorPropertyDictionary : public EditorProperty {
protected:
void _notification(int p_what);

static void _bind_methods();

public:
void setup(PropertyHint p_hint, const String &p_hint_string = "");
void set_preview_value(bool p_preview_value);
virtual void update_property() override;
virtual bool is_colored(ColorationMode p_mode) override;
virtual void unfold_all_children(bool p_unfold);
EditorPropertyDictionary();
};

Expand Down
23 changes: 23 additions & 0 deletions editor/editor_resource_picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "editor/audio_stream_preview.h"
#include "editor/editor_help.h"
#include "editor/editor_node.h"
#include "editor/editor_properties_array_dict.h"
#include "editor/editor_resource_preview.h"
#include "editor/editor_settings.h"
#include "editor/editor_string_names.h"
Expand Down Expand Up @@ -312,6 +313,12 @@ void EditorResourcePicker::_update_menu_items() {
relative_id++;
}
}

if (Object::cast_to<EditorPropertyArray>(resource_owner) || Object::cast_to<EditorPropertyDictionary>(resource_owner)) {
edit_menu->add_separator();
edit_menu->add_item(TTR("Expand All"), OBJ_MENU_EXPAND_ALL);
edit_menu->add_item(TTR("Collapse All"), OBJ_MENU_COLLAPSE_ALL);
}
}

void EditorResourcePicker::_edit_menu_cbk(int p_which) {
Expand Down Expand Up @@ -453,6 +460,22 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
FileSystemDock::get_singleton()->navigate_to_path(edited_resource->get_path());
} break;

case OBJ_MENU_EXPAND_ALL: {
if (EditorPropertyArray *owner_array = Object::cast_to<EditorPropertyArray>(resource_owner)) {
owner_array->unfold_all_children(true);
} else if (EditorPropertyDictionary *owner_dic = Object::cast_to<EditorPropertyDictionary>(resource_owner)) {
owner_dic->unfold_all_children(true);
}
} break;

case OBJ_MENU_COLLAPSE_ALL: {
if (EditorPropertyArray *owner_array = Object::cast_to<EditorPropertyArray>(resource_owner)) {
owner_array->unfold_all_children(false);
} else if (EditorPropertyDictionary *owner_dic = Object::cast_to<EditorPropertyDictionary>(resource_owner)) {
owner_dic->unfold_all_children(false);
}
} break;

default: {
// Allow subclasses to handle their own options first, only then fallback on the default branch logic.
if (handle_menu_selected(p_which)) {
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_resource_picker.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class EditorResourcePicker : public HBoxContainer {
OBJ_MENU_COPY,
OBJ_MENU_PASTE,
OBJ_MENU_SHOW_IN_FILE_SYSTEM,
OBJ_MENU_EXPAND_ALL,
OBJ_MENU_COLLAPSE_ALL,

TYPE_BASE_ID = 100,
CONVERT_BASE_ID = 1000,
Expand Down