Skip to content

Commit

Permalink
Merge pull request #100091 from AeioMuch/fix_nodepath_in_history
Browse files Browse the repository at this point in the history
Add missing cleanup of editor history & set appropriate class icon for object in it
  • Loading branch information
akien-mga committed Jan 7, 2025
2 parents 0c76360 + 96e59b9 commit f7b9a6a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 35 deletions.
20 changes: 19 additions & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4886,11 +4886,29 @@ Ref<Texture2D> EditorNode::get_object_icon(const Object *p_object, const String
ERR_FAIL_NULL_V_MSG(p_object, nullptr, "Object cannot be null.");

Ref<Script> scr = p_object->get_script();

if (Object::cast_to<EditorDebuggerRemoteObject>(p_object)) {
String class_name;
if (scr.is_valid()) {
class_name = scr->get_global_name();

if (class_name.is_empty()) {
// If there is no class_name in this script we just take the script path.
class_name = scr->get_path();
}
}
return get_class_icon(class_name.is_empty() ? Object::cast_to<EditorDebuggerRemoteObject>(p_object)->type_name : class_name, p_fallback);
}

if (scr.is_null() && p_object->is_class("Script")) {
scr = p_object;
}

return _get_class_or_script_icon(p_object->get_class(), scr, p_fallback);
if (Object::cast_to<MultiNodeEdit>(p_object)) {
return get_class_icon(Object::cast_to<MultiNodeEdit>(p_object)->get_edited_class_name(), p_fallback);
} else {
return _get_class_or_script_icon(p_object->get_class(), scr, p_fallback);
}
}

Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p_fallback) {
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,8 @@ class EditorNode : public Node {
};

struct SceneEditorDataEntry {
bool is_editable;
bool is_display_folded;
bool is_editable = false;
bool is_display_folded = false;
};

HashMap<int, SceneModificationsEntry> scenes_modification_table;
Expand Down
22 changes: 1 addition & 21 deletions editor/gui/editor_object_selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@

#include "editor_object_selector.h"

#include "editor/debugger/editor_debugger_inspector.h"
#include "editor/editor_data.h"
#include "editor/editor_node.h"
#include "editor/editor_string_names.h"
#include "editor/multi_node_edit.h"
#include "editor/themes/editor_scale.h"
#include "scene/gui/margin_container.h"

Expand Down Expand Up @@ -129,25 +127,7 @@ void EditorObjectSelector::update_path() {
continue;
}

Ref<Texture2D> obj_icon;
if (Object::cast_to<MultiNodeEdit>(obj)) {
obj_icon = EditorNode::get_singleton()->get_class_icon(Object::cast_to<MultiNodeEdit>(obj)->get_edited_class_name());
} else if (Object::cast_to<EditorDebuggerRemoteObject>(obj)) {
String class_name;
Ref<Script> base_script = obj->get_script();
if (base_script.is_valid()) {
class_name = base_script->get_global_name();

if (class_name.is_empty()) {
// If there is no class_name in this script we just take the script path.
class_name = base_script->get_path();
}
}

obj_icon = EditorNode::get_singleton()->get_class_icon(class_name.is_empty() ? Object::cast_to<EditorDebuggerRemoteObject>(obj)->type_name : class_name);
} else {
obj_icon = EditorNode::get_singleton()->get_object_icon(obj);
}
Ref<Texture2D> obj_icon = EditorNode::get_singleton()->get_object_icon(obj);

if (obj_icon.is_valid()) {
current_object_icon->set_texture(obj_icon);
Expand Down
2 changes: 2 additions & 0 deletions editor/inspector_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ Ref<Resource> InspectorDock::_get_current_resource() const {

void InspectorDock::_prepare_history() {
EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history();
editor_history->cleanup_history();

int history_to = MAX(0, editor_history->get_history_len() - 25);

Expand Down Expand Up @@ -505,6 +506,7 @@ void InspectorDock::clear() {

void InspectorDock::update(Object *p_object) {
EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history();

backward_button->set_disabled(editor_history->is_at_beginning());
forward_button->set_disabled(editor_history->is_at_end());

Expand Down
20 changes: 9 additions & 11 deletions editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2300,7 +2300,6 @@ void SceneTreeDock::_node_reparent(NodePath p_path, bool p_keep_global_xform) {
ERR_FAIL_NULL(new_parent);

List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> full_selection = editor_selection->get_full_selected_node_list();

if (selection.is_empty()) {
return; // Nothing to reparent.
Expand All @@ -2313,10 +2312,6 @@ void SceneTreeDock::_node_reparent(NodePath p_path, bool p_keep_global_xform) {
}

_do_reparent(new_parent, -1, nodes, p_keep_global_xform);

for (Node *E : full_selection) {
editor_selection->add_node(E);
}
}

void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, Vector<Node *> p_nodes, bool p_keep_global_xform) {
Expand Down Expand Up @@ -2509,12 +2504,20 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V

perform_node_renames(nullptr, &path_renames);

undo_redo->commit_action();
undo_redo->add_do_method(editor_selection, "clear");
undo_redo->add_undo_method(editor_selection, "clear");
List<Node *> full_selection = editor_selection->get_full_selected_node_list();
for (Node *E : full_selection) {
undo_redo->add_do_method(editor_selection, "add_node", E);
undo_redo->add_undo_method(editor_selection, "add_node", E);
}

if (need_edit) {
EditorNode::get_singleton()->edit_current();
editor_selection->clear();
}

undo_redo->commit_action();
}

void SceneTreeDock::_script_created(Ref<Script> p_script) {
Expand Down Expand Up @@ -3653,7 +3656,6 @@ void SceneTreeDock::_nodes_dragged(const Array &p_nodes, NodePath p_to, int p_ty
}

List<Node *> selection = editor_selection->get_selected_node_list();
List<Node *> full_selection = editor_selection->get_full_selected_node_list();

if (selection.is_empty()) {
return; //nothing to reparent
Expand All @@ -3673,10 +3675,6 @@ void SceneTreeDock::_nodes_dragged(const Array &p_nodes, NodePath p_to, int p_ty

_normalize_drop(to_node, to_pos, p_type);
_do_reparent(to_node, to_pos, nodes, !Input::get_singleton()->is_key_pressed(Key::SHIFT));

for (Node *E : full_selection) {
editor_selection->add_node(E);
}
}

void SceneTreeDock::_add_children_to_popup(Object *p_obj, int p_depth) {
Expand Down

0 comments on commit f7b9a6a

Please sign in to comment.