1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-24 16:01:16 +02:00

Move AudacityProject::RemoveTrack

This commit is contained in:
Paul Licameli 2018-10-27 20:16:39 -04:00
parent 83f504e30f
commit 51c3541716
5 changed files with 43 additions and 41 deletions

View File

@ -140,6 +140,7 @@ namespace TrackActions {
};
/// Move a track up, down, to top or to bottom.
void DoMoveTrack( AudacityProject &project, Track* target, MoveChoice choice );
void DoRemoveTrack( AudacityProject &project, Track * toRemove );
void DoRemoveTracks( AudacityProject & );
}

View File

@ -5328,43 +5328,6 @@ void AudacityProject::DoTrackSolo(Track *t, bool exclusive)
mTrackPanel->Refresh(false);
}
/// Removes the specified track. Called from HandleClosing.
void AudacityProject::RemoveTrack(Track * toRemove)
{
// If it was focused, then NEW focus is the next or, if
// unavailable, the previous track. (The NEW focus is set
// after the track has been removed.)
bool toRemoveWasFocused = mTrackPanel->GetFocusedTrack() == toRemove;
Track* newFocus{};
if (toRemoveWasFocused) {
auto iterNext = mTracks->FindLeader(toRemove), iterPrev = iterNext;
newFocus = *++iterNext;
if (!newFocus) {
newFocus = *--iterPrev;
}
}
wxString name = toRemove->GetName();
auto channels = TrackList::Channels(toRemove);
// Be careful to post-increment over positions that get erased!
auto &iter = channels.first;
while (iter != channels.end())
mTracks->Remove( * iter++ );
if (toRemoveWasFocused)
mTrackPanel->SetFocusedTrack(newFocus);
PushState(
wxString::Format(_("Removed track '%s.'"),
name),
_("Track Remove"));
TP_RedrawScrollbars();
HandleResize();
GetTrackPanel()->Refresh(false);
}
void AudacityProject::HandleTrackMute(Track *t, const bool exclusive)
{
// Whatever t is, replace with lead channel

View File

@ -428,8 +428,6 @@ public:
void DoTrackMute(Track *pTrack, bool exclusive);
void DoTrackSolo(Track *pTrack, bool exclusive);
void RemoveTrack(Track * toRemove);
// "exclusive" mute means mute the chosen track and unmute all others.
void HandleTrackMute(Track *t, const bool exclusive);

View File

@ -575,6 +575,45 @@ void DoRemoveTracks( AudacityProject &project )
trackPanel->Refresh(false);
}
void DoRemoveTrack(AudacityProject &project, Track * toRemove)
{
auto &tracks = *project.GetTracks();
auto &trackPanel = *project.GetTrackPanel();
// If it was focused, then NEW focus is the next or, if
// unavailable, the previous track. (The NEW focus is set
// after the track has been removed.)
bool toRemoveWasFocused = trackPanel.GetFocusedTrack() == toRemove;
Track* newFocus{};
if (toRemoveWasFocused) {
auto iterNext = tracks.FindLeader(toRemove), iterPrev = iterNext;
newFocus = *++iterNext;
if (!newFocus) {
newFocus = *--iterPrev;
}
}
wxString name = toRemove->GetName();
auto channels = TrackList::Channels(toRemove);
// Be careful to post-increment over positions that get erased!
auto &iter = channels.first;
while (iter != channels.end())
tracks.Remove( * iter++ );
if (toRemoveWasFocused)
trackPanel.SetFocusedTrack(newFocus);
project.PushState(
wxString::Format(_("Removed track '%s.'"),
name),
_("Track Remove"));
project.FixScrollbars();
project.HandleResize();
trackPanel.Refresh(false);
}
void DoMoveTrack
(AudacityProject &project, Track* target, MoveChoice choice)
{
@ -1229,7 +1268,7 @@ void OnTrackClose(const CommandContext &context)
return;
}
project.RemoveTrack(t);
DoRemoveTrack(project, t);
trackPanel->UpdateViewIfNoTracks();
trackPanel->Refresh(false);

View File

@ -12,6 +12,7 @@ Paul Licameli split from TrackPanel.cpp
#include "TrackButtonHandles.h"
#include "../../HitTestResult.h"
#include "../../Menus.h"
#include "../../Project.h"
#include "../../RefreshCode.h"
#include "../../Track.h"
@ -95,7 +96,7 @@ UIHandle::Result CloseButtonHandle::CommitChanges
pProject->StopIfPaused();
if (!pProject->IsAudioActive()) {
// This pushes an undo item:
pProject->RemoveTrack(pTrack.get());
TrackActions::DoRemoveTrack(*pProject, pTrack.get());
// Redraw all tracks when any one of them closes
// (Could we invent a return code that draws only those at or below
// the affected track?)