1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-03 09:09:47 +02:00

Merge branch 'Bug30'

This commit is contained in:
Paul Licameli 2016-01-23 11:42:13 -05:00
commit 554f215948
3 changed files with 30 additions and 9 deletions

View File

@ -99,7 +99,7 @@ LabelTrack::LabelTrack(DirManager * projDirManager):
mSelIndex(-1),
mMouseOverLabelLeft(-1),
mMouseOverLabelRight(-1),
mpRestoreFocus(0),
mRestoreFocus(-1),
mClipLen(0.0),
mIsAdjustingLabel(false)
{
@ -1841,9 +1841,14 @@ bool LabelTrack::OnKeyDown(SelectedRegion &newSel, wxKeyEvent & event)
case WXK_NUMPAD_ENTER:
case WXK_ESCAPE:
if (mpRestoreFocus) {
GetActiveProject()->GetTrackPanel()->SetFocusedTrack(mpRestoreFocus);
mpRestoreFocus = 0;
if (mRestoreFocus >= 0) {
TrackListIterator iter(GetActiveProject()->GetTracks());
Track *track = iter.First();
while (track && mRestoreFocus--)
track = iter.Next();
if (track)
GetActiveProject()->GetTrackPanel()->SetFocusedTrack(track);
mRestoreFocus = -1;
}
mSelIndex = -1;
break;
@ -2647,7 +2652,7 @@ int LabelTrack::GetLabelIndex(double t, double t1)
}
int LabelTrack::AddLabel(const SelectedRegion &selectedRegion,
const wxString &title, Track *pRestoreFocus)
const wxString &title, int restoreFocus)
{
LabelStruct *l = new LabelStruct(selectedRegion, title);
mCurrentCursorPos = title.length();
@ -2674,7 +2679,7 @@ int LabelTrack::AddLabel(const SelectedRegion &selectedRegion,
// mDrawCursor flag will be reset once the action is complete.
mDrawCursor = true;
mpRestoreFocus = pRestoreFocus;
mRestoreFocus = restoreFocus;
return pos;
}

View File

@ -205,7 +205,7 @@ class AUDACITY_DLL_API LabelTrack : public Track
//This returns the index of the label we just added.
int AddLabel(const SelectedRegion &region, const wxString &title = wxT(""),
Track *pRestoreFocus = 0);
int restoreFocus = -1);
//And this tells us the index, if there is a label already there.
int GetLabelIndex(double t, double t1);
@ -268,7 +268,7 @@ class AUDACITY_DLL_API LabelTrack : public Track
bool mResetCursorPos; /// flag to reset cursor position(used in the dragging the glygh)
bool mRightDragging; /// flag to tell if it's a valid dragging
bool mDrawCursor; /// flag to tell if drawing the cursor or not
Track *mpRestoreFocus; /// Restore focus to this track when done editing
int mRestoreFocus; /// Restore focus to this track when done editing
// Set in copied label tracks
double mClipLen;

View File

@ -6347,7 +6347,23 @@ int AudacityProject::DoAddLabel(const SelectedRegion &region, bool preserveFocus
// SelectNone();
lt->SetSelected(true);
int index = lt->AddLabel(region, wxString(), (preserveFocus ? pFocusedTrack : 0));
int focusTrackNumber = -1;
if (pFocusedTrack && preserveFocus) {
// Must remember the track to re-focus after finishing a label edit.
// do NOT identify it by a pointer, which might dangle! Identify
// by position.
TrackListIterator iter(GetTracks());
Track *track = iter.First();
do
++focusTrackNumber;
while (track != pFocusedTrack &&
NULL != (track = iter.Next()));
if (!track)
// How could we not find it?
focusTrackNumber = -1;
}
int index = lt->AddLabel(region, wxString(), focusTrackNumber);
PushState(_("Added label"), _("Label"));