1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-16 00:24:14 +02:00

Each toolbar registers its menu item

This commit is contained in:
Paul Licameli 2020-02-14 10:20:25 -05:00
parent 4bbf8bfb6a
commit d0a99d5ae5
17 changed files with 185 additions and 217 deletions

@ -1189,7 +1189,13 @@ void MenuCreator::CreateMenusAndCommands(AudacityProject &project)
)},
{wxT("/View/Windows"), wxT("UndoHistory,Karaoke,MixerBoard")},
{wxT("/Analyze/Analyzers/Windows"), wxT("ContrastAnalyser,PlotSpectrum")},
{wxT("/Transport/Basic"),wxT("Play,Record,Scrubbing,Cursor")},
{wxT("/Transport/Basic"), wxT("Play,Record,Scrubbing,Cursor")},
{wxT("/View/Other/Toolbars/Toolbars/Other"), wxT(
"ShowTransportTB,ShowToolsTB,ShowRecordMeterTB,ShowPlayMeterTB,"
//"ShowMeterTB,"
"ShowMixerTB,"
"ShowEditTB,ShowTranscriptionTB,ShowScrubbingTB,ShowDeviceTB,ShowSelectionTB,"
"ShowSpectralSelectionTB") }
}
};

@ -28,9 +28,10 @@ class wxEvtHandler;
// couldn't satisfy the requirement for both base classes at once.
using CommandHandlerObject = wxEvtHandler;
// First of two function pointers registered with each command: an extractor
// First of two functions registered with each command: an extractor
// of the handler object from the AudacityProject
using CommandHandlerFinder = CommandHandlerObject &(*)(AudacityProject&);
using CommandHandlerFinder =
std::function< CommandHandlerObject&(AudacityProject &) >;
// Second of two function pointers registered with each command: a pointer
// to a member function of the handler object

@ -1,5 +1,4 @@
#include "../Audacity.h"
#include "../Experimental.h"
#include "../Menus.h"
#include "../TrackPanel.h"
@ -43,141 +42,6 @@ void OnResetToolBars(const CommandContext &context)
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowTransportToolBar(const CommandContext &context)
{
auto &project = context.project;
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide(TransportBarID);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowTimeToolBar(const CommandContext &context)
{
auto &project = context.project;
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( TimeBarID );
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowToolsToolBar(const CommandContext &context)
{
auto &project = context.project;
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( ToolsBarID );
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowRecordMeterToolBar(const CommandContext &context)
{
auto &project = context.project;
auto &toolManager = ToolManager::Get( project );
if( !toolManager.IsVisible( RecordMeterBarID ) )
{
toolManager.Expose( MeterBarID, false );
}
toolManager.ShowHide( RecordMeterBarID );
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowPlayMeterToolBar(const CommandContext &context)
{
auto &project = context.project;
auto &toolManager = ToolManager::Get( project );
if( !toolManager.IsVisible( PlayMeterBarID ) )
{
toolManager.Expose( MeterBarID, false );
}
toolManager.ShowHide( PlayMeterBarID );
MenuManager::Get(project).ModifyToolbarMenus(project);
}
#if 0
void OnShowMeterToolBar(const CommandContext &context)
{
auto &project = context.project;
auto &toolManager = ToolManager::Get( project );
if( !toolManager.IsVisible( MeterBarID ) )
{
toolManager.Expose( PlayMeterBarID, false );
toolManager.Expose( RecordMeterBarID, false );
}
toolManager.ShowHide( MeterBarID );
MenuManager::Get(project).ModifyToolbarMenus(project);
}
#endif
void OnShowMixerToolBar(const CommandContext &context)
{
auto &project = context.project;
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( MixerBarID );
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowEditToolBar(const CommandContext &context)
{
auto &project = context.project;
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( EditBarID );
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowTranscriptionToolBar(const CommandContext &context)
{
auto &project = context.project;
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( TranscriptionBarID );
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowScrubbingToolBar(const CommandContext &context)
{
auto &project = context.project;
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( ScrubbingBarID );
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowDeviceToolBar(const CommandContext &context)
{
auto &project = context.project;
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( DeviceBarID );
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowSelectionToolBar(const CommandContext &context)
{
auto &project = context.project;
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( SelectionBarID );
MenuManager::Get(project).ModifyToolbarMenus(project);
}
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
void OnShowSpectralSelectionToolBar(const CommandContext &context)
{
auto &project = context.project;
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( SpectralSelectionBarID );
MenuManager::Get(project).ModifyToolbarMenus(project);
}
#endif
/// Handler to set the select tool active
void OnSelectTool(const CommandContext &context)
{
@ -278,83 +142,7 @@ BaseItemSharedPtr ToolbarsMenu()
FN(OnResetToolBars), AlwaysEnabledFlag )
),
Section( "Other",
/* i18n-hint: Clicking this menu item shows the toolbar
with the big buttons on it (play record etc)*/
Command( wxT("ShowTransportTB"), XXO("&Transport Toolbar"),
FN(OnShowTransportToolBar), AlwaysEnabledFlag,
Options{}.CheckTest( ToolbarCheckFn( TransportBarID ) ) ),
/* i18n-hint: Clicking this menu item shows a toolbar
that has some tools in it*/
Command( wxT("ShowToolsTB"), XXO("T&ools Toolbar"),
FN(OnShowToolsToolBar), AlwaysEnabledFlag,
Options{}.CheckTest( ToolbarCheckFn( ToolsBarID ) ) ),
/* i18n-hint: Clicking this menu item shows the toolbar
with the recording level meters*/
Command( wxT("ShowRecordMeterTB"), XXO("&Recording Meter Toolbar"),
FN(OnShowRecordMeterToolBar), AlwaysEnabledFlag,
Options{}.CheckTest( ToolbarCheckFn( RecordMeterBarID ) ) ),
/* i18n-hint: Clicking this menu item shows the toolbar
with the playback level meter*/
Command( wxT("ShowPlayMeterTB"), XXO("&Playback Meter Toolbar"),
FN(OnShowPlayMeterToolBar), AlwaysEnabledFlag,
Options{}.CheckTest( ToolbarCheckFn( PlayMeterBarID ) ) )
/* --i18nhint: Clicking this menu item shows the toolbar
which has sound level meters*/
//Command( wxT("ShowMeterTB"), XXO("Co&mbined Meter Toolbar"),
// FN(OnShowMeterToolBar), AlwaysEnabledFlag,
// Options{}.CheckTest( ToolbarCheckFn( MeterBarID ) ) )
,
/* i18n-hint: Clicking this menu item shows the toolbar
with the mixer*/
Command( wxT("ShowMixerTB"), XXO("Mi&xer Toolbar"),
FN(OnShowMixerToolBar), AlwaysEnabledFlag,
Options{}.CheckTest( ToolbarCheckFn( MixerBarID ) ) ),
/* i18n-hint: Clicking this menu item shows the toolbar for editing*/
Command( wxT("ShowEditTB"), XXO("&Edit Toolbar"),
FN(OnShowEditToolBar), AlwaysEnabledFlag,
Options{}.CheckTest( ToolbarCheckFn( EditBarID ) ) ),
/* i18n-hint: Clicking this menu item shows the toolbar
for transcription (currently just vary play speed)*/
Command( wxT("ShowTranscriptionTB"), XXO("Pla&y-at-Speed Toolbar"),
FN(OnShowTranscriptionToolBar), AlwaysEnabledFlag,
Options{}.CheckTest( ToolbarCheckFn( TranscriptionBarID ) ) ),
/* i18n-hint: Clicking this menu item shows the toolbar
that enables Scrub or Seek playback and Scrub Ruler*/
Command( wxT("ShowScrubbingTB"), XXO("Scru&b Toolbar"),
FN(OnShowScrubbingToolBar), AlwaysEnabledFlag,
Options{}.CheckTest( ToolbarCheckFn( ScrubbingBarID ) ) ),
/* i18n-hint: Clicking this menu item shows the toolbar
that manages devices*/
Command( wxT("ShowDeviceTB"), XXO("&Device Toolbar"),
FN(OnShowDeviceToolBar), AlwaysEnabledFlag,
Options{}.CheckTest( ToolbarCheckFn( DeviceBarID ) ) ),
/* i18n-hint: Clicking this menu item shows the toolbar
for selecting a time range of audio*/
Command( wxT("ShowSelectionTB"), XXO("&Selection Toolbar"),
FN(OnShowSelectionToolBar), AlwaysEnabledFlag,
Options{}.CheckTest( ToolbarCheckFn( SelectionBarID ) ) )
#ifdef EXPERIMENTAL_TIMER_TOOLBAR
,
/* i18n-hint: Clicking this menu item shows the toolbar
for viewing actual time of the cursor*/
Command( wxT("ShowTimeToolBarTB"), XXO("&Time Toolbar"),
FN(OnShowTimeToolBar), AlwaysEnabledFlag,
Options{}.CheckTest( ToolbarCheckFn( TimeBarID ) ) )
#endif
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
,
Command( wxT("ShowSpectralSelectionTB"),
/* i18n-hint: Clicking this menu item shows the toolbar
for selecting a frequency range of audio*/
XXO("Spe&ctral Selection Toolbar"),
FN(OnShowSpectralSelectionToolBar), AlwaysEnabledFlag,
Options{}.CheckTest( ToolbarCheckFn( SpectralSelectionBarID ) ) )
#endif
)
Section( "Other" )
)
) ) };
return menu;

@ -799,3 +799,11 @@ static RegisteredToolbarFactory factory{ TransportBarID,
[]( AudacityProject &project ){
return ToolBar::Holder{ safenew ControlToolBar{ project } }; }
};
namespace {
AttachedToolBarMenuItem sAttachment{
/* i18n-hint: Clicking this menu item shows the toolbar
with the big buttons on it (play record etc) */
TransportBarID, wxT("ShowTransportTB"), XXO("&Transport Toolbar")
};
}

@ -872,3 +872,12 @@ static RegisteredToolbarFactory factory{ DeviceBarID,
[]( AudacityProject &project ){
return ToolBar::Holder{ safenew DeviceToolBar{ project } }; }
};
namespace {
AttachedToolBarMenuItem sAttachment{
/* i18n-hint: Clicking this menu item shows the toolbar
that manages devices */
DeviceBarID, wxT("ShowDeviceTB"), XXO("&Device Toolbar")
};
}

@ -308,3 +308,13 @@ static RegisteredToolbarFactory factory{ EditBarID,
[]( AudacityProject &project ){
return ToolBar::Holder{ safenew EditToolBar{ project } }; }
};
#include "ToolManager.h"
namespace {
AttachedToolBarMenuItem sAttachment{
/* i18n-hint: Clicking this menu item shows the toolbar for editing */
EditBarID, wxT("ShowEditTB"), XXO("&Edit Toolbar")
};
}

@ -271,3 +271,27 @@ static RegisteredToolbarFactory factory3{ MeterBarID,
return ToolBar::Holder{
safenew MeterToolBar{ project, MeterBarID } }; }
};
#include "ToolManager.h"
namespace {
AttachedToolBarMenuItem sAttachment1{
/* i18n-hint: Clicking this menu item shows the toolbar
with the recording level meters */
RecordMeterBarID, wxT("ShowRecordMeterTB"), XXO("&Recording Meter Toolbar"),
{}, { MeterBarID }
};
AttachedToolBarMenuItem sAttachment2{
/* i18n-hint: Clicking this menu item shows the toolbar
with the playback level meter */
PlayMeterBarID, wxT("ShowPlayMeterTB"), XXO("&Playback Meter Toolbar"),
{}, { MeterBarID }
};
//AttachedToolBarMenuItem sAttachment3{
// /* --i18nhint: Clicking this menu item shows the toolbar
// which has sound level meters */
// MeterBarID, wxT("ShowMeterTB"), XXO("Co&mbined Meter Toolbar"),
// { Registry::OrderingHint::After, "ShowPlayMeterTB" },
// { PlayMeterBarID, RecordMeterBarID }
//};
}

@ -315,3 +315,11 @@ static RegisteredToolbarFactory factory{ MixerBarID,
[]( AudacityProject &project ){
return ToolBar::Holder{ safenew MixerToolBar{ project } }; }
};
namespace {
AttachedToolBarMenuItem sAttachment{
/* i18n-hint: Clicking this menu item shows the toolbar
with the mixer */
MixerBarID, wxT("ShowMixerTB"), XXO("Mi&xer Toolbar")
};
}

@ -287,3 +287,12 @@ static RegisteredToolbarFactory factory{ ScrubbingBarID,
[]( AudacityProject &project ){
return ToolBar::Holder{ safenew ScrubbingToolBar{ project } }; }
};
namespace {
AttachedToolBarMenuItem sAttachment{
/* i18n-hint: Clicking this menu item shows the toolbar
that enables Scrub or Seek playback and Scrub Ruler */
ScrubbingBarID, wxT("ShowScrubbingTB"), XXO("Scru&b Toolbar")
};
}

@ -814,3 +814,12 @@ static RegisteredToolbarFactory factory{ SelectionBarID,
[]( AudacityProject &project ){
return ToolBar::Holder{ safenew SelectionBar{ project } }; }
};
namespace {
AttachedToolBarMenuItem sAttachment{
/* i18n-hint: Clicking this menu item shows the toolbar
for selecting a time range of audio */
SelectionBarID, wxT("ShowSelectionTB"), XXO("&Selection Toolbar")
};
}

@ -510,4 +510,13 @@ static RegisteredToolbarFactory factory{ SpectralSelectionBarID,
return ToolBar::Holder{ safenew SpectralSelectionBar{ project } }; }
};
namespace {
AttachedToolBarMenuItem sAttachment{
SpectralSelectionBarID,
/* i18n-hint: Clicking this menu item shows the toolbar
for selecting a frequency range of audio */
wxT("ShowSpectralSelectionTB"), XXO("Spe&ctral Selection Toolbar")
};
}
#endif // #ifdef EXPERIMENTAL_SPECTRAL_EDITING

@ -13,6 +13,8 @@
#include "../Audacity.h"
#include "../Experimental.h"
#include "SelectionBar.h"
#include "SelectionBarListener.h"
@ -344,3 +346,15 @@ static RegisteredToolbarFactory factory{ TimeBarID,
[]( AudacityProject &project ){
return ToolBar::Holder{ safenew TimerToolBar{ project } }; }
};
#ifdef EXPERIMENTAL_TIMER_TOOLBAR
namespace {
AttachedToolBarMenuItem sAttachment{
/* i18n-hint: Clicking this menu item shows the toolbar
for viewing actual time of the cursor */
TimeBarID, wxT("ShowTimeToolBarTB"), XXO("&Time Toolbar"),
{ Registry::OrderingHint::After, "ShowSelectionTB" }
};
}
#endif

@ -64,7 +64,7 @@ DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TOOLBAR_UPDATED, -1);
//
// ToolBar IDs
//
enum
enum ToolBarID
{
NoBarID = -1,
TransportBarID,

@ -1538,3 +1538,40 @@ bool ToolManager::RestoreFocus()
}
return false;
}
#include "../commands/CommandContext.h"
#include "../Menus.h"
AttachedToolBarMenuItem::AttachedToolBarMenuItem(
ToolBarID id, const CommandID &name, const TranslatableString &label_in,
const Registry::OrderingHint &hint,
std::vector< ToolBarID > excludeIDs )
: mId{ id }
, mAttachedItem{
Registry::Placement{ wxT("View/Other/Toolbars/Toolbars/Other"), hint },
( MenuTable::FinderScope(
[this](AudacityProject &) -> CommandHandlerObject&
{ return *this; } ),
MenuTable::Command( name, label_in,
&AttachedToolBarMenuItem::OnShowToolBar,
AlwaysEnabledFlag,
CommandManager::Options{}.CheckTest( [id](AudacityProject &project){
auto &toolManager = ToolManager::Get( project );
return toolManager.IsVisible( id ); } ) ) ) }
, mExcludeIds{ std::move( excludeIDs ) }
{}
void AttachedToolBarMenuItem::OnShowToolBar( const CommandContext &context )
{
auto &project = context.project;
auto &toolManager = ToolManager::Get( project );
if( !toolManager.IsVisible( mId ) )
{
for ( const auto excludedID : mExcludeIds )
toolManager.Expose( excludedID, false );
}
toolManager.ShowHide(mId);
MenuManager::Get(project).ModifyToolbarMenus(project);
}

@ -210,4 +210,23 @@ public:
};
#include "../commands/CommandFunctors.h"
#include "../commands/CommandManager.h"
// Construct a static instance of this class to add a menu item that shows and
// hides a toolbar
struct AttachedToolBarMenuItem : CommandHandlerObject {
AttachedToolBarMenuItem(
ToolBarID id, const CommandID &name, const TranslatableString &label_in,
const Registry::OrderingHint &hint = {},
// IDs of other toolbars not to be shown simultaneously with this one:
std::vector< ToolBarID > excludeIds = {} );
void OnShowToolBar(const CommandContext &context);
const ToolBarID mId;
const MenuTable::AttachedItem mAttachedItem;
const std::vector< ToolBarID > mExcludeIds;
};
#endif

@ -297,3 +297,11 @@ static RegisteredToolbarFactory factory{ ToolsBarID,
[]( AudacityProject &project ){
return ToolBar::Holder{ safenew ToolsToolBar{ project } }; }
};
namespace {
AttachedToolBarMenuItem sAttachment{
/* i18n-hint: Clicking this menu item shows a toolbar
that has some tools in it */
ToolsBarID, wxT("ShowToolsTB"), XXO("T&ools Toolbar"),
};
}

@ -1006,3 +1006,12 @@ static RegisteredToolbarFactory factory{ TranscriptionBarID,
[]( AudacityProject &project ){
return ToolBar::Holder{ safenew TranscriptionToolBar{ project } }; }
};
namespace {
AttachedToolBarMenuItem sAttachment{
/* i18n-hint: Clicking this menu item shows the toolbar
for transcription (currently just vary play speed) */
TranscriptionBarID, wxT("ShowTranscriptionTB"), XXO("Pla&y-at-Speed Toolbar")
};
}