1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +02:00

ToolManager does not depend on ProjectWindow

This commit is contained in:
Paul Licameli 2019-06-15 09:27:23 -04:00
parent 0b897c81b0
commit e1908ab8e2
3 changed files with 38 additions and 6 deletions

View File

@ -1887,3 +1887,12 @@ void ProjectWindow::ZoomOutByFactor( double ZoomFactor )
// newh = (newh > 0) ? newh : 0;
TP_ScrollWindow(newh);
}
static struct InstallTopPanelHook{ InstallTopPanelHook() {
ToolManager::SetGetTopPanelHook(
[]( wxWindow &window ){
auto pProjectWindow = dynamic_cast< ProjectWindow* >( &window );
return pProjectWindow ? pProjectWindow->GetTopPanel() : nullptr;
}
);
}} installTopPanelHook;

View File

@ -57,7 +57,6 @@
#include "../ImageManipulation.h"
#include "../Prefs.h"
#include "../Project.h"
#include "../ProjectWindow.h"
#include "../widgets/AButton.h"
#include "../widgets/ASlider.h"
#include "../widgets/MeterPanelBase.h"
@ -73,7 +72,7 @@
//
ToolFrame::ToolFrame
( AudacityProject *parent, ToolManager *manager, ToolBar *bar, wxPoint pos )
: wxFrame( ProjectWindow::Find( parent ),
: wxFrame( FindProjectFrame( parent ),
bar->GetId(),
wxEmptyString,
pos,
@ -312,10 +311,26 @@ BEGIN_EVENT_TABLE( ToolManager, wxEvtHandler )
EVT_TIMER( wxID_ANY, ToolManager::OnTimer )
END_EVENT_TABLE()
static ToolManager::GetTopPanelHook &getTopPanelHook()
{
static ToolManager::GetTopPanelHook theHook;
return theHook;
}
auto ToolManager::SetGetTopPanelHook( const GetTopPanelHook &hook )
-> GetTopPanelHook
{
auto &theHook = getTopPanelHook();
auto result = theHook;
theHook = hook;
return result;
}
static const AudacityProject::AttachedObjects::RegisteredFactory key{
[]( AudacityProject &parent ){
auto &window = ProjectWindow::Get( parent );
return std::make_shared< ToolManager >( &parent, window.GetTopPanel() ); }
auto &window = GetProjectFrame( parent );
return std::make_shared< ToolManager >(
&parent, getTopPanelHook()( window ) ); }
};
ToolManager &ToolManager::Get( AudacityProject &project )
@ -334,7 +349,10 @@ const ToolManager &ToolManager::Get( const AudacityProject &project )
ToolManager::ToolManager( AudacityProject *parent, wxWindow *topDockParent )
: wxEvtHandler()
{
auto &window = ProjectWindow::Get( *parent );
if ( !topDockParent )
THROW_INCONSISTENCY_EXCEPTION;
auto &window = GetProjectFrame( *parent );
wxPoint pt[ 3 ];
#if defined(__WXMAC__)
@ -653,7 +671,7 @@ int ToolManager::FilterEvent(wxEvent &event)
if ( window &&
!dynamic_cast<Grabber*>( window ) &&
!dynamic_cast<ToolFrame*>( window ) &&
top == ProjectWindow::Find( mParent ) )
top == FindProjectFrame( mParent ) )
// Note this is a dangle-proof wxWindowRef:
mLastFocus = window;
}

View File

@ -13,6 +13,8 @@
#ifndef __AUDACITY_TOOLMANAGER__
#define __AUDACITY_TOOLMANAGER__
#include <functional>
#include <wx/defs.h>
#include <wx/eventfilter.h> // to inherit
#include <wx/frame.h> // to inherit
@ -48,6 +50,9 @@ class ToolManager final
{
public:
// a hook function to break dependency of ToolManager on ProjectWindow
using GetTopPanelHook = std::function< wxWindow*( wxWindow& ) >;
static GetTopPanelHook SetGetTopPanelHook( const GetTopPanelHook& );
static ToolManager &Get( AudacityProject &project );
static const ToolManager &Get( const AudacityProject &project );