Audacity  3.0.3
BatchCommandDialog.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  BatchCommandDialog.cpp
6 
7  Dominic Mazzoni
8  James Crook
9 
10 *******************************************************************//*******************************************************************/
20 
21 
22 #include "BatchCommandDialog.h"
23 
24 #ifdef __WXMSW__
25  #include <wx/ownerdrw.h>
26 #endif
27 
28 //
29 #include <wx/defs.h>
30 #include <wx/checkbox.h>
31 #include <wx/choice.h>
32 #include <wx/intl.h>
33 #include <wx/sizer.h>
34 #include <wx/statbox.h>
35 #include <wx/stattext.h>
36 #include <wx/textctrl.h>
37 #include <wx/listctrl.h>
38 #include <wx/radiobut.h>
39 #include <wx/button.h>
40 #include <wx/string.h>
41 #include <wx/dialog.h>
42 
43 
44 #include "Project.h"
45 #include "effects/EffectManager.h"
46 #include "ShuttleGui.h"
47 #include "widgets/HelpSystem.h"
48 
49 
50 #define CommandsListID 7001
51 #define EditParamsButtonID 7002
52 #define UsePresetButtonID 7003
53 
54 BEGIN_EVENT_TABLE(MacroCommandDialog, wxDialogWrapper)
63 
65  wxWindow * parent, wxWindowID id, AudacityProject &project):
66  wxDialogWrapper(parent, id, XO("Select Command"),
67  wxDefaultPosition, wxDefaultSize,
68  wxCAPTION | wxRESIZE_BORDER)
69  , mCatalog{ &project }
70 {
71  SetLabel(XO("Select Command")); // Provide visual label
72  SetName(XO("Select Command")); // Provide audible label
73  Populate();
74 }
75 
77 {
78  //------------------------- Main section --------------------
79  ShuttleGui S(this, eIsCreating);
81  // ----------------------- End of main section --------------
82 }
83 
85 {
86  S.StartVerticalLay(true);
87  {
88  S.StartMultiColumn(4, wxEXPAND);
89  {
90  S.SetStretchyCol(1);
91  mCommand = S.AddTextBox(XXO("&Command"), wxT(""), 20);
92  mCommand->SetEditable(false);
94  .Disable() // disable button as box is empty
95  .AddButton(XXO("&Edit Parameters"));
97  .Disable() // disable button as box is empty
98  .AddButton(XXO("&Use Preset"));
99  }
100  S.EndMultiColumn();
101 
102  S.StartMultiColumn(2, wxEXPAND);
103  {
104  S.SetStretchyCol(1);
105  mParameters = S.AddTextBox(XXO("&Parameters"), wxT(""), 0);
106  mParameters->SetEditable(false);
107  auto prompt = XXO("&Details");
108  S.Prop(0).AddPrompt(prompt);
109  mDetails = S
110  .Name( prompt )
111  .AddTextWindow( wxT(""));
112  mDetails->SetEditable(false);
113  }
114  S.EndMultiColumn();
115 
116  S.Prop(10).StartStatic(XO("Choose command"), true);
117  {
119  .Style(wxSUNKEN_BORDER | wxLC_LIST | wxLC_SINGLE_SEL)
120  .AddListControl();
121  }
122  S.EndStatic();
123  }
124  S.EndVerticalLay();
125 
127 
129  if (mChoices->GetItemCount() > 0) {
130  // set first item to be selected (and the focus when the
131  // list first becomes the focus)
132  mChoices->SetItemState(0, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED,
133  wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
134  }
135 
136  SetMinSize(wxSize(780, 560));
137  Fit();
138  Center();
139 }
140 
142 {
143  mChoices->DeleteAllItems();
144  long ii = 0;
145  for ( const auto &entry : mCatalog )
146  // insert the user-facing string
147  mChoices->InsertItem( ii++, entry.name.StrippedTranslation() );
148 }
149 
151 {
152 }
153 
154 void MacroCommandDialog::OnChoice(wxCommandEvent & WXUNUSED(event))
155 {
156 }
157 
158 void MacroCommandDialog::OnOk(wxCommandEvent & WXUNUSED(event))
159 {
161  // .Strip(wxString::both) // PRL: used to do this, here only,
162  // but ultimately mSelectedCommand is looked up in the catalog without
163  // similar adjustment of whitespace in the comparison
164  ;
165  mSelectedParameters = mParameters->GetValue().Strip(wxString::trailing);
166  EndModal(true);
167 }
168 
169 void MacroCommandDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
170 {
171  EndModal(false);
172 }
173 
174 void MacroCommandDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
175 {
176  const auto &page = GetHelpPageName();
177  HelpSystem::ShowHelp(this, page, true);
178 }
179 
180 void MacroCommandDialog::OnItemSelected(wxListEvent &event)
181 {
182  const auto &command = mCatalog[ event.GetIndex() ];
183 
185  PluginID ID = em.GetEffectByIdentifier( command.name.Internal() );
186 
187  // If ID is empty, then the effect wasn't found, in which case, the user must have
188  // selected one of the "special" commands.
189  mEditParams->Enable(!ID.empty());
190  mUsePreset->Enable(em.HasPresets(ID));
191 
192  auto value = command.name.StrippedTranslation();
193  if ( value == mCommand->GetValue() )
194  // This uses the assumption of uniqueness of translated names!
195  return;
196 
197  mCommand->SetValue(value);
198  mInternalCommandName = command.name.Internal();
199 
201  if (params.empty())
202  {
203  params = em.GetDefaultPreset(ID);
204  }
205 
206  // using GET to expose a CommandID to the user!
207  // Cryptic command and category.
208  // Later we can put help information there, perhaps.
209  // Macro command details are one place that we do expose Identifier
210  // to (more sophisticated) users
211  mDetails->SetValue(
212  mInternalCommandName.GET() + "\r\n" + command.category.Translation() );
213  mParameters->SetValue(params);
214 }
215 
216 void MacroCommandDialog::OnEditParams(wxCommandEvent & WXUNUSED(event))
217 {
218  auto command = mInternalCommandName;
219  wxString params = mParameters->GetValue();
220 
221  params = MacroCommands::PromptForParamsFor(command, params, *this).Trim();
222 
223  mParameters->SetValue(params);
224  mParameters->Refresh();
225 }
226 
227 void MacroCommandDialog::OnUsePreset(wxCommandEvent & WXUNUSED(event))
228 {
229  auto command = mInternalCommandName;
230  wxString params = mParameters->GetValue();
231 
232  wxString preset = MacroCommands::PromptForPresetFor(command, params, this).Trim();
233 
234  mParameters->SetValue(preset);
235  mParameters->Refresh();
236 }
237 
238 void MacroCommandDialog::SetCommandAndParams(const CommandID &Command, const wxString &Params)
239 {
240  auto iter = mCatalog.ByCommandId( Command );
241 
242  mParameters->SetValue( Params );
243 
245  if (iter == mCatalog.end())
246  // uh oh, using GET to expose an internal name to the user!
247  // in default of any better friendly name
248  mCommand->SetValue( Command.GET() );
249  else {
250  mCommand->SetValue( iter->name.StrippedTranslation() );
251  // using GET to expose a CommandID to the user!
252  // Macro command details are one place that we do expose Identifier
253  // to (more sophisticated) users
254  mDetails->SetValue(
255  iter->name.Internal() + "\r\n" + iter->category.Translation() );
256  mChoices->SetItemState(iter - mCatalog.begin(),
257  wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
258 
261 
262  // If ID is empty, then the effect wasn't found, in which case, the user must have
263  // selected one of the "special" commands.
264  mEditParams->Enable(!ID.empty());
265  mUsePreset->Enable(em.HasPresets(ID));
266  }
267 }
EVT_BUTTON
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
MacroCommandDialog::OnChoice
void OnChoice(wxCommandEvent &event)
Definition: BatchCommandDialog.cpp:154
MacroCommandDialog::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S)
Definition: BatchCommandDialog.cpp:84
eIsCreating
@ eIsCreating
Definition: ShuttleGui.h:38
ShuttleGuiBase::StartVerticalLay
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:1184
MacroCommandDialog::SetCommandAndParams
void SetCommandAndParams(const CommandID &Command, const wxString &Params)
Definition: BatchCommandDialog.cpp:238
HelpSystem.h
eHelpButton
@ eHelpButton
Definition: ShuttleGui.h:604
Project.h
MacroCommandDialog::mDetails
wxTextCtrl * mDetails
Definition: BatchCommandDialog.h:56
EVT_LIST_ITEM_SELECTED
EVT_LIST_ITEM_SELECTED(CurvesListID, EditCurvesDialog::OnListSelectionChange) EVT_LIST_ITEM_DESELECTED(CurvesListID
Constructor.
MacroCommands::GetCurrentParamsFor
static wxString GetCurrentParamsFor(const CommandID &command)
Definition: BatchCommands.cpp:434
MacroCommands::PromptForPresetFor
static wxString PromptForPresetFor(const CommandID &command, const wxString &params, wxWindow *parent)
Definition: BatchCommands.cpp:471
MacroCommandsCatalog::end
Entries::const_iterator end() const
Definition: BatchCommands.h:48
MacroCommandDialog::mCatalog
const MacroCommandsCatalog mCatalog
Definition: BatchCommandDialog.h:60
MacroCommandDialog::Populate
void Populate()
Definition: BatchCommandDialog.cpp:76
XO
#define XO(s)
Definition: Internat.h:31
MacroCommandsCatalog::ByCommandId
Entries::const_iterator ByCommandId(const CommandID &commandId) const
Definition: BatchCommands.cpp:425
BatchCommandDialog.h
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1238
EffectManager::Get
static EffectManager & Get()
Definition: EffectManager.cpp:42
ShuttleGuiBase::AddListControl
wxListCtrl * AddListControl(std::initializer_list< const ListControlColumn > columns={}, long listControlStyles=0)
Definition: ShuttleGui.cpp:782
HelpSystem::ShowHelp
static void ShowHelp(wxWindow *parent, const FilePath &localFileName, const URLString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:237
MacroCommandDialog::OnUsePreset
void OnUsePreset(wxCommandEvent &event)
Definition: BatchCommandDialog.cpp:227
MacroCommandDialog::OnItemSelected
void OnItemSelected(wxListEvent &event)
Definition: BatchCommandDialog.cpp:180
MacroCommandDialog::ValidateChoices
void ValidateChoices()
Definition: BatchCommandDialog.cpp:150
ShuttleGui::Id
ShuttleGui & Id(int id)
Definition: ShuttleGui.cpp:2274
ShuttleGui::Style
ShuttleGui & Style(long iStyle)
Definition: ShuttleGui.h:727
CommandsListID
#define CommandsListID
Definition: BatchCommandDialog.cpp:50
XXO
#define XXO(s)
Definition: Internat.h:44
eCancelButton
@ eCancelButton
Definition: ShuttleGui.h:601
EffectManager
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:46
MacroCommandDialog::mSelectedCommand
CommandID mSelectedCommand
Definition: BatchCommandDialog.h:33
ShuttleGuiBase::AddTextBox
wxTextCtrl * AddTextBox(const TranslatableString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:638
ShuttleGui::Disable
ShuttleGui & Disable(bool disabled=true)
Definition: ShuttleGui.h:650
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
ShuttleGuiBase::EndVerticalLay
void EndVerticalLay()
Definition: ShuttleGui.cpp:1203
PluginID
wxString PluginID
Definition: EffectManager.h:30
MacroCommandDialog::OnEditParams
void OnEditParams(wxCommandEvent &event)
Definition: BatchCommandDialog.cpp:216
MacroCommandDialog::mSelectedParameters
wxString mSelectedParameters
Definition: BatchCommandDialog.h:34
MacroCommandDialog::OnHelp
void OnHelp(wxCommandEvent &event)
Definition: BatchCommandDialog.cpp:174
ShuttleGui.h
MacroCommandDialog::OnCancel
void OnCancel(wxCommandEvent &event)
Definition: BatchCommandDialog.cpp:169
EditParamsButtonID
#define EditParamsButtonID
Definition: BatchCommandDialog.cpp:51
ShuttleGui::Prop
ShuttleGui & Prop(int iProp)
Definition: ShuttleGui.h:725
MacroCommandDialog::mInternalCommandName
CommandID mInternalCommandName
Definition: BatchCommandDialog.h:58
ShuttleGuiBase::AddButton
wxButton * AddButton(const TranslatableString &Text, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:360
Identifier::GET
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
Definition: Identifier.h:66
EffectManager::HasPresets
bool HasPresets(const PluginID &ID)
Definition: EffectManager.cpp:333
EffectManager::GetDefaultPreset
wxString GetDefaultPreset(const PluginID &ID)
Definition: EffectManager.cpp:660
MacroCommandDialog::mParameters
wxTextCtrl * mParameters
Definition: BatchCommandDialog.h:55
ShuttleGuiBase::StartStatic
wxStaticBox * StartStatic(const TranslatableString &Str, int iProp=0)
Definition: ShuttleGui.cpp:893
ShuttleGui::Name
ShuttleGui & Name(const TranslatableString &name)
Definition: ShuttleGui.h:663
wxDialogWrapper
Definition: wxPanelWrapper.h:81
UsePresetButtonID
#define UsePresetButtonID
Definition: BatchCommandDialog.cpp:52
eOkButton
@ eOkButton
Definition: ShuttleGui.h:600
MacroCommandDialog::OnOk
void OnOk(wxCommandEvent &event)
Definition: BatchCommandDialog.cpp:158
TaggedIdentifier< CommandIdTag, false >
MacroCommands::PromptForParamsFor
static wxString PromptForParamsFor(const CommandID &command, const wxString &params, wxWindow &parent)
Definition: BatchCommands.cpp:446
MacroCommandDialog::PopulateCommandList
void PopulateCommandList()
Definition: BatchCommandDialog.cpp:141
MenuTable::Command
std::unique_ptr< CommandItem > Command(const CommandID &name, const TranslatableString &label_in, void(Handler::*pmf)(const CommandContext &), CommandFlag flags, const CommandManager::Options &options={}, CommandHandlerFinder finder=FinderScope::DefaultFinder())
Definition: CommandManager.h:662
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:113
MacroCommandsCatalog::begin
Entries::const_iterator begin() const
Definition: BatchCommands.h:47
EffectManager::GetEffectByIdentifier
const PluginID & GetEffectByIdentifier(const CommandID &strTarget)
Definition: EffectManager.cpp:821
MacroCommandDialog::mChoices
wxListCtrl * mChoices
Definition: BatchCommandDialog.h:53
MacroCommandDialog::GetHelpPageName
ManualPageID GetHelpPageName()
Definition: BatchCommandDialog.h:45
ShuttleGuiBase::AddTextWindow
wxTextCtrl * AddTextWindow(const wxString &Value)
Multiline text box that grows.
Definition: ShuttleGui.cpp:712
EVT_LIST_ITEM_ACTIVATED
EVT_LIST_ITEM_ACTIVATED(wxID_ANY, SuccessDialog::OnItemActivated) ExportMultipleDialog
Definition: ExportMultiple.cpp:122
ShuttleGui::AddStandardButtons
void AddStandardButtons(long buttons=eOkButton|eCancelButton, wxWindow *extra=NULL)
Definition: ShuttleGui.cpp:2432
MacroCommandDialog::mEditParams
wxButton * mEditParams
Definition: BatchCommandDialog.h:51
params
EffectDistortion::Params params
Definition: Distortion.cpp:99
ShuttleGuiBase::AddPrompt
void AddPrompt(const TranslatableString &Prompt, int wrapWidth=0)
Right aligned text string.
Definition: ShuttleGui.cpp:238
ShuttleGuiBase::EndStatic
void EndStatic()
Definition: ShuttleGui.cpp:922
EffectManager.h
ShuttleGuiBase::SetStretchyCol
void SetStretchyCol(int i)
Used to modify an already placed FlexGridSizer to make a column stretchy.
Definition: ShuttleGui.cpp:202
END_EVENT_TABLE
END_EVENT_TABLE()
MacroCommandDialog
Provides a list of configurable commands for use with MacroCommands.
Definition: BatchCommandDialog.h:27
MacroCommandDialog::mUsePreset
wxButton * mUsePreset
Definition: BatchCommandDialog.h:52
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
MacroCommandDialog::mCommand
wxTextCtrl * mCommand
Definition: BatchCommandDialog.h:54