From 7b880058996fa53ac08c844402c6f7700195bcaa Mon Sep 17 00:00:00 2001 From: David Bailes Date: Thu, 21 May 2015 14:16:06 +0100 Subject: [PATCH] Change to the initial row selected in label editor. The initial row is the nearest previous label. If there is not one, then its the first label. --- src/LabelDialog.cpp | 44 +++++++++++++++++++++++++++++++++++++++++--- src/LabelDialog.h | 1 + 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/LabelDialog.cpp b/src/LabelDialog.cpp index caf5402a8..c1979e899 100644 --- a/src/LabelDialog.cpp +++ b/src/LabelDialog.cpp @@ -39,6 +39,7 @@ #include "widgets/NumericTextCtrl.h" #include "FileDialog.h" +#include enum Column { @@ -380,7 +381,6 @@ void LabelDialog::FindAllLabels() TrackListIterator iter(mTracks); Track *t; - mInitialRow = -1; // Add labels from all label tracks for (t = iter.First(); t; t = iter.Next()) { @@ -389,6 +389,8 @@ void LabelDialog::FindAllLabels() } } + FindInitialRow(); + if (mData.GetCount() == 0) { wxCommandEvent e; OnInsert(e); @@ -414,9 +416,45 @@ void LabelDialog::AddLabels(LabelTrack *t) rd->title = ls->title; mData.Add(rd); + } +} - if (i == t->getSelectedIndex()) { - mInitialRow = mData.GetCount() - 1; +void LabelDialog::FindInitialRow() +{ + int cnt = mData.GetCount(); + mInitialRow = -1; + + if (cnt == 0) + return; + + // find closest previous label + + double distMin = std::numeric_limits::max(); + double dist; + double t0 = mViewInfo->selectedRegion.t0(); + int i; + for (i = 0; i < cnt; i++) + { + dist = t0 - mData[i]->selectedRegion.t0(); + if (dist >= 0.0 && dist < distMin) + { + mInitialRow = i; + distMin = dist; + } + } + + // if no previous label was found, find first label + + if (mInitialRow == -1) + { + double t0Min = std::numeric_limits::max(); + for (i = 0; i < cnt; i++) + { + if (mData[i]->selectedRegion.t0() < t0Min) + { + mInitialRow = i; + t0Min = mData[i]->selectedRegion.t0(); + } } } } diff --git a/src/LabelDialog.h b/src/LabelDialog.h index 7bff60cc0..29640d620 100644 --- a/src/LabelDialog.h +++ b/src/LabelDialog.h @@ -50,6 +50,7 @@ class LabelDialog:public wxDialog bool Validate(); void FindAllLabels(); void AddLabels(LabelTrack *t); + void FindInitialRow(); wxString TrackName(int & index, wxString dflt = _("Label Track")); void OnUpdate(wxCommandEvent &event);