Fewer uses of ::GetActiveProject()...
... where we have a window, ascend the chain of parent pointers instead to find the project window.
This commit is contained in:
parent
9029eee5bd
commit
275797bbb4
|
@ -20,7 +20,8 @@
|
|||
#include <wx/mimetype.h>
|
||||
|
||||
#include "AudioIO.h"
|
||||
#include "Project.h" // for GetActiveProject
|
||||
#include "Project.h"
|
||||
#include "ProjectWindowBase.h"
|
||||
#include "LabelTrack.h"
|
||||
#include "commands/CommandManager.h"
|
||||
#include "UndoManager.h"
|
||||
|
@ -57,7 +58,7 @@ void HighlightTextCtrl::OnMouseEvent(wxMouseEvent& event)
|
|||
if (nNewSyl != nCurSyl)
|
||||
{
|
||||
Syllable* pCurSyl = mLyricsPanel->GetSyllable(nNewSyl);
|
||||
AudacityProject* pProj = GetActiveProject();
|
||||
auto pProj = FindProjectFromWindow( this );
|
||||
auto &selectedRegion = ViewInfo::Get( *pProj ).selectedRegion;
|
||||
selectedRegion.setT0( pCurSyl->t );
|
||||
|
||||
|
@ -440,7 +441,7 @@ void LyricsPanel::Update(double t)
|
|||
{
|
||||
// TrackPanel::OnTimer passes gAudioIO->GetStreamTime(), which is -DBL_MAX if !IsStreamActive().
|
||||
// In that case, use the selection start time.
|
||||
AudacityProject* pProj = GetActiveProject();
|
||||
auto pProj = FindProjectFromWindow( this );
|
||||
const auto &selectedRegion = ViewInfo::Get( *pProj ).selectedRegion;
|
||||
mT = selectedRegion.t0();
|
||||
}
|
||||
|
@ -529,7 +530,7 @@ void LyricsPanel::OnShow(wxShowEvent &e)
|
|||
|
||||
void LyricsPanel::OnKeyEvent(wxKeyEvent & event)
|
||||
{
|
||||
AudacityProject *project = GetActiveProject();
|
||||
auto project = FindProjectFromWindow( this );
|
||||
auto &commandManager = CommandManager::Get( *project );
|
||||
commandManager.FilterKeyEvent(project, event, true);
|
||||
event.Skip();
|
||||
|
|
|
@ -24,3 +24,26 @@ ProjectWindowBase::ProjectWindowBase(wxWindow * parent, wxWindowID id,
|
|||
ProjectWindowBase::~ProjectWindowBase()
|
||||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
ProjectWindowBase *FindProjectWindow( wxWindow *pWindow )
|
||||
{
|
||||
while ( pWindow && pWindow->GetParent() )
|
||||
pWindow = pWindow->GetParent();
|
||||
return dynamic_cast< ProjectWindowBase* >( pWindow );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AudacityProject *FindProjectFromWindow( wxWindow *pWindow )
|
||||
{
|
||||
auto pProjectWindow = FindProjectWindow( pWindow );
|
||||
return pProjectWindow ? &pProjectWindow->GetProject() : nullptr;
|
||||
}
|
||||
|
||||
const AudacityProject *FindProjectFromWindow( const wxWindow *pWindow )
|
||||
{
|
||||
return FindProjectFromWindow( const_cast< wxWindow* >( pWindow ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -33,5 +33,8 @@ protected:
|
|||
AudacityProject &mProject;
|
||||
};
|
||||
|
||||
AudacityProject *FindProjectFromWindow( wxWindow *pWindow );
|
||||
const AudacityProject *FindProjectFromWindow( const wxWindow *pWindow );
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "../Prefs.h"
|
||||
#include "../Project.h"
|
||||
#include "../ProjectSettings.h"
|
||||
#include "../ProjectWindowBase.h"
|
||||
#include "../ShuttleGui.h"
|
||||
#include "../FileNames.h"
|
||||
#include "../ViewInfo.h"
|
||||
|
@ -52,7 +53,7 @@ bool ContrastDialog::GetDB(float &dB)
|
|||
// For stereo tracks: sqrt((mean(L)+mean(R))/2)
|
||||
double meanSq = 0.0;
|
||||
|
||||
AudacityProject *p = GetActiveProject();
|
||||
auto p = FindProjectFromWindow( this );
|
||||
auto range =
|
||||
TrackList::Get( *p ).SelectedLeaders< const WaveTrack >();
|
||||
auto numberSelectedTracks = range.size();
|
||||
|
@ -132,7 +133,7 @@ bool ContrastDialog::GetDB(float &dB)
|
|||
|
||||
void ContrastDialog::SetStartAndEndTime()
|
||||
{
|
||||
AudacityProject *p = GetActiveProject();
|
||||
auto p = FindProjectFromWindow( this );
|
||||
auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
|
||||
mT0 = selectedRegion.t0();
|
||||
mT1 = selectedRegion.t1();
|
||||
|
@ -211,7 +212,7 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
|
|||
wxTextValidator vld(wxFILTER_NUMERIC);
|
||||
wxString number;
|
||||
|
||||
AudacityProject *p = GetActiveProject();
|
||||
auto p = FindProjectFromWindow( this );
|
||||
const auto &settings = ProjectSettings::Get( *p );
|
||||
mProjectRate = settings.GetRate();
|
||||
|
||||
|
@ -374,7 +375,7 @@ void ContrastDialog::OnClose(wxCommandEvent & WXUNUSED(event))
|
|||
|
||||
void ContrastDialog::OnGetForeground(wxCommandEvent & /*event*/)
|
||||
{
|
||||
AudacityProject *p = GetActiveProject();
|
||||
auto p = FindProjectFromWindow( this );
|
||||
auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
|
||||
|
||||
if( TrackList::Get( *p ).Selected< const WaveTrack >() ) {
|
||||
|
@ -390,7 +391,7 @@ void ContrastDialog::OnGetForeground(wxCommandEvent & /*event*/)
|
|||
|
||||
void ContrastDialog::OnGetBackground(wxCommandEvent & /*event*/)
|
||||
{
|
||||
AudacityProject *p = GetActiveProject();
|
||||
auto p = FindProjectFromWindow( this );
|
||||
auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
|
||||
|
||||
if( TrackList::Get( *p ).Selected< const WaveTrack >() ) {
|
||||
|
@ -528,7 +529,7 @@ void ContrastDialog::results()
|
|||
void ContrastDialog::OnExport(wxCommandEvent & WXUNUSED(event))
|
||||
{
|
||||
// TODO: Handle silence checks better (-infinity dB)
|
||||
AudacityProject * project = GetActiveProject();
|
||||
auto project = FindProjectFromWindow( this );
|
||||
wxString fName = wxT("contrast.txt");
|
||||
|
||||
fName = FileNames::SelectFile(FileNames::Operation::Export,
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
//This is needed for tooltips
|
||||
#include "../Project.h"
|
||||
#include "../ProjectStatus.h"
|
||||
#include "../ProjectWindowBase.h"
|
||||
#include <wx/tooltip.h>
|
||||
|
||||
#if wxUSE_ACCESSIBILITY
|
||||
|
@ -502,7 +503,9 @@ void AButton::OnMouseEvent(wxMouseEvent & event)
|
|||
if (mCursorIsInWindow)
|
||||
UpdateStatus();
|
||||
else {
|
||||
ProjectStatus::Get( *GetActiveProject() ).Set({});
|
||||
auto pProject = FindProjectFromWindow( this );
|
||||
if (pProject)
|
||||
ProjectStatus::Get( *pProject ).Set({});
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -519,7 +522,9 @@ void AButton::UpdateStatus()
|
|||
auto tipText = Verbatim( pTip->GetTip() );
|
||||
if (!mEnabled)
|
||||
tipText.Join( XO("(disabled)"), " " );
|
||||
ProjectStatus::Get( *GetActiveProject() ).Set(tipText);
|
||||
auto pProject = FindProjectFromWindow( this );
|
||||
if (pProject)
|
||||
ProjectStatus::Get( *pProject ).Set( tipText );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ or ASlider.
|
|||
#include "../ImageManipulation.h"
|
||||
#include "../Project.h"
|
||||
#include "../ProjectStatus.h"
|
||||
#include "../ProjectWindowBase.h"
|
||||
#include "../ShuttleGui.h"
|
||||
|
||||
#include "../AllThemeResources.h"
|
||||
|
@ -1094,7 +1095,9 @@ void LWSlider::OnMouseEvent(wxMouseEvent & event)
|
|||
{
|
||||
// Display the tooltip in the status bar
|
||||
auto tip = GetTip(mCurrentValue);
|
||||
ProjectStatus::Get( *GetActiveProject() ).Set(tip);
|
||||
auto pProject = FindProjectFromWindow( mParent );
|
||||
if (pProject)
|
||||
ProjectStatus::Get( *pProject ).Set( tip );
|
||||
Refresh();
|
||||
}
|
||||
else if (event.Leaving())
|
||||
|
@ -1103,7 +1106,9 @@ void LWSlider::OnMouseEvent(wxMouseEvent & event)
|
|||
{
|
||||
ShowTip(false);
|
||||
}
|
||||
ProjectStatus::Get( *GetActiveProject() ).Set({});
|
||||
auto pProject = FindProjectFromWindow( mParent );
|
||||
if (pProject)
|
||||
ProjectStatus::Get( *pProject ).Set({});
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue