1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-25 00:30:07 +02:00

Update commands for moving clips using the keyboard

Second attempt at getting the commands to update history, so that they can be undone (previous attempt at b911607, which didn't call the undo manager for each keydown).

Both a single keypress (keydown, then keyup), and holding down a key (multiple keydowns followed by a keyup) result in a single entry in Audacity's history dialog. Note that this code relies on a change to the undo mananger in commit 63ae687.
This commit is contained in:
David Bailes 2017-05-23 10:18:48 +01:00
parent 646c285913
commit f46ac268f4
2 changed files with 42 additions and 10 deletions

View File

@ -1438,8 +1438,8 @@ void AudacityProject::CreateMenusAndCommands()
c->AddItem(wxT("CursorLongJumpLeft"), _("Cursor Long Jump Left"), FN(OnCursorLongJumpLeft), wxT("Shift+,")); 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("CursorLongJumpRight"), _("Cursor Long Jump Right"), FN(OnCursorLongJumpRight), wxT("Shift+."));
c->AddItem(wxT("ClipLeft"), _("Clip Left"), FN(OnClipLeft), wxT("")); c->AddItem(wxT("ClipLeft"), _("Clip Left"), FN(OnClipLeft), wxT("\twantKeyup"));
c->AddItem(wxT("ClipRight"), _("Clip Right"), FN(OnClipRight), wxT("")); c->AddItem(wxT("ClipRight"), _("Clip Right"), FN(OnClipRight), wxT("\twantKeyup"));
c->EndSubMenu(); c->EndSubMenu();
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -3081,8 +3081,15 @@ void AudacityProject::OnSelContractRight(const wxEvent * evt)
OnCursorLeft( true, true, bKeyUp ); OnCursorLeft( true, true, bKeyUp );
} }
void AudacityProject::DoClipLeftOrRight( bool right ) void AudacityProject::DoClipLeftOrRight(bool right, bool keyUp )
{ {
if (keyUp) {
nKeyDown = 0;
return;
}
else
nKeyDown++;
auto &panel = *GetTrackPanel(); auto &panel = *GetTrackPanel();
auto amount = TrackPanel::OnClipMove auto amount = TrackPanel::OnClipMove
@ -3092,18 +3099,40 @@ void AudacityProject::DoClipLeftOrRight( bool right )
panel.ScrollIntoView(mViewInfo.selectedRegion.t0()); panel.ScrollIntoView(mViewInfo.selectedRegion.t0());
panel.Refresh(false); panel.Refresh(false);
if (amount != 0.0) {
wxString message = right? _("Time shifted clips to the right") :
_("Time shifted clips to the left");
// The following use of the UndoPush flags is so that both a single
// keypress (keydown, then keyup), and holding down a key
// (multiple keydowns followed by a keyup) result in a single
// entry in Audacity's history dialog.
PushState(message, _("Time-Shift"),
nKeyDown == 1 ? UndoPush::MINIMAL : UndoPush::CONSOLIDATE);
}
if ( amount == 0.0 ) if ( amount == 0.0 )
panel.MessageForScreenReader( _("clip not moved")); panel.MessageForScreenReader( _("clip not moved"));
} }
void AudacityProject::OnClipLeft() void AudacityProject::OnClipLeft(const wxEvent* evt)
{ {
DoClipLeftOrRight( false ); if (evt)
DoClipLeftOrRight( false, evt->GetEventType() == wxEVT_KEY_UP );
else { // called from menu, so simulate keydown and keyup
DoClipLeftOrRight( false, false );
DoClipLeftOrRight( false, true );
}
} }
void AudacityProject::OnClipRight() void AudacityProject::OnClipRight(const wxEvent* evt)
{ {
DoClipLeftOrRight( true ); if (evt)
DoClipLeftOrRight( true, evt->GetEventType() == wxEVT_KEY_UP );
else { // called from menu, so simulate keydown and keyup
DoClipLeftOrRight( true, false );
DoClipLeftOrRight( true, true );
}
} }
//this pops up a dialog which allows the left selection to be set. //this pops up a dialog which allows the left selection to be set.

View File

@ -160,9 +160,12 @@ void OnSelExtendRight(const wxEvent * evt);
void OnSelContractLeft(const wxEvent * evt); void OnSelContractLeft(const wxEvent * evt);
void OnSelContractRight(const wxEvent * evt); void OnSelContractRight(const wxEvent * evt);
void DoClipLeftOrRight( bool right ); private:
void OnClipLeft(); int nKeyDown{};
void OnClipRight(); public:
void DoClipLeftOrRight(bool right, bool keyUp );
void OnClipLeft(const wxEvent* evt);
void OnClipRight(const wxEvent* evt);
void OnCursorShortJumpLeft(); void OnCursorShortJumpLeft();
void OnCursorShortJumpRight(); void OnCursorShortJumpRight();