void ScenesDock::drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from){ if (!can_drop_data_fw(p_point,p_data,p_from)) return; Dictionary drag_data = p_data; if (drag_data.has("type") && String(drag_data["type"])=="resource") { Ref<Resource> res = drag_data["resource"]; if (!res.is_valid()) { return; } if (p_from==tree) { TreeItem *ti = tree->get_item_at_pos(p_point); if (!ti) return; String path = ti->get_metadata(0); if (path==String()) return; EditorNode::get_singleton()->save_resource_as(res,path); return; } if (p_from==files) { String save_path=path; int at_pos = files->get_item_at_pos(p_point); if (at_pos!=-1) { String to_dir = files->get_item_metadata(at_pos); if (to_dir.ends_with("/")) { save_path=to_dir; if (save_path!="res://") save_path=save_path.substr(0,save_path.length()-1); } } EditorNode::get_singleton()->save_resource_as(res,save_path); return; } } if (drag_data.has("type") && ( String(drag_data["type"])=="files" || String(drag_data["type"])=="files_and_dirs")) { if (p_from==files || p_from==tree) { String to_dir; if (p_from==files) { int at_pos = files->get_item_at_pos(p_point); ERR_FAIL_COND(at_pos==-1); String to_dir = files->get_item_metadata(at_pos); } else { TreeItem *ti = tree->get_item_at_pos(p_point); if (!ti) return; to_dir = ti->get_metadata(0); ERR_FAIL_COND(to_dir==String()); } if (to_dir!="res://" && to_dir.ends_with("/")) { to_dir=to_dir.substr(0,to_dir.length()-1); } Vector<String> fnames = drag_data["files"]; move_files.clear(); move_dirs.clear(); for(int i=0;i<fnames.size();i++) { if (fnames[i].ends_with("/")) move_dirs.push_back(fnames[i]); else move_files.push_back(fnames[i]); } _move_operation(to_dir); } } }
void ScenesDock::drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from){ if (!can_drop_data_fw(p_point,p_data,p_from)) return; Dictionary drag_data = p_data; if (drag_data.has("type") && String(drag_data["type"])=="favorite") { //moving favorite around TreeItem *ti = tree->get_item_at_pos(p_point); if (!ti) return; Vector<String> files = drag_data["files"]; ERR_FAIL_COND(files.size()!=1); String swap = files[0]; if (swap!="res://" && swap.ends_with("/")) { swap=swap.substr(0,swap.length()-1); } int what = tree->get_drop_section_at_pos(p_point); TreeItem *swap_item=NULL; if (ti==tree->get_root()->get_children()) { swap_item=tree->get_root()->get_children()->get_children(); } else if (ti->get_parent() && tree->get_root()->get_children()==ti->get_parent()) { if (what==-1) { swap_item=ti; } else { swap_item=ti->get_next(); } } String swap_with; if (swap_item) { swap_with=swap_item->get_metadata(0); if (swap_with!="res://" && swap_with.ends_with("/")) { swap_with=swap_with.substr(0,swap_with.length()-1); } } if (swap==swap_with) return; Vector<String> dirs = EditorSettings::get_singleton()->get_favorite_dirs(); ERR_FAIL_COND(dirs.find(swap)==-1); ERR_FAIL_COND(swap_with!=String() && dirs.find(swap_with)==-1); dirs.erase(swap); if (swap_with==String()) { dirs.push_back(swap); } else { int idx = dirs.find(swap_with); dirs.insert(idx,swap); } EditorSettings::get_singleton()->set_favorite_dirs(dirs); _update_tree(); return; } if (drag_data.has("type") && String(drag_data["type"])=="resource") { Ref<Resource> res = drag_data["resource"]; if (!res.is_valid()) { return; } if (p_from==tree) { TreeItem *ti = tree->get_item_at_pos(p_point); if (!ti) return; String path = ti->get_metadata(0); if (path==String()) return; EditorNode::get_singleton()->save_resource_as(res,path); return; } if (p_from==files) { String save_path=path; int at_pos = files->get_item_at_pos(p_point); if (at_pos!=-1) { String to_dir = files->get_item_metadata(at_pos); if (to_dir.ends_with("/")) { save_path=to_dir; if (save_path!="res://") save_path=save_path.substr(0,save_path.length()-1); } } EditorNode::get_singleton()->save_resource_as(res,save_path); return; } } if (drag_data.has("type") && ( String(drag_data["type"])=="files" || String(drag_data["type"])=="files_and_dirs")) { if (p_from==files || p_from==tree) { String to_dir; if (p_from==files) { int at_pos = files->get_item_at_pos(p_point); ERR_FAIL_COND(at_pos==-1); to_dir = files->get_item_metadata(at_pos); } else { TreeItem *ti = tree->get_item_at_pos(p_point); if (!ti) return; to_dir = ti->get_metadata(0); ERR_FAIL_COND(to_dir==String()); } if (to_dir!="res://" && to_dir.ends_with("/")) { to_dir=to_dir.substr(0,to_dir.length()-1); } Vector<String> fnames = drag_data["files"]; move_files.clear(); move_dirs.clear(); for(int i=0;i<fnames.size();i++) { if (fnames[i].ends_with("/")) move_dirs.push_back(fnames[i]); else move_files.push_back(fnames[i]); } _move_operation(to_dir); } } }