Added parameters to skip hidden and/or navigational file system entries

This commit is contained in:
Ray Koopa 2017-01-16 23:19:43 +01:00
parent d13f2f9e25
commit 1ce9bbc8ed
2 changed files with 19 additions and 4 deletions

View file

@ -1819,16 +1819,28 @@ Error _Directory::open(const String& p_path) {
return OK; 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); ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
_list_skip_navigational = p_skip_navigational;
_list_skip_hidden = p_skip_hidden;
return d->list_dir_begin(); return d->list_dir_begin();
} }
String _Directory::get_next(){ String _Directory::get_next(){
ERR_FAIL_COND_V(!d,""); 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{ bool _Directory::current_is_dir() const{
@ -1958,7 +1970,7 @@ void _Directory::_bind_methods() {
ClassDB::bind_method(_MD("open:Error","path"),&_Directory::open); 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("get_next"),&_Directory::get_next);
ClassDB::bind_method(_MD("current_is_dir"),&_Directory::current_is_dir); ClassDB::bind_method(_MD("current_is_dir"),&_Directory::current_is_dir);
ClassDB::bind_method(_MD("list_dir_end"),&_Directory::list_dir_end); ClassDB::bind_method(_MD("list_dir_end"),&_Directory::list_dir_end);

View file

@ -456,7 +456,7 @@ public:
Error open(const String& p_path); 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(); String get_next();
bool current_is_dir() const; bool current_is_dir() const;
@ -485,6 +485,9 @@ public:
_Directory(); _Directory();
virtual ~_Directory(); virtual ~_Directory();
private:
bool _list_skip_navigational;
bool _list_skip_hidden;
}; };
class _Marshalls : public Reference { class _Marshalls : public Reference {