summaryrefslogtreecommitdiffstats
path: root/editor/filesystem_dock.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/filesystem_dock.cpp')
-rw-r--r--editor/filesystem_dock.cpp62
1 files changed, 60 insertions, 2 deletions
diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp
index dd80ff49ac..87ba7f53b0 100644
--- a/editor/filesystem_dock.cpp
+++ b/editor/filesystem_dock.cpp
@@ -47,6 +47,7 @@
#include "editor/gui/editor_dir_dialog.h"
#include "editor/import/resource_importer_scene.h"
#include "editor/import_dock.h"
+#include "editor/plugins/editor_resource_tooltip_plugins.h"
#include "editor/scene_create_dialog.h"
#include "editor/scene_tree_dock.h"
#include "editor/shader_create_dialog.h"
@@ -54,10 +55,27 @@
#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/progress_bar.h"
+#include "scene/gui/texture_rect.h"
#include "scene/main/window.h"
#include "scene/resources/packed_scene.h"
#include "servers/display_server.h"
+Control *FileSystemTree::make_custom_tooltip(const String &p_text) const {
+ TreeItem *item = get_item_at_position(get_local_mouse_position());
+ if (!item) {
+ return nullptr;
+ }
+ return FileSystemDock::get_singleton()->create_tooltip_for_path(item->get_metadata(0));
+}
+
+Control *FileSystemList::make_custom_tooltip(const String &p_text) const {
+ int idx = get_item_at_position(get_local_mouse_position());
+ if (idx == -1) {
+ return nullptr;
+ }
+ return FileSystemDock::get_singleton()->create_tooltip_for_path(get_item_metadata(idx));
+}
+
FileSystemDock *FileSystemDock::singleton = nullptr;
Ref<Texture2D> FileSystemDock::_get_tree_item_icon(bool p_is_valid, String p_file_type) {
@@ -2249,6 +2267,41 @@ void FileSystemDock::set_file_list_display_mode(FileListDisplayMode p_mode) {
_toggle_file_display();
}
+void FileSystemDock::add_resource_tooltip_plugin(const Ref<EditorResourceTooltipPlugin> &p_plugin) {
+ tooltip_plugins.push_back(p_plugin);
+}
+
+void FileSystemDock::remove_resource_tooltip_plugin(const Ref<EditorResourceTooltipPlugin> &p_plugin) {
+ int index = tooltip_plugins.find(p_plugin);
+ ERR_FAIL_COND_MSG(index == -1, "Can't remove plugin that wasn't registered.");
+ tooltip_plugins.remove_at(index);
+}
+
+Control *FileSystemDock::create_tooltip_for_path(const String &p_path) const {
+ if (DirAccess::exists(p_path)) {
+ // No tooltip for directory.
+ return nullptr;
+ }
+
+ const String type = ResourceLoader::get_resource_type(p_path);
+ Control *tooltip = nullptr;
+
+ for (const Ref<EditorResourceTooltipPlugin> &plugin : tooltip_plugins) {
+ if (plugin->handles(type)) {
+ tooltip = plugin->make_tooltip_for_path(p_path, EditorResourcePreview::get_singleton()->get_preview_metadata(p_path));
+ }
+
+ if (tooltip) {
+ break;
+ }
+ }
+
+ if (!tooltip) {
+ tooltip = EditorResourceTooltipPlugin::make_default_tooltip(p_path);
+ }
+ return tooltip;
+}
+
Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
bool all_favorites = true;
bool all_not_favorites = true;
@@ -3130,6 +3183,9 @@ void FileSystemDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("_update_import_dock"), &FileSystemDock::_update_import_dock);
+ ClassDB::bind_method(D_METHOD("add_resource_tooltip_plugin", "plugin"), &FileSystemDock::add_resource_tooltip_plugin);
+ ClassDB::bind_method(D_METHOD("remove_resource_tooltip_plugin", "plugin"), &FileSystemDock::remove_resource_tooltip_plugin);
+
ADD_SIGNAL(MethodInfo("inherit", PropertyInfo(Variant::STRING, "file")));
ADD_SIGNAL(MethodInfo("instantiate", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files")));
@@ -3227,7 +3283,7 @@ FileSystemDock::FileSystemDock() {
split_box->set_v_size_flags(SIZE_EXPAND_FILL);
add_child(split_box);
- tree = memnew(Tree);
+ tree = memnew(FileSystemTree);
tree->set_hide_root(true);
SET_DRAG_FORWARDING_GCD(tree, FileSystemDock);
@@ -3266,7 +3322,7 @@ FileSystemDock::FileSystemDock() {
button_file_list_display_mode->set_flat(true);
path_hb->add_child(button_file_list_display_mode);
- files = memnew(ItemList);
+ files = memnew(FileSystemList);
files->set_v_size_flags(SIZE_EXPAND_FILL);
files->set_select_mode(ItemList::SELECT_MULTI);
SET_DRAG_FORWARDING_GCD(files, FileSystemDock);
@@ -3355,6 +3411,8 @@ FileSystemDock::FileSystemDock() {
display_mode = DISPLAY_MODE_TREE_ONLY;
old_display_mode = DISPLAY_MODE_TREE_ONLY;
file_list_display_mode = FILE_LIST_DISPLAY_THUMBNAILS;
+
+ add_resource_tooltip_plugin(memnew(EditorTextureTooltipPlugin));
}
FileSystemDock::~FileSystemDock() {