1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +02:00

static MenuManager::Get()...

... not member functions of AudacityProject
This commit is contained in:
Paul Licameli 2019-05-01 13:20:52 -04:00
parent 2f0a76ed10
commit 0923bc19a9
16 changed files with 72 additions and 60 deletions

View File

@ -802,7 +802,7 @@ bool MacroCommands::ApplyCommandInBatchMode( const wxString &friendlyCommand,
{
AudacityProject *project = GetActiveProject();
// Recalc flags and enable items that may have become enabled.
GetMenuManager(*project).UpdateMenus(*project, false);
MenuManager::Get(*project).UpdateMenus(*project, false);
// enter batch mode...
bool prevShowMode = project->GetShowId3Dialog();
project->mBatchMode++;

View File

@ -750,7 +750,7 @@ void MacrosWindow::UpdateMenus()
{
// OK even on mac, as dialog is modal.
auto p = GetActiveProject();
GetMenuManager(*p).RebuildMenuBar(*p);
MenuManager::Get(*p).RebuildMenuBar(*p);
}
void MacrosWindow::UpdateDisplay( bool bExpanded )

View File

@ -52,9 +52,6 @@
#include <wx/menu.h>
MenuManager &GetMenuManager(AudacityProject &project)
{ return *project.mMenuManager; }
MenuCreator::MenuCreator()
{
}
@ -63,6 +60,21 @@ MenuCreator::~MenuCreator()
{
}
static const AudacityProject::AttachedObjects::RegisteredFactory key{
[]( AudacityProject&){
return std::make_shared< MenuManager >(); }
};
MenuManager &MenuManager::Get( AudacityProject &project )
{
return project.AttachedObjects::Get< MenuManager >( key );
}
const MenuManager &MenuManager::Get( const AudacityProject &project )
{
return Get( const_cast< AudacityProject & >( project ) );
}
MenuManager::MenuManager()
{
UpdatePrefs();
@ -563,7 +575,7 @@ void MenuManager::ModifyAllProjectToolbarMenus()
AProjectArray::iterator i;
for (i = gAudacityProjects.begin(); i != gAudacityProjects.end(); ++i) {
auto &project = **i;
GetMenuManager(project).ModifyToolbarMenus(project);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
}
@ -647,7 +659,7 @@ void MenuManager::UpdateMenus(AudacityProject &project, bool checkActive)
if (&project != GetActiveProject())
return;
auto flags = GetMenuManager(project).GetUpdateFlags(project, checkActive);
auto flags = MenuManager::Get(project).GetUpdateFlags(project, checkActive);
auto flags2 = flags;
// We can enable some extra items if we have select-all-on-none.
@ -730,7 +742,7 @@ void MenuCreator::RebuildAllMenuBars()
for( size_t i = 0; i < gAudacityProjects.size(); i++ ) {
AudacityProject *p = gAudacityProjects[i].get();
GetMenuManager(*p).RebuildMenuBar(*p);
MenuManager::Get(*p).RebuildMenuBar(*p);
#if defined(__WXGTK__)
// Workaround for:
//
@ -767,7 +779,7 @@ bool MenuManager::TryToMakeActionAllowed
bool bAllowed;
if( !flags )
flags = GetMenuManager(project).GetUpdateFlags(project);
flags = MenuManager::Get(project).GetUpdateFlags(project);
bAllowed = ((flags & mask) == (flagsRqd & mask));
if( bAllowed )
@ -780,7 +792,7 @@ bool MenuManager::TryToMakeActionAllowed
if( mStopIfWasPaused && (MissingFlags & AudioIONotBusyFlag ) ){
TransportActions::StopIfPaused( project );
// Hope this will now reflect stopped audio.
flags = GetMenuManager(project).GetUpdateFlags(project);
flags = MenuManager::Get(project).GetUpdateFlags(project);
bAllowed = ((flags & mask) == (flagsRqd & mask));
if( bAllowed )
return true;
@ -812,7 +824,7 @@ bool MenuManager::TryToMakeActionAllowed
// When autoselect triggers, it might not select all audio in all tracks.
// So changed to DoSelectAllAudio.
SelectActions::DoSelectAllAudio(project);
flags = GetMenuManager(project).GetUpdateFlags(project);
flags = MenuManager::Get(project).GetUpdateFlags(project);
bAllowed = ((flags & mask) == (flagsRqd & mask));
return bAllowed;
}

View File

@ -14,6 +14,7 @@
#include <wx/string.h> // member variable
#include "Prefs.h"
#include "ClientData.h"
class wxArrayString;
class AudacityProject;
@ -50,9 +51,16 @@ public:
PluginID mLastEffect{};
};
class MenuManager final : public MenuCreator, private PrefsListener
class MenuManager final
: public MenuCreator
, public ClientData::Base
, private PrefsListener
{
public:
static MenuManager &Get( AudacityProject &project );
static const MenuManager &Get( const AudacityProject &project );
MenuManager();
static void ModifyUndoMenuItems(AudacityProject &project);
@ -89,8 +97,6 @@ private:
};
MenuManager &GetMenuManager(AudacityProject &project);
// Exported helper functions from various menu handling source files

View File

@ -1099,8 +1099,6 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
auto &viewInfo = ViewInfo::Get( *this );
mMenuManager = std::make_unique<MenuManager>();
mLockPlayRegion = false;
// Make sure valgrind sees mIsSyncLocked is initialized, even
@ -1251,7 +1249,7 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
mTrackPanel->AddOverlay( mScrubOverlay );
#endif
mMenuManager->CreateMenusAndCommands(*this);
MenuManager::Get( project ).CreateMenusAndCommands( project );
mTrackPanel->SetBackgroundCell(mBackgroundCell);
@ -2105,7 +2103,7 @@ void AudacityProject::FixScrollbars()
mTrackPanel->Refresh(false);
}
GetMenuManager(*this).UpdateMenus(*this);
MenuManager::Get( project ).UpdateMenus( project );
if (oldhstate != newhstate || oldvstate != newvstate) {
UpdateLayout();
@ -2353,7 +2351,7 @@ void AudacityProject::OnMenu(wxCommandEvent & event)
auto &project = *this;
auto &commandManager = CommandManager::Get( project );
bool handled = commandManager.HandleMenuID(
event.GetId(), GetMenuManager(*this).GetUpdateFlags(*this),
event.GetId(), MenuManager::Get( project ).GetUpdateFlags( project ),
NoFlagsSpecified);
if (handled)
@ -2366,7 +2364,8 @@ void AudacityProject::OnMenu(wxCommandEvent & event)
void AudacityProject::OnUpdateUI(wxUpdateUIEvent & WXUNUSED(event))
{
GetMenuManager(*this).UpdateMenus(*this);
auto &project = *this;
MenuManager::Get( project ).UpdateMenus( project );
}
void AudacityProject::MacShowUndockedToolbars(bool show)
@ -4632,9 +4631,9 @@ void AudacityProject::InitialState()
undoManager.StateSaved();
GetMenuManager(*this).ModifyUndoMenuItems(*this);
GetMenuManager(*this).UpdateMenus(*this);
auto &menuManager = MenuManager::Get( project );
menuManager.ModifyUndoMenuItems( project );
menuManager.UpdateMenus( project );
}
bool AudacityProject::UndoAvailable()
@ -4675,9 +4674,9 @@ void AudacityProject::PushState(const wxString &desc,
mDirty = true;
GetMenuManager(*this).ModifyUndoMenuItems(*this);
GetMenuManager(*this).UpdateMenus(*this);
auto &menuManager = MenuManager::Get( project );
menuManager.ModifyUndoMenuItems( project );
menuManager.UpdateMenus( project );
if (GetTracksFitVerticallyZoomed())
ViewActions::DoZoomFitV(*this);
@ -4762,7 +4761,7 @@ void AudacityProject::PopState(const UndoState &state)
HandleResize();
GetMenuManager(*this).UpdateMenus(*this);
MenuManager::Get( project ).UpdateMenus( project );
AutoSave();
}
@ -4777,7 +4776,7 @@ void AudacityProject::SetStateTo(unsigned int n)
HandleResize();
mTrackPanel->SetFocusedTrack(NULL);
mTrackPanel->Refresh(false);
GetMenuManager(*this).ModifyUndoMenuItems(*this);
MenuManager::Get( project ).ModifyUndoMenuItems( project );
}
// Utility function called by other zoom methods

View File

@ -661,12 +661,7 @@ private:
private:
#endif
private:
std::unique_ptr<MenuManager> mMenuManager;
public:
friend MenuManager &GetMenuManager(AudacityProject &project);
class PlaybackScroller final : public wxEvtHandler
{
public:

View File

@ -1156,7 +1156,7 @@ bool CommandManager::FilterKeyEvent(AudacityProject *project, const wxKeyEvent &
return false;
}
auto flags = GetMenuManager(*project).GetUpdateFlags(*project);
auto flags = MenuManager::Get(*project).GetUpdateFlags(*project);
wxKeyEvent temp = evt;
@ -1248,7 +1248,7 @@ bool CommandManager::HandleCommandEntry(const CommandListEntry * entry,
NiceName.Replace(".","");// remove ...
// NB: The call may have the side effect of changing flags.
bool allowed =
GetMenuManager(*proj).ReportIfActionNotAllowed( *proj,
MenuManager::Get(*proj).ReportIfActionNotAllowed( *proj,
NiceName, flags, entry->flags, combinedMask );
// If the function was disallowed, it STILL should count as having been
// handled (by doing nothing or by telling the user of the problem).

View File

@ -3276,7 +3276,7 @@ void EffectUIHost::OnApply(wxCommandEvent & evt)
{
auto flags = AlwaysEnabledFlag;
bool allowed =
GetMenuManager(*mProject).ReportIfActionNotAllowed(
MenuManager::Get(*mProject).ReportIfActionNotAllowed(
*mProject,
mEffect->GetTranslatedName(),
flags,

View File

@ -180,7 +180,7 @@ void DoReloadPreferences( AudacityProject &project )
for (size_t i = 0; i < gAudacityProjects.size(); i++) {
AudacityProject *p = gAudacityProjects[i].get();
GetMenuManager(*p).RebuildMenuBar(*p);
MenuManager::Get(*p).RebuildMenuBar(*p);
// TODO: The comment below suggests this workaround is obsolete.
#if defined(__WXGTK__)
// Workaround for:
@ -1018,7 +1018,7 @@ void OnPreferences(const CommandContext &context)
for (size_t i = 0; i < gAudacityProjects.size(); i++) {
AudacityProject *p = gAudacityProjects[i].get();
GetMenuManager(*p).RebuildMenuBar(*p);
MenuManager::Get(*p).RebuildMenuBar(*p);
// TODO: The comment below suggests this workaround is obsolete.
#if defined(__WXGTK__)
// Workaround for:

View File

@ -432,7 +432,7 @@ bool DoEffect(
// For now, we're limiting realtime preview to a single effect, so
// make sure the menus reflect that fact that one may have just been
// opened.
GetMenuManager(project).UpdateMenus(project, false);
MenuManager::Get(project).UpdateMenus(project, false);
}
} );
@ -470,7 +470,7 @@ bool DoEffect(
// or analyze effects.
if (type == EffectTypeProcess) {
wxString shortDesc = em.GetCommandName(ID);
GetMenuManager(project).mLastEffect = ID;
MenuManager::Get(project).mLastEffect = ID;
wxString lastEffectDesc;
/* i18n-hint: %s will be the name of the effect which will be
* repeated if this menu item is chosen */
@ -575,7 +575,7 @@ void OnManageEffects(const CommandContext &context)
void OnRepeatLastEffect(const CommandContext &context)
{
auto lastEffect = GetMenuManager(context.project).mLastEffect;
auto lastEffect = MenuManager::Get(context.project).mLastEffect;
if (!lastEffect.empty())
{
DoEffect( lastEffect, context, kConfigured );
@ -878,7 +878,7 @@ MenuTable::BaseItemPtr EffectMenu( AudacityProject &project )
// All of this is a bit hacky until we can get more things connected into
// the plugin manager...sorry! :-(
const auto &lastEffect = GetMenuManager(project).mLastEffect;
const auto &lastEffect = MenuManager::Get(project).mLastEffect;
wxString buildMenuLabel;
if (!lastEffect.empty()) {
buildMenuLabel.Printf(_("Repeat %s"),

View File

@ -499,7 +499,7 @@ void SelectNone( AudacityProject &project )
void SelectAllIfNone( AudacityProject &project )
{
auto &viewInfo = ViewInfo::Get( project );
auto flags = GetMenuManager( project ).GetUpdateFlags( project );
auto flags = MenuManager::Get( project ).GetUpdateFlags( project );
if(!(flags & TracksSelectedFlag) ||
viewInfo.selectedRegion.isPoint())
DoSelectAllAudio( project );

View File

@ -40,7 +40,7 @@ void OnResetToolBars(const CommandContext &context)
auto &toolManager = ToolManager::Get( project );
toolManager.Reset();
GetMenuManager(project).ModifyToolbarMenus(project);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowTransportToolBar(const CommandContext &context)
@ -49,7 +49,7 @@ void OnShowTransportToolBar(const CommandContext &context)
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide(TransportBarID);
GetMenuManager(project).ModifyToolbarMenus(project);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowToolsToolBar(const CommandContext &context)
@ -58,7 +58,7 @@ void OnShowToolsToolBar(const CommandContext &context)
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( ToolsBarID );
GetMenuManager(project).ModifyToolbarMenus(project);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowRecordMeterToolBar(const CommandContext &context)
@ -71,7 +71,7 @@ void OnShowRecordMeterToolBar(const CommandContext &context)
toolManager.Expose( MeterBarID, false );
}
toolManager.ShowHide( RecordMeterBarID );
GetMenuManager(project).ModifyToolbarMenus(project);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowPlayMeterToolBar(const CommandContext &context)
@ -85,7 +85,7 @@ void OnShowPlayMeterToolBar(const CommandContext &context)
}
toolManager.ShowHide( PlayMeterBarID );
GetMenuManager(project).ModifyToolbarMenus(project);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
#if 0
@ -100,7 +100,7 @@ void OnShowMeterToolBar(const CommandContext &context)
toolManager.Expose( RecordMeterBarID, false );
}
toolManager.ShowHide( MeterBarID );
GetMenuManager(project).ModifyToolbarMenus(project);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
#endif
@ -110,7 +110,7 @@ void OnShowMixerToolBar(const CommandContext &context)
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( MixerBarID );
GetMenuManager(project).ModifyToolbarMenus(project);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowEditToolBar(const CommandContext &context)
@ -119,7 +119,7 @@ void OnShowEditToolBar(const CommandContext &context)
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( EditBarID );
GetMenuManager(project).ModifyToolbarMenus(project);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowTranscriptionToolBar(const CommandContext &context)
@ -128,7 +128,7 @@ void OnShowTranscriptionToolBar(const CommandContext &context)
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( TranscriptionBarID );
GetMenuManager(project).ModifyToolbarMenus(project);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowScrubbingToolBar(const CommandContext &context)
@ -137,7 +137,7 @@ void OnShowScrubbingToolBar(const CommandContext &context)
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( ScrubbingBarID );
GetMenuManager(project).ModifyToolbarMenus(project);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowDeviceToolBar(const CommandContext &context)
@ -146,7 +146,7 @@ void OnShowDeviceToolBar(const CommandContext &context)
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( DeviceBarID );
GetMenuManager(project).ModifyToolbarMenus(project);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
void OnShowSelectionToolBar(const CommandContext &context)
@ -155,7 +155,7 @@ void OnShowSelectionToolBar(const CommandContext &context)
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( SelectionBarID );
GetMenuManager(project).ModifyToolbarMenus(project);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
@ -165,7 +165,7 @@ void OnShowSpectralSelectionToolBar(const CommandContext &context)
auto &toolManager = ToolManager::Get( project );
toolManager.ShowHide( SpectralSelectionBarID );
GetMenuManager(project).ModifyToolbarMenus(project);
MenuManager::Get(project).ModifyToolbarMenus(project);
}
#endif

View File

@ -197,7 +197,7 @@ namespace TransportActions {
// Stop playing or recording, if paused.
void StopIfPaused( AudacityProject &project )
{
auto flags = GetMenuManager( project ).GetUpdateFlags( project );
auto flags = MenuManager::Get( project ).GetUpdateFlags( project );
if( flags & PausedFlag )
DoStop( project );
}

View File

@ -44,7 +44,7 @@ void DoMacMinimize(AudacityProject *project)
#endif
// So that the Minimize menu command disables
GetMenuManager(*project).UpdateMenus(*project);
MenuManager::Get(*project).UpdateMenus(*project);
}
}

View File

@ -1067,7 +1067,7 @@ bool ControlToolBar::DoRecord(AudacityProject &project,
CommandFlag flags = AlwaysEnabledFlag; // 0 means recalc flags.
// NB: The call may have the side effect of changing flags.
bool allowed = GetMenuManager(project).TryToMakeActionAllowed(
bool allowed = MenuManager::Get(project).TryToMakeActionAllowed(
project,
flags,
AudioIONotBusyFlag | CanStopAudioStreamFlag,

View File

@ -299,7 +299,7 @@ void EditToolBar::OnButton(wxCommandEvent &event)
if (!p) return;
auto &cm = CommandManager::Get( *p );
auto flags = GetMenuManager(*p).GetUpdateFlags(*p);
auto flags = MenuManager::Get(*p).GetUpdateFlags(*p);
const CommandContext context( *GetActiveProject() );
cm.HandleTextualCommand(EditToolbarButtonList[id].commandName, context, flags, NoFlagsSpecified);
}