diff options
Diffstat (limited to 'tools/editor/filesystem_dock.cpp')
-rw-r--r-- | tools/editor/filesystem_dock.cpp | 289 |
1 files changed, 174 insertions, 115 deletions
diff --git a/tools/editor/filesystem_dock.cpp b/tools/editor/filesystem_dock.cpp index 1bf91d4ceb..bce0e9148a 100644 --- a/tools/editor/filesystem_dock.cpp +++ b/tools/editor/filesystem_dock.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* scenes_dock.cpp */ +/* filesystem_dock.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,14 +27,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "filesystem_dock.h" + #include "os/dir_access.h" #include "os/file_access.h" -#include "globals.h" - +#include "global_config.h" #include "io/resource_loader.h" #include "os/os.h" #include "editor_node.h" - #include "editor_settings.h" #include "scene/main/viewport.h" @@ -171,7 +170,7 @@ void FileSystemDock::_notification(int p_what) { _update_tree(); //maybe it finished already if (EditorFileSystem::get_singleton()->is_scanning()) { - _set_scannig_mode(); + _set_scanning_mode(); } } break; @@ -186,7 +185,7 @@ void FileSystemDock::_notification(int p_what) { case NOTIFICATION_DRAG_BEGIN: { Dictionary dd = get_viewport()->gui_get_drag_data(); - if (tree->is_visible() && dd.has("type") ) { + if (tree->is_visible_in_tree() && dd.has("type") ) { if ( (String(dd["type"])=="files") || (String(dd["type"])=="files_and_dirs") || (String(dd["type"])=="resource")) { tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM); } @@ -288,11 +287,44 @@ String FileSystemDock::get_current_path() const { return path; } +void FileSystemDock::navigate_to_path(const String& p_path) { + // If the path is a file, do not only go to the directory in the tree, also select the file in the file list. + String dir_path=""; + String file_name=""; + DirAccess* dirAccess=DirAccess::open("res://"); + if (dirAccess->file_exists(p_path)) { + dir_path=p_path.get_base_dir(); + file_name=p_path.get_file(); + } else if (dirAccess->dir_exists(p_path)) { + dir_path=p_path; + } else { + ERR_EXPLAIN(TTR("Cannot navigate to '" + p_path + "' as it has not been found in the file system!")); + ERR_FAIL(); + } + + path=dir_path; + _update_tree(); + tree->ensure_cursor_is_visible(); + + if (!file_name.empty()) { + _open_pressed(); // Seems to be the only way to get into the file view. This also pushes to history. + + // Focus the given file. + for (int i=0; i<files->get_item_count(); i++) { + if (files->get_item_text(i) == file_name) { + files->select(i,true); + files->ensure_current_is_visible(); + break; + } + } + } +} + void FileSystemDock::_thumbnail_done(const String& p_path,const Ref<Texture>& p_preview, const Variant& p_udata) { bool valid=false; - if (!search_box->is_hidden()) { + if (search_box->is_visible()) { valid=true; } else { valid=(path==p_path.get_base_dir()); @@ -351,25 +383,9 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path,List<FileInfo>* m FileInfo fi; fi.name=file; fi.type=p_path->get_file_type(i); - fi.path=p_path->get_file_path(i); - if (p_path->get_file_meta(i)) { - if (p_path->is_missing_sources(i)) { - fi.import_status=3; - } else if (p_path->have_sources_changed(i)) { - fi.import_status=2; - } else { - fi.import_status=1; - } - } else { - fi.import_status=0; - } - for(int j=0;j<p_path->get_source_count(i);j++) { - String s = EditorImportPlugin::expand_source_path(p_path->get_source_file(i,j)); - if (p_path->is_source_file_missing(i,j)) { - s+=" (Missing)"; - } - fi.sources.push_back(s); - } + fi.path=p_path->get_file_path(i); + fi.import_status=0; + matches->push_back(fi); if (matches->size()>p_max_items) @@ -396,7 +412,7 @@ void FileSystemDock::_update_files(bool p_keep_selection) { current_path->set_text(path); - EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->get_path(path); + EditorFileSystemDirectory *efd = EditorFileSystem::get_singleton()->get_filesystem_path(path); if (!efd) return; @@ -501,25 +517,7 @@ void FileSystemDock::_update_files(bool p_keep_selection) { fi.name=efd->get_file(i); fi.path=path.plus_file(fi.name); fi.type=efd->get_file_type(i); - if (efd->get_file_meta(i)) { - if (efd->is_missing_sources(i)) { - fi.import_status=3; - } else if (efd->have_sources_changed(i)) { - fi.import_status=2; - } else { - fi.import_status=1; - } - - for(int j=0;j<efd->get_source_count(i);j++) { - String s = EditorImportPlugin::expand_source_path(efd->get_source_file(i,j)); - if (efd->is_source_file_missing(i,j)) { - s+=" (Missing)"; - } - fi.sources.push_back(s); - } - } else { - fi.import_status=0; - } + fi.import_status=0; @@ -624,7 +622,7 @@ void FileSystemDock::_go_to_dir(const String& p_dir){ void FileSystemDock::_preview_invalidated(const String& p_path) { - if (p_path.get_base_dir()==path && search_box->get_text()==String() && file_list_vb->is_visible()) { + if (p_path.get_base_dir()==path && search_box->get_text()==String() && file_list_vb->is_visible_in_tree()) { for(int i=0;i<files->get_item_count();i++) { @@ -649,13 +647,13 @@ void FileSystemDock::_fs_changed() { scanning_vb->hide(); split_box->show(); - if (!tree->is_hidden()) { + if (tree->is_visible()) { button_favorite->show(); _update_tree(); } - if (!file_list_vb->is_hidden()) { + if (file_list_vb->is_visible()) { _update_files(true); } @@ -663,7 +661,7 @@ void FileSystemDock::_fs_changed() { set_process(false); } -void FileSystemDock::_set_scannig_mode() { +void FileSystemDock::_set_scanning_mode() { split_box->hide(); button_hist_prev->set_disabled(true); @@ -685,14 +683,14 @@ void FileSystemDock::_fw_history() { path=history[history_pos]; - if (!tree->is_hidden()) { + if (tree->is_visible()) { _update_tree(); tree->grab_focus(); tree->ensure_cursor_is_visible(); } - if (!file_list_vb->is_hidden()) { + if (file_list_vb->is_visible()) { _update_files(false); current_path->set_text(path); } @@ -710,13 +708,13 @@ void FileSystemDock::_bw_history() { path=history[history_pos]; - if (!tree->is_hidden()) { + if (tree->is_visible()) { _update_tree(); tree->grab_focus(); tree->ensure_cursor_is_visible(); } - if (!file_list_vb->is_hidden()) { + if (file_list_vb->is_visible()) { _update_files(false); current_path->set_text(path); } @@ -832,7 +830,7 @@ void FileSystemDock::_move_operation(const String& p_to_path) { return; } - EditorFileSystemDirectory *efsd=EditorFileSystem::get_singleton()->get_path(move_dirs[i]); + EditorFileSystemDirectory *efsd=EditorFileSystem::get_singleton()->get_filesystem_path(move_dirs[i]); if (!efsd) continue; _find_inside_move_files(efsd,inside_files); @@ -990,7 +988,7 @@ void FileSystemDock::_file_option(int p_option) { } break; case FILE_MOVE: { - move_dirs.clear();; + move_dirs.clear(); move_files.clear(); for(int i=0;i<files->get_item_count();i++) { @@ -1015,7 +1013,7 @@ void FileSystemDock::_file_option(int p_option) { if (move_dirs.empty() && move_files.size()==1) { rename_dialog->clear_filters(); - rename_dialog->add_filter("*."+move_files[0].extension()); + rename_dialog->add_filter("*."+move_files[0].get_extension()); rename_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); rename_dialog->set_current_path(move_files[0]); rename_dialog->popup_centered_ratio(); @@ -1069,7 +1067,7 @@ void FileSystemDock::_file_option(int p_option) { } 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(); @@ -1087,6 +1085,7 @@ void FileSystemDock::_file_option(int p_option) { rimp->reimport_multiple_files(reimport); } + */ } break; case FILE_COPY_PATH: @@ -1149,7 +1148,7 @@ void FileSystemDock::_open_pressed(){ current_path->set_text(path); _push_to_history(); -// emit_signal("open",path); + //emit_signal("open",path); } @@ -1167,7 +1166,7 @@ void FileSystemDock::_dir_rmb_pressed(const Vector2& p_pos) { void FileSystemDock::_search_changed(const String& p_text) { - if (!search_box->is_visible()) + if (!search_box->is_visible_in_tree()) return; //wtf _update_files(false); @@ -1175,7 +1174,7 @@ void FileSystemDock::_search_changed(const String& p_text) { void FileSystemDock::_rescan() { - _set_scannig_mode(); + _set_scanning_mode(); EditorFileSystem::get_singleton()->scan(); } @@ -1187,6 +1186,14 @@ void FileSystemDock::fix_dependencies(const String& p_for_file) { void FileSystemDock::focus_on_filter() { + if (!search_box->is_visible_in_tree()) { + // Tree mode, switch to files list with search box + tree->hide(); + file_list_vb->show(); + button_favorite->hide(); + } + + search_box->grab_focus(); } void FileSystemDock::set_display_mode(int p_mode) { @@ -1242,8 +1249,10 @@ Variant FileSystemDock::get_drag_data_fw(const Point2& p_point,Control* p_from) if (seldirs.empty() && selfiles.empty()) return Variant(); - //if (seldirs.size() && selfiles.size()) - // return Variant(); //can't really mix files and dirs (i think?) - yes you can, commenting + /* + if (seldirs.size() && selfiles.size()) + return Variant(); //can't really mix files and dirs (i think?) - yes you can, commenting + */ /*if (selfiles.size()==1) { Ref<Resource> resource = ResourceLoader::load(files->get_item_metadata(selfiles.front()->get())); @@ -1528,25 +1537,6 @@ void FileSystemDock::_files_list_rmb_select(int p_item,const Vector2& p_pos) { if (efsd) { - if (!efsd->get_file_meta(pos)) { - all_can_reimport=false; - - - } else { - Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(path); - if (rimd.is_valid()) { - - String editor=rimd->get_editor(); - if (editor.begins_with("texture_")) { //compatibility fix for old texture format - editor="texture"; - } - types.insert(editor); - - } else { - all_can_reimport=false; - - } - } } else { all_can_reimport=false; @@ -1594,7 +1584,7 @@ void FileSystemDock::_files_list_rmb_select(int p_item,const Vector2& p_pos) { if (all_can_reimport && types.size()==1) { //all can reimport and are of the same type - +/* bool valid=true; Ref<EditorImportPlugin> rimp = EditorImportExport::get_singleton()->get_import_plugin_by_name(types.front()->get()); if (rimp.is_valid()) { @@ -1610,6 +1600,7 @@ void FileSystemDock::_files_list_rmb_select(int p_item,const Vector2& p_pos) { file_options->add_separator(); file_options->add_item(TTR("Re-Import.."),FILE_REIMPORT); } + */ } file_options->set_pos(files->get_global_pos() + p_pos); @@ -1617,37 +1608,103 @@ void FileSystemDock::_files_list_rmb_select(int p_item,const Vector2& p_pos) { } +void FileSystemDock::select_file(const String& p_file) { + + _go_to_dir(p_file.get_base_dir()); + for(int i=0;i<files->get_item_count();i++) { + if (files->get_item_metadata(i)==p_file) { + files->select(i); + files->ensure_current_is_visible(); + break; + } + } + +} + +void FileSystemDock::_file_multi_selected(int p_index,bool p_selected) { + + + _file_selected(); +} + +void FileSystemDock::_file_selected() { + + //check import + Vector<String> imports; + String import_type; + + for(int i=0;i<files->get_item_count();i++) { + if (!files->is_selected(i)) + continue; + + String p = files->get_item_metadata(i); + if (!FileAccess::exists(p+".import")) { + imports.clear(); + break; + } + Ref<ConfigFile> cf; + cf.instance(); + Error err = cf->load(p+".import"); + if (err!=OK) { + imports.clear(); + break; + } + + String type = cf->get_value("remap","type"); + if (import_type=="") { + import_type=type; + } else if (import_type!=type) { + //all should be the same type + imports.clear(); + break; + } + imports.push_back(p); + } + + + if (imports.size()==0) { + EditorNode::get_singleton()->get_import_dock()->clear(); + } else if (imports.size()==1) { + EditorNode::get_singleton()->get_import_dock()->set_edit_path(imports[0]); + } else { + EditorNode::get_singleton()->get_import_dock()->set_edit_multiple_paths(imports); + } +} + + void FileSystemDock::_bind_methods() { - ClassDB::bind_method(_MD("_update_tree"),&FileSystemDock::_update_tree); - ClassDB::bind_method(_MD("_rescan"),&FileSystemDock::_rescan); - ClassDB::bind_method(_MD("_favorites_pressed"),&FileSystemDock::_favorites_pressed); -// ClassDB::bind_method(_MD("_instance_pressed"),&ScenesDock::_instance_pressed); - ClassDB::bind_method(_MD("_open_pressed"),&FileSystemDock::_open_pressed); - ClassDB::bind_method(_MD("_dir_rmb_pressed"),&FileSystemDock::_dir_rmb_pressed); - - ClassDB::bind_method(_MD("_thumbnail_done"),&FileSystemDock::_thumbnail_done); - ClassDB::bind_method(_MD("_select_file"), &FileSystemDock::_select_file); - ClassDB::bind_method(_MD("_go_to_tree"), &FileSystemDock::_go_to_tree); - ClassDB::bind_method(_MD("_go_to_dir"), &FileSystemDock::_go_to_dir); - ClassDB::bind_method(_MD("_change_file_display"), &FileSystemDock::_change_file_display); - ClassDB::bind_method(_MD("_fw_history"), &FileSystemDock::_fw_history); - ClassDB::bind_method(_MD("_bw_history"), &FileSystemDock::_bw_history); - ClassDB::bind_method(_MD("_fs_changed"), &FileSystemDock::_fs_changed); - ClassDB::bind_method(_MD("_dir_selected"), &FileSystemDock::_dir_selected); - ClassDB::bind_method(_MD("_file_option"), &FileSystemDock::_file_option); - ClassDB::bind_method(_MD("_folder_option"), &FileSystemDock::_folder_option); - ClassDB::bind_method(_MD("_move_operation"), &FileSystemDock::_move_operation); - ClassDB::bind_method(_MD("_rename_operation"), &FileSystemDock::_rename_operation); - - ClassDB::bind_method(_MD("_search_changed"), &FileSystemDock::_search_changed); - - ClassDB::bind_method(_MD("get_drag_data_fw"), &FileSystemDock::get_drag_data_fw); - ClassDB::bind_method(_MD("can_drop_data_fw"), &FileSystemDock::can_drop_data_fw); - ClassDB::bind_method(_MD("drop_data_fw"), &FileSystemDock::drop_data_fw); - ClassDB::bind_method(_MD("_files_list_rmb_select"),&FileSystemDock::_files_list_rmb_select); - - ClassDB::bind_method(_MD("_preview_invalidated"),&FileSystemDock::_preview_invalidated); + ClassDB::bind_method(D_METHOD("_update_tree"),&FileSystemDock::_update_tree); + ClassDB::bind_method(D_METHOD("_rescan"),&FileSystemDock::_rescan); + ClassDB::bind_method(D_METHOD("_favorites_pressed"),&FileSystemDock::_favorites_pressed); + //ClassDB::bind_method(D_METHOD("_instance_pressed"),&ScenesDock::_instance_pressed); + ClassDB::bind_method(D_METHOD("_open_pressed"),&FileSystemDock::_open_pressed); + ClassDB::bind_method(D_METHOD("_dir_rmb_pressed"),&FileSystemDock::_dir_rmb_pressed); + + ClassDB::bind_method(D_METHOD("_thumbnail_done"),&FileSystemDock::_thumbnail_done); + ClassDB::bind_method(D_METHOD("_select_file"), &FileSystemDock::_select_file); + ClassDB::bind_method(D_METHOD("_go_to_tree"), &FileSystemDock::_go_to_tree); + ClassDB::bind_method(D_METHOD("_go_to_dir"), &FileSystemDock::_go_to_dir); + ClassDB::bind_method(D_METHOD("_change_file_display"), &FileSystemDock::_change_file_display); + ClassDB::bind_method(D_METHOD("_fw_history"), &FileSystemDock::_fw_history); + ClassDB::bind_method(D_METHOD("_bw_history"), &FileSystemDock::_bw_history); + ClassDB::bind_method(D_METHOD("_fs_changed"), &FileSystemDock::_fs_changed); + ClassDB::bind_method(D_METHOD("_dir_selected"), &FileSystemDock::_dir_selected); + ClassDB::bind_method(D_METHOD("_file_option"), &FileSystemDock::_file_option); + ClassDB::bind_method(D_METHOD("_folder_option"), &FileSystemDock::_folder_option); + ClassDB::bind_method(D_METHOD("_move_operation"), &FileSystemDock::_move_operation); + ClassDB::bind_method(D_METHOD("_rename_operation"), &FileSystemDock::_rename_operation); + + ClassDB::bind_method(D_METHOD("_search_changed"), &FileSystemDock::_search_changed); + + ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &FileSystemDock::get_drag_data_fw); + ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &FileSystemDock::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("drop_data_fw"), &FileSystemDock::drop_data_fw); + ClassDB::bind_method(D_METHOD("_files_list_rmb_select"),&FileSystemDock::_files_list_rmb_select); + + ClassDB::bind_method(D_METHOD("_preview_invalidated"),&FileSystemDock::_preview_invalidated); + ClassDB::bind_method(D_METHOD("_file_selected"),&FileSystemDock::_file_selected); + ClassDB::bind_method(D_METHOD("_file_multi_selected"),&FileSystemDock::_file_multi_selected); ADD_SIGNAL(MethodInfo("instance", PropertyInfo(Variant::POOL_STRING_ARRAY, "files"))); @@ -1700,7 +1757,7 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { button_favorite->set_focus_mode(FOCUS_NONE); -// Control *spacer = memnew( Control); + //Control *spacer = memnew( Control); @@ -1752,6 +1809,8 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { files->set_select_mode(ItemList::SELECT_MULTI); files->set_drag_forwarding(this); files->connect("item_rmb_selected",this,"_files_list_rmb_select"); + files->connect("item_selected",this,"_file_selected"); + files->connect("multi_selected",this,"_file_multi_selected"); files->set_allow_rmb_select(true); file_list_vb = memnew( VBoxContainer ); @@ -1770,8 +1829,8 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { path_hb->add_child(search_box); search_box->connect("text_changed",this,"_search_changed"); - search_icon = memnew( TextureFrame ); - search_icon->set_stretch_mode(TextureFrame::STRETCH_KEEP_CENTERED); + search_icon = memnew( TextureRect ); + search_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); path_hb->add_child(search_icon); button_display_mode = memnew( ToolButton ); |