[ 1521481 ] wxPathList modernization
Applied part II. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41269 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -19,7 +19,7 @@ to extract the filename from the path.
|
||||
|
||||
\wxheading{See also}
|
||||
|
||||
\helpref{wxArrayString}{wxarraystring}
|
||||
\helpref{wxArrayString}{wxarraystring}, \helpref{wxStandardPaths}{wxstandardpaths}, \helpref{wxFileName}{wxfilename}
|
||||
|
||||
\latexignore{\rtfignore{\wxheading{Members}}}
|
||||
|
||||
@@ -50,11 +50,16 @@ example.
|
||||
|
||||
\func{void}{Add}{\param{const wxArrayString\& }{arr}}
|
||||
|
||||
The first form adds the given directory (the filename if present is removed)
|
||||
to the path list, if the path is not already in the list.
|
||||
|
||||
The first form adds the given directory to the path list, if the path is not already in the list.
|
||||
The second form just calls the first form on all elements of the given array.
|
||||
|
||||
The {\it path} is always considered a directory but no existence checks will be done on it
|
||||
(because if it doesn't exist, it could be created later and thus result a valid path when
|
||||
\helpref{FindValidPath}{wxpathlistfindvalidpath} is called).
|
||||
|
||||
{\bf Note:} if the given path is relative, it won't be made absolute before adding it
|
||||
(this is why \helpref{FindValidPath}{wxpathlistfindvalidpath} may return relative paths).
|
||||
|
||||
|
||||
\membersection{wxPathList::EnsureFileAccessible}\label{wxpathlistensurefileaccessible}
|
||||
|
||||
@@ -69,7 +74,7 @@ filename and adding the path to the list if not already there.
|
||||
|
||||
\constfunc{wxString}{FindAbsoluteValidPath}{\param{const wxString\& }{file}}
|
||||
|
||||
Searches for a full path for an existing file by appending {\it file} to
|
||||
Searches for a full (i.e. absolute) path for an existing file by appending {\it file} to
|
||||
successive members of the path list. If the file wasn't found, an empty
|
||||
string is returned.
|
||||
|
||||
@@ -78,7 +83,13 @@ string is returned.
|
||||
|
||||
\constfunc{wxString}{FindValidPath}{\param{const wxString\& }{file}}
|
||||
|
||||
Searches for a full path for an existing file by appending {\it file} to
|
||||
successive members of the path list. If the file wasn't found, an empty string
|
||||
is returned. This path may be relative to the current working directory.
|
||||
Searches for a path for an existing file by appending {\it file} to
|
||||
successive members of the path list.
|
||||
If the file wasn't found, an empty string is returned.
|
||||
|
||||
The returned path may be relative to the current working directory.
|
||||
|
||||
The given string must be a file name, eventually with a path prefix (if the path
|
||||
prefix is absolute, only its name will be searched); i.e. it must not end with
|
||||
a directory separator (see \helpref{wxFileName::GetPathSeparator}{wxfilenamegetpathseparator})
|
||||
otherwise an assertion will fail.
|
||||
|
@@ -146,11 +146,15 @@ WXDLLEXPORT int wxOpen( const wxChar *pathname, int flags, mode_t mode )
|
||||
// wxPathList
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxPathList::Add (const wxString& path)
|
||||
void wxPathList::Add(const wxString& path)
|
||||
{
|
||||
// add only the path part of the given string (not the filename, in case it's present)
|
||||
// add a path separator to force wxFileName to interpret it always as a directory
|
||||
// (i.e. if we are called with '/home/user' we want to consider it a folder and
|
||||
// not, as wxFileName would consider, a filename).
|
||||
wxFileName fn(path + wxFileName::GetPathSeparator());
|
||||
fn.Normalize(); // add only normalized paths
|
||||
|
||||
// add only normalized relative/absolute paths
|
||||
fn.Normalize(wxPATH_NORM_DOTS|wxPATH_NORM_TILDE|wxPATH_NORM_LONG|wxPATH_NORM_ENV_VARS);
|
||||
|
||||
wxString toadd = fn.GetPath();
|
||||
if (Index(toadd) == wxNOT_FOUND)
|
||||
@@ -211,12 +215,17 @@ bool wxPathList::Member (const wxString& path) const
|
||||
|
||||
wxString wxPathList::FindValidPath (const wxString& file) const
|
||||
{
|
||||
// normalize the given string as it could be a path + a filename
|
||||
// and not only a filename
|
||||
wxFileName fn(file);
|
||||
wxString strend;
|
||||
|
||||
fn.Normalize();
|
||||
// NB: normalize without making absolute !
|
||||
fn.Normalize(wxPATH_NORM_DOTS|wxPATH_NORM_TILDE|wxPATH_NORM_LONG|wxPATH_NORM_ENV_VARS);
|
||||
|
||||
wxASSERT_MSG(!fn.IsDir(), wxT("Cannot search for directories; only for files"));
|
||||
if (fn.IsAbsolute())
|
||||
strend = fn.GetFullName();
|
||||
strend = fn.GetFullName(); // search for the file name and ignore the path part
|
||||
else
|
||||
strend = fn.GetFullPath();
|
||||
|
||||
|
Reference in New Issue
Block a user