Audacity 3.2.0
Functions | Variables
anonymous_namespace{NavigationMenus.cpp} Namespace Reference

Functions

void NextOrPrevFrame (AudacityProject &project, bool forward)
 
void DoPrevTrack (AudacityProject &project, bool shift, bool circularTrackNavigation)
 
void DoNextTrack (AudacityProject &project, bool shift, bool circularTrackNavigation)
 
auto ExtraGlobalCommands ()
 
auto ExtraFocusMenu ()
 

Variables

AttachedItem sAttachment2
 
AttachedItem sAttachment3
 

Function Documentation

◆ DoNextTrack()

void anonymous_namespace{NavigationMenus.cpp}::DoNextTrack ( AudacityProject project,
bool  shift,
bool  circularTrackNavigation 
)

The following method moves to the next track, selecting and unselecting depending if you are on the start of a block or not.

Definition at line 183 of file NavigationMenus.cpp.

185{
186 auto &projectHistory = ProjectHistory::Get(project);
187 auto &trackFocus = TrackFocus::Get(project);
189 auto &selectionState = SelectionState::Get(project);
190 auto &viewport = Viewport::Get(project);
191
192 const auto t = trackFocus.Get();
193 if (!t) {
194 // if there isn't one, focus on first
195 const auto first = *tracks.begin();
196 trackFocus.Set(first);
197 if (first) {
198 viewport.ShowTrack(*first);
199 projectHistory.ModifyState(false);
200 }
201 return;
202 }
203
204 if (shift) {
205 auto n = * ++ tracks.Find(t); // Get next track
206 if (!n) {
207 // On last track so stay there
208 wxBell();
209 if (circularTrackNavigation)
210 n = *tracks.begin();
211 else {
212 viewport.ShowTrack(*t);
213 return;
214 }
215 }
216 // If here, then there is a nonempty list and a next track
217 // (maybe circularly)
218 assert(n);
219 auto tSelected = t->GetSelected();
220 auto nSelected = n->GetSelected();
221 if (tSelected && nSelected) {
222 selectionState.SelectTrack(*t, false, false);
223 trackFocus.Set(n); // move focus to next track down
224 if (n) {
225 viewport.ShowTrack(*n);
226 projectHistory.ModifyState(false);
227 }
228 return;
229 }
230 if (tSelected && !nSelected) {
231 selectionState.SelectTrack(*n, true, false);
232 trackFocus.Set(n); // move focus to next track down
233 if (n) {
234 viewport.ShowTrack(*n);
235 projectHistory.ModifyState(false);
236 }
237 return;
238 }
239 if (!tSelected && nSelected) {
240 selectionState.SelectTrack(*n, false, false);
241 trackFocus.Set(n); // move focus to next track down
242 if (n) {
243 viewport.ShowTrack(*n);
244 projectHistory.ModifyState(false);
245 }
246 return;
247 }
248 if (!tSelected && !nSelected) {
249 selectionState.SelectTrack(*t, true, false);
250 trackFocus.Set(n); // move focus to next track down
251 if (n) {
252 viewport.ShowTrack(*n);
253 projectHistory.ModifyState(false);
254 }
255 return;
256 }
257 }
258 else {
259 auto n = * ++ tracks.Find(t); // Get next track
260 if (!n) {
261 // On last track so stay there
262 wxBell();
263 if (circularTrackNavigation) {
264 n = *tracks.begin();
265 trackFocus.Set(n); // Wrap to the first track
266 if (n) {
267 viewport.ShowTrack(*n);
268 projectHistory.ModifyState(false);
269 }
270 return;
271 }
272 else {
273 viewport.ShowTrack(*t);
274 return;
275 }
276 }
277 else {
278 trackFocus.Set(n); // move focus to next track down
279 viewport.ShowTrack(*n);
280 projectHistory.ModifyState(false);
281 return;
282 }
283 }
284}
const auto tracks
const auto project
static ProjectHistory & Get(AudacityProject &project)
static SelectionState & Get(AudacityProject &project)
Track * Get()
Definition: TrackFocus.cpp:156
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:33

References TrackFocus::Get(), ProjectHistory::Get(), SelectionState::Get(), TrackList::Get(), Viewport::Get(), project, and tracks.

Referenced by NavigationActions::Handler::OnCursorDown(), and NavigationActions::Handler::OnShiftDown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoPrevTrack()

void anonymous_namespace{NavigationMenus.cpp}::DoPrevTrack ( AudacityProject project,
bool  shift,
bool  circularTrackNavigation 
)
Todo:
Merge related methods, OnPrevTrack and OnNextTrack.

Definition at line 74 of file NavigationMenus.cpp.

76{
77 auto &projectHistory = ProjectHistory::Get(project);
78 auto &trackFocus = TrackFocus::Get(project);
80 auto &selectionState = SelectionState::Get(project);
81 auto &viewport = Viewport::Get(project);
82
83 const auto t = trackFocus.Get();
84 if (!t) {
85 // if there isn't one, focus on last
86 const auto last = *tracks.rbegin();
87 trackFocus.Set(last);
88 if (last) {
89 viewport.ShowTrack(*last);
90 projectHistory.ModifyState(false);
91 }
92 return;
93 }
94
95 if (shift) {
96 auto p = * -- tracks.Find(t); // Get previous track
97 if (!p) {
98 // On first track
99 // JKC: wxBell() is probably for accessibility, so a blind
100 // user knows they were at the top track.
101 wxBell();
102 if (circularTrackNavigation)
103 p = *tracks.rbegin();
104 else {
105 viewport.ShowTrack(*t);
106 return;
107 }
108 }
109 // If here, then there is a nonempty list and a previous track
110 // (maybe circularly)
111 assert(p);
112 auto tSelected = t->GetSelected();
113 auto pSelected = p->GetSelected();
114 if (tSelected && pSelected) {
115 selectionState.SelectTrack(*t, false, false);
116 trackFocus.Set(p); // move focus to next track up
117 if (p) {
118 viewport.ShowTrack(*p);
119 projectHistory.ModifyState(false);
120 }
121 return;
122 }
123 if (tSelected && !pSelected) {
124 selectionState.SelectTrack(*p, true, false);
125 trackFocus.Set(p); // move focus to next track up
126 if (p) {
127 viewport.ShowTrack(*p);
128 projectHistory.ModifyState(false);
129 }
130 return;
131 }
132 if (!tSelected && pSelected) {
133 selectionState.SelectTrack(*p, false, false);
134 trackFocus.Set(p); // move focus to next track up
135 if (p) {
136 viewport.ShowTrack(*p);
137 projectHistory.ModifyState(false);
138 }
139 return;
140 }
141 if (!tSelected && !pSelected) {
142 selectionState.SelectTrack(*t, true, false);
143 trackFocus.Set(p); // move focus to next track up
144 if (p) {
145 viewport.ShowTrack(*p);
146 projectHistory.ModifyState(false);
147 }
148 return;
149 }
150 }
151 else {
152 auto p = * -- tracks.Find(t); // Get previous track
153 if (!p) {
154 // On first track so stay there?
155 wxBell();
156 if (circularTrackNavigation) {
157 auto range = tracks.Any();
158 p = * range.rbegin(); // null if range is empty
159 trackFocus.Set(p); // Wrap to the last track
160 if (p) {
161 viewport.ShowTrack(*p);
162 projectHistory.ModifyState(false);
163 }
164 return;
165 }
166 else {
167 viewport.ShowTrack(*t);
168 return;
169 }
170 }
171 else {
172 trackFocus.Set(p); // move focus to next track up
173 viewport.ShowTrack(*p);
174 projectHistory.ModifyState(false);
175 return;
176 }
177 }
178}

References TrackFocus::Get(), ProjectHistory::Get(), SelectionState::Get(), TrackList::Get(), Viewport::Get(), project, and tracks.

Referenced by NavigationActions::Handler::OnCursorUp(), and NavigationActions::Handler::OnShiftUp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ExtraFocusMenu()

auto anonymous_namespace{NavigationMenus.cpp}::ExtraFocusMenu ( )

Definition at line 581 of file NavigationMenus.cpp.

582{
583 static const auto FocusedTracksFlags =
585 static auto menu = std::shared_ptr{
587 Menu( wxT("Focus"), XXO("Foc&us"),
588 Command( wxT("PrevFrame"),
589 XXO("Move &Backward from Toolbars to Tracks"), FN(OnPrevFrame),
590 AlwaysEnabledFlag, wxT("Ctrl+Shift+F6") ),
591 Command( wxT("NextFrame"),
592 XXO("Move F&orward from Toolbars to Tracks"), FN(OnNextFrame),
593 AlwaysEnabledFlag, wxT("Ctrl+F6") ),
594 Command( wxT("PrevTrack"), XXO("Move Focus to &Previous Track"),
595 FN(OnCursorUp), FocusedTracksFlags, wxT("Up") ),
596 Command( wxT("NextTrack"), XXO("Move Focus to &Next Track"),
597 FN(OnCursorDown), FocusedTracksFlags, wxT("Down") ),
598 Command( wxT("FirstTrack"), XXO("Move Focus to &First Track"),
599 FN(OnFirstTrack), FocusedTracksFlags, wxT("Ctrl+Home") ),
600 Command( wxT("LastTrack"), XXO("Move Focus to &Last Track"),
601 FN(OnLastTrack), FocusedTracksFlags, wxT("Ctrl+End") ),
602 Command( wxT("ShiftUp"), XXO("Move Focus to P&revious and Select"),
603 FN(OnShiftUp), FocusedTracksFlags, wxT("Shift+Up") ),
604 Command( wxT("ShiftDown"), XXO("Move Focus to N&ext and Select"),
605 FN(OnShiftDown), FocusedTracksFlags, wxT("Shift+Down") ),
606 Command( wxT("Toggle"), XXO("&Toggle Focused Track"), FN(OnToggle),
607 FocusedTracksFlags, wxT("Return") ),
608 Command( wxT("ToggleAlt"), XXO("Toggle Focuse&d Track"), FN(OnToggle),
609 FocusedTracksFlags, wxT("NUMPAD_ENTER") )
610 ) ) };
611 return menu;
612}
wxT("CloseDown"))
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:34
const ReservedCommandFlag & TracksExistFlag()
const ReservedCommandFlag & TrackPanelHasFocus()
XXO("&Cut/Copy/Paste Toolbar")
#define FN(X)
static CommandHandlerObject & findCommandHandler(AudacityProject &project)
constexpr auto Command
Definition: MenuRegistry.h:456
constexpr auto Menu
Items will appear in a main toolbar menu or in a sub-menu.
Definition: MenuRegistry.h:445

References AlwaysEnabledFlag, MenuRegistry::Command, findCommandHandler(), FN, MenuRegistry::Menu, TrackPanelHasFocus(), TracksExistFlag(), wxT(), and XXO().

Here is the call graph for this function:

◆ ExtraGlobalCommands()

auto anonymous_namespace{NavigationMenus.cpp}::ExtraGlobalCommands ( )

Definition at line 561 of file NavigationMenus.cpp.

562{
563 // Ceci n'est pas un menu
564 static auto items = std::shared_ptr{
566 Items( wxT("Navigation"),
567 Command( wxT("PrevWindow"), XXO("Move Backward Through Active Windows"),
568 FN(OnPrevWindow), AlwaysEnabledFlag,
569 Options{ wxT("Alt+Shift+F6") }.IsGlobal() ),
570 Command( wxT("NextWindow"), XXO("Move Forward Through Active Windows"),
571 FN(OnNextWindow), AlwaysEnabledFlag,
572 Options{ wxT("Alt+F6") }.IsGlobal() )
573 ) ) };
574 return items;
575}
constexpr auto Items
Definition: MenuRegistry.h:427

References AlwaysEnabledFlag, MenuRegistry::Command, findCommandHandler(), FN, MenuRegistry::Items, wxT(), and XXO().

Here is the call graph for this function:

◆ NextOrPrevFrame()

void anonymous_namespace{NavigationMenus.cpp}::NextOrPrevFrame ( AudacityProject project,
bool  forward 
)

Definition at line 23 of file NavigationMenus.cpp.

24{
25 // Focus won't take in a dock unless at least one descendant window
26 // accepts focus. Tell controls to take focus for the duration of this
27 // function, only. Outside of this, they won't steal the focus when
28 // clicked.
29 auto temp1 = AButton::TemporarilyAllowFocus();
30 auto temp2 = ASlider::TemporarilyAllowFocus();
32
33 std::vector<wxWindow*> seq;
34 // Skip docks that are empty (Bug 1564).
35 if(!ToolManager::Get(project).GetTopDock()->GetChildren().IsEmpty())
36 seq.push_back(ProjectWindow::Get( project ).GetTopPanel());
37 seq.push_back(&TrackPanel::Get( project ));
38 seq.push_back(&RealtimeEffectPanel::Get(project));
39 if(!ToolManager::Get( project ).GetBotDock()->GetChildren().IsEmpty())
40 seq.push_back(ToolManager::Get( project ).GetBotDock());
41
42 auto FindAncestor = [&]() {
43 wxWindow *pWindow = wxWindow::FindFocus();
44 while (pWindow)
45 {
46 auto it = std::find(seq.cbegin(), seq.cend(), pWindow);
47 if(it != seq.cend())
48 return static_cast<size_t>(std::distance(seq.cbegin(), it));
49 pWindow = pWindow->GetParent();
50 }
51 return seq.size();
52 };
53
54 const auto idx = FindAncestor();
55 if (idx == seq.size())
56 return;
57
58 auto idx2 = idx;
59 const auto increment = (forward ? 1 : static_cast<int>(seq.size()) - 1);
60
61 while( idx != (idx2 = (idx2 + increment) % seq.size()) ) {
62 wxWindow *toFocus = seq[idx2];
63 if(!toFocus->IsShown())
64 continue;
65
66 toFocus->SetFocus();
67 if ( FindAncestor() == idx2 )
68 // The focus took!
69 break;
70 }
71}
static TempAllowFocus TemporarilyAllowFocus()
Definition: AButton.cpp:658
static TempAllowFocus TemporarilyAllowFocus()
Definition: ASlider.cpp:1884
static TempAllowFocus TemporarilyAllowFocus()
static ProjectWindow & Get(AudacityProject &project)
static RealtimeEffectPanel & Get(AudacityProject &project)
static ToolManager & Get(AudacityProject &project)
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:234
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:375

References BasicUI::FindFocus(), forward, ProjectWindow::Get(), RealtimeEffectPanel::Get(), ToolManager::Get(), TrackPanel::Get(), project, AButton::TemporarilyAllowFocus(), ASlider::TemporarilyAllowFocus(), and MeterPanelBase::TemporarilyAllowFocus().

Referenced by NavigationActions::Handler::OnNextFrame(), and NavigationActions::Handler::OnPrevFrame().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ sAttachment2

AttachedItem anonymous_namespace{NavigationMenus.cpp}::sAttachment2
Initial value:
wxT("Optional/Extra/Part2")
}
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
Definition: Registry.h:175

Definition at line 577 of file NavigationMenus.cpp.

◆ sAttachment3

AttachedItem anonymous_namespace{NavigationMenus.cpp}::sAttachment3
Initial value:

Definition at line 614 of file NavigationMenus.cpp.