mirror of
https://github.com/cookiengineer/audacity
synced 2025-04-30 23:59:41 +02:00
LabelTrackView, not LabelTrack, handles focus changes when adding
This commit is contained in:
parent
8ff5a4b345
commit
aa5f9550bd
@ -420,7 +420,7 @@ bool LabelDialog::TransferDataFromWindow()
|
||||
return false;
|
||||
|
||||
// Add the label to it
|
||||
lt->AddLabel(rd.selectedRegion, rd.title, -2);
|
||||
lt->AddLabel(rd.selectedRegion, rd.title);
|
||||
lt->Unselect();
|
||||
}
|
||||
|
||||
@ -723,7 +723,7 @@ void LabelDialog::OnExport(wxCommandEvent & WXUNUSED(event))
|
||||
for (i = 0; i < cnt; i++) {
|
||||
RowData &rd = mData[i];
|
||||
|
||||
lt->AddLabel(rd.selectedRegion, rd.title,-2);
|
||||
lt->AddLabel(rd.selectedRegion, rd.title);
|
||||
}
|
||||
|
||||
// Export them and clean
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -213,9 +213,9 @@ public:
|
||||
const LabelStruct *GetLabel(int index) const;
|
||||
const LabelArray &GetLabels() const { return mLabels; }
|
||||
|
||||
void OnLabelAdded( const wxString &title, int pos );
|
||||
//This returns the index of the label we just added.
|
||||
int AddLabel(const SelectedRegion ®ion, const wxString &title = {},
|
||||
int restoreFocus = -1);
|
||||
int AddLabel(const SelectedRegion ®ion, const wxString &title);
|
||||
//And this tells us the index, if there is a label already there.
|
||||
int GetLabelIndex(double t, double t1);
|
||||
|
||||
|
@ -114,8 +114,7 @@ void ProjectAudioManager::OnAudioIOStopRecording()
|
||||
pTrack->AddLabel(
|
||||
SelectedRegion{ interval.first,
|
||||
interval.first + interval.second },
|
||||
wxString::Format(wxT("%ld"), counter++),
|
||||
-2 );
|
||||
wxString::Format(wxT("%ld"), counter++));
|
||||
ShowWarningDialog(&window, wxT("DropoutDetected"), _("\
|
||||
Recorded audio was lost at the labeled locations. Possible causes:\n\
|
||||
\n\
|
||||
|
@ -216,8 +216,7 @@ bool EffectFindClipping::ProcessOne(LabelTrack * lt,
|
||||
if (stoprun >= mStop) {
|
||||
lt->AddLabel(SelectedRegion(startTime,
|
||||
wt->LongSamplesToTime(start + s - mStop)),
|
||||
wxString::Format(wxT("%lld of %lld"), startrun.as_long_long(), (samps - mStop).as_long_long()),
|
||||
-2);
|
||||
wxString::Format(wxT("%lld of %lld"), startrun.as_long_long(), (samps - mStop).as_long_long()));
|
||||
startrun = 0;
|
||||
stoprun = 0;
|
||||
samps = 0;
|
||||
|
@ -1406,7 +1406,7 @@ bool NyquistEffect::ProcessOne()
|
||||
// let Nyquist analyzers define more complicated selections
|
||||
nyx_get_label(l, &t0, &t1, &str);
|
||||
|
||||
ltrack->AddLabel(SelectedRegion(t0 + mT0, t1 + mT0), UTF8CTOWX(str), -2);
|
||||
ltrack->AddLabel(SelectedRegion(t0 + mT0, t1 + mT0), UTF8CTOWX(str));
|
||||
}
|
||||
return (GetType() != EffectTypeProcess || mIsPrompt);
|
||||
}
|
||||
|
@ -759,7 +759,7 @@ void VampEffect::AddFeatures(LabelTrack *ltrack,
|
||||
}
|
||||
}
|
||||
|
||||
ltrack->AddLabel(SelectedRegion(ltime0, ltime1), label, -2);
|
||||
ltrack->AddLabel(SelectedRegion(ltime0, ltime1), label);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "../WaveTrack.h"
|
||||
#include "../commands/CommandContext.h"
|
||||
#include "../commands/CommandManager.h"
|
||||
#include "../tracks/labeltrack/ui/LabelTrackView.h"
|
||||
|
||||
// private helper classes and functions
|
||||
namespace {
|
||||
@ -57,22 +58,22 @@ int DoAddLabel(
|
||||
// SelectNone();
|
||||
lt->SetSelected(true);
|
||||
|
||||
int focusTrackNumber;
|
||||
int index;
|
||||
if (useDialog) {
|
||||
focusTrackNumber = -2;
|
||||
index = lt->AddLabel(region, title);
|
||||
}
|
||||
else {
|
||||
focusTrackNumber = -1;
|
||||
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.
|
||||
focusTrackNumber = pFocusedTrack->GetIndex();
|
||||
}
|
||||
index =
|
||||
LabelTrackView::Get( *lt ).AddLabel(region, title, focusTrackNumber);
|
||||
}
|
||||
|
||||
int index = lt->AddLabel(region, title, focusTrackNumber);
|
||||
|
||||
ProjectHistory::Get( project ).PushState(_("Added label"), _("Label"));
|
||||
|
||||
window.RedrawProject();
|
||||
@ -322,7 +323,7 @@ void OnPasteNewLabel(const CommandContext &context)
|
||||
|
||||
// Add a NEW label, paste into it
|
||||
// Paul L: copy whatever defines the selected region, not just times
|
||||
lt->AddLabel(selectedRegion);
|
||||
LabelTrackView::Get( *lt ).AddLabel(selectedRegion);
|
||||
if (lt->PasteSelectedText(selectedRegion.t0(),
|
||||
selectedRegion.t1()))
|
||||
bPastedSomething = true;
|
||||
|
@ -37,6 +37,11 @@ public:
|
||||
bool DoKeyDown(SelectedRegion &sel, wxKeyEvent & event);
|
||||
bool DoChar(SelectedRegion &sel, wxKeyEvent & event);
|
||||
|
||||
//This returns the index of the label we just added.
|
||||
int AddLabel(const SelectedRegion ®ion,
|
||||
const wxString &title = {},
|
||||
int restoreFocus = -1);
|
||||
|
||||
private:
|
||||
std::vector<UIHandlePtr> DetailedHitTest
|
||||
(const TrackPanelMouseState &state,
|
||||
|
Loading…
x
Reference in New Issue
Block a user