From 492a44894bd43e31db21e4042d1662e0b73b5473 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 24 Oct 2018 13:44:11 -0400 Subject: [PATCH] Move MenuManager functions out of Project.cpp --- src/Menus.cpp | 72 +++++++++++++++++++++++++++++++++++++++ src/Project.cpp | 72 --------------------------------------- src/prefs/PrefsDialog.cpp | 2 +- 3 files changed, 73 insertions(+), 73 deletions(-) diff --git a/src/Menus.cpp b/src/Menus.cpp index fae759c03..bb837ab9b 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -741,3 +741,75 @@ void MenuCreator::RebuildAllMenuBars() #endif } } + +bool MenuManager::ReportIfActionNotAllowed +( AudacityProject &project, + const wxString & Name, CommandFlag & flags, CommandFlag flagsRqd, CommandFlag mask ) +{ + bool bAllowed = TryToMakeActionAllowed( project, flags, flagsRqd, mask ); + if( bAllowed ) + return true; + CommandManager* cm = project.GetCommandManager(); + if (!cm) return false; + cm->TellUserWhyDisallowed( Name, flags & mask, flagsRqd & mask); + return false; +} + + +/// Determines if flags for command are compatible with current state. +/// If not, then try some recovery action to make it so. +/// @return whether compatible or not after any actions taken. +bool MenuManager::TryToMakeActionAllowed +( AudacityProject &project, + CommandFlag & flags, CommandFlag flagsRqd, CommandFlag mask ) +{ + bool bAllowed; + + if( !flags ) + flags = GetMenuManager(project).GetUpdateFlags(project); + + bAllowed = ((flags & mask) == (flagsRqd & mask)); + if( bAllowed ) + return true; + + // Why is action not allowed? + // 1's wherever a required flag is missing. + auto MissingFlags = (~flags & flagsRqd) & mask; + + if( mStopIfWasPaused && (MissingFlags & AudioIONotBusyFlag ) ){ + project.StopIfPaused(); + // Hope this will now reflect stopped audio. + flags = GetMenuManager(project).GetUpdateFlags(project); + bAllowed = ((flags & mask) == (flagsRqd & mask)); + if( bAllowed ) + return true; + } + + //We can only make the action allowed if we select audio when no selection. + // IF not set up to select all audio when none, THEN return with failure. + if( mWhatIfNoSelection != 1 ) + return false; + + // Some effects disallow autoselection. + if( flagsRqd & NoAutoSelect ) + return false; + + // Why is action still not allowed? + // 0's wherever a required flag is missing (or is don't care) + MissingFlags = (flags & ~flagsRqd) & mask; + + // IF selecting all audio won't do any good, THEN return with failure. + if( !(flags & WaveTracksExistFlag) ) + return false; + // returns if mask wants a zero in some flag and that's not present. + // logic seems a bit peculiar and worth revisiting. + if( (MissingFlags & ~( TimeSelectedFlag | WaveTracksSelectedFlag)) ) + return false; + + // This was 'OnSelectAll'. Changing it to DoSelectSomething means if + // selecting all tracks is enough, we just do that. + SelectActions::DoSelectSomething(project); + flags = GetMenuManager(project).GetUpdateFlags(project); + bAllowed = ((flags & mask) == (flagsRqd & mask)); + return bAllowed; +} diff --git a/src/Project.cpp b/src/Project.cpp index 1618748bd..e83878dce 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -2345,78 +2345,6 @@ void AudacityProject::DoScroll() GetTrackPanel()->HandleCursorForPresentMouseState(); } ); } -bool MenuManager::ReportIfActionNotAllowed -( AudacityProject &project, - const wxString & Name, CommandFlag & flags, CommandFlag flagsRqd, CommandFlag mask ) -{ - bool bAllowed = TryToMakeActionAllowed( project, flags, flagsRqd, mask ); - if( bAllowed ) - return true; - CommandManager* cm = project.GetCommandManager(); - if (!cm) return false; - cm->TellUserWhyDisallowed( Name, flags & mask, flagsRqd & mask); - return false; -} - - -/// Determines if flags for command are compatible with current state. -/// If not, then try some recovery action to make it so. -/// @return whether compatible or not after any actions taken. -bool MenuManager::TryToMakeActionAllowed -( AudacityProject &project, - CommandFlag & flags, CommandFlag flagsRqd, CommandFlag mask ) -{ - bool bAllowed; - - if( !flags ) - flags = GetMenuManager(project).GetUpdateFlags(project); - - bAllowed = ((flags & mask) == (flagsRqd & mask)); - if( bAllowed ) - return true; - - // Why is action not allowed? - // 1's wherever a required flag is missing. - auto MissingFlags = (~flags & flagsRqd) & mask; - - if( mStopIfWasPaused && (MissingFlags & AudioIONotBusyFlag ) ){ - project.StopIfPaused(); - // Hope this will now reflect stopped audio. - flags = GetMenuManager(project).GetUpdateFlags(project); - bAllowed = ((flags & mask) == (flagsRqd & mask)); - if( bAllowed ) - return true; - } - - //We can only make the action allowed if we select audio when no selection. - // IF not set up to select all audio when none, THEN return with failure. - if( mWhatIfNoSelection != 1 ) - return false; - - // Some effects disallow autoselection. - if( flagsRqd & NoAutoSelect ) - return false; - - // Why is action still not allowed? - // 0's wherever a required flag is missing (or is don't care) - MissingFlags = (flags & ~flagsRqd) & mask; - - // IF selecting all audio won't do any good, THEN return with failure. - if( !(flags & WaveTracksExistFlag) ) - return false; - // returns if mask wants a zero in some flag and that's not present. - // logic seems a bit peculiar and worth revisiting. - if( (MissingFlags & ~( TimeSelectedFlag | WaveTracksSelectedFlag)) ) - return false; - - // This was 'OnSelectAll'. Changing it to DoSelectSomething means if - // selecting all tracks is enough, we just do that. - SelectActions::DoSelectSomething(project); - flags = GetMenuManager(project).GetUpdateFlags(project); - bAllowed = ((flags & mask) == (flagsRqd & mask)); - return bAllowed; -} - void AudacityProject::OnMenu(wxCommandEvent & event) { #ifdef __WXMSW__ diff --git a/src/prefs/PrefsDialog.cpp b/src/prefs/PrefsDialog.cpp index 57d590f7f..b5d4804b1 100644 --- a/src/prefs/PrefsDialog.cpp +++ b/src/prefs/PrefsDialog.cpp @@ -553,7 +553,7 @@ void PrefsDialog::OnOK(wxCommandEvent & WXUNUSED(event)) // LL: wxMac can't handle recreating the menus when this dialog is still active, // so AudacityProject::UpdatePrefs() or any of the routines it calls must - // not cause AudacityProject::RebuildMenuBar() to be executed. + // not cause MenuCreator::RebuildMenuBar() to be executed. for (size_t i = 0; i < gAudacityProjects.size(); i++) { gAudacityProjects[i]->UpdatePrefs(); }