From 2db991f4576e7b08e4aa877c6350cca9656a60cc Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Fri, 5 Apr 2002 11:14:09 +0000
Subject: [PATCH] minor fix to wxFileName::MakeRelativeTo(), removed broken and
 misleading IsWild() method, added IsDir() one

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14948 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/filename.tex  | 13 ++++++++-----
 include/wx/filename.h       |  6 +++---
 samples/console/console.cpp | 11 ++++++++---
 src/common/filename.cpp     | 18 +++++++++++-------
 4 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/docs/latex/wx/filename.tex b/docs/latex/wx/filename.tex
index 2e2b4ce538..4c50db430f 100644
--- a/docs/latex/wx/filename.tex
+++ b/docs/latex/wx/filename.tex
@@ -94,8 +94,7 @@ does.
 
 Other functions returning information about the file format provided by this
 class are \helpref{GetVolumeSeparator}{wxfilenamegetvolumeseparator},\rtfsp
-\helpref{IsPathSeparator}{wxfilenameispathseparator} and\rtfsp
-\helpref{IsWild}{wxfilenameiswild}.
+\helpref{IsPathSeparator}{wxfilenameispathseparator}.
 
 \helpref{IsRelative}{wxfilenameisrelative}
 
@@ -477,11 +476,15 @@ Returns {\tt TRUE} if the char is a path separator for this format.
 
 Returns {\tt TRUE} if this filename is not absolute.
 
-\membersection{wxFileName::IsWild}\label{wxfilenameiswild}
+\membersection{wxFileName::IsDir}\label{wxfilenameisdir}
 
-\func{bool}{IsWild}{\param{wxPathFormat }{format = wxPATH\_NATIVE}}
+\constfunc{bool}{IsDir}{\void}
 
-FIXME: what exactly does this do?
+Returns {\tt TRUE} if this object represents a directory, {\tt FALSE} otherwise
+(i.e. if it is a file). Note that this method doesn't test whether the
+directory or file really exists, you should use 
+\helpref{DirExists}{wxfilenamedirexists} or 
+\helpref{FileExists}{wxfilenamefileexists} for this.
 
 \membersection{wxFileName::MakeRelativeTo}\label{wxfilenamemakerelativeto}
 
diff --git a/include/wx/filename.h b/include/wx/filename.h
index 9553b4c0e8..9768a87395 100644
--- a/include/wx/filename.h
+++ b/include/wx/filename.h
@@ -296,9 +296,6 @@ public:
     // is the char a path separator for this format?
     static bool IsPathSeparator(wxChar ch, wxPathFormat format = wxPATH_NATIVE);
 
-    // FIXME: what exactly does this do?
-    bool IsWild( wxPathFormat format = wxPATH_NATIVE );
-
     // Dir accessors
     void AppendDir( const wxString &dir );
     void PrependDir( const wxString &dir );
@@ -344,6 +341,9 @@ public:
     // Return the long form of the path (returns identity on non-Windows platforms)
     wxString GetLongPath() const;
 
+    // Is this a file or directory (not necessarily an existing one)
+    bool IsDir() const { return m_name.empty() && m_ext.empty(); }
+
     // various helpers
 
         // get the canonical path format for this platform
diff --git a/samples/console/console.cpp b/samples/console/console.cpp
index 518f525f3c..53990de434 100644
--- a/samples/console/console.cpp
+++ b/samples/console/console.cpp
@@ -91,7 +91,7 @@
     #undef TEST_ALL
     static const bool TEST_ALL = TRUE;
 #else
-    #define TEST_THREADS
+    #define TEST_FILENAME
 
     static const bool TEST_ALL = FALSE;
 #endif
@@ -802,7 +802,7 @@ static struct FileNameInfo
     { _T("c:\\Windows\\command.com"), _T("c"), _T("\\Windows"), _T("command"), _T("com"), TRUE, wxPATH_DOS },
     { _T("\\\\server\\foo.bar"), _T("server"), _T("\\"), _T("foo"), _T("bar"), TRUE, wxPATH_DOS },
 
-    // wxFileName support for Mac file names is broken crurently
+    // wxFileName support for Mac file names is broken currently
 #if 0
     // Mac file names
     { _T("Volume:Dir:File"), _T("Volume"), _T("Dir"), _T("File"), _T(""), TRUE, wxPATH_MAC },
@@ -900,7 +900,12 @@ static void TestFileNameTemp()
     for ( size_t n = 0; n < WXSIZEOF(tmpprefixes); n++ )
     {
         wxString path = wxFileName::CreateTempFileName(tmpprefixes[n]);
-        if ( !path.empty() )
+        if ( path.empty() )
+        {
+            // "error" is not in upper case because it may be ok
+            printf("Prefix '%s'\t-> error\n", tmpprefixes[n]);
+        }
+        else
         {
             printf("Prefix '%s'\t-> temp file '%s'\n",
                    tmpprefixes[n], path.c_str());
diff --git a/src/common/filename.cpp b/src/common/filename.cpp
index bc37751bbf..486f75b109 100644
--- a/src/common/filename.cpp
+++ b/src/common/filename.cpp
@@ -955,6 +955,17 @@ bool wxFileName::MakeRelativeTo(const wxString& pathBase, wxPathFormat format)
         m_dirs.Insert(wxT(".."), 0u);
     }
 
+    if ( format == wxPATH_UNIX || format == wxPATH_DOS )
+    {
+        // a directory made relative with respect to itself is '.' under Unix
+        // and DOS, by definition (but we don't have to insert "./" for the
+        // files)
+        if ( m_dirs.IsEmpty() && IsDir() )
+        {
+            m_dirs.Add(_T('.'));
+        }   
+    }
+
     m_relative = TRUE;
 
     // we were modified
@@ -1048,13 +1059,6 @@ bool wxFileName::IsPathSeparator(wxChar ch, wxPathFormat format)
     return GetPathSeparators(format).Find(ch) != wxNOT_FOUND;
 }
 
-bool wxFileName::IsWild( wxPathFormat WXUNUSED(format) )
-{
-    // FIXME: this is probably false for Mac and this is surely wrong for most
-    //        of Unix shells (think about "[...]")
-    return m_name.find_first_of(_T("*?")) != wxString::npos;
-}
-
 // ----------------------------------------------------------------------------
 // path components manipulation
 // ----------------------------------------------------------------------------
-- 
2.50.0

