New option to show/hide hidden files

This commit is contained in:
rollenrolm 2015-03-21 18:33:32 +01:00
parent 40496dd76a
commit db0a71fc58
13 changed files with 63 additions and 10 deletions

View file

@ -362,6 +362,10 @@ bool DirAccessPack::current_is_dir() const{
return cdir; return cdir;
} }
bool DirAccessPack::current_is_hidden() const{
return false;
}
void DirAccessPack::list_dir_end() { void DirAccessPack::list_dir_end() {
list_dirs.clear(); list_dirs.clear();

View file

@ -208,6 +208,7 @@ public:
virtual bool list_dir_begin(); virtual bool list_dir_begin();
virtual String get_next(); virtual String get_next();
virtual bool current_is_dir() const; virtual bool current_is_dir() const;
virtual bool current_is_hidden() const;
virtual void list_dir_end(); virtual void list_dir_end();
virtual int get_drive_count(); virtual int get_drive_count();

View file

@ -78,6 +78,7 @@ public:
virtual String get_next(bool* p_is_dir); // compatibility virtual String get_next(bool* p_is_dir); // compatibility
virtual String get_next()=0; virtual String get_next()=0;
virtual bool current_is_dir() const=0; virtual bool current_is_dir() const=0;
virtual bool current_is_hidden() const=0;
virtual void list_dir_end()=0; ///< virtual void list_dir_end()=0; ///<

View file

@ -161,6 +161,7 @@ String DirAccessUnix::get_next() {
} }
_cishidden=(fname!="." && fname!=".." && fname.begins_with("."));
@ -173,6 +174,11 @@ bool DirAccessUnix::current_is_dir() const {
return _cisdir; return _cisdir;
} }
bool DirAccessUnix::current_is_hidden() const {
return _cishidden;
}
void DirAccessUnix::list_dir_end() { void DirAccessUnix::list_dir_end() {

View file

@ -50,12 +50,14 @@ class DirAccessUnix : public DirAccess {
String current_dir; String current_dir;
bool _cisdir; bool _cisdir;
bool _cishidden;
public: public:
virtual bool list_dir_begin(); ///< This starts dir listing virtual bool list_dir_begin(); ///< This starts dir listing
virtual String get_next(); virtual String get_next();
virtual bool current_is_dir() const; virtual bool current_is_dir() const;
virtual bool current_is_hidden() const;
virtual void list_dir_end(); ///< virtual void list_dir_end(); ///<

View file

@ -68,6 +68,7 @@ struct DirAccessWindowsPrivate {
bool DirAccessWindows::list_dir_begin() { bool DirAccessWindows::list_dir_begin() {
_cisdir=false; _cisdir=false;
_cishidden=false;
if (unicode) { if (unicode) {
list_dir_end(); list_dir_end();
@ -95,6 +96,8 @@ String DirAccessWindows::get_next() {
if (unicode) { if (unicode) {
_cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); _cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
_cishidden=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN);
String name=p->fu.cFileName; String name=p->fu.cFileName;
if (FindNextFileW(p->h, &p->fu) == 0) { if (FindNextFileW(p->h, &p->fu) == 0) {
@ -108,6 +111,7 @@ String DirAccessWindows::get_next() {
#ifndef WINRT_ENABLED #ifndef WINRT_ENABLED
_cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); _cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
_cishidden=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN);
String name=p->f.cFileName; String name=p->f.cFileName;
@ -128,6 +132,11 @@ bool DirAccessWindows::current_is_dir() const {
return _cisdir; return _cisdir;
} }
bool DirAccessWindows::current_is_hidden() const {
return _cishidden;
}
void DirAccessWindows::list_dir_end() { void DirAccessWindows::list_dir_end() {
if (p->h!=INVALID_HANDLE_VALUE) { if (p->h!=INVALID_HANDLE_VALUE) {

View file

@ -58,6 +58,7 @@ class DirAccessWindows : public DirAccess {
bool unicode; bool unicode;
bool _cisdir; bool _cisdir;
bool _cishidden;
public: public:

View file

@ -79,6 +79,9 @@ bool DirAccessAndroid::current_is_dir() const{
return false; return false;
} }
bool DirAccessAndroid::current_is_hidden() const{
return current!="." && current!=".." && current.begins_with(".");
}
void DirAccessAndroid::list_dir_end(){ void DirAccessAndroid::list_dir_end(){
if (aad==NULL) if (aad==NULL)

View file

@ -52,6 +52,7 @@ public:
virtual bool list_dir_begin(); ///< This starts dir listing virtual bool list_dir_begin(); ///< This starts dir listing
virtual String get_next(); virtual String get_next();
virtual bool current_is_dir() const; virtual bool current_is_dir() const;
virtual bool current_is_hidden() const;
virtual void list_dir_end(); ///< virtual void list_dir_end(); ///<
virtual int get_drive_count(); virtual int get_drive_count();

View file

@ -105,6 +105,9 @@ bool DirAccessJAndroid::current_is_dir() const{
return true; return true;
} }
bool DirAccessAndroid::current_is_hidden() const{
return current!="." && current!=".." && current.begins_with(".");
}
void DirAccessJAndroid::list_dir_end(){ void DirAccessJAndroid::list_dir_end(){
if (id==0) if (id==0)

View file

@ -29,6 +29,8 @@
#include "file_dialog.h" #include "file_dialog.h"
#include "scene/gui/label.h" #include "scene/gui/label.h"
#include "print_string.h" #include "print_string.h"
#include "os/keyboard.h"
#include "tools/editor/editor_settings.h"
FileDialog::GetIconFunc FileDialog::get_icon_func=NULL; FileDialog::GetIconFunc FileDialog::get_icon_func=NULL;
@ -278,13 +280,20 @@ void FileDialog::update_file_list() {
List<String> dirs; List<String> dirs;
bool isdir; bool isdir;
bool ishidden;
bool show_hidden = EditorSettings::get_singleton()->get("file_dialog/show_hidden_files");
String item; String item;
while ((item=dir_access->get_next(&isdir))!="") { while ((item=dir_access->get_next(&isdir))!="") {
if (!isdir) ishidden = dir_access->current_is_hidden();
files.push_back(item);
else if (show_hidden || !ishidden) {
dirs.push_back(item); if (!isdir)
files.push_back(item);
else
dirs.push_back(item);
}
} }
dirs.sort_custom<NoCaseComparator>(); dirs.sort_custom<NoCaseComparator>();

View file

@ -28,6 +28,9 @@
/*************************************************************************/ /*************************************************************************/
#include "editor_dir_dialog.h" #include "editor_dir_dialog.h"
#include "os/os.h" #include "os/os.h"
#include "os/keyboard.h"
#include "tools/editor/editor_settings.h"
void EditorDirDialog::_update_dir(TreeItem* p_item) { void EditorDirDialog::_update_dir(TreeItem* p_item) {
@ -39,12 +42,21 @@ void EditorDirDialog::_update_dir(TreeItem* p_item) {
da->change_dir(cdir); da->change_dir(cdir);
da->list_dir_begin(); da->list_dir_begin();
String p=da->get_next(); String p=da->get_next();
bool ishidden;
bool show_hidden = EditorSettings::get_singleton()->get("file_dialog/show_hidden_files");
while(p!="") { while(p!="") {
if (da->current_is_dir() && !p.begins_with(".")) {
TreeItem *ti = tree->create_item(p_item); ishidden = da->current_is_hidden();
ti->set_text(0,p);
ti->set_icon(0,get_icon("Folder","EditorIcons")); if (show_hidden || !ishidden) {
ti->set_collapsed(true); if (da->current_is_dir() && !p.begins_with(".")) {
TreeItem *ti = tree->create_item(p_item);
ti->set_text(0,p);
ti->set_icon(0,get_icon("Folder","EditorIcons"));
ti->set_collapsed(true);
}
} }
p=da->get_next(); p=da->get_next();

View file

@ -446,6 +446,7 @@ void EditorSettings::_load_defaults() {
set("text_editor/create_signal_callbacks",true); set("text_editor/create_signal_callbacks",true);
set("file_dialog/show_hidden_files", false);
set("animation/autorename_animation_tracks",true); set("animation/autorename_animation_tracks",true);
set("animation/confirm_insert_track",true); set("animation/confirm_insert_track",true);