forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonCommandFlags.cpp
More file actions
370 lines (345 loc) · 13.4 KB
/
CommonCommandFlags.cpp
File metadata and controls
370 lines (345 loc) · 13.4 KB
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/**********************************************************************
Audacity: A Digital Audio Editor
CommonCommandFlags.cpp
Paul Licameli split from Menus.cpp
**********************************************************************/
#include "Audacity.h"
#include "CommonCommandFlags.h"
#include <wx/frame.h>
#include "AudioIO.h"
#include "Menus.h"
#include "NoteTrack.h"
#include "Project.h"
#include "ProjectAudioIO.h"
#include "ProjectFileIO.h"
#include "ProjectHistory.h"
#include "ProjectSettings.h"
#include "UndoManager.h"
#include "ViewInfo.h"
#include "WaveTrack.h"
#include "commands/CommandManagerWindowClasses.h"
/*
This file registers functions implementing many of the tests for enabling of
menu items. Sequence of a few of them has minor significance, but for most
there is little reason to keep them in one file. Flags used only by one
other file might instead be defined only where used.
They are collected here because Menus.cpp is too low level to have the
dependencies implied by the include directives above -- it would make dependency
cycles.
*/
// Strong predicate excludes tracks that do not support basic editing.
bool EditableTracksSelectedPred( const AudacityProject &project )
{
auto range = TrackList::Get( project ).Selected()
- []( const Track *pTrack ){
return !pTrack->SupportsBasicEditing(); };
return !range.empty();
};
// Weaker predicate.
bool AnyTracksSelectedPred( const AudacityProject &project )
{
auto range = TrackList::Get( project ).Selected();
return !range.empty();
};
bool AudioIOBusyPred( const AudacityProject &project )
{
return AudioIOBase::Get()->IsAudioTokenActive(
ProjectAudioIO::Get( project ).GetAudioIOToken());
};
bool TimeSelectedPred( const AudacityProject &project )
{
// This is equivalent to check if there is a valid selection,
// so it's used for Zoom to Selection too
return !ViewInfo::Get( project ).selectedRegion.isPoint();
};
const CommandFlagOptions &cutCopyOptions() {
static CommandFlagOptions result{
// In reporting the issue with cut or copy, we don't tell the user they could also select some text in a label.
[]( const TranslatableString &Name ) {
// PRL: These strings have hard-coded mention of a certain shortcut key,
// thus assuming the default shortcuts. That is questionable.
TranslatableString format;
#ifdef EXPERIMENTAL_DA
// i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
format = XO("You must first select some audio for '%s' to act on.\n\nCtrl + A selects all audio.");
#else
#ifdef __WXMAC__
// i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
format = XO("Select the audio for %s to use (for example, Cmd + A to Select All) then try again."
// No need to explain what a help button is for.
// "\n\nClick the Help button to learn more about selection methods."
);
#else
// i18n-hint: %s will be replaced by the name of an action, such as Normalize, Cut, Fade.
format = XO("Select the audio for %s to use (for example, Ctrl + A to Select All) then try again."
// No need to explain what a help button is for.
// "\n\nClick the Help button to learn more about selection methods."
);
#endif
#endif
return format.Format( Name );
},
"Selecting_Audio_-_the_basics",
XO("No Audio Selected")
};
return result;
}
// Noise Reduction has a custom error message, when nothing selected.
const CommandFlagOptions noiseReductionOptions{
[]( const TranslatableString &Name ) {
// i18n-hint: %s will be replaced by the name of an effect, usually 'Noise Reduction'.
auto format = XO("Select the audio for %s to use.\n\n1. Select audio that represents noise and use %s to get your 'noise profile'.\n\n2. When you have got your noise profile, select the audio you want to change\nand use %s to change that audio.");
return format.Format( Name, Name, Name );
},
"Noise_Reduction",
XO("No Audio Selected")
};
// The sequence of these definitions has a minor significance in determining
// which user error message has precedence if more than one might apply, so
// they should be kept in this sequence in one .cpp file if it is important
// to preserve that behavior. If they are dispersed to more than one file,
// then the precedence will be unspecified.
// The ordering of the flags that only disable the default message is not
// significant.
const ReservedCommandFlag&
AudioIONotBusyFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project ){
return !AudioIOBusyPred( project );
},
CommandFlagOptions{ []( const TranslatableString& ) { return
// This reason will not be shown, because options that require it will be greyed out.
XO("You can only do this when playing and recording are\nstopped. (Pausing is not sufficient.)");
} ,"FAQ:Errors:Audio Must Be Stopped"}
.QuickTest()
.Priority( 1 )
}; return flag; }//lll
const ReservedCommandFlag&
StereoRequiredFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
// True iff at least one stereo track is selected, i.e., at least
// one right channel is selected.
// TODO: more-than-two-channels
auto range = TrackList::Get( project ).Selected<const WaveTrack>()
- &Track::IsLeader;
return !range.empty();
},
{ []( const TranslatableString& ) { return
// This reason will not be shown, because the stereo-to-mono is greyed out if not allowed.
XO("You must first select some stereo audio to perform this\naction. (You cannot use this with mono.)");
} ,"Audacity_Selection"}
}; return flag; } //lda
const ReservedCommandFlag&
NoiseReductionTimeSelectedFlag() { static ReservedCommandFlag flag{
TimeSelectedPred,
noiseReductionOptions
}; return flag; }
const ReservedCommandFlag&
TimeSelectedFlag() { static ReservedCommandFlag flag{
TimeSelectedPred,
cutCopyOptions()
}; return flag; }
const ReservedCommandFlag&
WaveTracksSelectedFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
return !TrackList::Get( project ).Selected<const WaveTrack>().empty();
},
{ []( const TranslatableString& ) { return
XO("You must first select some audio to perform this action.\n(Selecting other kinds of track won't work.)");
} ,"Audacity_Selection"}
}; return flag; }
const ReservedCommandFlag&
TracksExistFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
return !TrackList::Get( project ).Any().empty();
},
CommandFlagOptions{}.DisableDefaultMessage()
}; return flag; }
const ReservedCommandFlag&
EditableTracksSelectedFlag() { static ReservedCommandFlag flag{
EditableTracksSelectedPred,
{ []( const TranslatableString &Name ){ return
// i18n-hint: %s will be replaced by the name of an action, such as "Remove Tracks".
XO("\"%s\" requires one or more tracks to be selected.").Format( Name );
},"Audacity_Selection" }
}; return flag; }
const ReservedCommandFlag&
AnyTracksSelectedFlag() { static ReservedCommandFlag flag{
AnyTracksSelectedPred,
{ []( const TranslatableString &Name ){ return
// i18n-hint: %s will be replaced by the name of an action, such as "Remove Tracks".
XO("\"%s\" requires one or more tracks to be selected.").Format( Name );
},"Audacity_Selection" }
}; return flag; }
const ReservedCommandFlag&
TrackPanelHasFocus() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
for (auto w = wxWindow::FindFocus(); w; w = w->GetParent()) {
if (dynamic_cast<const NonKeystrokeInterceptingWindow*>(w))
return true;
}
return false;
},
CommandFlagOptions{}.DisableDefaultMessage()
}; return flag; }; //lll
const ReservedCommandFlag&
AudioIOBusyFlag() { static ReservedCommandFlag flag{
AudioIOBusyPred,
CommandFlagOptions{}.QuickTest()
}; return flag; } //lll
const ReservedCommandFlag&
CaptureNotBusyFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &){
auto gAudioIO = AudioIO::Get();
return !(
gAudioIO->IsBusy() &&
gAudioIO->GetNumCaptureChannels() > 0
);
}
}; return flag; };
const ReservedCommandFlag&
LabelTracksExistFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
return !TrackList::Get( project ).Any<const LabelTrack>().empty();
}
}; return flag; }
const ReservedCommandFlag&
UnsavedChangesFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
auto &undoManager = UndoManager::Get( project );
return
undoManager.UnsavedChanges()
||
ProjectFileIO::Get( project ).IsModified()
;
}
}; return flag; }
const ReservedCommandFlag&
UndoAvailableFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
return ProjectHistory::Get( project ).UndoAvailable();
}
}; return flag; }
const ReservedCommandFlag&
RedoAvailableFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
return ProjectHistory::Get( project ).RedoAvailable();
}
}; return flag; }
const ReservedCommandFlag&
ZoomInAvailableFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
return
ViewInfo::Get( project ).ZoomInAvailable()
&&
!TrackList::Get( project ).Any().empty()
;
}
}; return flag; }
const ReservedCommandFlag&
ZoomOutAvailableFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
return
ViewInfo::Get( project ).ZoomOutAvailable()
&&
!TrackList::Get( project ).Any().empty()
;
}
}; return flag; }
const ReservedCommandFlag&
PlayRegionLockedFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
return ViewInfo::Get(project).playRegion.Locked();
}
}; return flag; } //msmeyer
const ReservedCommandFlag&
PlayRegionNotLockedFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
const auto &playRegion = ViewInfo::Get(project).playRegion;
return !playRegion.Locked() && !playRegion.Empty();
}
}; return flag; } //msmeyer
const ReservedCommandFlag&
WaveTracksExistFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
return !TrackList::Get( project ).Any<const WaveTrack>().empty();
}
}; return flag; }
#ifdef USE_MIDI
const ReservedCommandFlag&
NoteTracksExistFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
return !TrackList::Get( project ).Any<const NoteTrack>().empty();
}
}; return flag; } //gsw
const ReservedCommandFlag&
NoteTracksSelectedFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
return !TrackList::Get( project ).Selected<const NoteTrack>().empty();
}
}; return flag; } //gsw
#endif
const ReservedCommandFlag&
IsNotSyncLockedFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
return !ProjectSettings::Get( project ).IsSyncLocked();
}
}; return flag; } //awd
const ReservedCommandFlag&
IsSyncLockedFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
return ProjectSettings::Get( project ).IsSyncLocked();
}
}; return flag; } //awd
const ReservedCommandFlag&
NotMinimizedFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
const wxWindow *focus = FindProjectFrame( &project );
if (focus) {
while (focus && focus->GetParent())
focus = focus->GetParent();
}
return (focus &&
!static_cast<const wxTopLevelWindow*>(focus)->IsIconized()
);
},
CommandFlagOptions{}.QuickTest()
}; return flag; } // prl
const ReservedCommandFlag&
PausedFlag() { static ReservedCommandFlag flag{
[](const AudacityProject&){
return AudioIOBase::Get()->IsPaused();
},
CommandFlagOptions{}.QuickTest()
}; return flag; }
const ReservedCommandFlag&
PlayableTracksExistFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
auto &tracks = TrackList::Get( project );
return
#ifdef EXPERIMENTAL_MIDI_OUT
!tracks.Any<const NoteTrack>().empty()
||
#endif
!tracks.Any<const WaveTrack>().empty()
;
}
}; return flag; }
const ReservedCommandFlag&
AudioTracksSelectedFlag() { static ReservedCommandFlag flag{
[](const AudacityProject &project){
auto &tracks = TrackList::Get( project );
return
#ifdef USE_MIDI
!tracks.Selected<const NoteTrack>().empty()
// even if not EXPERIMENTAL_MIDI_OUT
||
#endif
!tracks.Selected<const WaveTrack>().empty()
;
}
}; return flag; }
const ReservedCommandFlag&
NoAutoSelect() { static ReservedCommandFlag flag{
[](const AudacityProject &){ return true; }
}; return flag; } // jkc
;