void ScenesDock::_open_pressed(){ TreeItem *sel = tree->get_selected(); if (!sel) { return; } path = sel->get_metadata(0); /*if (path!="res://" && path.ends_with("/")) { path=path.substr(0,path.length()-1); }*/ //tree_mode=false; if (split_mode) { tree->hide(); file_list_vb->show(); button_favorite->hide(); button_fav_up->hide(); button_fav_down->hide(); } //file_options->show(); _update_files(false); current_path->set_text(path); _push_to_history(); // emit_signal("open",path); }
void ScenesDock::open(const String& p_path) { String npath; String nfile; if (p_path.ends_with("/")) { if (p_path!="res://") npath=p_path.substr(0,p_path.length()-1); else npath="res://"; } else { nfile=p_path.get_file(); npath=p_path.get_base_dir(); } path=npath; if (tree_mode && nfile=="") { _update_tree(); tree->grab_focus(); tree->call_deferred("ensure_cursor_is_visible"); _push_to_history(); return; } else if (tree_mode){ _update_tree(); tree->grab_focus(); tree->ensure_cursor_is_visible(); _open_pressed(); current_path->set_text(path); } else { _update_files(false); _push_to_history(); } for(int i=0;i<files->get_item_count();i++) { String md = files->get_item_metadata(i); if (md==p_path) { files->select(i,true); files->ensure_current_is_visible(); break; } } }
void ScenesDock::_file_option(int p_option) { switch(p_option) { case FILE_SHOW_IN_EXPLORER: case FILE_OPEN: { int idx=-1; for(int i=0;i<files->get_item_count();i++) { if (files->is_selected(i)) { idx=i; break; } } if (idx<0) return; String path = files->get_item_metadata(idx); if (p_option == FILE_SHOW_IN_EXPLORER) { String dir = Globals::get_singleton()->globalize_path(path); dir = dir.substr(0, dir.find_last("/")); OS::get_singleton()->shell_open(String("file://")+dir); return; } if (path.ends_with("/")) { if (path!="res://") { path=path.substr(0,path.length()-1); } this->path=path; _update_files(false); current_path->set_text(path); _push_to_history(); } else { if (ResourceLoader::get_resource_type(path)=="PackedScene") { editor->open_request(path); } else { editor->load_resource(path); } } } break; case FILE_INSTANCE: { for (int i = 0; i<files->get_item_count(); i++) { String path =files->get_item_metadata(i); if (EditorFileSystem::get_singleton()->get_file_type(path)=="PackedScene") { emit_signal("instance",path); } } } break; case FILE_DEPENDENCIES: { int idx = files->get_current(); if (idx<0 || idx>=files->get_item_count()) break; String path = files->get_item_metadata(idx); deps_editor->edit(path); } break; case FILE_OWNERS: { int idx = files->get_current(); if (idx<0 || idx>=files->get_item_count()) break; String path = files->get_item_metadata(idx); owners_editor->show(path); } break; case FILE_MOVE: { move_dirs.clear();; move_files.clear(); for(int i=0;i<files->get_item_count();i++) { String path = files->get_item_metadata(i); if (!files->is_selected(i)) continue; if (files->get_item_text(i)=="..") { EditorNode::get_singleton()->show_warning(TTR("Can't operate on '..'")); return; } if (path.ends_with("/")) { move_dirs.push_back(path.substr(0,path.length()-1)); } else { move_files.push_back(path); } } if (move_dirs.empty() && move_files.size()==1) { rename_dialog->clear_filters(); rename_dialog->add_filter("*."+move_files[0].extension()); rename_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); rename_dialog->set_current_path(move_files[0]); rename_dialog->popup_centered_ratio(); rename_dialog->set_title(TTR("Pick New Name and Location For:")+" "+move_files[0].get_file()); } else { //just move move_dialog->popup_centered_ratio(); } } break; case FILE_REMOVE: { Vector<String> torem; for(int i=0;i<files->get_item_count();i++) { String path = files->get_item_metadata(i); if (path.ends_with("/") || !files->is_selected(i)) continue; torem.push_back(path); } if (torem.empty()) { EditorNode::get_singleton()->show_warning(TTR("No files selected!")); break; } remove_dialog->show(torem); //1) find if used //2) warn } break; case FILE_INFO: { } break; } }
void FileSystemDock::_file_option(int p_option) { switch(p_option) { case FILE_SHOW_IN_EXPLORER: case FILE_OPEN: { int idx=-1; for(int i=0;i<files->get_item_count();i++) { if (files->is_selected(i)) { idx=i; break; } } if (idx<0) return; String path = files->get_item_metadata(idx); if (p_option == FILE_SHOW_IN_EXPLORER) { String dir = Globals::get_singleton()->globalize_path(path); dir = dir.substr(0, dir.find_last("/")); OS::get_singleton()->shell_open(String("file://")+dir); return; } if (path.ends_with("/")) { if (path!="res://") { path=path.substr(0,path.length()-1); } this->path=path; _update_files(false); current_path->set_text(path); _push_to_history(); } else { if (ResourceLoader::get_resource_type(path)=="PackedScene") { editor->open_request(path); } else { editor->load_resource(path); } } } break; case FILE_INSTANCE: { Vector<String> paths; for (int i = 0; i<files->get_item_count(); i++) { if (!files->is_selected(i)) continue; String path =files->get_item_metadata(i); if (EditorFileSystem::get_singleton()->get_file_type(path)=="PackedScene") { paths.push_back(path); } } if (!paths.empty()) { emit_signal("instance", paths); } } break; case FILE_DEPENDENCIES: { int idx = files->get_current(); if (idx<0 || idx>=files->get_item_count()) break; String path = files->get_item_metadata(idx); deps_editor->edit(path); } break; case FILE_OWNERS: { int idx = files->get_current(); if (idx<0 || idx>=files->get_item_count()) break; String path = files->get_item_metadata(idx); owners_editor->show(path); } break; case FILE_MOVE: { move_dirs.clear();; move_files.clear(); for(int i=0;i<files->get_item_count();i++) { String path = files->get_item_metadata(i); if (!files->is_selected(i)) continue; if (files->get_item_text(i)=="..") { EditorNode::get_singleton()->show_warning(TTR("Can't operate on '..'")); return; } if (path.ends_with("/")) { move_dirs.push_back(path.substr(0,path.length()-1)); } else { move_files.push_back(path); } } if (move_dirs.empty() && move_files.size()==1) { rename_dialog->clear_filters(); rename_dialog->add_filter("*."+move_files[0].extension()); rename_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); rename_dialog->set_current_path(move_files[0]); rename_dialog->popup_centered_ratio(); rename_dialog->set_title(TTR("Pick New Name and Location For:")+" "+move_files[0].get_file()); } else { //just move move_dialog->popup_centered_ratio(); } } break; case FILE_REMOVE: { Vector<String> torem; for(int i=0;i<files->get_item_count();i++) { String path = files->get_item_metadata(i); if (path.ends_with("/") || !files->is_selected(i)) continue; torem.push_back(path); } if (torem.empty()) { EditorNode::get_singleton()->show_warning(TTR("No files selected!")); break; } remove_dialog->show(torem); //1) find if used //2) warn } break; case FILE_INFO: { } break; case FILE_REIMPORT: { Vector<String> reimport; for(int i=0;i<files->get_item_count();i++) { if (!files->is_selected(i)) continue; String path = files->get_item_metadata(i); reimport.push_back(path); } ERR_FAIL_COND(reimport.size()==0); Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(reimport[0]); ERR_FAIL_COND(!rimd.is_valid()); String editor=rimd->get_editor(); if (editor.begins_with("texture_")) { //compatibility fix for old texture format editor="texture"; } Ref<EditorImportPlugin> rimp = EditorImportExport::get_singleton()->get_import_plugin_by_name(editor); ERR_FAIL_COND(!rimp.is_valid()); if (reimport.size()==1) { rimp->import_dialog(reimport[0]); } else { rimp->reimport_multiple_files(reimport); } } break; case FILE_COPY_PATH: int idx = files->get_current(); if (idx<0 || idx>=files->get_item_count()) break; String path = files->get_item_metadata(idx); OS::get_singleton()->set_clipboard(path); } }
void ScenesDock::_open_pressed(){ if (tree_mode) { TreeItem *sel = tree->get_selected(); if (!sel) { return; } path = sel->get_metadata(0); /*if (path!="res://" && path.ends_with("/")) { path=path.substr(0,path.length()-1); }*/ tree_mode=false; tree->hide(); files->show(); path_hb->show(); button_favorite->hide(); button_fav_up->hide(); button_fav_down->hide(); button_instance->show(); button_open->show(); file_options->show(); _update_files(false); current_path->set_text(path); _push_to_history(); } else { int idx=-1; for(int i=0;i<files->get_item_count();i++) { if (files->is_selected(i)) { idx=i; break; } } if (idx<0) return; String path = files->get_item_metadata(idx); if (path.ends_with("/")) { if (path!="res://") { path=path.substr(0,path.length()-1); } this->path=path; _update_files(false); current_path->set_text(path); _push_to_history(); } else { if (ResourceLoader::get_resource_type(path)=="PackedScene") { editor->open_request(path); } else { editor->load_resource(path); } } } // emit_signal("open",path); }