mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-19 09:01:15 +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:
@@ -44,10 +44,27 @@ ShuttleGui.
|
||||
#include "../widgets/HelpSystem.h"
|
||||
#include "../widgets/ErrorDialog.h"
|
||||
|
||||
#include "../commands/ScreenshotCommand.h"
|
||||
|
||||
#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()
|
||||
{
|
||||
mProgress = NULL;
|
||||
@@ -105,7 +122,8 @@ bool AudacityCommand::ShowInterface(wxWindow *parent, bool WXUNUSED(forceModal))
|
||||
mUIDialog->SetMinSize(mUIDialog->GetSize());
|
||||
|
||||
// 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;
|
||||
|
||||
bool res = mUIDialog->ShowModal() != 0;
|
||||
|
@@ -45,6 +45,11 @@ class AUDACITY_DLL_API AudacityCommand /* not final */ : public wxEvtHandler,
|
||||
public:
|
||||
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
|
||||
|
||||
|
@@ -20,6 +20,8 @@ small calculations of rectangles.
|
||||
#include "../Audacity.h"
|
||||
#include "ScreenshotCommand.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "../Project.h"
|
||||
#include <wx/toplevel.h>
|
||||
#include <wx/dcscreen.h>
|
||||
@@ -31,6 +33,7 @@ small calculations of rectangles.
|
||||
|
||||
#include "../AdornedRulerPanel.h"
|
||||
#include "../TrackPanel.h"
|
||||
#include "../effects/Effect.h"
|
||||
#include "../toolbars/ToolManager.h"
|
||||
#include "../Prefs.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.DefineEnum( mWhat, wxT("CaptureWhat"), kwindow,kCaptureWhatStrings, nCaptureWhats );
|
||||
S.DefineEnum( mBack, wxT("Background"), kNone, kBackgroundStrings, nBackgrounds );
|
||||
|
@@ -78,7 +78,7 @@ public:
|
||||
nCaptureWhats
|
||||
};
|
||||
|
||||
ScreenshotCommand(){ mbBringToTop=true;mIgnore=NULL;};
|
||||
ScreenshotCommand();
|
||||
// ComponentInterface overrides
|
||||
ComponentInterfaceSymbol GetSymbol() override {return SCREENSHOT_PLUGIN_SYMBOL;};
|
||||
wxString GetDescription() override {return _("Takes screenshots.");};
|
||||
|
Reference in New Issue
Block a user