diff options
author | Ray Koopa <raykoopa@users.noreply.github.com> | 2017-01-14 18:14:46 +0100 |
---|---|---|
committer | Ray Koopa <raykoopa@users.noreply.github.com> | 2017-02-27 16:59:12 +0100 |
commit | c02eb9a07a487350064c3d1a25e6b45a5a336cf0 (patch) | |
tree | 9082f7a1e50ddc92209b16657f80fa887f8d3bf0 /tools/editor/filesystem_dock.cpp | |
parent | df365fdc3cd62b482d6ecc9a074f235886b6ee01 (diff) |
Add menu item for file resources in the inspector to reveal them in the FileSystem
Diffstat (limited to 'tools/editor/filesystem_dock.cpp')
-rw-r--r-- | tools/editor/filesystem_dock.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tools/editor/filesystem_dock.cpp b/tools/editor/filesystem_dock.cpp index f5e4ef661a..bce0e9148a 100644 --- a/tools/editor/filesystem_dock.cpp +++ b/tools/editor/filesystem_dock.cpp @@ -287,6 +287,39 @@ 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; |