From: Vadim Zeitlin Date: Mon, 8 Apr 2002 16:15:43 +0000 (+0000) Subject: added GetPath(flags) version to allow retrieving the volume as well X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/33b97389e59de9b2acd902a334c08976c7d83d44 added GetPath(flags) version to allow retrieving the volume as well git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15032 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/latex/wx/filename.tex b/docs/latex/wx/filename.tex index 4c50db430f..8bc66c81c0 100644 --- a/docs/latex/wx/filename.tex +++ b/docs/latex/wx/filename.tex @@ -374,17 +374,45 @@ convenience wrapper: get just the last mod time of the file \membersection{wxFileName::GetPath}\label{wxfilenamegetpath} -\constfunc{wxString}{GetPath}{\param{bool }{add\_separator = FALSE}, \param{wxPathFormat }{format = wxPATH\_NATIVE}} +\constfunc{wxString}{GetPath}{\param{int }{flags = $0$}, \param{wxPathFormat }{format = wxPATH\_NATIVE}} -Construct path only - possibly with the trailing separator +Return the path part of the filename (without the name nor extension). The +possible flags values are: +\twocolwidtha{5cm}% +\begin{twocollist}\itemsep=0pt +\twocolitem{\tt wxPATH\_GET\_VOLUME}{Return the path with the volume (does +nothing for the filename formats without volumes)} +\twocolitem{\tt wxPATH\_GET\_SEPARATOR}{Return the path with the trailing +separator, if this flag is not given there will be no separator at the end of +the path.} +\end{twocollist} + +\membersection{wxFileName::GetPathSeparator}\label{wxfilenamegetpathseparator} + +\func{wxChar}{GetPathSeparator}{\param{wxPathFormat }{format = wxPATH\_NATIVE}} + +Return the usually used path separator for this format. For all formats but +{\tt wxPATH\_DOS} there is only one path separator anyhow, but for DOS there +are two of them and the native one, i.e. the backslash is returned by this +method. + +\wxheading{See also} + +\helpref{GetPathSeparators}{wxfilenamegetpathseparators} \membersection{wxFileName::GetPathSeparators}\label{wxfilenamegetpathseparators} \func{wxString}{GetPathSeparators}{\param{wxPathFormat }{format = wxPATH\_NATIVE}} -get the string of path separators for this format +Get the string containing all the path separators for this format. For all +formats but {\tt wxPATH\_DOS} this string contains only one character but for +DOS and Windows both {\tt '/'} and {\tt '\backslash'} may be used as +separators. + +\wxheading{See also} +\helpref{GetPathSeparator}{wxfilenamegetpathseparator} \membersection{wxFileName::GetPathWithSep}\label{wxfilenamegetpathwithsep} diff --git a/include/wx/filename.h b/include/wx/filename.h index 9768a87395..646e239303 100644 --- a/include/wx/filename.h +++ b/include/wx/filename.h @@ -73,6 +73,13 @@ enum wxPathNormalize wxPATH_NORM_ALL = 0x003f }; +// what exactly should GetPath() return? +enum +{ + wxPATH_GET_VOLUME = 0x0001, // include the volume if applicable + wxPATH_GET_SEPARATOR = 0x0002 // terminate the path with the separator +}; + // ---------------------------------------------------------------------------- // wxFileName: encapsulates a file path // ---------------------------------------------------------------------------- @@ -322,16 +329,12 @@ public: const wxArrayString& GetDirs() const { return m_dirs; } - // Construct path only - possibly with the trailing separator - wxString GetPath( bool add_separator = FALSE, - wxPathFormat format = wxPATH_NATIVE ) const; + // flags are combination of wxPATH_GET_XXX flags + wxString GetPath(int flags = 0, wxPathFormat format = wxPATH_NATIVE) const; + // Replace current path with this one void SetPath( const wxString &path, wxPathFormat format = wxPATH_NATIVE ); - // more readable synonym - wxString GetPathWithSep(wxPathFormat format = wxPATH_NATIVE ) const - { return GetPath(TRUE /* add separator */, format); } - // Construct full path with name and ext wxString GetFullPath( wxPathFormat format = wxPATH_NATIVE ) const; @@ -365,6 +368,16 @@ public: wxString *ext, wxPathFormat format = wxPATH_NATIVE); + + // deprecated methods, don't use any more + // -------------------------------------- + + wxString GetPath( bool withSep, wxPathFormat format = wxPATH_NATIVE ) const + { return GetPath(withSep ? wxPATH_GET_SEPARATOR : 0, format); } + + wxString GetPathWithSep(wxPathFormat format = wxPATH_NATIVE ) const + { return GetPath(wxPATH_GET_SEPARATOR, format); } + private: // the drive/volume/device specification (always empty for Unix) wxString m_volume; diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 15179463a4..7a5340f90d 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -392,7 +392,7 @@ void wxFileName::Assign(const wxString& fullpathOrig, wxString fullpath = fullpathOrig; if ( !wxEndsWithPathSeparator(fullpath) ) { - fullpath += GetPathSeparators(format)[0u]; + fullpath += GetPathSeparator(format); } wxString volume, path, name, ext; @@ -1128,26 +1128,33 @@ wxString wxFileName::GetFullName() const return fullname; } -wxString wxFileName::GetPath( bool add_separator, wxPathFormat format ) const +wxString wxFileName::GetPath( int flags, wxPathFormat format ) const { format = GetFormat( format ); wxString fullpath; + // return the volume with the path as well if requested + if ( flags & wxPATH_GET_VOLUME ) + { + fullpath += wxGetVolumeString(GetVolume(), format); + } + // the leading character - if ( format == wxPATH_MAC && m_relative ) + if ( format == wxPATH_MAC ) { - fullpath += wxFILE_SEP_PATH_MAC; + if ( m_relative ) + fullpath += wxFILE_SEP_PATH_MAC; } else if ( format == wxPATH_DOS ) { - if (!m_relative) - fullpath += wxFILE_SEP_PATH_DOS; + if (!m_relative) + fullpath += wxFILE_SEP_PATH_DOS; } else if ( format == wxPATH_UNIX ) { - if (!m_relative) - fullpath += wxFILE_SEP_PATH_UNIX; + if (!m_relative) + fullpath += wxFILE_SEP_PATH_UNIX; } // then concatenate all the path components using the path separator @@ -1159,7 +1166,6 @@ wxString wxFileName::GetPath( bool add_separator, wxPathFormat format ) const fullpath += wxT('['); } - for ( size_t i = 0; i < dirCount; i++ ) { // TODO: What to do with ".." under VMS @@ -1205,9 +1211,9 @@ wxString wxFileName::GetPath( bool add_separator, wxPathFormat format ) const } } - if ( add_separator && !fullpath.empty() ) + if ( (flags & wxPATH_GET_SEPARATOR) && !fullpath.empty() ) { - fullpath += GetPathSeparators(format)[0u]; + fullpath += GetPathSeparator(format); } return fullpath;