Audacity  3.0.3
SelectFile.cpp
Go to the documentation of this file.
1 /*!********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  @file SelectFile.cpp
6 
7  Paul Licameli split from FileNames.cpp
8 
9  **********************************************************************/
10 
11 #include "SelectFile.h"
12 #include "FileNames.h"
15 
18  const TranslatableString& message,
19  const FilePath& default_path,
20  const FilePath& default_filename,
21  const FileExtension& default_extension,
22  const FileTypes& fileTypes,
23  int flags,
24  wxWindow *parent)
25 {
26  return WithDefaultPath(op, default_path, [&](const FilePath &path) {
27  wxString filter;
28  if ( !default_extension.empty() )
29  filter = wxT("*.") + default_extension;
30  return FileSelector(
31  message.Translation(), path, default_filename, filter,
32  FormatWildcard( fileTypes ),
33  flags, parent, wxDefaultCoord, wxDefaultCoord);
34  });
35 }
36 
37 #if defined(__WXMSW__)
38 static wxCharBuffer mFilename;
39 
40 //
41 // On Windows, wxString::mb_str() can return a NULL pointer if the
42 // conversion to multi-byte fails. So, based on direction intent,
43 // returns a pointer to an empty string or prompts for a NEW name.
44 //
45 char *VerifyFilename(const wxString &s, bool input)
46 {
47  static wxCharBuffer buf;
48  wxString name = s;
49 
50  if (input) {
51  if ((char *) (const char *)name.mb_str() == NULL) {
52  name = wxEmptyString;
53  }
54  }
55  else {
56  wxFileName ff(name);
57  FileExtension ext;
58  while ((char *) (const char *)name.mb_str() == NULL) {
60  XO(
61 "The specified filename could not be converted due to Unicode character use."));
62 
63  ext = ff.GetExt();
64  name = SelectFile(FileNames::Operation::_None,
65  XO("Specify New Filename:"),
66  wxEmptyString,
67  name,
68  ext,
69  { ext.empty()
71  : FileNames::FileType{ {}, { ext } }
72  },
73  wxFD_SAVE | wxRESIZE_BORDER,
74  wxGetTopLevelParent(NULL));
75  }
76  }
77 
78  mFilename = name.mb_str();
79 
80  return (char *) (const char *) mFilename;
81 }
82 #endif
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
FileSelector
wxString FileSelector(const wxString &title, const wxString &defaultDir, const wxString &defaultFileName, const wxString &defaultExtension, const wxString &filter, int flags, wxWindow *parent, int x, int y)
Definition: FileDialog.cpp:61
TranslatableString::empty
bool empty() const
Definition: TranslatableString.h:72
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
Definition: AudacityMessageBox.cpp:17
SelectFile
FilePath SelectFile(FileNames::Operation op, const TranslatableString &message, const FilePath &default_path, const FilePath &default_filename, const FileExtension &default_extension, const FileTypes &fileTypes, int flags, wxWindow *parent)
Definition: SelectFile.cpp:17
XO
#define XO(s)
Definition: Internat.h:31
FileNames::AllFiles
FILES_API const FileType AllFiles
Definition: FileNames.h:71
FileNames::WithDefaultPath
FilePath WithDefaultPath(Operation op, const FilePath &defaultPath, F function)
Definition: FileNames.h:185
FileExtension
wxString FileExtension
File extension, not including any leading dot.
Definition: Identifier.h:224
FilePath
wxString FilePath
Definition: Project.h:20
FileTypes
std::vector< FileNames::FileType > FileTypes
Definition: SelectFile.h:23
FileDialog.h
name
const TranslatableString name
Definition: Distortion.cpp:98
SelectFile.h
FileNames.h
AudacityMessageBox.h
TranslatableString::Translation
wxString Translation() const
Definition: TranslatableString.h:79
FileNames::FormatWildcard
FILES_API wxString FormatWildcard(const FileTypes &fileTypes)
FileNames::FileType
Definition: FileNames.h:52
FileNames::Operation
Operation
Definition: FileNames.h:154