Merge pull request #55761 from KoBeWi/alt_hack

This commit is contained in:
Rémi Verschelde 2021-12-21 11:35:14 +01:00 committed by GitHub
commit c972948c21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 12 deletions

View File

@ -2727,6 +2727,29 @@ void EditorPropertyNodePath::_node_clear() {
update_property();
}
bool EditorPropertyNodePath::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
return !is_read_only() && is_drop_valid(p_data);
}
void EditorPropertyNodePath::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
ERR_FAIL_COND(!is_drop_valid(p_data));
Dictionary data = p_data;
Array nodes = data["nodes"];
Node *node = get_tree()->get_edited_scene_root()->get_node(nodes[0]);
if (node) {
_node_selected(node->get_path());
}
}
bool EditorPropertyNodePath::is_drop_valid(const Dictionary &p_drag_data) const {
if (p_drag_data["type"] != "nodes") {
return false;
}
Array nodes = p_drag_data["nodes"];
return nodes.size() == 1;
}
void EditorPropertyNodePath::update_property() {
NodePath p = get_edited_object()->get(get_edited_property());
@ -2781,6 +2804,8 @@ void EditorPropertyNodePath::_notification(int p_what) {
}
void EditorPropertyNodePath::_bind_methods() {
ClassDB::bind_method(D_METHOD("_can_drop_data_fw", "position", "data", "from"), &EditorPropertyNodePath::can_drop_data_fw);
ClassDB::bind_method(D_METHOD("_drop_data_fw", "position", "data", "from"), &EditorPropertyNodePath::drop_data_fw);
}
EditorPropertyNodePath::EditorPropertyNodePath() {
@ -2791,6 +2816,7 @@ EditorPropertyNodePath::EditorPropertyNodePath() {
assign->set_h_size_flags(SIZE_EXPAND_FILL);
assign->set_clip_text(true);
assign->connect("pressed", callable_mp(this, &EditorPropertyNodePath::_node_assign));
assign->set_drag_forwarding(this);
hbc->add_child(assign);
clear = memnew(Button);

View File

@ -625,6 +625,10 @@ class EditorPropertyNodePath : public EditorProperty {
void _node_assign();
void _node_clear();
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const;
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
bool is_drop_valid(const Dictionary &p_drag_data) const;
protected:
virtual void _set_read_only(bool p_read_only) override;
static void _bind_methods();

View File

@ -233,7 +233,7 @@ void SceneTreeDock::_perform_instantiate_scenes(const Vector<String> &p_files, N
}
editor_data->get_undo_redo().commit_action();
editor->push_item(instances[instances.size() - 1]);
_push_item(instances[instances.size() - 1]);
for (int i = 0; i < instances.size(); i++) {
emit_signal(SNAME("node_created"), instances[i]);
}
@ -750,7 +750,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
editor_data->get_undo_redo().commit_action();
if (dupsingle) {
editor->push_item(dupsingle);
_push_item(dupsingle);
}
} break;
case TOOL_REPARENT: {
@ -854,7 +854,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
mne->add_node(root->get_path_to(E.key));
}
EditorNode::get_singleton()->push_item(mne.ptr());
_push_item(mne.ptr());
} break;
@ -1164,7 +1164,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
Object *obj = ObjectDB::get_instance(subresources[idx]);
ERR_FAIL_COND(!obj);
editor->push_item(obj);
_push_item(obj);
}
}
}
@ -1368,6 +1368,12 @@ void SceneTreeDock::_script_open_request(const Ref<Script> &p_script) {
editor->edit_resource(p_script);
}
void SceneTreeDock::_push_item(Object *p_object) {
if (!Input::get_singleton()->is_key_pressed(Key::ALT)) {
editor->push_item(p_object);
}
}
void SceneTreeDock::_node_selected() {
Node *node = scene_tree->get_selected();
@ -1379,7 +1385,7 @@ void SceneTreeDock::_node_selected() {
restore_script_editor_on_drag = true;
}
editor->push_item(node);
_push_item(node);
}
void SceneTreeDock::_node_renamed() {
@ -1950,7 +1956,7 @@ void SceneTreeDock::_script_created(Ref<Script> p_script) {
editor_data->get_undo_redo().commit_action();
editor->push_item(p_script.operator->());
_push_item(p_script.operator->());
_update_script_button();
}
@ -2098,7 +2104,7 @@ void SceneTreeDock::_delete_confirm(bool p_cut) {
editor->get_viewport_control()->update();
}
editor->push_item(nullptr);
_push_item(nullptr);
// Fixes the EditorHistory from still offering deleted notes
EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history();
@ -2142,9 +2148,9 @@ void SceneTreeDock::_selection_changed() {
//automatically turn on multi-edit
_tool_selected(TOOL_MULTI_EDIT);
} else if (selection_size == 1) {
editor->push_item(editor_selection->get_selection().front()->key());
_push_item(editor_selection->get_selection().front()->key());
} else if (selection_size == 0) {
editor->push_item(nullptr);
_push_item(nullptr);
}
_update_script_button();
@ -2180,7 +2186,7 @@ void SceneTreeDock::_do_create(Node *p_parent) {
}
editor_data->get_undo_redo().commit_action();
editor->push_item(c);
_push_item(c);
editor_selection->clear();
editor_selection->add_node(child);
if (Object::cast_to<Control>(c)) {
@ -2338,7 +2344,7 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop
memdelete(default_oldnode);
}
editor->push_item(nullptr);
_push_item(nullptr);
//reconnect signals
List<MethodInfo> sl;
@ -2382,7 +2388,7 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop
}
newnode->set_name(newname);
editor->push_item(newnode);
_push_item(newnode);
if (p_remove_old) {
memdelete(n);

View File

@ -197,6 +197,7 @@ class SceneTreeDock : public VBoxContainer {
void _node_replace_owner(Node *p_base, Node *p_node, Node *p_root, ReplaceOwnerMode p_mode = MODE_BIDI);
void _load_request(const String &p_path);
void _script_open_request(const Ref<Script> &p_script);
void _push_item(Object *p_object);
bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);
bool _track_inherit(const String &p_target_scene_path, Node *p_desired_node);