mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-23 17:30:17 +01:00
Track::SetSelected is not virtual...
... which will simplify later rewrites that associate selection state with the track group, not the track. Since LabelTrack isn't notified immediately of selection changes, instead it always tests whether it is selected, before using the stored selected label index.
This commit is contained in:
@@ -751,7 +751,7 @@ void LabelStruct::getXPos( wxDC & dc, int * xPos1, int cursorPos) const
|
||||
|
||||
bool LabelTrack::CalcCursorX(int * x) const
|
||||
{
|
||||
if (mSelIndex >= 0) {
|
||||
if ( HasSelection() ) {
|
||||
wxMemoryDC dc;
|
||||
|
||||
if (msFont.Ok()) {
|
||||
@@ -883,7 +883,7 @@ void LabelTrack::Draw
|
||||
#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
|
||||
highlight = highlightTrack && target->GetLabelNum() == i;
|
||||
#endif
|
||||
bool selected = mSelIndex == i;
|
||||
bool selected = GetSelectedIndex() == i;
|
||||
|
||||
if( selected )
|
||||
dc.SetBrush( AColor::labelTextEditBrush );
|
||||
@@ -897,7 +897,7 @@ void LabelTrack::Draw
|
||||
}
|
||||
|
||||
// Draw highlights
|
||||
if ((mInitialCursorPos != mCurrentCursorPos) && (mSelIndex >= 0 ))
|
||||
if ( (mInitialCursorPos != mCurrentCursorPos) && HasSelection() )
|
||||
{
|
||||
int xpos1, xpos2;
|
||||
CalcHighlightXs(&xpos1, &xpos2);
|
||||
@@ -906,15 +906,15 @@ void LabelTrack::Draw
|
||||
|
||||
// Draw the text and the label boxes.
|
||||
{ int i = -1; for (auto &labelStruct : mLabels) { ++i;
|
||||
if( mSelIndex==i)
|
||||
if( GetSelectedIndex() == i )
|
||||
dc.SetBrush(AColor::labelTextEditBrush);
|
||||
labelStruct.DrawText( dc, r );
|
||||
if( mSelIndex==i)
|
||||
if( GetSelectedIndex() == i )
|
||||
dc.SetBrush(AColor::labelTextNormalBrush);
|
||||
}}
|
||||
|
||||
// Draw the cursor, if there is one.
|
||||
if( mDrawCursor && mSelIndex >=0 )
|
||||
if( mDrawCursor && HasSelection() )
|
||||
{
|
||||
const auto &labelStruct = mLabels[mSelIndex];
|
||||
int xPos = labelStruct.xText;
|
||||
@@ -1011,7 +1011,7 @@ void LabelTrack::calculateFontHeight(wxDC & dc) const
|
||||
|
||||
bool LabelTrack::IsTextSelected() const
|
||||
{
|
||||
if (mSelIndex == -1)
|
||||
if ( !HasSelection() )
|
||||
return false;
|
||||
if (mCurrentCursorPos == mInitialCursorPos)
|
||||
return false;
|
||||
@@ -1064,7 +1064,7 @@ bool LabelTrack::CutSelectedText()
|
||||
/// @return true if text is selected in text box, false otherwise
|
||||
bool LabelTrack::CopySelectedText()
|
||||
{
|
||||
if (mSelIndex == -1)
|
||||
if ( !HasSelection() )
|
||||
return false;
|
||||
|
||||
const auto &labelStruct = mLabels[mSelIndex];
|
||||
@@ -1095,7 +1095,7 @@ bool LabelTrack::CopySelectedText()
|
||||
/// @return true if mouse is clicked in text box, false otherwise
|
||||
bool LabelTrack::PasteSelectedText(double sel0, double sel1)
|
||||
{
|
||||
if (mSelIndex == -1)
|
||||
if ( !HasSelection() )
|
||||
AddLabel(SelectedRegion(sel0, sel1), wxT(""));
|
||||
|
||||
wxString text, left, right;
|
||||
@@ -1139,6 +1139,16 @@ bool LabelTrack::IsTextClipSupported()
|
||||
}
|
||||
|
||||
|
||||
int LabelTrack::GetSelectedIndex() const
|
||||
{
|
||||
// may make delayed update of mutable mSelIndex after track selection change
|
||||
if ( GetSelected() )
|
||||
return mSelIndex = std::max( -1,
|
||||
std::min<int>( mLabels.size() - 1, mSelIndex ) );
|
||||
else
|
||||
return mSelIndex = -1;
|
||||
}
|
||||
|
||||
double LabelTrack::GetOffset() const
|
||||
{
|
||||
return mOffset;
|
||||
@@ -1173,13 +1183,6 @@ Track::Holder LabelTrack::Clone() const
|
||||
return std::make_shared<LabelTrack>( *this );
|
||||
}
|
||||
|
||||
void LabelTrack::SetSelected(bool s)
|
||||
{
|
||||
Track::SetSelected(s);
|
||||
if (!s)
|
||||
Unselect();
|
||||
}
|
||||
|
||||
/// TODO: Investigate what happens with large
|
||||
/// numbers of labels, might need a binary search
|
||||
/// rather than a linear one.
|
||||
@@ -1555,7 +1558,7 @@ bool LabelTrack::HandleGlyphDragRelease
|
||||
MayAdjustLabel( hit, hit.mMouseOverLabelRight, +1, bAllowSwapping, fNewX );
|
||||
}
|
||||
|
||||
if( mSelIndex >=0 )
|
||||
if( HasSelection() )
|
||||
{
|
||||
//Set the selection region to be equal to
|
||||
//the NEW size of the label.
|
||||
@@ -1600,7 +1603,7 @@ void LabelTrack::HandleTextDragRelease(const wxMouseEvent & evt)
|
||||
}
|
||||
|
||||
if (evt.RightUp()) {
|
||||
if ((mSelIndex != -1) && OverTextBox(GetLabel(mSelIndex), evt.m_x, evt.m_y)) {
|
||||
if (HasSelection() && OverTextBox(GetLabel(mSelIndex), evt.m_x, evt.m_y)) {
|
||||
// popup menu for editing
|
||||
ShowContextMenu();
|
||||
}
|
||||
@@ -1753,7 +1756,7 @@ bool LabelTrackView::DoCaptureKey(wxKeyEvent & event)
|
||||
!mLabels.empty())
|
||||
return true;
|
||||
|
||||
if ( pTrack->mSelIndex >= 0 ) {
|
||||
if ( pTrack->HasSelection() ) {
|
||||
if (IsGoodLabelEditKey(event)) {
|
||||
return true;
|
||||
}
|
||||
@@ -1888,7 +1891,7 @@ bool LabelTrackView::DoKeyDown(SelectedRegion &newSel, wxKeyEvent & event)
|
||||
auto &mInitialCursorPos = pTrack->mInitialCursorPos;
|
||||
auto &mCurrentCursorPos = pTrack->mCurrentCursorPos;
|
||||
auto &mRestoreFocus = pTrack->mRestoreFocus;
|
||||
if ( pTrack->mSelIndex >= 0 ) {
|
||||
if ( pTrack->HasSelection() ) {
|
||||
auto &labelStruct = mLabels[mSelIndex];
|
||||
auto &title = labelStruct.title;
|
||||
switch (keyCode) {
|
||||
@@ -2123,7 +2126,7 @@ bool LabelTrackView::DoChar(SelectedRegion &WXUNUSED(newSel), wxKeyEvent & event
|
||||
|
||||
// If we've reached this point and aren't currently editing, add NEW label
|
||||
const auto pTrack = FindLabelTrack();
|
||||
if ( pTrack->mSelIndex < 0 ) {
|
||||
if ( !pTrack->HasSelection() ) {
|
||||
// Don't create a NEW label for a space
|
||||
if (wxIsspace(charCode)) {
|
||||
event.Skip();
|
||||
@@ -2216,7 +2219,11 @@ void LabelTrack::ShowContextMenu()
|
||||
menu.Enable(OnDeleteSelectedLabelID, true);
|
||||
menu.Enable(OnEditSelectedLabelID, true);
|
||||
|
||||
wxASSERT(mSelIndex >= 0);
|
||||
if( !HasSelection() ) {
|
||||
wxASSERT( false );
|
||||
return;
|
||||
}
|
||||
|
||||
const LabelStruct *ls = GetLabel(mSelIndex);
|
||||
|
||||
wxClientDC dc(parent);
|
||||
@@ -2318,7 +2325,8 @@ void LabelTrack::Unselect()
|
||||
|
||||
bool LabelTrack::HasSelection() const
|
||||
{
|
||||
return (mSelIndex >= 0 && mSelIndex < (int)mLabels.size());
|
||||
auto selIndex = GetSelectedIndex();
|
||||
return (selIndex >= 0 && selIndex < (int)mLabels.size());
|
||||
}
|
||||
|
||||
/// Export labels including label start and end-times.
|
||||
|
||||
Reference in New Issue
Block a user