diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-01-25 20:22:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-25 20:22:34 +0100 |
commit | 831d9b925af2caaff8f7723723f46e1d98ef0c14 (patch) | |
tree | 257a34da937bcf8b8011e6cd10fafae9506b258b | |
parent | 266fbd8c7624a0f4c41c5c6296f12059c69c77fb (diff) | |
parent | 1ce9bbc8ed8dd9746eadac82beaf5a6f4c22fdcf (diff) |
Merge pull request #7563 from RayKoopa/extended_list_dir_begin
Add parameters to Directory.list_dir_begin() to skip navigational or hidden entries
-rw-r--r-- | core/bind/core_bind.cpp | 18 | ||||
-rw-r--r-- | core/bind/core_bind.h | 5 |
2 files changed, 19 insertions, 4 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 954ebbc30c..80adafe092 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -1825,16 +1825,28 @@ Error _Directory::open(const String& p_path) { return OK; } -Error _Directory::list_dir_begin() { +Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) { ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED); + + _list_skip_navigational = p_skip_navigational; + _list_skip_hidden = p_skip_hidden; + return d->list_dir_begin(); } String _Directory::get_next(){ ERR_FAIL_COND_V(!d,""); - return d->get_next(); + + String next = d->get_next(); + while (next != "" + && ((_list_skip_navigational && (next == "." || next == "..")) + || (_list_skip_hidden && d->current_is_hidden()))) { + + next = d->get_next(); + } + return next; } bool _Directory::current_is_dir() const{ @@ -1964,7 +1976,7 @@ void _Directory::_bind_methods() { ClassDB::bind_method(_MD("open:Error","path"),&_Directory::open); - ClassDB::bind_method(_MD("list_dir_begin"),&_Directory::list_dir_begin); + ClassDB::bind_method(_MD("list_dir_begin", "skip_navigational", "skip_hidden"), &_Directory::list_dir_begin, DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(_MD("get_next"),&_Directory::get_next); ClassDB::bind_method(_MD("current_is_dir"),&_Directory::current_is_dir); ClassDB::bind_method(_MD("list_dir_end"),&_Directory::list_dir_end); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index fe710704f2..13081fc867 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -458,7 +458,7 @@ public: Error open(const String& p_path); - Error list_dir_begin(); ///< This starts dir listing + Error list_dir_begin(bool p_skip_internal = false, bool p_skip_hidden = false); ///< This starts dir listing String get_next(); bool current_is_dir() const; @@ -487,6 +487,9 @@ public: _Directory(); virtual ~_Directory(); +private: + bool _list_skip_navigational; + bool _list_skip_hidden; }; class _Marshalls : public Reference { |