From cf442759b41466b67ba73b7924b6da4f3ef13302 Mon Sep 17 00:00:00 2001 From: James Crook Date: Mon, 6 Aug 2018 15:56:56 +0100 Subject: [PATCH] Add AUDACITY_FILE_SUFFIX_EVENT to ExportPCM This signals a change in the file suffix, and it is received by the Exporter. However, there is currently no way to change the displayed filename in the file selection dialog. This was a step towards a fix for Bug 1355 - "Other uncompressed files" does not (visually) update target file extension according to the chosen "Header" type --- src/export/Export.cpp | 21 +++++++++++++++++++++ src/export/Export.h | 5 +++++ src/export/ExportPCM.cpp | 8 ++++++++ 3 files changed, 34 insertions(+) diff --git a/src/export/Export.cpp b/src/export/Export.cpp index 6fedd03df..2c10cf426 100644 --- a/src/export/Export.cpp +++ b/src/export/Export.cpp @@ -266,8 +266,12 @@ void ExportPlugin::InitProgress(std::unique_ptr &pDialog, // Export //---------------------------------------------------------------------------- + +wxDEFINE_EVENT(AUDACITY_FILE_SUFFIX_EVENT, wxCommandEvent); + BEGIN_EVENT_TABLE(Exporter, wxEvtHandler) EVT_FILECTRL_FILTERCHANGED(wxID_ANY, Exporter::OnFilterChanged) + EVT_COMMAND( wxID_ANY, AUDACITY_FILE_SUFFIX_EVENT, Exporter::OnExtensionChanged) END_EVENT_TABLE() Exporter::Exporter() @@ -305,6 +309,23 @@ Exporter::~Exporter() { } +// Beginnings of a fix for bug 1355. +// 'Other Uncompressed Files' Header option updates do not update +// the extension shown in the file dialog. +// Unfortunately, although we get the new extension here, we +// can't do anything with it as the FileDialog does not provide +// methods for setting its standard controls. +// We would need OS specific code that 'knows' about the system +// dialogs. +void Exporter::OnExtensionChanged(wxCommandEvent &Evt) { + wxString ext = Evt.GetString(); + ext = ext.BeforeFirst(' ').Lower(); + wxLogDebug("Extension changed to '.%s'", ext); +// wxString Name = mDialog->GetFilename(); +// Name = Name.BeforeLast('.')+ext; +// mDialog->SetFilename(Name); +} + void Exporter::SetFileDialogTitle( const wxString & DialogTitle ) { // The default title is "Export File" diff --git a/src/export/Export.h b/src/export/Export.h index 7b67a7225..7009e834a 100644 --- a/src/export/Export.h +++ b/src/export/Export.h @@ -152,6 +152,10 @@ WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxWindow *, WindowPtrArray, class AUDACITY_DLL //---------------------------------------------------------------------------- // Exporter //---------------------------------------------------------------------------- + +// For a file suffix change from the options. +wxDECLARE_EVENT(AUDACITY_FILE_SUFFIX_EVENT, wxCommandEvent); + class AUDACITY_DLL_API Exporter final : public wxEvtHandler { public: @@ -188,6 +192,7 @@ public: int GetAutoExportSubFormat(); int GetAutoExportFilterIndex(); wxFileName GetAutoExportFileName(); + void OnExtensionChanged(wxCommandEvent &Evt); private: bool ExamineTracks(); diff --git a/src/export/ExportPCM.cpp b/src/export/ExportPCM.cpp index 15abe06ff..73503e2b7 100644 --- a/src/export/ExportPCM.cpp +++ b/src/export/ExportPCM.cpp @@ -280,6 +280,14 @@ void ExportPCMOptions::OnHeaderChoice(wxCommandEvent & WXUNUSED(evt)) ValidatePair(GetFormat()); TransferDataFromWindow(); + + // Send the event indicating a file suffix change. + // We pass the entire header string, which starts with the suffix. + wxCommandEvent event(AUDACITY_FILE_SUFFIX_EVENT, GetId()); + event.SetEventObject(this); + event.SetString(mHeaderChoice->GetString(mHeaderChoice->GetSelection())); + ProcessWindowEvent(event); + } int ExportPCMOptions::GetFormat()