Skip to content

Commit 96e59b9

Browse files
committed
Cleanup editor history when opening the history menu popup & set appropriate class icon for object in it. Handle do&undo for selection when reparenting
1 parent aa65940 commit 96e59b9

File tree

5 files changed

+33
-35
lines changed

5 files changed

+33
-35
lines changed

editor/editor_node.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4886,11 +4886,29 @@ Ref<Texture2D> EditorNode::get_object_icon(const Object *p_object, const String
48864886
ERR_FAIL_NULL_V_MSG(p_object, nullptr, "Object cannot be null.");
48874887

48884888
Ref<Script> scr = p_object->get_script();
4889+
4890+
if (Object::cast_to<EditorDebuggerRemoteObject>(p_object)) {
4891+
String class_name;
4892+
if (scr.is_valid()) {
4893+
class_name = scr->get_global_name();
4894+
4895+
if (class_name.is_empty()) {
4896+
// If there is no class_name in this script we just take the script path.
4897+
class_name = scr->get_path();
4898+
}
4899+
}
4900+
return get_class_icon(class_name.is_empty() ? Object::cast_to<EditorDebuggerRemoteObject>(p_object)->type_name : class_name, p_fallback);
4901+
}
4902+
48894903
if (scr.is_null() && p_object->is_class("Script")) {
48904904
scr = p_object;
48914905
}
48924906

4893-
return _get_class_or_script_icon(p_object->get_class(), scr, p_fallback);
4907+
if (Object::cast_to<MultiNodeEdit>(p_object)) {
4908+
return get_class_icon(Object::cast_to<MultiNodeEdit>(p_object)->get_edited_class_name(), p_fallback);
4909+
} else {
4910+
return _get_class_or_script_icon(p_object->get_class(), scr, p_fallback);
4911+
}
48944912
}
48954913

48964914
Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p_fallback) {

editor/editor_node.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,8 @@ class EditorNode : public Node {
832832
};
833833

834834
struct SceneEditorDataEntry {
835-
bool is_editable;
836-
bool is_display_folded;
835+
bool is_editable = false;
836+
bool is_display_folded = false;
837837
};
838838

839839
HashMap<int, SceneModificationsEntry> scenes_modification_table;

editor/gui/editor_object_selector.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@
3030

3131
#include "editor_object_selector.h"
3232

33-
#include "editor/debugger/editor_debugger_inspector.h"
3433
#include "editor/editor_data.h"
3534
#include "editor/editor_node.h"
3635
#include "editor/editor_string_names.h"
37-
#include "editor/multi_node_edit.h"
3836
#include "editor/themes/editor_scale.h"
3937
#include "scene/gui/margin_container.h"
4038

@@ -129,25 +127,7 @@ void EditorObjectSelector::update_path() {
129127
continue;
130128
}
131129

132-
Ref<Texture2D> obj_icon;
133-
if (Object::cast_to<MultiNodeEdit>(obj)) {
134-
obj_icon = EditorNode::get_singleton()->get_class_icon(Object::cast_to<MultiNodeEdit>(obj)->get_edited_class_name());
135-
} else if (Object::cast_to<EditorDebuggerRemoteObject>(obj)) {
136-
String class_name;
137-
Ref<Script> base_script = obj->get_script();
138-
if (base_script.is_valid()) {
139-
class_name = base_script->get_global_name();
140-
141-
if (class_name.is_empty()) {
142-
// If there is no class_name in this script we just take the script path.
143-
class_name = base_script->get_path();
144-
}
145-
}
146-
147-
obj_icon = EditorNode::get_singleton()->get_class_icon(class_name.is_empty() ? Object::cast_to<EditorDebuggerRemoteObject>(obj)->type_name : class_name);
148-
} else {
149-
obj_icon = EditorNode::get_singleton()->get_object_icon(obj);
150-
}
130+
Ref<Texture2D> obj_icon = EditorNode::get_singleton()->get_object_icon(obj);
151131

152132
if (obj_icon.is_valid()) {
153133
current_object_icon->set_texture(obj_icon);

editor/inspector_dock.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ Ref<Resource> InspectorDock::_get_current_resource() const {
316316

317317
void InspectorDock::_prepare_history() {
318318
EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history();
319+
editor_history->cleanup_history();
319320

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

@@ -505,6 +506,7 @@ void InspectorDock::clear() {
505506

506507
void InspectorDock::update(Object *p_object) {
507508
EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history();
509+
508510
backward_button->set_disabled(editor_history->is_at_beginning());
509511
forward_button->set_disabled(editor_history->is_at_end());
510512

editor/scene_tree_dock.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,7 +2308,6 @@ void SceneTreeDock::_node_reparent(NodePath p_path, bool p_keep_global_xform) {
23082308
ERR_FAIL_NULL(new_parent);
23092309

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

23132312
if (selection.is_empty()) {
23142313
return; // Nothing to reparent.
@@ -2321,10 +2320,6 @@ void SceneTreeDock::_node_reparent(NodePath p_path, bool p_keep_global_xform) {
23212320
}
23222321

23232322
_do_reparent(new_parent, -1, nodes, p_keep_global_xform);
2324-
2325-
for (Node *E : full_selection) {
2326-
editor_selection->add_node(E);
2327-
}
23282323
}
23292324

23302325
void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, Vector<Node *> p_nodes, bool p_keep_global_xform) {
@@ -2517,12 +2512,20 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
25172512

25182513
perform_node_renames(nullptr, &path_renames);
25192514

2520-
undo_redo->commit_action();
2515+
undo_redo->add_do_method(editor_selection, "clear");
2516+
undo_redo->add_undo_method(editor_selection, "clear");
2517+
List<Node *> full_selection = editor_selection->get_full_selected_node_list();
2518+
for (Node *E : full_selection) {
2519+
undo_redo->add_do_method(editor_selection, "add_node", E);
2520+
undo_redo->add_undo_method(editor_selection, "add_node", E);
2521+
}
25212522

25222523
if (need_edit) {
25232524
EditorNode::get_singleton()->edit_current();
25242525
editor_selection->clear();
25252526
}
2527+
2528+
undo_redo->commit_action();
25262529
}
25272530

25282531
void SceneTreeDock::_script_created(Ref<Script> p_script) {
@@ -3661,7 +3664,6 @@ void SceneTreeDock::_nodes_dragged(const Array &p_nodes, NodePath p_to, int p_ty
36613664
}
36623665

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

36663668
if (selection.is_empty()) {
36673669
return; //nothing to reparent
@@ -3681,10 +3683,6 @@ void SceneTreeDock::_nodes_dragged(const Array &p_nodes, NodePath p_to, int p_ty
36813683

36823684
_normalize_drop(to_node, to_pos, p_type);
36833685
_do_reparent(to_node, to_pos, nodes, !Input::get_singleton()->is_key_pressed(Key::SHIFT));
3684-
3685-
for (Node *E : full_selection) {
3686-
editor_selection->add_node(E);
3687-
}
36883686
}
36893687

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

0 commit comments

Comments
 (0)