Skip to content

Commit

Permalink
New library lib-menus
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Licameli committed Oct 28, 2023
1 parent c1d1c23 commit fe0bc9c
Show file tree
Hide file tree
Showing 76 changed files with 177 additions and 148 deletions.
1 change: 1 addition & 0 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ set( LIBRARIES
lib-mixer
lib-channel
lib-stretching-sequence
lib-menus
)

if ( ${_OPT}has_networking )
Expand Down
30 changes: 30 additions & 0 deletions libraries/lib-menus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#[[
Vocabulary to describe toolbar menu items, their grouping, conditions to enable
them, and their actions.
A global registry of menu descriptions and a visitor function.
It does not contain a visitor to build menus, becuase that is not
toolkit-neutral.
]]

set(SOURCES
CommandContext.cpp
CommandContext.h
CommandFlag.cpp
CommandFlag.h
CommandFunctors.h
CommandTargets.cpp
CommandTargets.h
Keyboard.cpp
Keyboard.h
MenuRegistry.cpp
MenuRegistry.h
)

set( LIBRARIES
lib-project-interface
)

audacity_library(lib-menus "${SOURCES}" "${LIBRARIES}"
"" "" )
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct TemporarySelection {
Track *pTrack = nullptr;
};

class AUDACITY_DLL_API CommandContext {
class MENUS_API CommandContext {
public:
struct TargetFactory : DefaultedGlobalHook< TargetFactory,
Callable::UniquePtrFactory<CommandOutputTargets>::Function
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

// Flags used in command handling.

#include "TranslatableString.h"

#include <bitset>
#include <functional>
#include <utility>

#include "audacity/Types.h"

class AudacityProject;

// Increase the template parameter as needed to allow more flags
Expand Down Expand Up @@ -84,7 +84,7 @@ struct CommandFlagOptions{
// Construct one statically to register (and reserve) a bit position in the set
// an associate it with a test function; those with quickTest = true are cheap
// to compute and always checked
class AUDACITY_DLL_API ReservedCommandFlag : public CommandFlag
class MENUS_API ReservedCommandFlag : public CommandFlag
{
public:
using Predicate = std::function< bool( const AudacityProject& ) >;
Expand Down Expand Up @@ -122,7 +122,7 @@ struct MenuItemEnabler {
using MenuItemEnablers = std::vector<MenuItemEnabler>;

// Typically this is statically constructed:
struct AUDACITY_DLL_API RegisteredMenuItemEnabler{
struct MENUS_API RegisteredMenuItemEnabler{
static const MenuItemEnablers &Enablers();
RegisteredMenuItemEnabler( const MenuItemEnabler &enabler );
};
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CommandProgressTarget /* not final */
};

/// Interface for objects that can receive (string) messages from a command
class AUDACITY_DLL_API CommandMessageTarget /* not final */
class MENUS_API CommandMessageTarget /* not final */
{
public:
CommandMessageTarget() {mCounts.push_back(0);}
Expand All @@ -87,10 +87,11 @@ class AUDACITY_DLL_API CommandMessageTarget /* not final */
std::vector<int> mCounts;
};

class CommandMessageTargetDecorator : public CommandMessageTarget
class MENUS_API CommandMessageTargetDecorator : public CommandMessageTarget
{
public:
CommandMessageTargetDecorator( CommandMessageTarget & target): mTarget(target) {}
CommandMessageTargetDecorator(CommandMessageTarget & target)
: mTarget(target) {}
~CommandMessageTargetDecorator() override;
void Update(const wxString &message) override { mTarget.Update( message );}
void StartArray() override { mTarget.StartArray();}
Expand All @@ -112,48 +113,58 @@ class CommandMessageTargetDecorator : public CommandMessageTarget
CommandMessageTarget & mTarget;
};

class LispyCommandMessageTarget : public CommandMessageTargetDecorator /* not final */
class MENUS_API LispyCommandMessageTarget
: public CommandMessageTargetDecorator /* not final */
{
public:
LispyCommandMessageTarget( CommandMessageTarget & target): CommandMessageTargetDecorator(target) {};
LispyCommandMessageTarget( CommandMessageTarget & target)
: CommandMessageTargetDecorator(target) {};
~LispyCommandMessageTarget() override;
virtual void StartArray() override;
virtual void EndArray() override;
virtual void StartStruct() override;
virtual void EndStruct() override;
virtual void AddItem(const wxString &value , const wxString &name = {} )override;
virtual void AddBool(const bool value , const wxString &name = {} )override;
virtual void AddItem(const double value , const wxString &name = {} )override;
virtual void AddItem(const wxString &value , const wxString &name = {})
override;
virtual void AddBool(const bool value , const wxString &name = {})
override;
virtual void AddItem(const double value , const wxString &name = {})
override;
virtual void StartField( const wxString &name = {} )override;
virtual void EndField( ) override;
};

class BriefCommandMessageTarget : public CommandMessageTargetDecorator /* not final */
class MENUS_API BriefCommandMessageTarget
: public CommandMessageTargetDecorator /* not final */
{
public:
BriefCommandMessageTarget( CommandMessageTarget & target): CommandMessageTargetDecorator(target) {};
BriefCommandMessageTarget( CommandMessageTarget & target)
: CommandMessageTargetDecorator(target) {};
~BriefCommandMessageTarget() override;
virtual void StartArray() override;
virtual void EndArray() override;
virtual void StartStruct() override;
virtual void EndStruct() override;
virtual void AddItem(const wxString &value , const wxString &name = {} )override;
virtual void AddBool(const bool value , const wxString &name = {} )override;
virtual void AddItem(const double value , const wxString &name = {} )override;
virtual void AddItem(const wxString &value , const wxString &name = {})
override;
virtual void AddBool(const bool value , const wxString &name = {})
override;
virtual void AddItem(const double value , const wxString &name = {})
override;
virtual void StartField( const wxString &name = {} )override;
virtual void EndField( ) override;
};

/// Used to ignore a command's progress updates
class NullProgressTarget final : public CommandProgressTarget
class MENUS_API NullProgressTarget final : public CommandProgressTarget
{
public:
~NullProgressTarget() override;
void Update(double WXUNUSED(completed)) override {}
};

///
class ProgressToMessageTarget final : public CommandProgressTarget
class MENUS_API ProgressToMessageTarget final : public CommandProgressTarget
{
private:
std::unique_ptr<CommandMessageTarget> mTarget;
Expand All @@ -169,23 +180,23 @@ class ProgressToMessageTarget final : public CommandProgressTarget
};

/// Used to ignore a command's message updates
class NullMessageTarget final : public CommandMessageTarget
class MENUS_API NullMessageTarget final : public CommandMessageTarget
{
public:
~NullMessageTarget() override;
void Update(const wxString &) override {}
};

/// Displays messages from a command in a BasicUI::MessageBox
class AUDACITY_DLL_API MessageBoxTarget final : public CommandMessageTarget
class MENUS_API MessageBoxTarget final : public CommandMessageTarget
{
public:
~MessageBoxTarget() override;
void Update(const wxString &message) override;
};

/// Constructs a response (to be sent back to a script)
class ResponseTarget final : public CommandMessageTarget
class MENUS_API ResponseTarget final : public CommandMessageTarget
{
private:
wxSemaphore mSemaphore;
Expand Down Expand Up @@ -215,7 +226,7 @@ class ResponseTarget final : public CommandMessageTarget
};

/// Sends messages to two message targets at once
class CombinedMessageTarget final : public CommandMessageTarget
class MENUS_API CombinedMessageTarget final : public CommandMessageTarget
{
private:
std::unique_ptr<CommandMessageTarget> m1, m2;
Expand All @@ -238,8 +249,8 @@ class CombinedMessageTarget final : public CommandMessageTarget

/**
\class TargetFactory
\brief TargetFactory makes Command output targets. By default, we ignore progress
updates but display all other messages directly
\brief TargetFactory makes Command output targets.
By default, we ignore progress updates but display all other messages directly
*/
class TargetFactory
{
Expand Down Expand Up @@ -267,12 +278,13 @@ class CommandOutputTargets /* not final */
std::shared_ptr<CommandMessageTarget> mStatusTarget;
std::shared_ptr<CommandMessageTarget> mErrorTarget;
public:
// && is not a reference to a reference, but rather a way to allow reference to a temporary
// that will be gone or transferred after we have taken it. It's a reference to an xvalue,
// or 'expiring value'.
CommandOutputTargets(std::unique_ptr<CommandProgressTarget> &&pt = TargetFactory::ProgressDefault(),
std::shared_ptr<CommandMessageTarget> &&st = TargetFactory::MessageDefault(),
std::shared_ptr<CommandMessageTarget> &&et = TargetFactory::MessageDefault())
CommandOutputTargets(
std::unique_ptr<CommandProgressTarget> pt =
TargetFactory::ProgressDefault(),
std::shared_ptr<CommandMessageTarget> st =
TargetFactory::MessageDefault(),
std::shared_ptr<CommandMessageTarget> et =
TargetFactory::MessageDefault())
: mProgressTarget(std::move(pt)), mStatusTarget(st), mErrorTarget(et)
{ }
~CommandOutputTargets()
Expand Down Expand Up @@ -344,7 +356,7 @@ class CommandOutputTargets /* not final */
}
};

class AUDACITY_DLL_API LispifiedCommandOutputTargets
class MENUS_API LispifiedCommandOutputTargets
: public CommandOutputTargets
{
public :
Expand All @@ -354,7 +366,7 @@ public :
CommandOutputTargets * pToRestore;
};

class AUDACITY_DLL_API BriefCommandOutputTargets : public CommandOutputTargets
class MENUS_API BriefCommandOutputTargets : public CommandOutputTargets
{
public :
BriefCommandOutputTargets( CommandOutputTargets & target );
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/commands/Keyboard.h → libraries/lib-menus/Keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct NormalizedKeyStringTag;
// Case insensitive comparisons
using NormalizedKeyStringBase = TaggedIdentifier<NormalizedKeyStringTag, false>;

struct AUDACITY_DLL_API NormalizedKeyString : NormalizedKeyStringBase
struct MENUS_API NormalizedKeyString : NormalizedKeyStringBase
{
NormalizedKeyString() = default;
explicit NormalizedKeyString( const wxString &key );
Expand Down
12 changes: 10 additions & 2 deletions src/MenuRegistry.cpp → libraries/lib-menus/MenuRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@
*//*******************************************************************/
#include "MenuRegistry.h"
#include <wx/frame.h>
#include "Project.h"
#include "ProjectWindows.h"
#include "BasicUI.h"
#include <wx/log.h>

namespace MenuRegistry {
auto Options::MakeCheckFn(const wxString key, bool defaultValue ) -> CheckFn
{
return [=](AudacityProject&){ return gPrefs->ReadBool( key, defaultValue ); };
}

auto Options::MakeCheckFn(const BoolSetting &setting ) -> CheckFn
{
return MakeCheckFn( setting.GetPath(), setting.GetDefault() );
}

std::pair<bool, bool> detail::VisitorBase::ShouldBeginGroup(
const ItemProperties *pProperties)
{
Expand Down
Loading

0 comments on commit fe0bc9c

Please sign in to comment.