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/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"
46#include "ShuttleGui.h"
47#include "widgets/HelpSystem.h"
48
49
50#define CommandsListID 7001
51#define EditParamsButtonID 7002
52#define UsePresetButtonID 7003
53
54BEGIN_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 --------------------
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
126 S.AddStandardButtons( eOkButton | eCancelButton | eHelpButton);
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
154void MacroCommandDialog::OnChoice(wxCommandEvent & WXUNUSED(event))
155{
156}
157
158void 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
169void MacroCommandDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
170{
171 EndModal(false);
172}
173
174void MacroCommandDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
175{
176 const auto &page = GetHelpPageName();
177 HelpSystem::ShowHelp(this, page, true);
178}
179
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
216void 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
227void 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
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}
#define EditParamsButtonID
#define UsePresetButtonID
#define CommandsListID
END_EVENT_TABLE()
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
EffectDistortion::Params params
Definition: Distortion.cpp:83
wxString PluginID
Definition: EffectManager.h:30
EVT_LIST_ITEM_SELECTED(CurvesListID, EditCurvesDialog::OnListSelectionChange) EVT_LIST_ITEM_DESELECTED(CurvesListID
Constructor.
EVT_LIST_ITEM_ACTIVATED(wxID_ANY, SuccessDialog::OnItemActivated) ExportMultipleDialog
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
static ProjectFileIORegistry::AttributeWriterEntry entry
EffectReverbSettings preset
Definition: Reverb.cpp:46
@ eIsCreating
Definition: ShuttleGui.h:39
@ eOkButton
Definition: ShuttleGui.h:597
@ eCancelButton
Definition: ShuttleGui.h:598
@ eHelpButton
Definition: ShuttleGui.h:601
#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:89
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:237
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:628
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())