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

LabelTrackView, not LabelTrack, handles focus changes when adding

This commit is contained in:
Paul Licameli
2018-12-05 16:16:31 -05:00
parent 8ff5a4b345
commit aa5f9550bd
9 changed files with 56 additions and 35 deletions

View File

@@ -119,7 +119,7 @@ LabelTrack::Holder TrackFactory::NewLabelTrack()
LabelTrack::LabelTrack(const std::shared_ptr<DirManager> &projDirManager):
Track(projDirManager),
mSelIndex(-1),
mRestoreFocus(-1),
mRestoreFocus(-2),
mClipLen(0.0),
miLastLabel(-1)
{
@@ -1113,7 +1113,7 @@ bool LabelTrack::CopySelectedText()
bool LabelTrack::PasteSelectedText(double sel0, double sel1)
{
if ( !HasSelection() )
AddLabel(SelectedRegion(sel0, sel1), wxT(""));
LabelTrackView::Get( *this ).AddLabel(SelectedRegion(sel0, sel1));
wxString text, left, right;
@@ -2026,7 +2026,7 @@ bool LabelTrackView::DoKeyDown(SelectedRegion &newSel, wxKeyEvent & event)
.begin().advance(mRestoreFocus);
if (track)
TrackPanel::Get( *GetActiveProject() ).SetFocusedTrack(track);
mRestoreFocus = -1;
mRestoreFocus = -2;
}
mSelIndex = -1;
break;
@@ -2161,13 +2161,13 @@ bool LabelTrackView::DoChar(SelectedRegion &WXUNUSED(newSel), wxKeyEvent & event
return false;
}
pTrack->SetSelected(true);
pTrack->AddLabel(selectedRegion, title, -2);
pTrack->AddLabel(selectedRegion, title);
ProjectHistory::Get( *p ).PushState(_("Added label"), _("Label"));
return false;
}
else {
pTrack->SetSelected(true);
pTrack->AddLabel(selectedRegion);
AddLabel( selectedRegion );
ProjectHistory::Get( *p ).PushState(_("Added label"), _("Label"));
}
}
@@ -2793,27 +2793,27 @@ int LabelTrack::GetLabelIndex(double t, double t1)
// restoreFocus of -1 is the default, and sets the focus to this label.
// restoreFocus of -2 or other value leaves the focus unchanged.
// restoreFocus >= 0 will later cause focus to move to that track.
int LabelTrack::AddLabel(const SelectedRegion &selectedRegion,
int LabelTrackView::AddLabel(const SelectedRegion &selectedRegion,
const wxString &title, int restoreFocus)
{
LabelStruct l { selectedRegion, title };
mInitialCursorPos = mCurrentCursorPos = title.length();
int len = mLabels.size();
int pos = 0;
while (pos < len && mLabels[pos].getT0() < selectedRegion.t0())
pos++;
mLabels.insert(mLabels.begin() + pos, l);
const auto pTrack = FindLabelTrack();
pTrack->mRestoreFocus = restoreFocus;
auto pos = pTrack->AddLabel( selectedRegion, title );
return pos;
}
void LabelTrack::OnLabelAdded( const wxString &title, int pos )
{
// restoreFocus is -2 e.g. from Nyquist label creation, when we should not
// even lose the focus and open the label to edit in the first place.
// -1 means we don't need to restore it to anywhere.
// 0 or above is the track to restore to afetr editing the label is complete.
if( restoreFocus >= -1 )
// 0 or above is the track to restore to after editing the label is complete.
if( mRestoreFocus >= -1 )
mSelIndex = pos;
if( mRestoreFocus < 0 )
mRestoreFocus = -2;
// Make sure the caret is visible
//
// LLL: The cursor will not be drawn when the first label
@@ -2825,7 +2825,24 @@ int LabelTrack::AddLabel(const SelectedRegion &selectedRegion,
// mDrawCursor flag will be reset once the action is complete.
mDrawCursor = true;
mRestoreFocus = restoreFocus;
mInitialCursorPos = mCurrentCursorPos = title.length();
}
int LabelTrack::AddLabel(const SelectedRegion &selectedRegion,
const wxString &title)
{
LabelStruct l { selectedRegion, title };
int len = mLabels.size();
int pos = 0;
while (pos < len && mLabels[pos].getT0() < selectedRegion.t0())
pos++;
mLabels.insert(mLabels.begin() + pos, l);
OnLabelAdded( title, pos );
return pos;
}