From b80e52f04899d28ea191ce3eaad9fdb76bc11b52 Mon Sep 17 00:00:00 2001 From: kobewi Date: Tue, 26 Apr 2022 23:52:20 +0200 Subject: [PATCH] Expose move_to_trash() --- core/core_bind.cpp | 5 +++++ core/core_bind.h | 1 + doc/classes/Directory.xml | 3 ++- doc/classes/OS.xml | 8 ++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 892b74c26a7..8308c4fe539 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -483,6 +483,10 @@ void OS::dump_resources_to_file(const String &p_file) { ::OS::get_singleton()->dump_resources_to_file(p_file.utf8().get_data()); } +Error OS::move_to_trash(const String &p_path) const { + return ::OS::get_singleton()->move_to_trash(p_path); +} + String OS::get_user_data_dir() const { return ::OS::get_singleton()->get_user_data_dir(); } @@ -597,6 +601,7 @@ void OS::_bind_methods() { ClassDB::bind_method(D_METHOD("get_static_memory_usage"), &OS::get_static_memory_usage); ClassDB::bind_method(D_METHOD("get_static_memory_peak_usage"), &OS::get_static_memory_peak_usage); + ClassDB::bind_method(D_METHOD("move_to_trash", "path"), &OS::move_to_trash); ClassDB::bind_method(D_METHOD("get_user_data_dir"), &OS::get_user_data_dir); ClassDB::bind_method(D_METHOD("get_system_dir", "dir", "shared_storage"), &OS::get_system_dir, DEFVAL(true)); ClassDB::bind_method(D_METHOD("get_config_dir"), &OS::get_config_dir); diff --git a/core/core_bind.h b/core/core_bind.h index 591cacdabb8..bc68be3f629 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -235,6 +235,7 @@ public: String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const; + Error move_to_trash(const String &p_path) const; String get_user_data_dir() const; String get_config_dir() const; String get_data_dir() const; diff --git a/doc/classes/Directory.xml b/doc/classes/Directory.xml index 7d72cd867c5..bd16fd39366 100644 --- a/doc/classes/Directory.xml +++ b/doc/classes/Directory.xml @@ -196,7 +196,8 @@ - Deletes the target file or an empty directory. The argument can be relative to the current directory, or an absolute path. If the target directory is not empty, the operation will fail. + Permanently deletes the target file or an empty directory. The argument can be relative to the current directory, or an absolute path. If the target directory is not empty, the operation will fail. + If you don't want to delete the file/directory permanently, use [method OS.move_to_trash] instead. Returns one of the [enum Error] code constants ([code]OK[/code] on success). diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index b2e325d226b..f45bee4db4e 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -455,6 +455,14 @@ [b]Note:[/b] This method is implemented on Android, iOS, Linux, macOS and Windows. + + + + + Moves the file or directory to the system's recycle bin. See also [method Directory.remove]. + [b]Note:[/b] If the user has disabled the recycle bin on their system, the file will be permanently deleted instead. + +