Hides special folders in FileDialog for macOS

This commit is contained in:
Haoyu Qiu 2020-09-28 14:06:36 +08:00
parent 80165210c3
commit 1998f78679
4 changed files with 18 additions and 1 deletions

View File

@ -152,7 +152,7 @@ String DirAccessUnix::get_next() {
_cisdir = (entry->d_type == DT_DIR); _cisdir = (entry->d_type == DT_DIR);
} }
_cishidden = (fname != "." && fname != ".." && fname.begins_with(".")); _cishidden = is_hidden(fname);
return fname; return fname;
} }
@ -400,6 +400,10 @@ String DirAccessUnix::get_filesystem_type() const {
return ""; //TODO this should be implemented return ""; //TODO this should be implemented
} }
bool DirAccessUnix::is_hidden(const String &p_name) {
return p_name != "." && p_name != ".." && p_name.begins_with(".");
}
DirAccessUnix::DirAccessUnix() { DirAccessUnix::DirAccessUnix() {
dir_stream = nullptr; dir_stream = nullptr;
_cisdir = false; _cisdir = false;

View File

@ -51,6 +51,7 @@ class DirAccessUnix : public DirAccess {
protected: protected:
virtual String fix_unicode_name(const char *p_name) const { return String::utf8(p_name); } virtual String fix_unicode_name(const char *p_name) const { return String::utf8(p_name); }
virtual bool is_hidden(const String &p_name);
public: public:
virtual Error list_dir_begin(); ///< This starts dir listing virtual Error list_dir_begin(); ///< This starts dir listing

View File

@ -47,6 +47,8 @@ protected:
virtual int get_drive_count(); virtual int get_drive_count();
virtual String get_drive(int p_drive); virtual String get_drive(int p_drive);
virtual bool is_hidden(const String &p_name);
}; };
#endif //UNIX ENABLED #endif //UNIX ENABLED

View File

@ -68,4 +68,14 @@ String DirAccessOSX::get_drive(int p_drive) {
return volname; return volname;
} }
bool DirAccessOSX::is_hidden(const String &p_name) {
String f = get_current_dir().plus_file(p_name);
NSURL *url = [NSURL fileURLWithPath:@(f.utf8().get_data())];
NSNumber *hidden = nil;
if (![url getResourceValue:&hidden forKey:NSURLIsHiddenKey error:nil]) {
return DirAccessUnix::is_hidden(p_name);
}
return [hidden boolValue];
}
#endif //posix_enabled #endif //posix_enabled