1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-18 17:10:05 +02:00

Remove tab key target cycling and snap escape; reimplement for Esc

This commit is contained in:
Paul Licameli 2017-07-15 20:13:18 -04:00
parent d3572ebe10
commit 7a038c9e51
6 changed files with 107 additions and 37 deletions

View File

@ -767,11 +767,12 @@ void TrackPanel::Uncapture(wxMouseState *pState)
HandleMotion( *pState ); HandleMotion( *pState );
} }
void TrackPanel::CancelDragging() bool TrackPanel::CancelDragging()
{ {
if (mUIHandle) { if (mUIHandle) {
// copy shared_ptr for safety, as in HandleClick // copy shared_ptr for safety, as in HandleClick
auto handle = mUIHandle; auto handle = mUIHandle;
// UIHANDLE CANCEL
UIHandle::Result refreshResult = handle->Cancel(GetProject()); UIHandle::Result refreshResult = handle->Cancel(GetProject());
auto pTrack = GetTracks()->Lock(mpClickedTrack); auto pTrack = GetTracks()->Lock(mpClickedTrack);
if (pTrack) if (pTrack)
@ -781,7 +782,9 @@ void TrackPanel::CancelDragging()
mpClickedTrack.reset(); mpClickedTrack.reset();
mUIHandle.reset(), handle.reset(), ClearTargets(); mUIHandle.reset(), handle.reset(), ClearTargets();
Uncapture(); Uncapture();
return true;
} }
return false;
} }
bool TrackPanel::HandleEscapeKey(bool down) bool TrackPanel::HandleEscapeKey(bool down)
@ -789,13 +792,22 @@ bool TrackPanel::HandleEscapeKey(bool down)
if (!down) if (!down)
return false; return false;
auto target = Target();
if (target && target->HasEscape() && target->Escape()) {
HandleCursorForPresentMouseState(false);
return true;
}
if (mUIHandle) { if (mUIHandle) {
// UIHANDLE CANCEL
CancelDragging(); CancelDragging();
return true; return true;
} }
// Not escaping from a mouse drag if (ChangeTarget(true, false)) {
HandleCursorForPresentMouseState(false);
return true;
}
return false; return false;
} }
@ -972,9 +984,9 @@ void TrackPanel::HandleMotion
pCursor = &defaultCursor; pCursor = &defaultCursor;
} }
if (HasRotation()) if (HasEscape())
/* i18n-hint TAB is a key on the keyboard */ /* i18n-hint TAB is a key on the keyboard */
tip += wxT(" "), tip += _("(Tab for more choices)"); tip += wxT(" "), tip += _("(Esc to cancel)");
this->SetToolTip(tip); this->SetToolTip(tip);
mListener->TP_DisplayStatusMessage(tip); mListener->TP_DisplayStatusMessage(tip);
if (pCursor) if (pCursor)
@ -993,21 +1005,39 @@ bool TrackPanel::HasRotation()
return target && target->HasRotation(); return target && target->HasRotation();
} }
void TrackPanel::RotateTarget(bool forward) bool TrackPanel::HasEscape()
{
if (HasCapture())
return true;
if (mTarget + 1 == mTargets.size() &&
Target() &&
!Target()->HasEscape())
return false;
return true;
}
bool TrackPanel::ChangeTarget(bool forward, bool cycle)
{ {
auto size = mTargets.size(); auto size = mTargets.size();
auto target = Target(); auto target = Target();
if (target && target->HasRotation()) { if (target && target->HasRotation()) {
if(target->Rotate(forward)) if(target->Rotate(forward))
return; return true;
else if (size == 1 || IsMouseCaptured()) { else if (cycle && (size == 1 || IsMouseCaptured())) {
// Rotate through the states of this target only. // Rotate through the states of this target only.
target->Enter(forward); target->Enter(forward);
return; return true;
} }
} }
if (!cycle &&
((forward && mTarget + 1 == size) ||
(!forward && mTarget == 0)))
return false;
if (size > 1) { if (size > 1) {
if (forward) if (forward)
++mTarget; ++mTarget;
@ -1016,7 +1046,10 @@ void TrackPanel::RotateTarget(bool forward)
mTarget %= size; mTarget %= size;
if (Target()) if (Target())
Target()->Enter(forward); Target()->Enter(forward);
return true;
} }
return false;
} }
void TrackPanel::UpdateSelectionDisplay() void TrackPanel::UpdateSelectionDisplay()
@ -1401,6 +1434,7 @@ void TrackPanel::OnCaptureKey(wxCommandEvent & event)
event.Skip(kevent->GetSkipped()); event.Skip(kevent->GetSkipped());
} }
#if 0
// Special TAB key handling, but only if the track didn't capture it // Special TAB key handling, but only if the track didn't capture it
if ( !(t && !kevent->GetSkipped()) && if ( !(t && !kevent->GetSkipped()) &&
WXK_TAB == code && HasRotation() ) { WXK_TAB == code && HasRotation() ) {
@ -1409,7 +1443,9 @@ void TrackPanel::OnCaptureKey(wxCommandEvent & event)
mEnableTab = true; mEnableTab = true;
return; return;
} }
else if (!t) else
#endif
if (!t)
event.Skip(); event.Skip();
} }
@ -1444,14 +1480,16 @@ void TrackPanel::OnKeyDown(wxKeyEvent & event)
HandlePageDownKey(); HandlePageDownKey();
return; return;
#if 0
case WXK_TAB: case WXK_TAB:
if ( mEnableTab && HasRotation() ) { if ( mEnableTab && HasRotation() ) {
RotateTarget( !event.ShiftDown() ); ChangeTarget( !event.ShiftDown(), true );
HandleCursorForPresentMouseState(false); HandleCursorForPresentMouseState(false);
return; return;
} }
else else
break; break;
#endif
} }
Track *const t = GetFocusedTrack(); Track *const t = GetFocusedTrack();
@ -1611,7 +1649,7 @@ try
::wxGetMouseState().ButtonIsDown(wxMOUSE_BTN_ANY); ::wxGetMouseState().ButtonIsDown(wxMOUSE_BTN_ANY);
if(!buttons) { if(!buttons) {
HandleEscapeKey( true ); CancelDragging();
#if defined(__WXMAC__) #if defined(__WXMAC__)
@ -1692,7 +1730,7 @@ try
catch( ... ) catch( ... )
{ {
// Abort any dragging, as if by hitting Esc // Abort any dragging, as if by hitting Esc
if ( HandleEscapeKey( true ) ) if ( CancelDragging() )
; ;
else { else {
Uncapture(); Uncapture();

View File

@ -316,7 +316,7 @@ class AUDACITY_DLL_API TrackPanel final : public OverlayPanel {
void HandleInterruptedDrag(); void HandleInterruptedDrag();
void Uncapture( wxMouseState *pState = nullptr ); void Uncapture( wxMouseState *pState = nullptr );
void CancelDragging(); bool CancelDragging();
bool HandleEscapeKey(bool down); bool HandleEscapeKey(bool down);
void UpdateMouseState(const wxMouseState &state); void UpdateMouseState(const wxMouseState &state);
void HandleModifierKey(); void HandleModifierKey();
@ -552,8 +552,9 @@ protected:
} }
bool HasRotation(); bool HasRotation();
bool HasEscape();
void RotateTarget(bool forward); bool ChangeTarget(bool forward, bool cycle);
std::weak_ptr<Track> mpClickedTrack; std::weak_ptr<Track> mpClickedTrack;
UIHandlePtr mUIHandle; UIHandlePtr mUIHandle;

View File

@ -10,6 +10,7 @@ Paul Licameli
#include "Audacity.h" #include "Audacity.h"
#include "UIHandle.h" #include "UIHandle.h"
#include "RefreshCode.h"
UIHandle::~UIHandle() UIHandle::~UIHandle()
{ {
@ -29,6 +30,16 @@ bool UIHandle::Rotate(bool)
return false; return false;
} }
bool UIHandle::HasEscape() const
{
return false;
}
bool UIHandle::Escape()
{
return false;
}
void UIHandle::DrawExtras void UIHandle::DrawExtras
(DrawingPass, wxDC *, const wxRegion &, const wxRect &) (DrawingPass, wxDC *, const wxRegion &, const wxRect &)
{ {

View File

@ -62,6 +62,15 @@ public:
// Default does nothing and returns false // Default does nothing and returns false
virtual bool Rotate(bool forward); virtual bool Rotate(bool forward);
// Tell whether the handle has its own escape action. In case it is already
// clicked, it will not cancel on Escape key if true.
// Default is always false.
virtual bool HasEscape() const;
// The handle may change state and mark itself for highlight change.
// Default does nothing and returns false
virtual bool Escape();
// Assume hit test (implemented in other classes) was positive. // Assume hit test (implemented in other classes) was positive.
// May return Cancelled, overriding the hit test decision and stopping drag. // May return Cancelled, overriding the hit test decision and stopping drag.
// Otherwise the framework will later call Release or Cancel after // Otherwise the framework will later call Release or Cancel after

View File

@ -474,11 +474,16 @@ namespace {
} }
} }
void SelectHandle::Enter(bool forward) void SelectHandle::Enter(bool)
{ {
mUseSnap = forward; SetUseSnap(true);
}
bool hasSnap = HasRotation(); void SelectHandle::SetUseSnap(bool use)
{
mUseSnap = use;
bool hasSnap = HasSnap();
if (hasSnap) if (hasSnap)
// Repaint to turn the snap lines on or off // Repaint to turn the snap lines on or off
mChangeHighlight = RefreshCode::RefreshAll; mChangeHighlight = RefreshCode::RefreshAll;
@ -491,20 +496,23 @@ void SelectHandle::Enter(bool forward)
nullptr); nullptr);
} }
bool SelectHandle::HasRotation() const bool SelectHandle::HasSnap() const
{ {
return return
mSnapStart.snappedPoint || (IsClicked() && mSnapEnd.snappedPoint); (IsClicked() ? mSnapEnd : mSnapStart).snappedPoint;
} }
bool SelectHandle::Rotate(bool forward) bool SelectHandle::HasEscape() const
{ {
if (SelectHandle::HasRotation()) { return HasSnap() && mUseSnap;
if (mUseSnap == forward) { }
Enter(!forward);
bool SelectHandle::Escape()
{
if (SelectHandle::HasEscape()) {
SetUseSnap(false);
return true; return true;
} }
}
return false; return false;
} }
@ -866,7 +874,8 @@ UIHandle::Result SelectHandle::Drag
HitTestPreview SelectHandle::Preview HitTestPreview SelectHandle::Preview
(const TrackPanelMouseState &st, const AudacityProject *pProject) (const TrackPanelMouseState &st, const AudacityProject *pProject)
{ {
if (!HasRotation()) if (!HasSnap() && !mUseSnap)
// Moved out of snapping; revert to un-escaped state
mUseSnap = true; mUseSnap = true;
auto pTrack = mpTrack.lock(); auto pTrack = mpTrack.lock();
@ -963,13 +972,10 @@ HitTestPreview SelectHandle::Preview
if (ttb) if (ttb)
tip = ttb->GetMessageForTool(selectTool); tip = ttb->GetMessageForTool(selectTool);
} }
if (HasRotation()) { if (HasEscape() && mUseSnap) {
tip += wxT(" ") + (mUseSnap tip += wxT(" ") +
/* i18n-hint: "Snapping" means automatic alignment of selection edges to any nearby label or clip boundaries */ /* i18n-hint: "Snapping" means automatic alignment of selection edges to any nearby label or clip boundaries */
? _("(snapping)") _("(snapping)");
/* i18n-hint: "Snapping" means automatic alignment of selection edges to any nearby label or clip boundaries */
: _("(not snapping)")
);
} }
return { tip, pCursor }; return { tip, pCursor };
} }
@ -1010,8 +1016,11 @@ void SelectHandle::DrawExtras
{ {
if (pass == Panel) { if (pass == Panel) {
// Draw snap guidelines if we have any // Draw snap guidelines if we have any
if ( mUseSnap && mSnapManager ) if ( mSnapManager ) {
mSnapManager->Draw( dc, mSnapStart.outCoord, mSnapEnd.outCoord ); auto coord1 = (mUseSnap || IsClicked()) ? mSnapStart.outCoord : -1;
auto coord2 = (!mUseSnap || !IsClicked()) ? -1 : mSnapEnd.outCoord;
mSnapManager->Draw( dc, coord1, coord2 );
}
} }
} }

View File

@ -52,11 +52,13 @@ public:
bool IsClicked() const; bool IsClicked() const;
void SetUseSnap(bool use);
void Enter(bool forward) override; void Enter(bool forward) override;
bool HasRotation() const override; bool HasSnap() const;
bool HasEscape() const override;
bool Rotate(bool forward) override; bool Escape() override;
Result Click Result Click
(const TrackPanelMouseEvent &event, AudacityProject *pProject) override; (const TrackPanelMouseEvent &event, AudacityProject *pProject) override;