MCPcopy Create free account
hub / github.com/audacity/audacity / ValidateAndFixExt

Method ValidateAndFixExt

src/export/ExportFilePanel.cpp:364–407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

362}
363
364void ExportFilePanel::ValidateAndFixExt()
365{
366 if(mSelectedPlugin == nullptr)
367 return;
368
369 const auto formatInfo = mSelectedPlugin->GetFormatInfo(mSelectedFormatIndex);
370 if(formatInfo.extensions.empty())
371 return;
372
373 wxFileName filename;
374 filename.SetFullName(mFullName->GetValue());
375 const auto desiredExt = filename.GetExt().Trim();
376
377 //See https://github.com/audacity/audacity/issues/5823
378 //check if extension is valid, i.e. does not contain whitespace characters.
379 //Otherwise everything after '.'(if present) is considered to be a part of name.
380 if(wxRegEx{R"(^[^ ]+$)"}.Matches(desiredExt))
381 {
382 auto it = std::find_if(
383 formatInfo.extensions.begin(),
384 formatInfo.extensions.end(),
385 // if typed extension uses different case (e.g. MP3 instead of mp3)
386 // we'll reset the file extension to one provided by FormatInfo
387 [&](const auto& ext) { return desiredExt.IsSameAs(ext, false); });
388
389 if(it == formatInfo.extensions.end())
390 it = formatInfo.extensions.begin();
391
392 if(!it->empty() && !it->IsSameAs(filename.GetExt()))
393 {
394 filename.SetExt(*it);
395 mFullName->SetValue(filename.GetFullName());
396 }
397 }
398 else if(!formatInfo.extensions.front().empty())
399 {
400 auto fullname = filename.GetFullName();
401 if(!fullname.EndsWith("."))
402 fullname.Append(".");
403 fullname.Append(formatInfo.extensions.front());
404 filename.SetFullName(fullname);
405 mFullName->SetValue(filename.GetFullName());
406 }
407}
408
409void ExportFilePanel::OnFullNameFocusKill(wxFocusEvent& event)
410{

Callers

nothing calls this directly

Calls 11

MatchesMethod · 0.80
GetFullNameMethod · 0.80
GetFormatInfoMethod · 0.45
emptyMethod · 0.45
GetValueMethod · 0.45
TrimMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
IsSameAsMethod · 0.45
SetValueMethod · 0.45
AppendMethod · 0.45

Tested by

no test coverage detected