forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBatchCommandDialog.cpp
267 lines (219 loc) · 8.11 KB
/
BatchCommandDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/**********************************************************************
Sneedacity: A Digital Audio Editor
BatchCommandDialog.cpp
Dominic Mazzoni
James Crook
*******************************************************************//*!
\class MacroCommandDialog
\brief Provides a list of configurable commands for use with MacroCommands
Provides a list of commands, mostly effects, which can be chained
together in a simple linear sequence. Can configure parameters on each
selected command.
*//*******************************************************************/
#include "BatchCommandDialog.h"
#ifdef __WXMSW__
#include <wx/ownerdrw.h>
#endif
//
#include <wx/defs.h>
#include <wx/checkbox.h>
#include <wx/choice.h>
#include <wx/intl.h>
#include <wx/sizer.h>
#include <wx/statbox.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include <wx/listctrl.h>
#include <wx/radiobut.h>
#include <wx/button.h>
#include <wx/string.h>
#include <wx/dialog.h>
#include "Project.h"
#include "effects/EffectManager.h"
#include "ShuttleGui.h"
#include "widgets/HelpSystem.h"
#define CommandsListID 7001
#define EditParamsButtonID 7002
#define UsePresetButtonID 7003
BEGIN_EVENT_TABLE(MacroCommandDialog, wxDialogWrapper)
EVT_BUTTON(wxID_OK, MacroCommandDialog::OnOk)
EVT_BUTTON(wxID_CANCEL, MacroCommandDialog::OnCancel)
EVT_BUTTON(wxID_HELP, MacroCommandDialog::OnHelp)
EVT_BUTTON(EditParamsButtonID, MacroCommandDialog::OnEditParams)
EVT_BUTTON(UsePresetButtonID, MacroCommandDialog::OnUsePreset)
EVT_LIST_ITEM_ACTIVATED(CommandsListID, MacroCommandDialog::OnItemSelected)
EVT_LIST_ITEM_SELECTED(CommandsListID, MacroCommandDialog::OnItemSelected)
END_EVENT_TABLE();
MacroCommandDialog::MacroCommandDialog(
wxWindow * parent, wxWindowID id, SneedacityProject &project):
wxDialogWrapper(parent, id, XO("Select Command"),
wxDefaultPosition, wxDefaultSize,
wxCAPTION | wxRESIZE_BORDER)
, mCatalog{ &project }
{
SetLabel(XO("Select Command")); // Provide visual label
SetName(XO("Select Command")); // Provide audible label
Populate();
}
void MacroCommandDialog::Populate()
{
//------------------------- Main section --------------------
ShuttleGui S(this, eIsCreating);
PopulateOrExchange(S);
// ----------------------- End of main section --------------
}
void MacroCommandDialog::PopulateOrExchange(ShuttleGui &S)
{
S.StartVerticalLay(true);
{
S.StartMultiColumn(4, wxEXPAND);
{
S.SetStretchyCol(1);
mCommand = S.AddTextBox(XXO("&Command"), wxT(""), 20);
mCommand->SetEditable(false);
mEditParams = S.Id(EditParamsButtonID)
.Disable() // disable button as box is empty
.AddButton(XXO("&Edit Parameters"));
mUsePreset = S.Id(UsePresetButtonID)
.Disable() // disable button as box is empty
.AddButton(XXO("&Use Preset"));
}
S.EndMultiColumn();
S.StartMultiColumn(2, wxEXPAND);
{
S.SetStretchyCol(1);
mParameters = S.AddTextBox(XXO("&Parameters"), wxT(""), 0);
mParameters->SetEditable(false);
auto prompt = XXO("&Details");
S.Prop(0).AddPrompt(prompt);
mDetails = S
.Name( prompt )
.AddTextWindow( wxT(""));
mDetails->SetEditable(false);
}
S.EndMultiColumn();
S.Prop(10).StartStatic(XO("Choose command"), true);
{
mChoices = S.Id(CommandsListID)
.Style(wxSUNKEN_BORDER | wxLC_LIST | wxLC_SINGLE_SEL)
.AddListControl();
}
S.EndStatic();
}
S.EndVerticalLay();
S.AddStandardButtons( eOkButton | eCancelButton | eHelpButton);
PopulateCommandList();
if (mChoices->GetItemCount() > 0) {
// set first item to be selected (and the focus when the
// list first becomes the focus)
mChoices->SetItemState(0, wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED,
wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
}
SetMinSize(wxSize(780, 560));
Fit();
Center();
}
void MacroCommandDialog::PopulateCommandList()
{
mChoices->DeleteAllItems();
long ii = 0;
for ( const auto &entry : mCatalog )
// insert the user-facing string
mChoices->InsertItem( ii++, entry.name.StrippedTranslation() );
}
void MacroCommandDialog::ValidateChoices()
{
}
void MacroCommandDialog::OnChoice(wxCommandEvent & WXUNUSED(event))
{
}
void MacroCommandDialog::OnOk(wxCommandEvent & WXUNUSED(event))
{
mSelectedCommand = mInternalCommandName
// .Strip(wxString::both) // PRL: used to do this, here only,
// but ultimately mSelectedCommand is looked up in the catalog without
// similar adjustment of whitespace in the comparison
;
mSelectedParameters = mParameters->GetValue().Strip(wxString::trailing);
EndModal(true);
}
void MacroCommandDialog::OnCancel(wxCommandEvent & WXUNUSED(event))
{
EndModal(false);
}
void MacroCommandDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
{
const auto &page = GetHelpPageName();
HelpSystem::ShowHelp(this, page, true);
}
void MacroCommandDialog::OnItemSelected(wxListEvent &event)
{
const auto &command = mCatalog[ event.GetIndex() ];
EffectManager & em = EffectManager::Get();
PluginID ID = em.GetEffectByIdentifier( command.name.Internal() );
// If ID is empty, then the effect wasn't found, in which case, the user must have
// selected one of the "special" commands.
mEditParams->Enable(!ID.empty());
mUsePreset->Enable(em.HasPresets(ID));
auto value = command.name.StrippedTranslation();
if ( value == mCommand->GetValue() )
// This uses the assumption of uniqueness of translated names!
return;
mCommand->SetValue(value);
mInternalCommandName = command.name.Internal();
wxString params = MacroCommands::GetCurrentParamsFor(mInternalCommandName);
if (params.empty())
{
params = em.GetDefaultPreset(ID);
}
// using GET to expose a CommandID to the user!
// Cryptic command and category.
// Later we can put help information there, perhaps.
// Macro command details are one place that we do expose Identifier
// to (more sophisticated) users
mDetails->SetValue(
mInternalCommandName.GET() + "\r\n" + command.category.Translation() );
mParameters->SetValue(params);
}
void MacroCommandDialog::OnEditParams(wxCommandEvent & WXUNUSED(event))
{
auto command = mInternalCommandName;
wxString params = mParameters->GetValue();
params = MacroCommands::PromptForParamsFor(command, params, *this).Trim();
mParameters->SetValue(params);
mParameters->Refresh();
}
void MacroCommandDialog::OnUsePreset(wxCommandEvent & WXUNUSED(event))
{
auto command = mInternalCommandName;
wxString params = mParameters->GetValue();
wxString preset = MacroCommands::PromptForPresetFor(command, params, this).Trim();
mParameters->SetValue(preset);
mParameters->Refresh();
}
void MacroCommandDialog::SetCommandAndParams(const CommandID &Command, const wxString &Params)
{
auto iter = mCatalog.ByCommandId( Command );
mParameters->SetValue( Params );
mInternalCommandName = Command;
if (iter == mCatalog.end())
// uh oh, using GET to expose an internal name to the user!
// in default of any better friendly name
mCommand->SetValue( Command.GET() );
else {
mCommand->SetValue( iter->name.StrippedTranslation() );
// using GET to expose a CommandID to the user!
// Macro command details are one place that we do expose Identifier
// to (more sophisticated) users
mDetails->SetValue(
iter->name.Internal() + "\r\n" + iter->category.Translation() );
mChoices->SetItemState(iter - mCatalog.begin(),
wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
EffectManager & em = EffectManager::Get();
PluginID ID = em.GetEffectByIdentifier(Command);
// If ID is empty, then the effect wasn't found, in which case, the user must have
// selected one of the "special" commands.
mEditParams->Enable(!ID.empty());
mUsePreset->Enable(em.HasPresets(ID));
}
}