1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-16 09:31:14 +01:00

Add buttons to Edit Chains Dialog

- Added the Apply-to-Project and Apply-To-Files buttons
- Derived EditChainsDialog from BatchProcessDialog so as to share code.
- Added Edit button, for people who don't realise they can click on the list.
- Clicking on list now directly invokes the parameter editing.
- Insert and Edit now insert before --END-- if nothing was selected.
This commit is contained in:
James Crook
2018-03-01 17:54:08 +00:00
parent f01fed2ba2
commit f5929381ec
2 changed files with 139 additions and 51 deletions

View File

@@ -65,18 +65,19 @@ BEGIN_EVENT_TABLE(BatchProcessDialog, wxDialogWrapper)
EVT_BUTTON(wxID_CANCEL, BatchProcessDialog::OnCancel) EVT_BUTTON(wxID_CANCEL, BatchProcessDialog::OnCancel)
END_EVENT_TABLE() END_EVENT_TABLE()
BatchProcessDialog::BatchProcessDialog(wxWindow * parent): BatchProcessDialog::BatchProcessDialog(wxWindow * parent, bool bInherited):
wxDialogWrapper(parent, wxID_ANY, _("Apply Chain"), wxDialogWrapper(parent, wxID_ANY, _("Apply Chain"),
wxDefaultPosition, wxDefaultSize, wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{ {
//AudacityProject * p = GetActiveProject(); //AudacityProject * p = GetActiveProject();
mAbort = false;
if( bInherited )
return;
SetLabel(_("Apply Chain")); // Provide visual label SetLabel(_("Apply Chain")); // Provide visual label
SetName(_("Apply Chain")); // Provide audible label SetName(_("Apply Chain")); // Provide audible label
Populate(); Populate();
mAbort = false;
} }
BatchProcessDialog::~BatchProcessDialog() BatchProcessDialog::~BatchProcessDialog()
@@ -422,21 +423,25 @@ void BatchProcessDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
#include "BatchCommandDialog.h" #include "BatchCommandDialog.h"
enum { enum {
// ChainsListID 7005
AddButtonID = 10000, AddButtonID = 10000,
RemoveButtonID, RemoveButtonID,
// CommandsListID, 7002
ImportButtonID, ImportButtonID,
ExportButtonID, ExportButtonID,
DefaultsButtonID, DefaultsButtonID,
InsertButtonID, InsertButtonID,
EditButtonID,
DeleteButtonID, DeleteButtonID,
UpButtonID, UpButtonID,
DownButtonID, 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(ChainsListID, EditChainsDialog::OnChainSelected)
EVT_LIST_ITEM_SELECTED(CommandsListID, EditChainsDialog::OnListSelected) EVT_LIST_ITEM_SELECTED(CommandsListID, EditChainsDialog::OnListSelected)
EVT_LIST_BEGIN_LABEL_EDIT(ChainsListID, EditChainsDialog::OnChainsBeginEdit) 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_LIST_ITEM_ACTIVATED(CommandsListID, EditChainsDialog::OnCommandActivated)
EVT_BUTTON(InsertButtonID, EditChainsDialog::OnInsert) EVT_BUTTON(InsertButtonID, EditChainsDialog::OnInsert)
EVT_BUTTON(EditButtonID, EditChainsDialog::OnEditCommandParams)
EVT_BUTTON(DeleteButtonID, EditChainsDialog::OnDelete) EVT_BUTTON(DeleteButtonID, EditChainsDialog::OnDelete)
EVT_BUTTON(UpButtonID, EditChainsDialog::OnUp) EVT_BUTTON(UpButtonID, EditChainsDialog::OnUp)
EVT_BUTTON(DownButtonID, EditChainsDialog::OnDown) EVT_BUTTON(DownButtonID, EditChainsDialog::OnDown)
@@ -468,12 +474,14 @@ enum {
/// Constructor /// Constructor
EditChainsDialog::EditChainsDialog(wxWindow * parent): EditChainsDialog::EditChainsDialog(wxWindow * parent):
wxDialogWrapper(parent, wxID_ANY, _("Edit Chains"), BatchProcessDialog(parent, true)
wxDefaultPosition, wxDefaultSize, // , wxID_ANY, _("Edit Chains"),
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) // wxDefaultPosition, wxDefaultSize,
// wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{ {
SetLabel(_("Edit Chains")); // Provide visual label SetLabel(_("Edit Chains")); // Provide visual label
SetName(_("Edit Chains")); // Provide audible label SetName(_("Edit Chains")); // Provide audible label
SetTitle(_("Edit Chains"));
mChanged = false; mChanged = false;
mSelectedCommand = 0; mSelectedCommand = 0;
@@ -571,11 +579,25 @@ void EditChainsDialog::PopulateOrExchange(ShuttleGui & S)
S.StartHorizontalLay(wxCENTER, false); S.StartHorizontalLay(wxCENTER, false);
{ {
S.Id(InsertButtonID).AddButton(_("&Insert"), wxALIGN_LEFT); S.AddPrompt( _("Command:") );
S.Id(DeleteButtonID).AddButton(_("De&lete"), wxALIGN_LEFT); S.StartHorizontalLay(wxCENTER, false);
S.Id(UpButtonID).AddButton(_("Move &Up"), wxALIGN_LEFT); {
S.Id(DownButtonID).AddButton(_("Move &Down"), wxALIGN_LEFT); S.Id(InsertButtonID).AddButton(_("&Insert"), wxALIGN_LEFT);
mDefaults = S.Id(DefaultsButtonID).AddButton(_("De&faults")); 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(); S.EndHorizontalLay();
} }
@@ -881,6 +903,10 @@ void EditChainsDialog::OnRename(wxCommandEvent & WXUNUSED(event))
/// Bring up a dialog to allow its parameters to be edited. /// Bring up a dialog to allow its parameters to be edited.
void EditChainsDialog::OnCommandActivated(wxListEvent &event) void EditChainsDialog::OnCommandActivated(wxListEvent &event)
{ {
wxCommandEvent dummy;
OnEditCommandParams( dummy );
#if 0
int item = event.GetIndex(); int item = event.GetIndex();
BatchCommandDialog d(this, wxID_ANY); BatchCommandDialog d(this, wxID_ANY);
@@ -901,6 +927,7 @@ void EditChainsDialog::OnCommandActivated(wxListEvent &event)
mSelectedCommand = item; mSelectedCommand = item;
PopulateList(); PopulateList();
#endif
} }
/// ///
@@ -909,6 +936,14 @@ void EditChainsDialog::OnInsert(wxCommandEvent & WXUNUSED(event))
long item = mList->GetNextItem(-1, long item = mList->GetNextItem(-1,
wxLIST_NEXT_ALL, wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED); wxLIST_STATE_SELECTED);
if (item == -1) {
item = mList->GetItemCount()-1;
}
InsertCommandAt( item );
}
void EditChainsDialog::InsertCommandAt(int item)
{
if (item == -1) { if (item == -1) {
return; return;
} }
@@ -925,13 +960,42 @@ void EditChainsDialog::OnInsert(wxCommandEvent & WXUNUSED(event))
d.mSelectedParameters, d.mSelectedParameters,
item); item);
mChanged = true; mChanged = true;
mSelectedCommand = item + 1; mSelectedCommand = item + 1;
PopulateList(); 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)) void EditChainsDialog::OnDelete(wxCommandEvent & WXUNUSED(event))
{ {
@@ -943,15 +1007,12 @@ void EditChainsDialog::OnDelete(wxCommandEvent & WXUNUSED(event))
} }
mBatchCommands.DeleteFromChain(item); mBatchCommands.DeleteFromChain(item);
mChanged = true; mChanged = true;
if (item >= (mList->GetItemCount() - 2) && item >= 0) { if (item >= (mList->GetItemCount() - 2) && item >= 0) {
item--; item--;
} }
mSelectedCommand = item; mSelectedCommand = item;
PopulateList(); PopulateList();
} }
@@ -969,11 +1030,8 @@ void EditChainsDialog::OnUp(wxCommandEvent & WXUNUSED(event))
mBatchCommands.GetParams(item), mBatchCommands.GetParams(item),
item - 1); item - 1);
mBatchCommands.DeleteFromChain(item + 1); mBatchCommands.DeleteFromChain(item + 1);
mChanged = true; mChanged = true;
mSelectedCommand = item - 1; mSelectedCommand = item - 1;
PopulateList(); PopulateList();
} }
@@ -991,14 +1049,25 @@ void EditChainsDialog::OnDown(wxCommandEvent & WXUNUSED(event))
mBatchCommands.GetParams(item), mBatchCommands.GetParams(item),
item + 2); item + 2);
mBatchCommands.DeleteFromChain(item); mBatchCommands.DeleteFromChain(item);
mChanged = true; mChanged = true;
mSelectedCommand = item + 1; mSelectedCommand = item + 1;
PopulateList(); 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. /// Select the empty Command chain.
void EditChainsDialog::OnDefaults(wxCommandEvent & WXUNUSED(event)) void EditChainsDialog::OnDefaults(wxCommandEvent & WXUNUSED(event))
{ {
@@ -1009,29 +1078,35 @@ void EditChainsDialog::OnDefaults(wxCommandEvent & WXUNUSED(event))
PopulateList(); PopulateList();
} }
/// Send changed values back to Prefs, and update Audacity. bool EditChainsDialog::SaveChanges(){
void EditChainsDialog::OnOK(wxCommandEvent & WXUNUSED(event))
{
gPrefs->Write(wxT("/Batch/ActiveChain"), mActiveChain); gPrefs->Write(wxT("/Batch/ActiveChain"), mActiveChain);
gPrefs->Flush(); gPrefs->Flush();
if (mChanged) { if (mChanged) {
if (!mBatchCommands.WriteChain(mActiveChain)) { 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); EndModal(true);
} }
/// ///
void EditChainsDialog::OnCancel(wxCommandEvent & WXUNUSED(event)) void EditChainsDialog::OnCancel(wxCommandEvent & event)
{ {
if (!ChangeOK()) { if (!ChangeOK()) {
return; return;
} }
BatchProcessDialog::OnCancel( event );
EndModal(false); //EndModal(false);
} }
/// ///

View File

@@ -39,40 +39,45 @@ class wxButton;
class wxTextCtrl; class wxTextCtrl;
class ShuttleGui; class ShuttleGui;
class BatchProcessDialog final : public wxDialogWrapper { class BatchProcessDialog : public wxDialogWrapper {
public: public:
// constructors and destructors // constructors and destructors
BatchProcessDialog(wxWindow * parent); BatchProcessDialog(wxWindow * parent, bool bInherited=false);
virtual ~BatchProcessDialog(); virtual ~BatchProcessDialog();
public: public:
void Populate(); virtual void Populate();
void PopulateOrExchange( ShuttleGui & S ); virtual void PopulateOrExchange( ShuttleGui & S );
virtual void OnApplyToProject(wxCommandEvent & event);
virtual void OnApplyToFiles(wxCommandEvent & event);
virtual void OnCancel(wxCommandEvent & event);
void OnApplyToProject(wxCommandEvent & event); // These will be reused in the derived class...
void OnApplyToFiles(wxCommandEvent & event); wxListCtrl *mList;
void OnCancel(wxCommandEvent & event); wxListCtrl *mChains;
BatchCommands mBatchCommands; /// Provides list of available commands.
wxButton *mOK; wxButton *mOK;
wxButton *mCancel; wxButton *mCancel;
wxListCtrl *mChains;
wxListCtrl *mList;
BatchCommands mBatchCommands;
wxTextCtrl *mResults; wxTextCtrl *mResults;
bool mAbort; bool mAbort;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
class EditChainsDialog final : public wxDialogWrapper class EditChainsDialog final : public BatchProcessDialog
{ {
public: public:
EditChainsDialog(wxWindow * parent); EditChainsDialog(wxWindow * parent);
~EditChainsDialog(); ~EditChainsDialog();
private: private:
void Populate(); void Populate() override;
void PopulateOrExchange(ShuttleGui &S); void PopulateOrExchange(ShuttleGui &S) override;
void OnApplyToProject(wxCommandEvent & event) override;
void OnApplyToFiles(wxCommandEvent & event) override;
void OnCancel(wxCommandEvent &event) override;
void PopulateChains(); void PopulateChains();
void PopulateList(); void PopulateList();
void AddItem(const wxString &command, wxString const &params); void AddItem(const wxString &command, wxString const &params);
@@ -89,25 +94,33 @@ private:
void OnCommandActivated(wxListEvent &event); void OnCommandActivated(wxListEvent &event);
void OnInsert(wxCommandEvent &event); void OnInsert(wxCommandEvent &event);
void OnEditCommandParams(wxCommandEvent &event);
void OnDelete(wxCommandEvent &event); void OnDelete(wxCommandEvent &event);
void OnUp(wxCommandEvent &event); void OnUp(wxCommandEvent &event);
void OnDown(wxCommandEvent &event); void OnDown(wxCommandEvent &event);
void OnDefaults(wxCommandEvent &event); void OnDefaults(wxCommandEvent &event);
//void OnApplyToProject(wxCommandEvent &event);
//void OnApplyToFiles(wxCommandEvent &event);
void OnOK(wxCommandEvent &event); void OnOK(wxCommandEvent &event);
void OnCancel(wxCommandEvent &event);
void OnKeyDown(wxKeyEvent &event); void OnKeyDown(wxKeyEvent &event);
void FitColumns(); 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 *mRemove;
wxButton *mRename; wxButton *mRename;
wxButton *mDefaults; wxButton *mDefaults;
BatchCommands mBatchCommands; /// Provides list of available commands.
wxString mActiveChain; wxString mActiveChain;
int mSelectedCommand; int mSelectedCommand;