mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 08:09:32 +02:00
define CommandContext
This commit is contained in:
parent
aa5c3f12a3
commit
0a711d8b26
@ -13,6 +13,25 @@
|
|||||||
#include <wx/event.h>
|
#include <wx/event.h>
|
||||||
#include "../MemoryX.h"
|
#include "../MemoryX.h"
|
||||||
|
|
||||||
|
class AudacityProject;
|
||||||
|
class wxEvent;
|
||||||
|
|
||||||
|
struct CommandContext {
|
||||||
|
CommandContext(
|
||||||
|
AudacityProject &p
|
||||||
|
, const wxEvent *e = nullptr
|
||||||
|
, int ii = 0
|
||||||
|
)
|
||||||
|
: project{ p }
|
||||||
|
, pEvt{ e }
|
||||||
|
, index{ ii }
|
||||||
|
{}
|
||||||
|
|
||||||
|
AudacityProject &project;
|
||||||
|
const wxEvent *pEvt;
|
||||||
|
int index;
|
||||||
|
};
|
||||||
|
|
||||||
class wxEvent;
|
class wxEvent;
|
||||||
typedef wxString PluginID;
|
typedef wxString PluginID;
|
||||||
|
|
||||||
@ -21,7 +40,7 @@ class AUDACITY_DLL_API CommandFunctor /* not final */
|
|||||||
public:
|
public:
|
||||||
CommandFunctor(){};
|
CommandFunctor(){};
|
||||||
virtual ~CommandFunctor(){};
|
virtual ~CommandFunctor(){};
|
||||||
virtual void operator()(int index, const wxEvent *e) = 0;
|
virtual void operator()(const CommandContext &context) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
using CommandFunctorPointer = std::shared_ptr <CommandFunctor>;
|
using CommandFunctorPointer = std::shared_ptr <CommandFunctor>;
|
||||||
@ -39,7 +58,7 @@ class VoidFunctor final : public CommandFunctor
|
|||||||
public:
|
public:
|
||||||
explicit VoidFunctor(OBJ *This, audCommandFunction<OBJ> pfn)
|
explicit VoidFunctor(OBJ *This, audCommandFunction<OBJ> pfn)
|
||||||
: mThis{ This }, mCommandFunction{ pfn } {}
|
: mThis{ This }, mCommandFunction{ pfn } {}
|
||||||
void operator () (int, const wxEvent *) override
|
void operator () (const CommandContext &context) override
|
||||||
{ (mThis->*mCommandFunction) (); }
|
{ (mThis->*mCommandFunction) (); }
|
||||||
private:
|
private:
|
||||||
OBJ *const mThis;
|
OBJ *const mThis;
|
||||||
@ -55,8 +74,8 @@ class KeyFunctor final : public CommandFunctor
|
|||||||
public:
|
public:
|
||||||
explicit KeyFunctor(OBJ *This, audCommandKeyFunction<OBJ> pfn)
|
explicit KeyFunctor(OBJ *This, audCommandKeyFunction<OBJ> pfn)
|
||||||
: mThis{ This }, mCommandKeyFunction{ pfn } {}
|
: mThis{ This }, mCommandKeyFunction{ pfn } {}
|
||||||
void operator () (int, const wxEvent *evt) override
|
void operator () (const CommandContext &context) override
|
||||||
{ (mThis->*mCommandKeyFunction) (evt); }
|
{ (mThis->*mCommandKeyFunction) (context.pEvt); }
|
||||||
private:
|
private:
|
||||||
OBJ *const mThis;
|
OBJ *const mThis;
|
||||||
const audCommandKeyFunction<OBJ> mCommandKeyFunction;
|
const audCommandKeyFunction<OBJ> mCommandKeyFunction;
|
||||||
@ -73,7 +92,7 @@ class PopupFunctor final : public CommandFunctor
|
|||||||
public:
|
public:
|
||||||
explicit PopupFunctor(OBJ *This, audCommandPopupFunction<OBJ> pfn)
|
explicit PopupFunctor(OBJ *This, audCommandPopupFunction<OBJ> pfn)
|
||||||
: mThis{ This }, mCommandPopupFunction{ pfn } {}
|
: mThis{ This }, mCommandPopupFunction{ pfn } {}
|
||||||
void operator () (int, const wxEvent *) override
|
void operator () (const CommandContext &context) override
|
||||||
{ wxCommandEvent dummy; (mThis->*mCommandPopupFunction) (dummy); }
|
{ wxCommandEvent dummy; (mThis->*mCommandPopupFunction) (dummy); }
|
||||||
private:
|
private:
|
||||||
OBJ *const mThis;
|
OBJ *const mThis;
|
||||||
@ -89,8 +108,8 @@ class ListFunctor final : public CommandFunctor
|
|||||||
public:
|
public:
|
||||||
explicit ListFunctor(OBJ *This, audCommandListFunction<OBJ> pfn)
|
explicit ListFunctor(OBJ *This, audCommandListFunction<OBJ> pfn)
|
||||||
: mThis{ This }, mCommandListFunction{ pfn } {}
|
: mThis{ This }, mCommandListFunction{ pfn } {}
|
||||||
void operator () (int index, const wxEvent *) override
|
void operator () (const CommandContext &context) override
|
||||||
{ (mThis->*mCommandListFunction)(index); }
|
{ (mThis->*mCommandListFunction)(context.index); }
|
||||||
private:
|
private:
|
||||||
OBJ *const mThis;
|
OBJ *const mThis;
|
||||||
const audCommandListFunction<OBJ> mCommandListFunction;
|
const audCommandListFunction<OBJ> mCommandListFunction;
|
||||||
@ -105,7 +124,7 @@ class PluginFunctor final : public CommandFunctor
|
|||||||
public:
|
public:
|
||||||
explicit PluginFunctor(OBJ *This, const PluginID &id, audCommandPluginFunction<OBJ> pfn)
|
explicit PluginFunctor(OBJ *This, const PluginID &id, audCommandPluginFunction<OBJ> pfn)
|
||||||
: mPluginID{ id }, mThis{ This }, mCommandPluginFunction{ pfn } {}
|
: mPluginID{ id }, mThis{ This }, mCommandPluginFunction{ pfn } {}
|
||||||
void operator () (int, const wxEvent *) override
|
void operator () (const CommandContext &context) override
|
||||||
{ (mThis->*mCommandPluginFunction)
|
{ (mThis->*mCommandPluginFunction)
|
||||||
(mPluginID,
|
(mPluginID,
|
||||||
0 // AudacityProject::OnEffectFlags::kNone
|
0 // AudacityProject::OnEffectFlags::kNone
|
||||||
|
@ -1447,11 +1447,11 @@ bool CommandManager::HandleCommandEntry(const CommandListEntry * entry,
|
|||||||
if (!entry || !entry->enabled)
|
if (!entry || !entry->enabled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
auto proj = GetActiveProject();
|
||||||
|
|
||||||
auto combinedMask = (mask & entry->mask);
|
auto combinedMask = (mask & entry->mask);
|
||||||
if (combinedMask) {
|
if (combinedMask) {
|
||||||
|
|
||||||
AudacityProject * proj;
|
|
||||||
proj = GetActiveProject();
|
|
||||||
wxASSERT( proj );
|
wxASSERT( proj );
|
||||||
if( !proj )
|
if( !proj )
|
||||||
return false;
|
return false;
|
||||||
@ -1469,7 +1469,8 @@ bool CommandManager::HandleCommandEntry(const CommandListEntry * entry,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*(entry->callback))(entry->index, evt);
|
CommandContext context{ *proj, evt, entry->index };
|
||||||
|
(*(entry->callback))(context);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user