Many fixes to scene tree node dragging, closes #5341

This commit is contained in:
Juan Linietsky 2016-06-30 23:19:44 -03:00
parent 54571e94ac
commit a41a70ea3e
2 changed files with 14 additions and 4 deletions

View file

@ -1069,6 +1069,8 @@ void SceneTreeDock::_do_reparent(Node* p_new_parent,int p_position_in_parent,Vec
List<Pair<NodePath,NodePath> > path_renames; List<Pair<NodePath,NodePath> > path_renames;
int inc=0;
for(int ni=0;ni<p_nodes.size();ni++) { for(int ni=0;ni<p_nodes.size();ni++) {
//no undo for now, sorry //no undo for now, sorry
@ -1085,12 +1087,16 @@ void SceneTreeDock::_do_reparent(Node* p_new_parent,int p_position_in_parent,Vec
} }
if (new_parent==node->get_parent() && node->get_index() < p_position_in_parent+ni) {
//if child will generate a gap when moved, adjust
inc--;
}
editor_data->get_undo_redo().add_do_method(node->get_parent(),"remove_child",node); editor_data->get_undo_redo().add_do_method(node->get_parent(),"remove_child",node);
editor_data->get_undo_redo().add_do_method(new_parent,"add_child",node); editor_data->get_undo_redo().add_do_method(new_parent,"add_child",node);
if (p_position_in_parent>=0) if (p_position_in_parent>=0)
editor_data->get_undo_redo().add_do_method(new_parent,"move_child",node,p_position_in_parent+ni); editor_data->get_undo_redo().add_do_method(new_parent,"move_child",node,p_position_in_parent+inc);
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger(); ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
String new_name = new_parent->validate_child_name(node->get_name()); String new_name = new_parent->validate_child_name(node->get_name());
@ -1122,6 +1128,8 @@ void SceneTreeDock::_do_reparent(Node* p_new_parent,int p_position_in_parent,Vec
editor_data->get_undo_redo().add_undo_method(new_parent,"remove_child",node); editor_data->get_undo_redo().add_undo_method(new_parent,"remove_child",node);
inc++;
} }
//add and move in a second step.. (so old order is preserved) //add and move in a second step.. (so old order is preserved)
@ -1583,7 +1591,7 @@ static Node* _find_last_visible(Node*p_node) {
} }
void SceneTreeDock::_normalize_drop(Node*& to_node, int &to_pos,int p_type) { void SceneTreeDock::_normalize_drop(Node*& to_node, int &to_pos, int p_type) {
to_pos=-1; to_pos=-1;
@ -1624,6 +1632,7 @@ void SceneTreeDock::_normalize_drop(Node*& to_node, int &to_pos,int p_type) {
//just insert over this node because nothing is above at the same level //just insert over this node because nothing is above at the same level
to_pos=to_node->get_index(); to_pos=to_node->get_index();
to_node=to_node->get_parent(); to_node=to_node->get_parent();
} }
} else if (p_type==1) { } else if (p_type==1) {
@ -1650,12 +1659,13 @@ void SceneTreeDock::_normalize_drop(Node*& to_node, int &to_pos,int p_type) {
break; break;
} }
} }
if (lower_sibling) { if (lower_sibling) {
to_pos=lower_sibling->get_index(); to_pos=lower_sibling->get_index();
} }
to_node=to_node->get_parent(); to_node=to_node->get_parent();
} }
#if 0 #if 0
//quite complicated, look for next visible in tree //quite complicated, look for next visible in tree

View file

@ -139,7 +139,7 @@ class SceneTreeDock : public VBoxContainer {
void _fill_path_renames(Vector<StringName> base_path,Vector<StringName> new_base_path,Node * p_node, List<Pair<NodePath,NodePath> > *p_renames); void _fill_path_renames(Vector<StringName> base_path,Vector<StringName> new_base_path,Node * p_node, List<Pair<NodePath,NodePath> > *p_renames);
void _normalize_drop(Node*& to_node, int &to_pos,int p_type); void _normalize_drop(Node*& to_node, int &to_pos, int p_type);
void _nodes_dragged(Array p_nodes,NodePath p_to,int p_type); void _nodes_dragged(Array p_nodes,NodePath p_to,int p_type);
void _files_dropped(Vector<String> p_files,NodePath p_to,int p_type); void _files_dropped(Vector<String> p_files,NodePath p_to,int p_type);