Audacity 3.2.0
Functions
FileDialog.cpp File Reference
#include "FileDialog.h"
Include dependency graph for FileDialog.cpp:

Go to the source code of this file.

Functions

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)
 
wxString FileSelectorEx (const wxString &title, const wxString &defaultDir, const wxString &defaultFileName, int *defaultFilterIndex, const wxString &filter, int flags, wxWindow *parent, int x, int y)
 

Function Documentation

◆ 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 at line 61 of file FileDialog.cpp.

69{
70 // The defaultExtension, if non-empty, is
71 // appended to the filename if the user fails to type an extension. The new
72 // implementation (taken from FileSelectorEx) appends the extension
73 // automatically, by looking at the filter specification. In fact this
74 // should be better than the native Microsoft implementation because
75 // Windows only allows *one* default extension, whereas here we do the
76 // right thing depending on the filter the user has chosen.
77
78 // If there's a default extension specified but no filter, we create a
79 // suitable filter.
80
81 wxString filter2;
82 if ( !defaultExtension.empty() && filter.empty() )
83 filter2 = wxString(wxT("*.")) + defaultExtension;
84 else if ( !filter.empty() )
85 filter2 = filter;
86
87 FileDialog fileDialog(parent, title, defaultDir,
88 defaultFileName, filter2,
89 flags, wxPoint(x, y));
90
91 // if filter is of form "All files (*)|*|..." set correct filter index
92 if ( !defaultExtension.empty() && filter2.find(wxT('|')) != wxString::npos )
93 {
94 int filterIndex = 0;
95
96 wxArrayString descriptions, filters;
97 // don't care about errors, handled already by FileDialog
98 (void)wxParseCommonDialogsFilter(filter2, descriptions, filters);
99 for (size_t n=0; n<filters.GetCount(); n++)
100 {
101 if (filters[n].Contains(defaultExtension))
102 {
103 filterIndex = n;
104 break;
105 }
106 }
107
108 if (filterIndex > 0)
109 fileDialog.SetFilterIndex(filterIndex);
110 }
111
112 wxString filename;
113 if ( fileDialog.ShowModal() == wxID_OK )
114 {
115 filename = fileDialog.GetPath();
116 }
117
118 return filename;
119}
wxT("CloseDown"))
static const auto title
Dialog used to present platform specific "Save As" dialog with custom controls.

References FileDialog::GetPath(), FileDialog::SetFilterIndex(), FileDialog::ShowModal(), title, and wxT().

Referenced by SelectFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FileSelectorEx()

wxString FileSelectorEx ( const wxString &  title,
const wxString &  defaultDir,
const wxString &  defaultFileName,
int *  defaultFilterIndex,
const wxString &  filter,
int  flags,
wxWindow *  parent,
int  x,
int  y 
)

Definition at line 125 of file FileDialog.cpp.

135{
136 FileDialog fileDialog(parent,
137 title,
138 defaultDir,
139 defaultFileName,
140 filter,
141 flags, wxPoint(x, y));
142
143 wxString filename;
144 if ( fileDialog.ShowModal() == wxID_OK )
145 {
146 if ( defaultFilterIndex )
147 *defaultFilterIndex = fileDialog.GetFilterIndex();
148
149 filename = fileDialog.GetPath();
150 }
151
152 return filename;
153}

References FileDialog::GetFilterIndex(), FileDialog::GetPath(), FileDialog::ShowModal(), and title.

Here is the call graph for this function: