From b91160795dedce54745102027f8bb0908828772a Mon Sep 17 00:00:00 2001 From: David Bailes Date: Mon, 15 May 2017 13:05:35 +0100 Subject: [PATCH] Fix for keyboard commands for time shifting clips Commands didn't update history etc. Fix: Commands now call TrackPanel::MakeParentPushState. --- src/Menus.cpp | 24 ++++++++++++++++++------ src/Menus.h | 4 ++-- src/TrackPanel.cpp | 23 +++++++++++++++++++++-- src/TrackPanel.h | 4 +++- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index bf40705db..36f536ea6 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -1438,8 +1438,8 @@ void AudacityProject::CreateMenusAndCommands() c->AddItem(wxT("CursorLongJumpLeft"), _("Cursor Long Jump Left"), FN(OnCursorLongJumpLeft), wxT("Shift+,")); c->AddItem(wxT("CursorLongJumpRight"), _("Cursor Long Jump Right"), FN(OnCursorLongJumpRight), wxT("Shift+.")); - c->AddItem(wxT("ClipLeft"), _("Clip Left"), FN(OnClipLeft), wxT("")); - c->AddItem(wxT("ClipRight"), _("Clip Right"), FN(OnClipRight), wxT("")); + c->AddItem(wxT("ClipLeft"), _("Clip Left"), FN(OnClipLeft), wxT("\twantKeyup")); + c->AddItem(wxT("ClipRight"), _("Clip Right"), FN(OnClipRight), wxT("\twantKeyup")); c->EndSubMenu(); ////////////////////////////////////////////////////////////////////////// @@ -3081,14 +3081,26 @@ void AudacityProject::OnSelContractRight(const wxEvent * evt) OnCursorLeft( true, true, bKeyUp ); } -void AudacityProject::OnClipLeft() +void AudacityProject::OnClipLeft(const wxEvent* evt) { - mTrackPanel->OnClipMove(false); + if (evt) { + mTrackPanel->OnClipMove(false, evt->GetEventType() == wxEVT_KEY_UP); + } + else { // called from menu item, so simulate keydown and keyup + mTrackPanel->OnClipMove(false, false); + mTrackPanel->OnClipMove(false, true); + } } -void AudacityProject::OnClipRight() +void AudacityProject::OnClipRight(const wxEvent* evt) { - mTrackPanel->OnClipMove(true); + if (evt) { + mTrackPanel->OnClipMove(true, evt->GetEventType() == wxEVT_KEY_UP); + } + else { // called from menu item, so simulate keydown and keyup + mTrackPanel->OnClipMove(true, false); + mTrackPanel->OnClipMove(true, true); + } } //this pops up a dialog which allows the left selection to be set. diff --git a/src/Menus.h b/src/Menus.h index 8291c2ba3..f4828db7a 100644 --- a/src/Menus.h +++ b/src/Menus.h @@ -160,8 +160,8 @@ void OnSelExtendRight(const wxEvent * evt); void OnSelContractLeft(const wxEvent * evt); void OnSelContractRight(const wxEvent * evt); -void OnClipLeft(); -void OnClipRight(); +void OnClipLeft(const wxEvent* evt); +void OnClipRight(const wxEvent* evt); void OnCursorShortJumpLeft(); void OnCursorShortJumpRight(); diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index 94f1fd2bb..7c2f194f6 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -455,6 +455,7 @@ TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id, mMouseCapture = IsUncaptured; mSlideUpDownOnly = false; + mHSlideAmountTotal = 0.0; mLabelTrackStartXPos=-1; mCircularTrackNavigation = false; @@ -3983,10 +3984,27 @@ void TrackPanel::DoSlideHorizontal() } } -void TrackPanel::OnClipMove(bool right) +void TrackPanel::OnClipMove(bool right, bool keyUp) { - auto track = GetFocusedTrack(); + if (keyUp) { + if (mHSlideAmountTotal != 0.0) { + wxString message; + message.Printf(wxT("%s %s %.03f %s"), + _("Time shifted clips"), + mHSlideAmountTotal > 0 ? + /* i18n-hint: a direction as in left or right */ + _("right") : + /* i18n-hint: a direction as in left or right */ + _("left"), + fabs(mHSlideAmountTotal), + _("seconds")); + MakeParentPushState(message, _("Time-Shift"), UndoPush::CONSOLIDATE); + mHSlideAmountTotal = 0.0; + } + return; + } + auto track = GetFocusedTrack(); // just dealing with clips in wave tracks for the moment. Note tracks?? if (track && track->GetKind() == Track::Wave) { @@ -4012,6 +4030,7 @@ void TrackPanel::OnClipMove(bool right) desiredSlideAmount *= -1; mHSlideAmount = desiredSlideAmount; DoSlideHorizontal(); + mHSlideAmountTotal += mHSlideAmount; // update t0 and t1. There is the possibility that the updated // t0 may no longer be within the clip due to rounding errors, diff --git a/src/TrackPanel.h b/src/TrackPanel.h index 6c765f9a6..d9b30de03 100644 --- a/src/TrackPanel.h +++ b/src/TrackPanel.h @@ -256,7 +256,7 @@ class AUDACITY_DLL_API TrackPanel final : public OverlayPanel { // (ignoring any fisheye) virtual double GetScreenEndTime() const; - virtual void OnClipMove(bool right); + virtual void OnClipMove(bool right, bool keyUp); protected: virtual MixerBoard* GetMixerBoard(); @@ -682,6 +682,8 @@ protected: // us to undo the slide and then slide it by another amount double mHSlideAmount; + double mHSlideAmountTotal; // used for sliding horizontally using the keyboard + bool mDidSlideVertically; bool mRedrawAfterStop;