From 63de41b996db09e37816d941506b14753d8ed233 Mon Sep 17 00:00:00 2001 From: kobewi Date: Sun, 10 Apr 2022 21:25:24 +0200 Subject: [PATCH] Improvements to files_dropped signal --- doc/classes/Window.xml | 9 +++++++++ editor/editor_node.cpp | 2 +- editor/editor_node.h | 2 +- editor/project_manager.cpp | 2 +- editor/project_manager.h | 2 +- scene/main/window.cpp | 2 +- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml index 9853f906bca..87a65db1920 100644 --- a/doc/classes/Window.xml +++ b/doc/classes/Window.xml @@ -349,6 +349,15 @@ Emitted when files are dragged from the OS file manager and dropped in the game window. The argument is a list of file paths. + Note that this method only works with non-embedded windows, i.e. the main window and [Window]-derived nodes when [member Viewport.gui_embed_subwindows] is disabled in the main viewport. + Example usage: + [codeblock] + func _ready(): + get_viewport().files_dropped.connect(on_files_dropped) + + func on_files_dropped(files): + print(files) + [/codeblock] diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index a80c7853f55..1a1e16027e0 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5478,7 +5478,7 @@ void EditorNode::_global_menu_new_window(const Variant &p_tag) { } } -void EditorNode::_dropped_files(const Vector &p_files, int p_screen) { +void EditorNode::_dropped_files(const Vector &p_files) { String to_path = ProjectSettings::get_singleton()->globalize_path(FileSystemDock::get_singleton()->get_selected_path()); _add_dropped_files_recursive(p_files, to_path); diff --git a/editor/editor_node.h b/editor/editor_node.h index 685714cb47a..c6c1f09938f 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -575,7 +575,7 @@ private: void _open_recent_scene(int p_idx); void _global_menu_scene(const Variant &p_tag); void _global_menu_new_window(const Variant &p_tag); - void _dropped_files(const Vector &p_files, int p_screen); + void _dropped_files(const Vector &p_files); void _add_dropped_files_recursive(const Vector &p_files, String to_path); void _update_from_settings(); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 501cb88547b..eedcd0d3ef9 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -2402,7 +2402,7 @@ void ProjectManager::_install_project(const String &p_zip_path, const String &p_ npdialog->show_dialog(); } -void ProjectManager::_files_dropped(PackedStringArray p_files, int p_screen) { +void ProjectManager::_files_dropped(PackedStringArray p_files) { if (p_files.size() == 1 && p_files[0].ends_with(".zip")) { const String file = p_files[0].get_file(); _install_project(p_files[0], file.substr(0, file.length() - 4).capitalize()); diff --git a/editor/project_manager.h b/editor/project_manager.h index 9cea6e163f3..00f8cfc7216 100644 --- a/editor/project_manager.h +++ b/editor/project_manager.h @@ -127,7 +127,7 @@ class ProjectManager : public Control { void _dim_window(); virtual void shortcut_input(const Ref &p_ev) override; - void _files_dropped(PackedStringArray p_files, int p_screen); + void _files_dropped(PackedStringArray p_files); void _version_button_pressed(); void _on_order_option_changed(int p_idx); diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 2faa107fb41..2858ffba6dc 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -981,7 +981,7 @@ void Window::_window_input_text(const String &p_text) { } void Window::_window_drop_files(const Vector &p_files) { - emit_signal(SNAME("files_dropped"), p_files, current_screen); + emit_signal(SNAME("files_dropped"), p_files); } Viewport *Window::get_parent_viewport() const {