Don't show hidden directories and files in the project tree browser

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16207
This commit is contained in:
Jan Wichmann 2024-03-03 16:43:43 +00:00 committed by Jon Evans
parent 9e0cd7e6ee
commit 5cdf9fe8a0
5 changed files with 36 additions and 6 deletions

View File

@ -78,6 +78,8 @@
#include "project_tree_pane.h"
#include <widgets/kistatusbar.h>
#include <kiplatform/io.h>
/* Note about the project tree build process:
* Building the project tree can be *very* long if there are a lot of subdirectories in the
@ -392,12 +394,8 @@ wxTreeItemId PROJECT_TREE_PANE::addItemToProjectTree( const wxString& aName,
TREE_FILE_TYPE type = TREE_FILE_TYPE::UNKNOWN;
wxFileName fn( aName );
#ifndef __WXMSW__
// Files/dirs names starting by "." are not visible files under unices (including MacOS),
// but are under MSW.
if( fn.GetName().StartsWith( wxT( "." ) ) )
if( KIPLATFORM::IO::IsFileHidden( aName ) )
return wxTreeItemId();
#endif
if( wxDirExists( aName ) )
{

View File

@ -21,6 +21,7 @@
#include <wx/crt.h>
#include <wx/string.h>
#include <wx/filename.h>
#include <fcntl.h>
#include <sys/stat.h>
@ -58,3 +59,10 @@ bool KIPLATFORM::IO::DuplicatePermissions( const wxString &aSrc, const wxString
return false;
}
}
bool KIPLATFORM::IO::IsFileHidden( const wxString& aFileName )
{
wxFileName fn( aFileName );
return fn.GetName().StartsWith( wxT( "." ) );
}

View File

@ -44,6 +44,12 @@ namespace IO
* @return true if the process was successful
*/
bool DuplicatePermissions( const wxString& aSrc, const wxString& aDest );
/**
* Helper function to determine the status of the 'Hidden' file attribute.
* @return true if the file attribut is set.
*/
bool IsFileHidden( const wxString& aFileName );
} // namespace IO
} // namespace KIPLATFORM

View File

@ -114,3 +114,13 @@ bool KIPLATFORM::IO::DuplicatePermissions( const wxString &aSrc, const wxString
return retval;
}
bool KIPLATFORM::IO::IsFileHidden( const wxString& aFileName )
{
bool result = false;
if( ( GetFileAttributesW( aFileName.fn_str() ) & FILE_ATTRIBUTE_HIDDEN ) )
result = true;
return result;
}

View File

@ -23,6 +23,7 @@
#include <wx/crt.h>
#include <wx/string.h>
#include <wx/filename.h>
FILE* KIPLATFORM::IO::SeqFOpen( const wxString& aPath, const wxString& aMode )
{
@ -62,4 +63,11 @@ bool KIPLATFORM::IO::DuplicatePermissions(const wxString& sourceFilePath, const
NSLog(@"Error assigning permissions: %@", error);
return false;
}
}
}
bool KIPLATFORM::IO::IsFileHidden( const wxString& aFileName )
{
wxFileName fn( aFileName );
return fn.GetName().StartsWith( wxT( "." ) );
}