1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-23 16:08:07 +02: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)
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;
@ -569,15 +577,29 @@ void EditChainsDialog::PopulateOrExchange(ShuttleGui & S)
mList->InsertColumn(ActionColumn, _("Command "), wxLIST_FORMAT_RIGHT);
mList->InsertColumn(ParamsColumn, _("Parameters"), wxLIST_FORMAT_LEFT);
S.StartHorizontalLay(wxCENTER, false);
{
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();
}
S.EndStatic();
}
@ -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);
}
///

View File

@ -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 &params);
@ -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;