1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-13 08:06:32 +01:00

Eliminate GetActiveProject from ScreenshotCommand

This commit is contained in:
Paul Licameli
2020-01-07 16:31:40 -05:00
parent 54542c532f
commit 545fab88dd
2 changed files with 11 additions and 5 deletions

View File

@@ -131,11 +131,12 @@ void ScreenshotCommand::PopulateOrExchange(ShuttleGui & S)
// static member variable. // static member variable.
void (*ScreenshotCommand::mIdleHandler)(wxIdleEvent& event) = NULL; void (*ScreenshotCommand::mIdleHandler)(wxIdleEvent& event) = NULL;
static AudacityProject *pIdleHandlerProject = nullptr;
// This static variable is used to get from an idle event to the screenshot // This static variable is used to get from an idle event to the screenshot
// command that caused the idle event interception to be set up. // command that caused the idle event interception to be set up.
ScreenshotCommand * ScreenshotCommand::mpShooter=NULL; ScreenshotCommand * ScreenshotCommand::mpShooter=NULL;
// IdleHandler is expected to be called from EVT_IDLE when a dialog has been // IdleHandler is expected to be called from EVT_IDLE when a dialog has been
// fully created. Usually the dialog will have been created by invoking // fully created. Usually the dialog will have been created by invoking
// an effects gui. // an effects gui.
void IdleHandler(wxIdleEvent& event){ void IdleHandler(wxIdleEvent& event){
@@ -143,12 +144,17 @@ void IdleHandler(wxIdleEvent& event){
wxWindow * pWin = dynamic_cast<wxWindow*>(event.GetEventObject()); wxWindow * pWin = dynamic_cast<wxWindow*>(event.GetEventObject());
wxASSERT( pWin ); wxASSERT( pWin );
pWin->Unbind(wxEVT_IDLE, IdleHandler); pWin->Unbind(wxEVT_IDLE, IdleHandler);
CommandContext context( *GetActiveProject() ); CommandContext context( *pIdleHandlerProject );
// We have the relevant window, so go and capture it. // We have the relevant window, so go and capture it.
if( ScreenshotCommand::mpShooter ) if( ScreenshotCommand::mpShooter )
ScreenshotCommand::mpShooter->CaptureWindowOnIdle( context, pWin ); ScreenshotCommand::mpShooter->CaptureWindowOnIdle( context, pWin );
} }
void ScreenshotCommand::SetIdleHandler( AudacityProject &project )
{
mIdleHandler = IdleHandler;
pIdleHandlerProject = &project;
}
wxTopLevelWindow *ScreenshotCommand::GetFrontWindow(AudacityProject *project) wxTopLevelWindow *ScreenshotCommand::GetFrontWindow(AudacityProject *project)
{ {
@@ -450,7 +456,7 @@ void ScreenshotCommand::CapturePreferences(
for( int i=0;i<nPrefsPages;i++){ for( int i=0;i<nPrefsPages;i++){
// The handler is cleared each time it is used. // The handler is cleared each time it is used.
SetIdleHandler( IdleHandler ); SetIdleHandler( context.project );
gPrefs->Write(wxT("/Prefs/PrefsCategory"), (long)i); gPrefs->Write(wxT("/Prefs/PrefsCategory"), (long)i);
gPrefs->Flush(); gPrefs->Flush();
CommandID Command{ wxT("Preferences") }; CommandID Command{ wxT("Preferences") };
@@ -615,7 +621,7 @@ void ScreenshotCommand::CaptureCommands(
for( size_t i=0;i<Commands.size();i++){ for( size_t i=0;i<Commands.size();i++){
// The handler is cleared each time it is used. // The handler is cleared each time it is used.
SetIdleHandler( IdleHandler ); SetIdleHandler( context.project );
Str = Commands[i]; Str = Commands[i];
const CommandContext projectContext( *pProject ); const CommandContext projectContext( *pProject );
if( !manager.HandleTextualCommand( Str, projectContext, AlwaysEnabledFlag, true ) ) if( !manager.HandleTextualCommand( Str, projectContext, AlwaysEnabledFlag, true ) )

View File

@@ -141,7 +141,7 @@ private:
public: public:
static ScreenshotCommand * mpShooter; static ScreenshotCommand * mpShooter;
static void (*mIdleHandler)(wxIdleEvent& event); static void (*mIdleHandler)(wxIdleEvent& event);
static void SetIdleHandler( void (*pHandler)(wxIdleEvent& event) ){mIdleHandler=pHandler;}; static void SetIdleHandler( AudacityProject &project );
static bool MayCapture( wxDialog * pDlg ); static bool MayCapture( wxDialog * pDlg );
void CaptureWindowOnIdle( const CommandContext & context, wxWindow * pWin ); void CaptureWindowOnIdle( const CommandContext & context, wxWindow * pWin );