From bc6493120ea7b8e8fc84e95dd8942e4838ef3224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Sat, 17 Oct 2015 01:59:12 +0000 Subject: [PATCH] [INTERPRETER] * NEW: File.IsHidden() is a new static method that returns if a path is hidden, i.e. if its filename or one of its directory components starts with a dot. [GB.FORM] * NEW: Setting an hidden path to a DirChooser or FileChooser automatically toggles the ShowHidden property if needed. git-svn-id: svn://localhost/gambas/trunk@7414 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- .../.src/File/Chooser/FDirChooser.class | 3 +++ main/gbx/gbx_c_file.c | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/comp/src/gb.form/.src/File/Chooser/FDirChooser.class b/comp/src/gb.form/.src/File/Chooser/FDirChooser.class index a24eda2d4..e9ef94719 100644 --- a/comp/src/gb.form/.src/File/Chooser/FDirChooser.class +++ b/comp/src/gb.form/.src/File/Chooser/FDirChooser.class @@ -425,6 +425,9 @@ Public Sub SetPath(sPath As String) Dim sMsg As String If Not IsDir(File.Dir(sPath)) Then sMsg = ("Directory not found.") + + If File.IsHidden(sPath) Then SetShowHidden(True) + SetDir(File.Dir(sPath)) If Not GetMulti() Then diff --git a/main/gbx/gbx_c_file.c b/main/gbx/gbx_c_file.c index 9e92ca4d6..82bf56209 100644 --- a/main/gbx/gbx_c_file.c +++ b/main/gbx/gbx_c_file.c @@ -673,6 +673,25 @@ BEGIN_METHOD(File_IsRelative, GB_STRING path) END_METHOD +BEGIN_METHOD(File_IsHidden, GB_STRING path) + + char *path = STRING(path); + int len = LENGTH(path); + int i; + + for (i = 0; i < len; i++) + { + if (path[i] == '.' && (i == 0 || path[i - 1] == '/')) + { + GB_ReturnBoolean(TRUE); + return; + } + } + + GB_ReturnBoolean(FALSE); + +END_METHOD + //--------------------------------------------------------------------------- BEGIN_PROPERTY(Stream_Handle) @@ -910,6 +929,7 @@ GB_DESC NATIVE_File[] = GB_STATIC_METHOD("SetBaseName", "s", File_SetBaseName, "(Path)s(NewBaseName)s"), GB_STATIC_METHOD("IsRelative", "b", File_IsRelative, "(Path)s"), + GB_STATIC_METHOD("IsHidden", "b", File_IsHidden, "(Path)s"), GB_STATIC_METHOD("Load", "s", File_Load, "(FileName)s"), GB_STATIC_METHOD("Save", NULL, File_Save, "(FileName)s(Data)s"),