diff --git a/src/BatchProcessDialog.cpp b/src/BatchProcessDialog.cpp index 129238766..99a2bca8a 100644 --- a/src/BatchProcessDialog.cpp +++ b/src/BatchProcessDialog.cpp @@ -65,18 +65,19 @@ BEGIN_EVENT_TABLE(BatchProcessDialog, wxDialogWrapper) EVT_BUTTON(wxID_CANCEL, BatchProcessDialog::OnCancel) END_EVENT_TABLE() -BatchProcessDialog::BatchProcessDialog(wxWindow * parent): +BatchProcessDialog::BatchProcessDialog(wxWindow * parent, bool bInherited): wxDialogWrapper(parent, wxID_ANY, _("Apply Chain"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { //AudacityProject * p = GetActiveProject(); - + mAbort = false; + if( bInherited ) + return; SetLabel(_("Apply Chain")); // Provide visual label SetName(_("Apply Chain")); // Provide audible label Populate(); - mAbort = false; } BatchProcessDialog::~BatchProcessDialog() @@ -422,21 +423,25 @@ void BatchProcessDialog::OnCancel(wxCommandEvent & WXUNUSED(event)) #include "BatchCommandDialog.h" enum { -// ChainsListID 7005 AddButtonID = 10000, RemoveButtonID, -// CommandsListID, 7002 ImportButtonID, ExportButtonID, DefaultsButtonID, InsertButtonID, + EditButtonID, DeleteButtonID, UpButtonID, DownButtonID, - RenameButtonID + RenameButtonID, +// ChainsListID 7005 +// CommandsListID, 7002 +// Re-Use IDs from BatchProcessDialog. + ApplyToProjectButtonID = ApplyToProjectID, + ApplyToFilesButtonID = ApplyToFilesID, }; -BEGIN_EVENT_TABLE(EditChainsDialog, wxDialogWrapper) +BEGIN_EVENT_TABLE(EditChainsDialog, BatchProcessDialog) EVT_LIST_ITEM_SELECTED(ChainsListID, EditChainsDialog::OnChainSelected) EVT_LIST_ITEM_SELECTED(CommandsListID, EditChainsDialog::OnListSelected) EVT_LIST_BEGIN_LABEL_EDIT(ChainsListID, EditChainsDialog::OnChainsBeginEdit) @@ -448,6 +453,7 @@ BEGIN_EVENT_TABLE(EditChainsDialog, wxDialogWrapper) EVT_LIST_ITEM_ACTIVATED(CommandsListID, EditChainsDialog::OnCommandActivated) EVT_BUTTON(InsertButtonID, EditChainsDialog::OnInsert) + EVT_BUTTON(EditButtonID, EditChainsDialog::OnEditCommandParams) EVT_BUTTON(DeleteButtonID, EditChainsDialog::OnDelete) EVT_BUTTON(UpButtonID, EditChainsDialog::OnUp) EVT_BUTTON(DownButtonID, EditChainsDialog::OnDown) @@ -468,12 +474,14 @@ enum { /// Constructor EditChainsDialog::EditChainsDialog(wxWindow * parent): - wxDialogWrapper(parent, wxID_ANY, _("Edit Chains"), - wxDefaultPosition, wxDefaultSize, - wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) + BatchProcessDialog(parent, true) +// , wxID_ANY, _("Edit Chains"), +// wxDefaultPosition, wxDefaultSize, +// wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { SetLabel(_("Edit Chains")); // Provide visual label SetName(_("Edit Chains")); // Provide audible label + SetTitle(_("Edit Chains")); mChanged = false; mSelectedCommand = 0; @@ -571,11 +579,25 @@ void EditChainsDialog::PopulateOrExchange(ShuttleGui & S) S.StartHorizontalLay(wxCENTER, false); { - S.Id(InsertButtonID).AddButton(_("&Insert"), wxALIGN_LEFT); - S.Id(DeleteButtonID).AddButton(_("De&lete"), wxALIGN_LEFT); - S.Id(UpButtonID).AddButton(_("Move &Up"), wxALIGN_LEFT); - S.Id(DownButtonID).AddButton(_("Move &Down"), wxALIGN_LEFT); - mDefaults = S.Id(DefaultsButtonID).AddButton(_("De&faults")); + S.AddPrompt( _("Command:") ); + S.StartHorizontalLay(wxCENTER, false); + { + S.Id(InsertButtonID).AddButton(_("&Insert"), wxALIGN_LEFT); + S.Id(EditButtonID).AddButton(_("&Edit"), wxALIGN_LEFT); + S.Id(DeleteButtonID).AddButton(_("De&lete"), wxALIGN_LEFT); + S.Id(UpButtonID).AddButton(_("Move &Up"), wxALIGN_LEFT); + S.Id(DownButtonID).AddButton(_("Move &Down"), wxALIGN_LEFT); + mDefaults = S.Id(DefaultsButtonID).AddButton(_("De&faults")); + } + S.EndHorizontalLay(); + S.AddSpace( 40 ); + S.AddPrompt( _("Apply Chain to:") ); + S.StartHorizontalLay(wxCENTER, false); + { + S.Id(ApplyToProjectButtonID).AddButton(_("&Project"), wxALIGN_LEFT); + S.Id(ApplyToFilesButtonID).AddButton(_("&Files"), wxALIGN_LEFT); + } + S.EndHorizontalLay(); } S.EndHorizontalLay(); } @@ -881,6 +903,10 @@ void EditChainsDialog::OnRename(wxCommandEvent & WXUNUSED(event)) /// Bring up a dialog to allow its parameters to be edited. void EditChainsDialog::OnCommandActivated(wxListEvent &event) { + wxCommandEvent dummy; + OnEditCommandParams( dummy ); + +#if 0 int item = event.GetIndex(); BatchCommandDialog d(this, wxID_ANY); @@ -901,6 +927,7 @@ void EditChainsDialog::OnCommandActivated(wxListEvent &event) mSelectedCommand = item; PopulateList(); +#endif } /// @@ -909,6 +936,14 @@ void EditChainsDialog::OnInsert(wxCommandEvent & WXUNUSED(event)) long item = mList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + if (item == -1) { + item = mList->GetItemCount()-1; + } + InsertCommandAt( item ); +} + +void EditChainsDialog::InsertCommandAt(int item) +{ if (item == -1) { return; } @@ -925,13 +960,42 @@ void EditChainsDialog::OnInsert(wxCommandEvent & WXUNUSED(event)) d.mSelectedParameters, item); mChanged = true; - mSelectedCommand = item + 1; - PopulateList(); } } +void EditChainsDialog::OnEditCommandParams(wxCommandEvent & WXUNUSED(event)) +{ + int item = mList->GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED ); + + // LAST command in list is END. + // If nothing selected, add at END. + // If END selected, add at END. + // When adding at end we use InsertCommandAt, so that a new command + // can be chosen. + int lastItem = mList->GetItemCount()-1; + if( (item<0) || (item+1) == mList->GetItemCount() ) + { + InsertCommandAt( lastItem ); + return; + } + + // Just edit the parameters, and not the command. + wxString command = mBatchCommands.GetCommand(item); + wxString params = mBatchCommands.GetParams(item); + + params = BatchCommands::PromptForParamsFor(command, params, this).Trim(); + + mBatchCommands.DeleteFromChain(item); + mBatchCommands.AddToChain(command, + params, + item); + mChanged = true; + mSelectedCommand = item; + PopulateList(); +} + /// void EditChainsDialog::OnDelete(wxCommandEvent & WXUNUSED(event)) { @@ -943,15 +1007,12 @@ void EditChainsDialog::OnDelete(wxCommandEvent & WXUNUSED(event)) } mBatchCommands.DeleteFromChain(item); - mChanged = true; if (item >= (mList->GetItemCount() - 2) && item >= 0) { item--; } - mSelectedCommand = item; - PopulateList(); } @@ -969,11 +1030,8 @@ void EditChainsDialog::OnUp(wxCommandEvent & WXUNUSED(event)) mBatchCommands.GetParams(item), item - 1); mBatchCommands.DeleteFromChain(item + 1); - mChanged = true; - mSelectedCommand = item - 1; - PopulateList(); } @@ -991,14 +1049,25 @@ void EditChainsDialog::OnDown(wxCommandEvent & WXUNUSED(event)) mBatchCommands.GetParams(item), item + 2); mBatchCommands.DeleteFromChain(item); - mChanged = true; - mSelectedCommand = item + 1; - PopulateList(); } +void EditChainsDialog::OnApplyToProject(wxCommandEvent & event) +{ + if( !SaveChanges() ) + return; + BatchProcessDialog::OnApplyToProject( event ); +} + +void EditChainsDialog::OnApplyToFiles(wxCommandEvent & event) +{ + if( !SaveChanges() ) + return; + BatchProcessDialog::OnApplyToFiles( event ); +} + /// Select the empty Command chain. void EditChainsDialog::OnDefaults(wxCommandEvent & WXUNUSED(event)) { @@ -1009,29 +1078,35 @@ void EditChainsDialog::OnDefaults(wxCommandEvent & WXUNUSED(event)) PopulateList(); } -/// Send changed values back to Prefs, and update Audacity. -void EditChainsDialog::OnOK(wxCommandEvent & WXUNUSED(event)) -{ +bool EditChainsDialog::SaveChanges(){ gPrefs->Write(wxT("/Batch/ActiveChain"), mActiveChain); gPrefs->Flush(); if (mChanged) { if (!mBatchCommands.WriteChain(mActiveChain)) { - return; + return false; } } + mChanged = false; + return true; +} +/// Send changed values back to Prefs, and update Audacity. +void EditChainsDialog::OnOK(wxCommandEvent & WXUNUSED(event)) +{ + if( !SaveChanges() ) + return; EndModal(true); } /// -void EditChainsDialog::OnCancel(wxCommandEvent & WXUNUSED(event)) +void EditChainsDialog::OnCancel(wxCommandEvent & event) { if (!ChangeOK()) { return; } - - EndModal(false); + BatchProcessDialog::OnCancel( event ); + //EndModal(false); } /// diff --git a/src/BatchProcessDialog.h b/src/BatchProcessDialog.h index a3441a557..5f9fce2ff 100644 --- a/src/BatchProcessDialog.h +++ b/src/BatchProcessDialog.h @@ -39,40 +39,45 @@ class wxButton; class wxTextCtrl; class ShuttleGui; -class BatchProcessDialog final : public wxDialogWrapper { +class BatchProcessDialog : public wxDialogWrapper { public: // constructors and destructors - BatchProcessDialog(wxWindow * parent); + BatchProcessDialog(wxWindow * parent, bool bInherited=false); virtual ~BatchProcessDialog(); public: - void Populate(); - void PopulateOrExchange( ShuttleGui & S ); + virtual void Populate(); + virtual void PopulateOrExchange( ShuttleGui & S ); + virtual void OnApplyToProject(wxCommandEvent & event); + virtual void OnApplyToFiles(wxCommandEvent & event); + virtual void OnCancel(wxCommandEvent & event); - void OnApplyToProject(wxCommandEvent & event); - void OnApplyToFiles(wxCommandEvent & event); - void OnCancel(wxCommandEvent & event); + // These will be reused in the derived class... + wxListCtrl *mList; + wxListCtrl *mChains; + BatchCommands mBatchCommands; /// Provides list of available commands. wxButton *mOK; wxButton *mCancel; - wxListCtrl *mChains; - wxListCtrl *mList; - BatchCommands mBatchCommands; wxTextCtrl *mResults; - bool mAbort; DECLARE_EVENT_TABLE() }; -class EditChainsDialog final : public wxDialogWrapper +class EditChainsDialog final : public BatchProcessDialog { public: EditChainsDialog(wxWindow * parent); ~EditChainsDialog(); private: - void Populate(); - void PopulateOrExchange(ShuttleGui &S); + void Populate() override; + void PopulateOrExchange(ShuttleGui &S) override; + void OnApplyToProject(wxCommandEvent & event) override; + void OnApplyToFiles(wxCommandEvent & event) override; + void OnCancel(wxCommandEvent &event) override; + + void PopulateChains(); void PopulateList(); void AddItem(const wxString &command, wxString const ¶ms); @@ -89,25 +94,33 @@ private: void OnCommandActivated(wxListEvent &event); void OnInsert(wxCommandEvent &event); + void OnEditCommandParams(wxCommandEvent &event); + void OnDelete(wxCommandEvent &event); void OnUp(wxCommandEvent &event); void OnDown(wxCommandEvent &event); void OnDefaults(wxCommandEvent &event); + //void OnApplyToProject(wxCommandEvent &event); + //void OnApplyToFiles(wxCommandEvent &event); + void OnOK(wxCommandEvent &event); - void OnCancel(wxCommandEvent &event); void OnKeyDown(wxKeyEvent &event); void FitColumns(); + void InsertCommandAt(int item); + bool SaveChanges(); + + // These are already provided by BatchProcessDialog + //wxListCtrl *mList; /// List of commands in current command chain. + //BatchCommands mBatchCommands; /// Provides list of available commands. + //wxListCtrl *mChains; /// List of chains. - wxListCtrl *mChains; /// List of chains. - wxListCtrl *mList; /// List of commands in current command chain. wxButton *mRemove; wxButton *mRename; wxButton *mDefaults; - BatchCommands mBatchCommands; /// Provides list of available commands. wxString mActiveChain; int mSelectedCommand;