Expose move_to_trash()

(cherry picked from commit b80e52f048)
This commit is contained in:
kobewi 2022-04-26 23:52:20 +02:00 committed by Rémi Verschelde
parent 6f01a949c2
commit b7336524f2
4 changed files with 16 additions and 1 deletions

View file

@ -1102,6 +1102,10 @@ void _OS::dump_resources_to_file(const String &p_file) {
OS::get_singleton()->dump_resources_to_file(p_file.utf8().get_data()); 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 { String _OS::get_user_data_dir() const {
return OS::get_singleton()->get_user_data_dir(); return OS::get_singleton()->get_user_data_dir();
}; };
@ -1399,6 +1403,7 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_static_memory_peak_usage"), &_OS::get_static_memory_peak_usage); ClassDB::bind_method(D_METHOD("get_static_memory_peak_usage"), &_OS::get_static_memory_peak_usage);
ClassDB::bind_method(D_METHOD("get_dynamic_memory_usage"), &_OS::get_dynamic_memory_usage); ClassDB::bind_method(D_METHOD("get_dynamic_memory_usage"), &_OS::get_dynamic_memory_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_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_system_dir", "dir", "shared_storage"), &_OS::get_system_dir, DEFVAL(true));
ClassDB::bind_method(D_METHOD("get_config_dir"), &_OS::get_config_dir); ClassDB::bind_method(D_METHOD("get_config_dir"), &_OS::get_config_dir);

View file

@ -354,6 +354,7 @@ public:
String get_system_dir(SystemDir p_dir, bool p_shared_storage = true) const; 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_user_data_dir() const;
String get_config_dir() const; String get_config_dir() const;
String get_data_dir() const; String get_data_dir() const;

View file

@ -153,7 +153,8 @@
<return type="int" enum="Error" /> <return type="int" enum="Error" />
<argument index="0" name="path" type="String" /> <argument index="0" name="path" type="String" />
<description> <description>
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). Returns one of the [enum Error] code constants ([code]OK[/code] on success).
</description> </description>
</method> </method>

View file

@ -766,6 +766,14 @@
[b]Note:[/b] This method is implemented on Android, iOS, Linux, macOS and Windows. [b]Note:[/b] This method is implemented on Android, iOS, Linux, macOS and Windows.
</description> </description>
</method> </method>
<method name="move_to_trash" qualifiers="const">
<return type="int" enum="Error" />
<argument index="0" name="path" type="String" />
<description>
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.
</description>
</method>
<method name="move_window_to_foreground"> <method name="move_window_to_foreground">
<return type="void" /> <return type="void" />
<description> <description>