Skip to content

Commit

Permalink
Simplify hook used by ToolManager to find the docking panel
Browse files Browse the repository at this point in the history
(cherry picked from commit 09ce3f2;
modified for Tenacity)
Signed-off-by: Avery King <[email protected]>
  • Loading branch information
Paul-Licameli authored and generic-pers0n committed Apr 16, 2024
1 parent f9acea1 commit aff6ab1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
13 changes: 5 additions & 8 deletions src/ProjectWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1805,11 +1805,8 @@ void ProjectWindow::DoZoomFit()
window.TP_ScrollWindow(start);
}

static struct InstallTopPanelHook{ InstallTopPanelHook() {
ToolManager::SetGetTopPanelHook(
[]( wxWindow &window ){
auto pProjectWindow = dynamic_cast< ProjectWindow* >( &window );
return pProjectWindow ? pProjectWindow->GetTopPanel() : nullptr;
}
);
}} installTopPanelHook;
static ToolManager::TopPanelHook::Scope scope {
[]( wxWindow &window ){
auto pProjectWindow = dynamic_cast< ProjectWindow* >( &window );
return pProjectWindow ? pProjectWindow->GetTopPanel() : nullptr;
} };
18 changes: 2 additions & 16 deletions src/toolbars/ToolManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,21 +331,6 @@ 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 TenacityProject::AttachedObjects::RegisteredFactory key{
[]( TenacityProject &parent ){
return std::make_shared< ToolManager >( &parent ); }
Expand Down Expand Up @@ -449,7 +434,8 @@ void ToolManager::CreateWindows()
&ToolManager::OnCaptureLost,
this );

wxWindow *topDockParent = getTopPanelHook()( window );
wxWindow *topDockParent = TopPanelHook::Call( window );
wxASSERT(topDockParent);

// Create the top and bottom docks
mTopDock = safenew ToolDock( this, topDockParent, TopDockID );
Expand Down
4 changes: 2 additions & 2 deletions src/toolbars/ToolManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <wx/timer.h> // member variable

#include "ClientData.h"
#include "GlobalVariable.h"
#include "ToolDock.h"

#include "../commands/CommandFunctors.h"
Expand Down Expand Up @@ -57,8 +58,7 @@ class TENACITY_DLL_API ToolManager final

public:
// a hook function to break dependency of ToolManager on ProjectWindow
using GetTopPanelHook = std::function< wxWindow*( wxWindow& ) >;
static GetTopPanelHook SetGetTopPanelHook( const GetTopPanelHook& );
using TopPanelHook = GlobalHook< ToolManager, wxWindow*( wxWindow& ) >;

static ToolManager &Get( TenacityProject &project );
static const ToolManager &Get( const TenacityProject &project );
Expand Down

0 comments on commit aff6ab1

Please sign in to comment.