void SpriteFramesEditor::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 d = p_data; if (!d.has("type")) return; int at_pos = tree->get_item_at_pos(p_point, true); if (String(d["type"]) == "resource" && d.has("resource")) { RES r = d["resource"]; Ref<Texture> texture = r; if (texture.is_valid()) { undo_redo->create_action(TTR("Add Frame")); undo_redo->add_do_method(frames, "add_frame", edited_anim, texture, at_pos == -1 ? -1 : at_pos); undo_redo->add_undo_method(frames, "remove_frame", edited_anim, at_pos == -1 ? frames->get_frame_count(edited_anim) : at_pos); undo_redo->add_do_method(this, "_update_library"); undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); } } if (String(d["type"]) == "files") { DVector<String> files = d["files"]; _file_load_request(files, at_pos); } }
void SceneTreeEditor::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; TreeItem *item = tree->get_item_at_pos(p_point); if (!item) return; int section = tree->get_drop_section_at_pos(p_point); if (section<-1) return; NodePath np = item->get_metadata(0); Node *n=get_node(np); if (!n) return; Dictionary d=p_data; if (String(d["type"])=="nodes") { Array nodes=d["nodes"]; emit_signal("nodes_rearranged",nodes,np,section); } if (String(d["type"])=="files") { emit_signal("files_dropped",d["files"],np,section); } }
void ResourcePreloaderEditor::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 d = p_data; if (!d.has("type")) return; if (String(d["type"]) == "resource" && d.has("resource")) { RES r = d["resource"]; if (r.is_valid()) { String basename; if (r->get_name() != "") { basename = r->get_name(); } else if (r->get_path().is_resource_file()) { basename = r->get_path().get_basename(); } else { basename = "Resource"; } String name = basename; int counter = 0; while (preloader->has_resource(name)) { counter++; name = basename + "_" + itos(counter); } undo_redo->create_action(TTR("Add Resource")); undo_redo->add_do_method(preloader, "add_resource", name, r); undo_redo->add_undo_method(preloader, "remove_resource", name); undo_redo->add_do_method(this, "_update_library"); undo_redo->add_undo_method(this, "_update_library"); undo_redo->commit_action(); } } if (String(d["type"]) == "files") { Vector<String> files = d["files"]; _files_load_request(files); } }
void SceneTreeEditor::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; TreeItem *item = tree->get_item_at_position(p_point); if (!item) return; int section = tree->get_drop_section_at_position(p_point); if (section < -1) return; NodePath np = item->get_metadata(0); Node *n = get_node(np); if (!n) return; Dictionary d = p_data; if (String(d["type"]) == "nodes") { Array nodes = d["nodes"]; emit_signal("nodes_rearranged", nodes, np, section); } if (String(d["type"]) == "files") { Vector<String> files = d["files"]; String ftype = EditorFileSystem::get_singleton()->get_file_type(files[0]); if (_is_script_type(ftype)) { emit_signal("script_dropped", files[0], np); } else { emit_signal("files_dropped", files, np, section); } } }
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); } } }