From 5494185a88dc1f9fc3e24307c0aeb88056eb2e95 Mon Sep 17 00:00:00 2001 From: David Bailes Date: Wed, 24 Oct 2018 11:07:17 +0100 Subject: [PATCH] Dialog for the name of a label: positioning fixes Problems fixed: 1. When adding a label at playback position, the position of the dialog was calculated using the position of the edit cursor 2. When adding a label at selection, the dialog could be to the left of the Audacity Window, and indeed offscreen. --- src/LabelTrack.cpp | 2 +- src/Menus.cpp | 12 ++++++++---- src/Menus.h | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/LabelTrack.cpp b/src/LabelTrack.cpp index 1de49d6ba..e66d375c3 100644 --- a/src/LabelTrack.cpp +++ b/src/LabelTrack.cpp @@ -2102,7 +2102,7 @@ bool LabelTrack::OnChar(SelectedRegion &WXUNUSED(newSel), wxKeyEvent & event) gPrefs->Read(wxT("/Gui/DialogForNameNewLabel"), &useDialog, false); if (useDialog) { wxString title; - if (MenuCommandHandler::DialogForLabelName(*p, charCode, title) == + if (MenuCommandHandler::DialogForLabelName(*p, p->mViewInfo.selectedRegion, charCode, title) == wxID_CANCEL) { return false; } diff --git a/src/Menus.cpp b/src/Menus.cpp index 154ec190e..b68adf87c 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -9437,14 +9437,18 @@ void MenuCommandHandler::OnRescanDevices(const CommandContext &WXUNUSED(context) } int MenuCommandHandler::DialogForLabelName( - AudacityProject &project, const wxString& initialValue, wxString& value) + AudacityProject &project, + const SelectedRegion& region, const wxString& initialValue, wxString& value) { auto trackPanel = project.GetTrackPanel(); auto &viewInfo = project.GetViewInfo(); wxPoint position = trackPanel->FindTrackRect(trackPanel->GetFocusedTrack(), false).GetBottomLeft(); - // the start of the text in the text box will be roughly in line with Audacity's edit cursor - position.x += trackPanel->GetLabelWidth() + viewInfo.TimeToPosition(viewInfo.selectedRegion.t0()) - 40; + // The start of the text in the text box will be roughly in line with the label's position + // if it's a point label, or the start of its region if it's a region label. + position.x += trackPanel->GetLabelWidth() + + std::max(0, static_cast(viewInfo.TimeToPosition(region.t0()))) + -40; position.y += 2; // just below the bottom of the track position = trackPanel->ClientToScreen(position); AudacityTextEntryDialog dialog{ &project, @@ -9615,7 +9619,7 @@ int MenuCommandHandler::DoAddLabel( bool useDialog; gPrefs->Read(wxT("/GUI/DialogForNameNewLabel"), &useDialog, false); if (useDialog) { - if (DialogForLabelName(project, wxEmptyString, title) == wxID_CANCEL) + if (DialogForLabelName(project, region, wxEmptyString, title) == wxID_CANCEL) return -1; // index } diff --git a/src/Menus.h b/src/Menus.h index 49e3132d8..46154a64c 100644 --- a/src/Menus.h +++ b/src/Menus.h @@ -43,7 +43,8 @@ int DoAddLabel( AudacityProject &project, const SelectedRegion& region, bool preserveFocus = false); static int DialogForLabelName( - AudacityProject &project, const wxString& initialValue, wxString& value); + AudacityProject &project, + const SelectedRegion& region, const wxString& initialValue, wxString& value); double NearestZeroCrossing(AudacityProject &project, double t0);