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 184 of file NavigationMenus.cpp.

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

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

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 585 of file NavigationMenus.cpp.

586{
587 static const auto FocusedTracksFlags =
589 static auto menu = std::shared_ptr{
591 Menu( wxT("Focus"), XXO("Foc&us"),
592 Command( wxT("PrevFrame"),
593 XXO("Move &Backward from Toolbars to Tracks"), FN(OnPrevFrame),
594 AlwaysEnabledFlag, wxT("Ctrl+Shift+F6") ),
595 Command( wxT("NextFrame"),
596 XXO("Move F&orward from Toolbars to Tracks"), FN(OnNextFrame),
597 AlwaysEnabledFlag, wxT("Ctrl+F6") ),
598 Command( wxT("PrevTrack"), XXO("Move Focus to &Previous Track"),
599 FN(OnCursorUp), FocusedTracksFlags, wxT("Up") ),
600 Command( wxT("NextTrack"), XXO("Move Focus to &Next Track"),
601 FN(OnCursorDown), FocusedTracksFlags, wxT("Down") ),
602 Command( wxT("FirstTrack"), XXO("Move Focus to &First Track"),
603 FN(OnFirstTrack), FocusedTracksFlags, wxT("Ctrl+Home") ),
604 Command( wxT("LastTrack"), XXO("Move Focus to &Last Track"),
605 FN(OnLastTrack), FocusedTracksFlags, wxT("Ctrl+End") ),
606 Command( wxT("ShiftUp"), XXO("Move Focus to P&revious and Select"),
607 FN(OnShiftUp), FocusedTracksFlags, wxT("Shift+Up") ),
608 Command( wxT("ShiftDown"), XXO("Move Focus to N&ext and Select"),
609 FN(OnShiftDown), FocusedTracksFlags, wxT("Shift+Down") ),
610 Command( wxT("Toggle"), XXO("&Toggle Focused Track"), FN(OnToggle),
611 FocusedTracksFlags, wxT("Return") ),
612 Command( wxT("ToggleAlt"), XXO("Toggle Focuse&d Track"), FN(OnToggle),
613 FocusedTracksFlags, wxT("NUMPAD_ENTER") )
614 ) ) };
615 return menu;
616}
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 565 of file NavigationMenus.cpp.

566{
567 // Ceci n'est pas un menu
568 static auto items = std::shared_ptr{
570 Items( wxT("Navigation"),
571 Command( wxT("PrevWindow"), XXO("Move Backward Through Active Windows"),
572 FN(OnPrevWindow), AlwaysEnabledFlag,
573 Options{ wxT("Alt+Shift+F6") }.IsGlobal() ),
574 Command( wxT("NextWindow"), XXO("Move Forward Through Active Windows"),
575 FN(OnNextWindow), AlwaysEnabledFlag,
576 Options{ wxT("Alt+F6") }.IsGlobal() )
577 ) ) };
578 return items;
579}
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:1892
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:233
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:373

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 581 of file NavigationMenus.cpp.

◆ sAttachment3

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

Definition at line 618 of file NavigationMenus.cpp.