mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-26 01:18:06 +02:00
ScreenshotCommand uses hooks in AudacityCommand and Effect dialogs...
... so that they don't have a static linkage dependency on it, and that frees it from dependency cycles, to a high level
This commit is contained in:
parent
7677638ded
commit
87a9f34c22
@ -44,10 +44,27 @@ ShuttleGui.
|
|||||||
#include "../widgets/HelpSystem.h"
|
#include "../widgets/HelpSystem.h"
|
||||||
#include "../widgets/ErrorDialog.h"
|
#include "../widgets/ErrorDialog.h"
|
||||||
|
|
||||||
#include "../commands/ScreenshotCommand.h"
|
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
AudacityCommand::VetoDialogHook &GetVetoDialogHook()
|
||||||
|
{
|
||||||
|
static AudacityCommand::VetoDialogHook sHook = nullptr;
|
||||||
|
return sHook;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
auto AudacityCommand::SetVetoDialogHook( VetoDialogHook hook )
|
||||||
|
-> VetoDialogHook
|
||||||
|
{
|
||||||
|
auto &theHook = GetVetoDialogHook();
|
||||||
|
auto result = theHook;
|
||||||
|
theHook = hook;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
AudacityCommand::AudacityCommand()
|
AudacityCommand::AudacityCommand()
|
||||||
{
|
{
|
||||||
mProgress = NULL;
|
mProgress = NULL;
|
||||||
@ -105,7 +122,8 @@ bool AudacityCommand::ShowInterface(wxWindow *parent, bool WXUNUSED(forceModal))
|
|||||||
mUIDialog->SetMinSize(mUIDialog->GetSize());
|
mUIDialog->SetMinSize(mUIDialog->GetSize());
|
||||||
|
|
||||||
// The Screenshot command might be popping this dialog up, just to capture it.
|
// The Screenshot command might be popping this dialog up, just to capture it.
|
||||||
if( ScreenshotCommand::MayCapture( mUIDialog ) )
|
auto hook = GetVetoDialogHook();
|
||||||
|
if( hook && hook( mUIDialog ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool res = mUIDialog->ShowModal() != 0;
|
bool res = mUIDialog->ShowModal() != 0;
|
||||||
|
@ -45,6 +45,11 @@ class AUDACITY_DLL_API AudacityCommand /* not final */ : public wxEvtHandler,
|
|||||||
public:
|
public:
|
||||||
AudacityCommand();
|
AudacityCommand();
|
||||||
virtual ~AudacityCommand();
|
virtual ~AudacityCommand();
|
||||||
|
|
||||||
|
// Type of a registered function that, if it returns true,
|
||||||
|
// causes ShowInterface to return early without making any dialog
|
||||||
|
using VetoDialogHook = bool (*) ( wxDialog* );
|
||||||
|
static VetoDialogHook SetVetoDialogHook( VetoDialogHook hook );
|
||||||
|
|
||||||
// ComponentInterface implementation
|
// ComponentInterface implementation
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ small calculations of rectangles.
|
|||||||
#include "../Audacity.h"
|
#include "../Audacity.h"
|
||||||
#include "ScreenshotCommand.h"
|
#include "ScreenshotCommand.h"
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "../Project.h"
|
#include "../Project.h"
|
||||||
#include <wx/toplevel.h>
|
#include <wx/toplevel.h>
|
||||||
#include <wx/dcscreen.h>
|
#include <wx/dcscreen.h>
|
||||||
@ -31,6 +33,7 @@ small calculations of rectangles.
|
|||||||
|
|
||||||
#include "../AdornedRulerPanel.h"
|
#include "../AdornedRulerPanel.h"
|
||||||
#include "../TrackPanel.h"
|
#include "../TrackPanel.h"
|
||||||
|
#include "../effects/Effect.h"
|
||||||
#include "../toolbars/ToolManager.h"
|
#include "../toolbars/ToolManager.h"
|
||||||
#include "../Prefs.h"
|
#include "../Prefs.h"
|
||||||
#include "../Shuttle.h"
|
#include "../Shuttle.h"
|
||||||
@ -87,7 +90,19 @@ kBackgroundStrings[ ScreenshotCommand::nBackgrounds ] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
bool ScreenshotCommand::DefineParams( ShuttleParams & S ){
|
ScreenshotCommand::ScreenshotCommand()
|
||||||
|
{
|
||||||
|
mbBringToTop=true;
|
||||||
|
mIgnore=NULL;
|
||||||
|
|
||||||
|
static std::once_flag flag;
|
||||||
|
std::call_once( flag, []{
|
||||||
|
AudacityCommand::SetVetoDialogHook( MayCapture );
|
||||||
|
Effect::SetVetoDialogHook( MayCapture );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScreenshotCommand::DefineParams( ShuttleParams & S ){
|
||||||
S.Define( mPath, wxT("Path"), wxT(""));
|
S.Define( mPath, wxT("Path"), wxT(""));
|
||||||
S.DefineEnum( mWhat, wxT("CaptureWhat"), kwindow,kCaptureWhatStrings, nCaptureWhats );
|
S.DefineEnum( mWhat, wxT("CaptureWhat"), kwindow,kCaptureWhatStrings, nCaptureWhats );
|
||||||
S.DefineEnum( mBack, wxT("Background"), kNone, kBackgroundStrings, nBackgrounds );
|
S.DefineEnum( mBack, wxT("Background"), kNone, kBackgroundStrings, nBackgrounds );
|
||||||
|
@ -78,7 +78,7 @@ public:
|
|||||||
nCaptureWhats
|
nCaptureWhats
|
||||||
};
|
};
|
||||||
|
|
||||||
ScreenshotCommand(){ mbBringToTop=true;mIgnore=NULL;};
|
ScreenshotCommand();
|
||||||
// ComponentInterface overrides
|
// ComponentInterface overrides
|
||||||
ComponentInterfaceSymbol GetSymbol() override {return SCREENSHOT_PLUGIN_SYMBOL;};
|
ComponentInterfaceSymbol GetSymbol() override {return SCREENSHOT_PLUGIN_SYMBOL;};
|
||||||
wxString GetDescription() override {return _("Takes screenshots.");};
|
wxString GetDescription() override {return _("Takes screenshots.");};
|
||||||
|
@ -59,6 +59,7 @@ greater use in future.
|
|||||||
#include "../ShuttleGui.h"
|
#include "../ShuttleGui.h"
|
||||||
#include "../Shuttle.h"
|
#include "../Shuttle.h"
|
||||||
#include "../WaveTrack.h"
|
#include "../WaveTrack.h"
|
||||||
|
#include "../commands/Command.h"
|
||||||
#include "../toolbars/ControlToolBar.h"
|
#include "../toolbars/ControlToolBar.h"
|
||||||
#include "../widgets/AButton.h"
|
#include "../widgets/AButton.h"
|
||||||
#include "../widgets/ProgressDialog.h"
|
#include "../widgets/ProgressDialog.h"
|
||||||
@ -76,8 +77,6 @@ greater use in future.
|
|||||||
#include <Cocoa/Cocoa.h>
|
#include <Cocoa/Cocoa.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../commands/ScreenshotCommand.h"
|
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
// Effect application counter
|
// Effect application counter
|
||||||
@ -109,6 +108,25 @@ const wxString Effect::kFactoryDefaultsIdent = wxT("<Factory Defaults>");
|
|||||||
|
|
||||||
using t2bHash = std::unordered_map< void*, bool >;
|
using t2bHash = std::unordered_map< void*, bool >;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
Effect::VetoDialogHook &GetVetoDialogHook()
|
||||||
|
{
|
||||||
|
static Effect::VetoDialogHook sHook = nullptr;
|
||||||
|
return sHook;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
auto Effect::SetVetoDialogHook( VetoDialogHook hook )
|
||||||
|
-> VetoDialogHook
|
||||||
|
{
|
||||||
|
auto &theHook = GetVetoDialogHook();
|
||||||
|
auto result = theHook;
|
||||||
|
theHook = hook;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
Effect::Effect()
|
Effect::Effect()
|
||||||
{
|
{
|
||||||
mClient = NULL;
|
mClient = NULL;
|
||||||
@ -556,7 +574,8 @@ bool Effect::ShowInterface(wxWindow *parent, bool forceModal)
|
|||||||
mUIDialog->Fit();
|
mUIDialog->Fit();
|
||||||
mUIDialog->SetMinSize(mUIDialog->GetSize());
|
mUIDialog->SetMinSize(mUIDialog->GetSize());
|
||||||
|
|
||||||
if( ScreenshotCommand::MayCapture( mUIDialog ) )
|
auto hook = GetVetoDialogHook();
|
||||||
|
if( hook && hook( mUIDialog ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( SupportsRealtime() && !forceModal )
|
if( SupportsRealtime() && !forceModal )
|
||||||
|
@ -72,6 +72,11 @@ class AUDACITY_DLL_API Effect /* not final */ : public wxEvtHandler,
|
|||||||
Effect();
|
Effect();
|
||||||
virtual ~Effect();
|
virtual ~Effect();
|
||||||
|
|
||||||
|
// Type of a registered function that, if it returns true,
|
||||||
|
// causes ShowInterface to return early without making any dialog
|
||||||
|
using VetoDialogHook = bool (*) ( wxDialog* );
|
||||||
|
static VetoDialogHook SetVetoDialogHook( VetoDialogHook hook );
|
||||||
|
|
||||||
// ComponentInterface implementation
|
// ComponentInterface implementation
|
||||||
|
|
||||||
PluginPath GetPath() override;
|
PluginPath GetPath() override;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user