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 25, 2023
1 parent fca64ec commit 0b5a964
Show file tree
Hide file tree
Showing 77 changed files with 450 additions and 130 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
32 changes: 32 additions & 0 deletions libraries/lib-menus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#[[
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
Menus.cpp
Menus.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
2 changes: 0 additions & 2 deletions src/MenuRegistry.cpp → libraries/lib-menus/MenuRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
*//*******************************************************************/
#include "MenuRegistry.h"
#include <wx/frame.h>
#include "Project.h"
#include "ProjectWindows.h"
#include "BasicUI.h"
#include <wx/log.h>

Expand Down
26 changes: 13 additions & 13 deletions src/MenuRegistry.h → libraries/lib-menus/MenuRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

#include "Callable.h"
#include "MemoryX.h"
#include "commands/CommandFunctors.h"
#include "commands/CommandFlag.h"
#include "CommandFunctors.h"
#include "CommandFlag.h"
#include "Registry.h"
#include <functional>

Expand All @@ -30,7 +30,7 @@ namespace MenuRegistry {
// type of a function that determines checkmark state
using CheckFn = std::function< bool(AudacityProject&) >;

struct AUDACITY_DLL_API Options
struct MENUS_API Options
{
Options() {}
// Allow implicit construction from an accelerator string, which is
Expand Down Expand Up @@ -117,7 +117,7 @@ namespace MenuRegistry {
ConditionalGroupItem, MenuItem, MenuItems, MenuPart>;
};

struct AUDACITY_DLL_API Visitor : Registry::Visitor
struct MENUS_API Visitor : Registry::Visitor
{
// final overrides
void BeginGroup(const GroupItemBase &item, const Path &path) final;
Expand All @@ -137,20 +137,20 @@ namespace MenuRegistry {
};

//! As template argument to groups, lets computed items take a project argument
struct ProjectVisitor : Visitor
struct MENUS_API ProjectVisitor : Visitor
{
explicit ProjectVisitor(AudacityProject &p) : mProject{ p } {}
operator AudacityProject & () const { return mProject; }
AudacityProject &mProject;
};

void Visit(ProjectVisitor &visitor);
MENUS_API void Visit(ProjectVisitor &visitor);

// These are found by dynamic_cast
struct AUDACITY_DLL_API MenuSection {
struct MENUS_API MenuSection {
virtual ~MenuSection();
};
struct AUDACITY_DLL_API WholeMenu {
struct MENUS_API WholeMenu {
WholeMenu( bool extend = false ) : extension{ extend } {}
virtual ~WholeMenu();
bool extension;
Expand All @@ -162,7 +162,7 @@ namespace MenuRegistry {
};

// Describes a main menu in the toolbar, or a sub-menu
struct AUDACITY_DLL_API MenuItem final
struct MENUS_API MenuItem final
: Composite::Extension<
GroupItem<Traits>, MenuItemData, const Identifier&
>
Expand All @@ -177,7 +177,7 @@ namespace MenuRegistry {

// Collects other items that are conditionally shown or hidden, but are
// always available to macro programming
struct ConditionalGroupItem final
struct MENUS_API ConditionalGroupItem final
: Composite::Extension<
GroupItem<Traits>, Condition, const Identifier &
>
Expand All @@ -198,7 +198,7 @@ namespace MenuRegistry {
// This is used before a sequence of many calls to Command() and
// CommandGroup(), so that the finder argument need not be specified
// in each call.
class AUDACITY_DLL_API FinderScope : ValueRestorer< CommandHandlerFinder >
class MENUS_API FinderScope : ValueRestorer< CommandHandlerFinder >
{
static CommandHandlerFinder sFinder;

Expand All @@ -214,7 +214,7 @@ namespace MenuRegistry {
};

// Describes one command in a menu
struct AUDACITY_DLL_API CommandItem final : SingleItem {
struct MENUS_API CommandItem final : SingleItem {
CommandItem(const CommandID &name_,
const TranslatableString &label_in_,
CommandFunctorPointer callback_,
Expand Down Expand Up @@ -264,7 +264,7 @@ namespace MenuRegistry {
// Describes several successive commands in a menu that are closely related
// and dispatch to one common callback, which will be passed a number
// in the CommandContext identifying the command
struct AUDACITY_DLL_API CommandGroupItem final : SingleItem {
struct MENUS_API CommandGroupItem final : SingleItem {
CommandGroupItem(const Identifier &name_,
std::vector<ComponentInterfaceSymbol> items_,
CommandFunctorPointer callback_,
Expand Down
Loading

0 comments on commit 0b5a964

Please sign in to comment.