Audacity 3.2.0
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/statbox.h>
33#include <wx/stattext.h>
34#include <wx/textctrl.h>
35#include <wx/listctrl.h>
36#include <wx/button.h>
37
38
39#include "Project.h"
41#include "ShuttleGui.h"
42#include "HelpSystem.h"
43
44
45#define CommandsListID 7001
46#define EditParamsButtonID 7002
47#define UsePresetButtonID 7003
48
49BEGIN_EVENT_TABLE(MacroCommandDialog, wxDialogWrapper)
58
60 wxWindow * parent, wxWindowID id, AudacityProject &project):
61 wxDialogWrapper(parent, id, XO("Select Command"),
62 wxDefaultPosition, wxDefaultSize,
63 wxCAPTION | wxRESIZE_BORDER)
64 , mCatalog{ &project }
65{
66 SetLabel(XO("Select Command")); // Provide visual label
67 SetName(XO("Select Command")); // Provide audible label
68 Populate();
69}
70
72{
73 //------------------------- Main section --------------------
76 // ----------------------- End of main section --------------
77}
78
80{
81 S.StartVerticalLay(true);
82 {
83 S.StartMultiColumn(4, wxEXPAND);
84 {
85 S.SetStretchyCol(1);
86 mCommand = S.AddTextBox(XXO("&Command"), wxT(""), 20);
87 mCommand->SetEditable(false);
89 .Disable() // disable button as box is empty
90 .AddButton(XXO("&Edit Parameters"));
92 .Disable() // disable button as box is empty
93 .AddButton(XXO("&Use Preset"));
94 }
95 S.EndMultiColumn();
96
97 S.StartMultiColumn(2, wxEXPAND);
98 {
99 S.SetStretchyCol(1);
100 mParameters = S.AddTextBox(XXO("&Parameters"), wxT(""), 0);
101 mParameters->SetEditable(false);
102 auto prompt = XXO("&Details");
103 S.Prop(0).AddPrompt(prompt);
104 mDetails = S
105 .Name( prompt )
106 .AddTextWindow( wxT(""));
107 mDetails->SetEditable(false);
108 }
109 S.EndMultiColumn();
110
111 S.Prop(10).StartStatic(XO("Choose command"), true);
112 {
114 .Style(wxSUNKEN_BORDER | wxLC_LIST | wxLC_SINGLE_SEL)
115 .AddListControl();
116 }
117 S.EndStatic();
118 }
119 S.EndVerticalLay();
120
121 S.AddStandardButtons( eOkButton | eCancelButton | eHelpButton);
122
124 if (mChoices->GetItemCount() > 0) {
125 // set first item to be selected (and the focus when the
126 // list first becomes the focus)
127 mChoices->SetItemState(0, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED,
128 wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
129 }
130
131 SetMinSize(wxSize(780, 560));
132 Fit();
133 Center();
134}
135
137{
138 mChoices->DeleteAllItems();
139 long ii = 0;
140 for ( const auto &entry : mCatalog )
141 // insert the user-facing string
142 mChoices->InsertItem( ii++, entry.name.StrippedTranslation() );
143}
144
146{
147}
148
149void MacroCommandDialog::OnChoice(wxCommandEvent & WXUNUSED(event))
150{
151}
152
153void MacroCommandDialog::OnOk(wxCommandEvent & WXUNUSED(event))
154{
156 // .Strip(wxString::both) // PRL: used to do this, here only,
157 // but ultimately mSelectedCommand is looked up in the catalog without
158 // similar adjustment of whitespace in the comparison
159 ;
160 mSelectedParameters = mParameters->GetValue().Strip(wxString::trailing);
161 EndModal(true);
162}
163
164void MacroCommandDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
165{
166 EndModal(false);
167}
168
169void MacroCommandDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
170{
171 const auto &page = GetHelpPageName();
172 HelpSystem::ShowHelp(this, page, true);
173}
174
176{
177 const auto &command = mCatalog[ event.GetIndex() ];
178
180 PluginID ID = em.GetEffectByIdentifier( command.name.Internal() );
181
182 // If ID is empty, then the effect wasn't found, in which case, the user must have
183 // selected one of the "special" commands.
184 mEditParams->Enable(!ID.empty());
185 mUsePreset->Enable(em.HasPresets(ID));
186
187 auto value = command.name.StrippedTranslation();
188 if ( value == mCommand->GetValue() )
189 // This uses the assumption of uniqueness of translated names!
190 return;
191
192 mCommand->SetValue(value);
193 mInternalCommandName = command.name.Internal();
194
196 if (params.empty())
197 {
198 params = em.GetDefaultPreset(ID);
199 }
200
201 // using GET to expose a CommandID to the user!
202 // Cryptic command and category.
203 // Later we can put help information there, perhaps.
204 // Macro command details are one place that we do expose Identifier
205 // to (more sophisticated) users
206 mDetails->SetValue(
207 mInternalCommandName.GET() + "\r\n" + command.category.Translation() );
208 mParameters->SetValue(params);
209}
210
211void MacroCommandDialog::OnEditParams(wxCommandEvent & WXUNUSED(event))
212{
213 auto command = mInternalCommandName;
214 wxString params = mParameters->GetValue();
215
216 params = MacroCommands::PromptForParamsFor(command, params, *this).Trim();
217
218 mParameters->SetValue(params);
219 mParameters->Refresh();
220}
221
222void MacroCommandDialog::OnUsePreset(wxCommandEvent & WXUNUSED(event))
223{
224 auto command = mInternalCommandName;
225 wxString params = mParameters->GetValue();
226
227 wxString preset = MacroCommands::PromptForPresetFor(command, params, this).Trim();
228
229 mParameters->SetValue(preset);
230 mParameters->Refresh();
231}
232
234{
235 auto iter = mCatalog.ByCommandId( Command );
236
237 mParameters->SetValue( Params );
238
240 if (iter == mCatalog.end())
241 // uh oh, using GET to expose an internal name to the user!
242 // in default of any better friendly name
243 mCommand->SetValue( Command.GET() );
244 else {
245 mCommand->SetValue( iter->name.StrippedTranslation() );
246 // using GET to expose a CommandID to the user!
247 // Macro command details are one place that we do expose Identifier
248 // to (more sophisticated) users
249 mDetails->SetValue(
250 iter->name.Internal() + "\r\n" + iter->category.Translation() );
251 mChoices->SetItemState(iter - mCatalog.begin(),
252 wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
253
256
257 // If ID is empty, then the effect wasn't found, in which case, the user must have
258 // selected one of the "special" commands.
259 mEditParams->Enable(!ID.empty());
260 mUsePreset->Enable(em.HasPresets(ID));
261 }
262}
wxT("CloseDown"))
#define EditParamsButtonID
#define UsePresetButtonID
#define CommandsListID
END_EVENT_TABLE()
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
EffectDistortionSettings params
Definition: Distortion.cpp:77
wxString PluginID
Definition: EffectManager.h:30
EVT_LIST_ITEM_SELECTED(CurvesListID, EqualizationCurvesDialog::OnListSelectionChange) EVT_LIST_ITEM_DESELECTED(CurvesListID
EVT_LIST_ITEM_ACTIVATED(wxID_ANY, SuccessDialog::OnItemActivated) ExportMultipleDialog
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
static ProjectFileIORegistry::AttributeWriterEntry entry
EffectReverbSettings preset
Definition: Reverb.cpp:44
@ eIsCreating
Definition: ShuttleGui.h:37
@ eOkButton
Definition: ShuttleGui.h:594
@ eCancelButton
Definition: ShuttleGui.h:595
@ eHelpButton
Definition: ShuttleGui.h:598
#define S(N)
Definition: ToChars.cpp:64
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
EffectManager is the class that handles effects and effect categories.
Definition: EffectManager.h:48
bool HasPresets(const PluginID &ID)
static EffectManager & Get()
wxString GetDefaultPreset(const PluginID &ID)
const PluginID & GetEffectByIdentifier(const CommandID &strTarget)
static void ShowHelp(wxWindow *parent, const FilePath &localFileName, const URLString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:233
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
Provides a list of configurable commands for use with MacroCommands.
void OnOk(wxCommandEvent &event)
void OnCancel(wxCommandEvent &event)
void OnUsePreset(wxCommandEvent &event)
const MacroCommandsCatalog mCatalog
CommandID mInternalCommandName
void OnHelp(wxCommandEvent &event)
void OnEditParams(wxCommandEvent &event)
void PopulateOrExchange(ShuttleGui &S)
void OnItemSelected(wxListEvent &event)
void SetCommandAndParams(const CommandID &Command, const wxString &Params)
void OnChoice(wxCommandEvent &event)
ManualPageID GetHelpPageName()
wxTextCtrl * mParameters
Entries::const_iterator ByCommandId(const CommandID &commandId) const
Entries::const_iterator end() const
Definition: BatchCommands.h:48
Entries::const_iterator begin() const
Definition: BatchCommands.h:47
static wxString PromptForPresetFor(const CommandID &command, const wxString &params, wxWindow *parent)
static wxString GetCurrentParamsFor(const CommandID &command)
static wxString PromptForParamsFor(const CommandID &command, const wxString &params, wxWindow &parent)
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625
constexpr auto Command