| 17 | #include "Viewport.h" |
| 18 | |
| 19 | void TrackUtilities::DoRemoveTracks(AudacityProject &project) { |
| 20 | auto &tracks = TrackList::Get(project); |
| 21 | auto &trackPanel = TrackPanel::Get(project); |
| 22 | |
| 23 | auto range = tracks.Selected(); |
| 24 | using Iter = decltype(range.begin()); |
| 25 | |
| 26 | // Find the track preceding the first removed track |
| 27 | std::optional<Iter> focus; |
| 28 | if (!range.empty()) { |
| 29 | auto iter = tracks.Find(*range.begin()); |
| 30 | // TrackIter allows decrement even of begin iterators |
| 31 | focus.emplace(--iter); |
| 32 | } |
| 33 | |
| 34 | while (!range.empty()) |
| 35 | tracks.Remove(**range.first++); |
| 36 | |
| 37 | if (!(focus.has_value() && **focus)) |
| 38 | // try to use the last track |
| 39 | focus.emplace(tracks.end().advance(-1)); |
| 40 | assert(focus); |
| 41 | Track *f = **focus; |
| 42 | // Try to use the first track after the removal |
| 43 | // TrackIter allows increment even of end iterators |
| 44 | if (const auto nextF = * ++ *focus) |
| 45 | f = nextF; |
| 46 | |
| 47 | // If we actually have something left, then set focus and make sure it's seen |
| 48 | if (f) { |
| 49 | TrackFocus::Get(project).Set(f); |
| 50 | Viewport::Get(project).ShowTrack(*f); |
| 51 | } |
| 52 | |
| 53 | ProjectHistory::Get(project) |
| 54 | .PushState(XO("Removed audio track(s)"), XO("Remove Track")); |
| 55 | |
| 56 | trackPanel.UpdateViewIfNoTracks(); |
| 57 | } |
| 58 | |
| 59 | void TrackUtilities::DoTrackMute( |
| 60 | AudacityProject &project, Track &track, bool exclusive) |
nothing calls this directly
no test coverage detected