From 650c1b69d38d7dad37de9bdc64285651d327a068 Mon Sep 17 00:00:00 2001 From: lllucius Date: Fri, 11 Mar 2011 15:23:35 +0000 Subject: [PATCH] Fixes bug #64 and increase the default number of history items remembered by the FileHistory class to 12 from 9. --- src/export/ExportCL.cpp | 91 ++++++++++++++++++++++++++++++++++----- src/widgets/FileHistory.h | 2 +- 2 files changed, 81 insertions(+), 12 deletions(-) diff --git a/src/export/ExportCL.cpp b/src/export/ExportCL.cpp index 9be35a55d..39a751b46 100644 --- a/src/export/ExportCL.cpp +++ b/src/export/ExportCL.cpp @@ -7,19 +7,20 @@ Joshua Haberman This code allows Audacity to export data by piping it to an external - program. Although it could in theory be made to work on Windows - (and perhaps even Mac), it's not worth it to invest the effort because - commandline encoders are rarely installed there. + program. **********************************************************************/ #include "../Audacity.h" #include +#include #include #include #include +#include + #include "Export.h" #include "../Project.h" @@ -27,6 +28,7 @@ #include "../Prefs.h" #include "../Internat.h" #include "../float_cast.h" +#include "../widgets/FileHistory.h" //---------------------------------------------------------------------------- // ExportCLOptions @@ -40,13 +42,20 @@ public: void PopulateOrExchange(ShuttleGui & S); void OnOK(wxCommandEvent & event); + void OnBrowse(wxCommandEvent & event); + private: + wxComboBox *mCmd; + FileHistory mHistory; DECLARE_EVENT_TABLE() }; +#define ID_BROWSE 5000 + BEGIN_EVENT_TABLE(ExportCLOptions, wxDialog) EVT_BUTTON(wxID_OK, ExportCLOptions::OnOK) + EVT_BUTTON(ID_BROWSE, ExportCLOptions::OnBrowse) END_EVENT_TABLE() /// @@ -55,6 +64,17 @@ ExportCLOptions::ExportCLOptions(wxWindow *parent) : wxDialog(parent, wxID_ANY, wxString(_("Specify Command Line Encoder"))) { + mHistory.Load(*gPrefs, wxT("/FileFormats/ExternalProgramHistory")); + + if (mHistory.GetCount() == 0) { + mHistory.AddFileToHistory(wxT("ffmpeg -i - \"%f\""), false); + mHistory.AddFileToHistory(wxT("lame - \"%f\""), false); + } + + mHistory.AddFileToHistory(gPrefs->Read(wxT("/FileFormats/ExternalProgramExportCommand"), + mHistory.GetHistoryFile(0)), + false); + ShuttleGui S(this, eIsCreatingFromPrefs); PopulateOrExchange(S); @@ -64,17 +84,26 @@ ExportCLOptions::ExportCLOptions(wxWindow *parent) /// void ExportCLOptions::PopulateOrExchange(ShuttleGui & S) { + wxArrayString cmds; + wxString cmd; + + for (size_t i = 0; i < mHistory.GetCount(); i++) { + cmds.Add(mHistory.GetHistoryFile(i)); + } + cmd = cmds[0]; + S.StartHorizontalLay(wxEXPAND, 0); { S.StartStatic(_("Command Line Export Setup"), true); { - S.StartMultiColumn(2, wxEXPAND); + S.StartMultiColumn(3, wxEXPAND); { S.SetStretchyCol(1); - S.TieTextBox(_("Command:"), - wxT("/FileFormats/ExternalProgramExportCommand"), - wxT("lame - \"%f\""), - 64); + mCmd = S.AddCombo(_("Command:"), + cmd, + &cmds); + S.Id(ID_BROWSE).AddButton(_("Browse..."), + wxALIGN_CENTER_VERTICAL); S.AddFixedText(wxT("")); S.TieCheckBox(_("Show output"), wxT("/FileFormats/ExternalProgramShowOutput"), @@ -82,7 +111,6 @@ void ExportCLOptions::PopulateOrExchange(ShuttleGui & S) } S.EndMultiColumn(); - S.AddFixedText(_("Data will be piped to standard in. \"%f\" uses the file name in the export window.")); } S.EndStatic(); @@ -104,13 +132,54 @@ void ExportCLOptions::PopulateOrExchange(ShuttleGui & S) void ExportCLOptions::OnOK(wxCommandEvent& event) { ShuttleGui S(this, eIsSavingToPrefs); + wxString cmd = mCmd->GetValue(); + + gPrefs->Write(wxT("/FileFormats/ExternalProgramExportCommand"), cmd); + PopulateOrExchange(S); + mHistory.AddFileToHistory(cmd, false); + mHistory.Save(*gPrefs, wxT("/FileFormats/ExternalProgramHistory")); + EndModal(wxID_OK); return; } +/// +/// +void ExportCLOptions::OnBrowse(wxCommandEvent& event) +{ + wxString path; + wxString ext; + +#if defined(__WXMSW__) + ext = wxT(".exe"); +#endif + + path = FileSelector(_("Find path to command"), + wxEmptyString, + wxEmptyString, + ext, + wxT("*") + ext, + wxFD_OPEN | wxRESIZE_BORDER, + this); + if (path.IsEmpty()) { + return; + } + + if (path.Find(wxT(' ')) == wxNOT_FOUND) { + mCmd->SetValue(path); + } + else { + mCmd->SetValue(wxT('"') + path + wxT('"')); + } + + mCmd->SetInsertionPointEnd(); + + return; +} + //---------------------------------------------------------------------------- // ExportCLProcess //---------------------------------------------------------------------------- @@ -359,7 +428,7 @@ int ExportCL::Export(AudacityProject *project, ProgressDialog *progress = new ProgressDialog(_("Export"), selectionOnly ? _("Exporting the selected audio using command-line encoder") : - _("Exporting the entire project using command-line encoder")); + _("Exporting the entire project using command-line encoder")); // Start piping the mixed data to the command while (updateResult == eProgressSuccess && p->IsActive() && os->IsOk()) { @@ -428,7 +497,7 @@ int ExportCL::Export(AudacityProject *project, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER); ShuttleGui S(&dlg, eIsCreating); - S.AddTextWindow(output); + S.AddTextWindow(cmd + wxT("\n\n") + output); S.StartHorizontalLay(wxALIGN_CENTER, false); { S.Id(wxID_OK).AddButton(_("&OK"))->SetDefault(); diff --git a/src/widgets/FileHistory.h b/src/widgets/FileHistory.h index ed618bb13..bb71b5a00 100644 --- a/src/widgets/FileHistory.h +++ b/src/widgets/FileHistory.h @@ -22,7 +22,7 @@ class AUDACITY_DLL_API FileHistory { public: - FileHistory(size_t maxfiles = 9, wxWindowID idbase = wxID_FILE); + FileHistory(size_t maxfiles = 12, wxWindowID idbase = wxID_FILE); virtual ~FileHistory(); void AddFileToHistory(const wxString & file, bool update = true);