Merge pull request #15233 from sersoong/2.1-addshowinfilesystem

Porting show in filesystem to property editor
This commit is contained in:
Rémi Verschelde 2018-01-03 13:00:16 +01:00 committed by GitHub
commit 78eb274de2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 1 deletions

View file

@ -434,6 +434,37 @@ String FileSystemDock::get_selected_path() const {
return "res://" + 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 file_name = "";
DirAccess *dirAccess = DirAccess::open("res://");
if (dirAccess->file_exists(p_path)) {
path = p_path.get_base_dir();
file_name = p_path.get_file();
} else if (dirAccess->dir_exists(p_path)) {
path = p_path;
} else {
ERR_EXPLAIN(vformat(TTR("Cannot navigate to '%s' as it has not been found in the file system!"), p_path));
ERR_FAIL();
}
current_path->set_text(path);
_push_to_history();
_update_tree();
_update_files(false);
if (!file_name.empty()) {
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;
}
}
}
}
String FileSystemDock::get_current_path() const {
return path;
@ -1757,6 +1788,7 @@ void FileSystemDock::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_select_file"), &FileSystemDock::_select_file);
ObjectTypeDB::bind_method(_MD("_go_to_tree"), &FileSystemDock::_go_to_tree);
ObjectTypeDB::bind_method(_MD("_go_to_dir"), &FileSystemDock::_go_to_dir);
ObjectTypeDB::bind_method(_MD("navigate_to_path"), &FileSystemDock::navigate_to_path);
ObjectTypeDB::bind_method(_MD("_change_file_display"), &FileSystemDock::_change_file_display);
ObjectTypeDB::bind_method(_MD("_fw_history"), &FileSystemDock::_fw_history);
ObjectTypeDB::bind_method(_MD("_bw_history"), &FileSystemDock::_bw_history);

View file

@ -218,7 +218,7 @@ protected:
public:
String get_selected_path() const;
void navigate_to_path(const String &p_path);
String get_current_path() const;
void focus_on_filter();

View file

@ -204,6 +204,14 @@ void CustomPropertyEditor::_menu_option(int p_which) {
EditorNode::get_singleton()->get_scene_tree_dock()->open_script_dialog(owner->cast_to<Node>());
} break;
case OBJ_MENU_SHOW_IN_FILE_SYSTEM: {
RES r = v;
FileSystemDock *file_system_dock = EditorNode::get_singleton()->get_filesystem_dock();
file_system_dock->navigate_to_path(r->get_path());
// Ensure that the FileSystem dock is visible.
TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control();
tab_container->set_current_tab(file_system_dock->get_position_in_parent());
} break;
default: {
ERR_FAIL_COND(inheritors_array.empty());
@ -713,6 +721,10 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
menu->add_separator();
menu->add_icon_item(get_icon("ReloadSmall", "EditorIcons"), TTR("Re-Import"), OBJ_MENU_REIMPORT);
}
if (r.is_valid() && r->get_path().is_resource_file()) {
menu->add_separator();
menu->add_item(TTR("Show in File System"), OBJ_MENU_SHOW_IN_FILE_SYSTEM);
}
/*if (r.is_valid() && r->get_path().is_resource_file()) {
menu->set_item_tooltip(1,r->get_path());
} else if (r.is_valid()) {

View file

@ -65,6 +65,7 @@ class CustomPropertyEditor : public Popup {
OBJ_MENU_PASTE = 5,
OBJ_MENU_REIMPORT = 6,
OBJ_MENU_NEW_SCRIPT = 7,
OBJ_MENU_SHOW_IN_FILE_SYSTEM = 8,
TYPE_BASE_ID = 100
};