1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-12 14:47:43 +02:00

Bug1432 partial, keep correct focus in more cases, not all...

Works by using the newer and better logic of ToolManager for remembering which
window to focus.

It seems, at least on Windows, that when the toolbar with the focused control
is docked after the end of a docking (of itself or another bar), then focus
remains.

If the bar with the focus is undocked and another bar docks or undocks, focus
is still lost.
This commit is contained in:
Paul Licameli 2017-07-23 14:33:16 -04:00
parent 9aea0d3967
commit 503f3548a1
4 changed files with 13 additions and 27 deletions

View File

@ -1351,10 +1351,6 @@ void AudacityProject::UpdatePrefs()
if (mRuler) { if (mRuler) {
mRuler->UpdatePrefs(); mRuler->UpdatePrefs();
} }
// The toolbars will be recreated, so make sure we don't leave
// a stale pointer hanging around.
mLastFocusedWindow = NULL;
} }
void AudacityProject::SetMissingAliasFileDialog(wxDialog *dialog) void AudacityProject::SetMissingAliasFileDialog(wxDialog *dialog)
@ -2416,11 +2412,6 @@ void AudacityProject::OnActivate(wxActivateEvent & event)
mActive = event.GetActive(); mActive = event.GetActive();
#if defined(__WXGTK__)
// See bug #294 for explanation
mTrackPanel->SetFocus();
#endif
// Under Windows, focus can be "lost" when returning to // Under Windows, focus can be "lost" when returning to
// Audacity from a different application. // Audacity from a different application.
// //
@ -2428,17 +2419,11 @@ void AudacityProject::OnActivate(wxActivateEvent & event)
// then ALT+TAB to return to Audacity. Focus will be given to the // then ALT+TAB to return to Audacity. Focus will be given to the
// project window frame which is not at all useful. // project window frame which is not at all useful.
// //
// So, when the project window receives a deactivate event, we // So, we use ToolManager's observation of focus changes in a wxEventFilter.
// remember which child had the focus. Then, when we receive the // Then, when we receive the
// activate event, we restore that focus to the child or the track // activate event, we restore that focus to the child or the track
// panel if no child had the focus (which probably should never happen). // panel if no child had the focus (which probably should never happen).
if (!mActive) { if (!mActive) {
// We only want to remember the last focused window if FindFocus() returns
// a window within the current project frame.
wxWindow *w = FindFocus();
if (wxGetTopLevelParent(w) ==this) {
mLastFocusedWindow = w;
}
#ifdef __WXMAC__ #ifdef __WXMAC__
if (IsIconized()) if (IsIconized())
MacShowUndockedToolbars(false); MacShowUndockedToolbars(false);
@ -2446,16 +2431,11 @@ void AudacityProject::OnActivate(wxActivateEvent & event)
} }
else { else {
SetActiveProject(this); SetActiveProject(this);
if (mLastFocusedWindow) { if ( ! GetToolManager()->RestoreFocus() ) {
mLastFocusedWindow->SetFocus();
}
else {
if (mTrackPanel) { if (mTrackPanel) {
mTrackPanel->SetFocus(); mTrackPanel->SetFocus();
} }
} }
// No longer need to remember the last focused window
mLastFocusedWindow = NULL;
#ifdef __WXMAC__ #ifdef __WXMAC__
MacShowUndockedToolbars(true); MacShowUndockedToolbars(true);
@ -2616,7 +2596,6 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event)
// its size change. // its size change.
SaveWindowSize(); SaveWindowSize();
mLastFocusedWindow = NULL;
mIsDeleting = true; mIsDeleting = true;
// Mac: we never quit as the result of a close. // Mac: we never quit as the result of a close.

View File

@ -710,9 +710,6 @@ private:
bool mLockPlayRegion; bool mLockPlayRegion;
// See AudacityProject::OnActivate() for an explanation of this.
wxWindow *mLastFocusedWindow{};
std::unique_ptr<ImportXMLTagHandler> mImportXMLTagHandler; std::unique_ptr<ImportXMLTagHandler> mImportXMLTagHandler;
// Last auto-save file name and path (empty if none) // Last auto-save file name and path (empty if none)

View File

@ -1491,11 +1491,19 @@ void ToolManager::DoneDragging()
mDidDrag = false; mDidDrag = false;
mClicked = false; mClicked = false;
RestoreFocus();
}
bool ToolManager::RestoreFocus()
{
if (mLastFocus) { if (mLastFocus) {
auto temp1 = AButton::TemporarilyAllowFocus(); auto temp1 = AButton::TemporarilyAllowFocus();
auto temp2 = ASlider::TemporarilyAllowFocus(); auto temp2 = ASlider::TemporarilyAllowFocus();
auto temp3 = Meter::TemporarilyAllowFocus(); auto temp3 = Meter::TemporarilyAllowFocus();
auto parent = mLastFocus->GetParent(); auto parent = mLastFocus->GetParent();
mLastFocus->SetFocus(); mLastFocus->SetFocus();
return true;
} }
return false;
} }

View File

@ -71,6 +71,8 @@ class ToolManager final : public wxEvtHandler, public wxEventFilter
int FilterEvent(wxEvent &event) override; int FilterEvent(wxEvent &event) override;
bool RestoreFocus();
private: private:
ToolBar *Float( ToolBar *t, wxPoint & pos ); ToolBar *Float( ToolBar *t, wxPoint & pos );