Move functions into new file SelectUtilities.cpp ...

... so that other files do not have link dependency on SelectMenus.cpp

The new file enlarges the big s.c.c. to 24
This commit is contained in:
Paul Licameli 2019-06-21 19:38:38 -04:00
parent fab648e475
commit 02e620d35f
17 changed files with 216 additions and 160 deletions

View File

@ -33,6 +33,7 @@ processing. See also MacrosWindow and ApplyMacroDialog.
#include "Menus.h"
#include "PluginManager.h"
#include "Prefs.h"
#include "SelectUtilities.h"
#include "Shuttle.h"
#include "Track.h"
#include "export/ExportFLAC.h"
@ -722,7 +723,7 @@ bool MacroCommands::ApplyEffectCommand(
// IF nothing selected, THEN select everything
// (most effects require that you have something selected).
if( plug->GetPluginType() != PluginTypeAudacityCommand )
SelectActions::SelectAllIfNone( *project );
SelectUtilities::SelectAllIfNone( *project );
bool res = false;

View File

@ -46,6 +46,7 @@
#include "ProjectHistory.h"
#include "ProjectManager.h"
#include "ProjectWindow.h"
#include "SelectUtilities.h"
#include "commands/CommandManager.h"
#include "effects/Effect.h"
#include "../images/Arrow.xpm"
@ -467,7 +468,7 @@ void ApplyMacroDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event))
auto success = GuardedCall< bool >( [&] {
ProjectFileManager::Get( *project ).Import(files[i]);
ProjectWindow::Get( *project ).ZoomAfterImport(nullptr);
SelectActions::DoSelectAll(*project);
SelectUtilities::DoSelectAll(*project);
if (!mMacroCommands.ApplyMacro(mCatalog))
return false;

View File

@ -62,7 +62,7 @@ void HighlightTextCtrl::OnMouseEvent(wxMouseEvent& event)
selectedRegion.setT0( pCurSyl->t );
//v Should probably select to end as in
// SelectActions::Handler::OnSelectCursorEnd,
// SelectUtilities::Handler::OnSelectCursorEnd,
// but better to generalize that in AudacityProject methods.
selectedRegion.setT1( pCurSyl->t );
}

View File

@ -119,18 +119,6 @@ void DoReloadPreferences( AudacityProject & );
void DoUndo( AudacityProject &project );
}
/// Namespace for functions for Select menu
namespace SelectActions {
void SelectAllIfNone( AudacityProject &project );
void SelectNone( AudacityProject &project );
void DoListSelection(
AudacityProject &project, Track *t,
bool shift, bool ctrl, bool modifyState );
void DoSelectAll( AudacityProject &project );
void DoSelectAllAudio( AudacityProject &project );
void DoSelectSomething( AudacityProject &project );
}
/// Namespace for functions for View menu
namespace ViewActions {
double GetZoomOfToFit( const AudacityProject &project );

View File

@ -42,6 +42,7 @@
#include "ProjectHistory.h"
#include "ProjectSettings.h"
#include "ProjectWindow.h"
#include "SelectUtilities.h"
#include "TrackPanel.h" // for EVT_TRACK_PANEL_TIMER
#include "UndoManager.h"
#include "WaveTrack.h"
@ -672,7 +673,7 @@ wxColour MixerTrackCluster::GetTrackColor()
void MixerTrackCluster::HandleSelect(bool bShiftDown, bool bControlDown)
{
SelectActions::DoListSelection(*mProject,
SelectUtilities::DoListSelection(*mProject,
mTrack.get(), bShiftDown, bControlDown, true);
}
@ -834,7 +835,7 @@ void MixerBoardScrolledWindow::OnMouseEvent(wxMouseEvent& event)
//v Even when I implement MixerBoard::OnMouseEvent and call event.Skip()
// here, MixerBoard::OnMouseEvent never gets called.
// So, added mProject to MixerBoardScrolledWindow and just directly do what's needed here.
SelectActions::SelectNone( *mProject );
SelectUtilities::SelectNone( *mProject );
}
else
event.Skip();

View File

@ -34,6 +34,7 @@ Paul Licameli split from AudacityProject.cpp
#include "ProjectSelectionManager.h"
#include "ProjectSettings.h"
#include "ProjectWindow.h"
#include "SelectUtilities.h"
#include "SelectionState.h"
#include "Sequence.h"
#include "Tags.h"
@ -1546,7 +1547,7 @@ ProjectFileManager::AddImportedTracks(const FilePath &fileName,
std::vector< std::shared_ptr< Track > > results;
SelectActions::SelectNone( project );
SelectUtilities::SelectNone( project );
bool initiallyEmpty = tracks.empty();
double newRate = 0;
@ -1708,8 +1709,8 @@ bool ProjectFileManager::Import(
int mode = gPrefs->Read(wxT("/AudioFiles/NormalizeOnLoad"), 0L);
if (mode == 1) {
//TODO: All we want is a SelectAll()
SelectActions::SelectNone( project );
SelectActions::SelectAllIfNone( project );
SelectUtilities::SelectNone( project );
SelectUtilities::SelectAllIfNone( project );
const CommandContext context( project );
PluginActions::DoEffect(
EffectManager::Get().GetEffectByIdentifier(wxT("Normalize")),

View File

@ -31,6 +31,7 @@ Paul Licameli split from AudacityProject.cpp
#include "ProjectSelectionManager.h"
#include "ProjectSettings.h"
#include "ProjectWindow.h"
#include "SelectUtilities.h"
#include "TrackPanel.h"
#include "UndoManager.h"
#include "WaveTrack.h"
@ -734,7 +735,7 @@ void ProjectManager::ResetProjectToEmpty() {
auto &projectHistory = ProjectHistory::Get( project );
auto &viewInfo = ViewInfo::Get( project );
SelectActions::DoSelectAll( project );
SelectUtilities::DoSelectAll( project );
TrackActions::DoRemoveTracks( project );
// A new DirManager.

View File

@ -0,0 +1,146 @@
/**********************************************************************
Audacity: A Digital Audio Editor
SelectUtilities.cpp
Paul Licameli split from SelectMenus.cpp
**********************************************************************/
#include "SelectUtilities.h"
#include <wx/frame.h>
#include "CommonCommandFlags.h"
#include "Menus.h"
#include "Project.h"
#include "ProjectHistory.h"
#include "ProjectSettings.h"
#include "SelectionState.h"
#include "TrackPanel.h"
#include "ViewInfo.h"
#include "WaveTrack.h"
namespace {
// Temporal selection (not TimeTrack selection)
// potentially for all wave tracks.
void DoSelectTimeAndAudioTracks
(AudacityProject &project, bool bAllTime, bool bAllTracks)
{
auto &tracks = TrackList::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
if( bAllTime )
selectedRegion.setTimes(
tracks.GetMinOffset(), tracks.GetEndTime());
if( bAllTracks ) {
// Unselect all tracks before selecting audio.
for (auto t : tracks.Any())
t->SetSelected(false);
for (auto t : tracks.Any<WaveTrack>())
t->SetSelected(true);
ProjectHistory::Get( project ).ModifyState(false);
trackPanel.Refresh(false);
}
}
}
namespace SelectUtilities {
void DoSelectTimeAndTracks
(AudacityProject &project, bool bAllTime, bool bAllTracks)
{
auto &tracks = TrackList::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
if( bAllTime )
selectedRegion.setTimes(
tracks.GetMinOffset(), tracks.GetEndTime());
if( bAllTracks ) {
for (auto t : tracks.Any())
t->SetSelected(true);
ProjectHistory::Get( project ).ModifyState(false);
trackPanel.Refresh(false);
}
}
void SelectNone( AudacityProject &project )
{
auto &tracks = TrackList::Get( project );
for (auto t : tracks.Any())
t->SetSelected(false);
auto &trackPanel = TrackPanel::Get( project );
trackPanel.Refresh(false);
}
// Select the full time range, if no
// time range is selected.
void SelectAllIfNone( AudacityProject &project )
{
auto &viewInfo = ViewInfo::Get( project );
auto flags = MenuManager::Get( project ).GetUpdateFlags();
if((flags & TracksSelectedFlag).none() ||
viewInfo.selectedRegion.isPoint())
DoSelectAllAudio( project );
}
void DoListSelection
(AudacityProject &project, Track *t, bool shift, bool ctrl, bool modifyState)
{
auto &tracks = TrackList::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &selectionState = SelectionState::Get( project );
const auto &settings = ProjectSettings::Get( project );
auto &viewInfo = ViewInfo::Get( project );
auto &window = GetProjectFrame( project );
auto isSyncLocked = settings.IsSyncLocked();
selectionState.HandleListSelection(
tracks, viewInfo, *t,
shift, ctrl, isSyncLocked );
if (! ctrl )
trackPanel.SetFocusedTrack(t);
window.Refresh(false);
if (modifyState)
ProjectHistory::Get( project ).ModifyState(true);
}
void DoSelectAll(AudacityProject &project)
{
DoSelectTimeAndTracks( project, true, true );
}
void DoSelectAllAudio(AudacityProject &project)
{
DoSelectTimeAndAudioTracks( project, true, true );
}
// This function selects all tracks if no tracks selected,
// and all time if no time selected.
// There is an argument for making it just count wave tracks,
// However you could then not select a label and cut it,
// without this function selecting all tracks.
void DoSelectSomething(AudacityProject &project)
{
auto &tracks = TrackList::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
bool bTime = selectedRegion.isPoint();
bool bTracks = tracks.Selected().empty();
if( bTime || bTracks )
DoSelectTimeAndTracks( project, bTime, bTracks );
}
}

View File

@ -0,0 +1,33 @@
/**********************************************************************
Audacity: A Digital Audio Editor
SelectUtilities.h
Paul Licameli split from SelectMenus.h
**********************************************************************/
#ifndef __AUDACITY_SELECT_UTILITIES__
#define __AUDACITY_SELECT_UTILITIES__
class AudacityProject;
class Track;
/// Namespace for functions for Select menu
namespace SelectUtilities {
void DoSelectTimeAndTracks(
AudacityProject &project, bool bAllTime, bool bAllTracks);
void SelectAllIfNone( AudacityProject &project );
void SelectNone( AudacityProject &project );
void DoListSelection(
AudacityProject &project, Track *t,
bool shift, bool ctrl, bool modifyState );
void DoSelectAll( AudacityProject &project );
void DoSelectAllAudio( AudacityProject &project );
void DoSelectSomething( AudacityProject &project );
}
#endif

View File

@ -10,6 +10,7 @@
#include "../ProjectHistory.h"
#include "../ProjectSettings.h"
#include "../ProjectWindow.h"
#include "../SelectUtilities.h"
#include "../Tags.h"
#include "../TimeTrack.h"
#include "../TrackPanel.h"
@ -1263,7 +1264,7 @@ auto canSelectAll = [](const AudacityProject &project){
auto selectAll = []( AudacityProject &project, CommandFlag flagsRqd ){
if ( MenuManager::Get( project ).mWhatIfNoSelection == 1 &&
(flagsRqd & NoAutoSelect).none() )
SelectActions::DoSelectAllAudio(project);
SelectUtilities::DoSelectAllAudio(project);
};
RegisteredMenuItemEnabler selectTracks{{

View File

@ -6,7 +6,6 @@
#include "../FileNames.h"
#include "../LabelTrack.h"
#include "../MissingAliasFileDialog.h"
#include "../Menus.h"
#include "../NoteTrack.h"
#include "../Prefs.h"
#include "../Printing.h"
@ -15,6 +14,7 @@
#include "../ProjectHistory.h"
#include "../ProjectManager.h"
#include "../ProjectWindow.h"
#include "../SelectUtilities.h"
#include "../TrackPanel.h"
#include "../ViewInfo.h"
#include "../WaveTrack.h"
@ -129,7 +129,7 @@ AudacityProject *DoImportMIDI(
if (::ImportMIDI(fileName, newTrack.get())) {
SelectActions::SelectNone( *pProject );
SelectUtilities::SelectNone( *pProject );
auto pTrack = tracks.Add( newTrack );
pTrack->SetSelected(true);
@ -485,7 +485,7 @@ void OnImportLabels(const CommandContext &context)
newTrack->Import(f);
SelectActions::SelectNone( project );
SelectUtilities::SelectNone( project );
newTrack->SetSelected(true);
tracks.Add( newTrack );

View File

@ -15,6 +15,7 @@
#include "../ProjectSettings.h"
#include "../ProjectWindow.h"
#include "../Screenshot.h"
#include "../SelectUtilities.h"
#include "../TrackPanel.h"
#include "../ViewInfo.h"
#include "../WaveTrack.h"
@ -449,7 +450,7 @@ bool DoEffect(
if (flags & kConfigured)
{
TransportActions::DoStop(project);
SelectActions::SelectAllIfNone( project );
SelectUtilities::SelectAllIfNone( project );
}
MissingAliasFilesDialog::SetShouldShow(true);

View File

@ -5,7 +5,6 @@
#include "../AudioIO.h"
#include "../CommonCommandFlags.h"
#include "../FreqWindow.h"
#include "../Menus.h" // for PrefsListener
#include "../Prefs.h"
#include "../Project.h"
#include "../ProjectAudioIO.h"
@ -13,12 +12,10 @@
#include "../ProjectSelectionManager.h"
#include "../ProjectSettings.h"
#include "../ProjectWindow.h"
#include "../SelectionState.h"
#include "../SelectUtilities.h"
#include "../TimeDialog.h"
#include "../TrackPanel.h"
#include "../ViewInfo.h"
#include "../WaveTrack.h"
#include "../NoteTrack.h"
#include "../commands/CommandContext.h"
#include "../commands/CommandManager.h"
#include "../toolbars/ControlToolBar.h"
@ -27,51 +24,6 @@
// private helper classes and functions
namespace {
void DoSelectTimeAndTracks
(AudacityProject &project, bool bAllTime, bool bAllTracks)
{
auto &tracks = TrackList::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
if( bAllTime )
selectedRegion.setTimes(
tracks.GetMinOffset(), tracks.GetEndTime());
if( bAllTracks ) {
for (auto t : tracks.Any())
t->SetSelected(true);
ProjectHistory::Get( project ).ModifyState(false);
trackPanel.Refresh(false);
}
}
// Temporal selection (not TimeTrack selection)
// potentially for all wave tracks.
void DoSelectTimeAndAudioTracks
(AudacityProject &project, bool bAllTime, bool bAllTracks)
{
auto &tracks = TrackList::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
if( bAllTime )
selectedRegion.setTimes(
tracks.GetMinOffset(), tracks.GetEndTime());
if( bAllTracks ) {
// Unselect all tracks before selecting audio.
for (auto t : tracks.Any())
t->SetSelected(false);
for (auto t : tracks.Any<WaveTrack>())
t->SetSelected(true);
ProjectHistory::Get( project ).ModifyState(false);
trackPanel.Refresh(false);
}
}
void DoNextPeakFrequency(AudacityProject &project, bool up)
{
auto &tracks = TrackList::Get( project );
@ -496,78 +448,6 @@ void DoBoundaryMove(AudacityProject &project, int step, SeekInfo &info)
namespace SelectActions {
// exported helper functions
void SelectNone( AudacityProject &project )
{
auto &tracks = TrackList::Get( project );
for (auto t : tracks.Any())
t->SetSelected(false);
auto &trackPanel = TrackPanel::Get( project );
trackPanel.Refresh(false);
}
// Select the full time range, if no
// time range is selected.
void SelectAllIfNone( AudacityProject &project )
{
auto &viewInfo = ViewInfo::Get( project );
auto flags = MenuManager::Get( project ).GetUpdateFlags();
if((flags & TracksSelectedFlag).none() ||
viewInfo.selectedRegion.isPoint())
DoSelectAllAudio( project );
}
void DoListSelection
(AudacityProject &project, Track *t, bool shift, bool ctrl, bool modifyState)
{
auto &tracks = TrackList::Get( project );
auto &trackPanel = TrackPanel::Get( project );
auto &selectionState = SelectionState::Get( project );
const auto &settings = ProjectSettings::Get( project );
auto &viewInfo = ViewInfo::Get( project );
auto &window = GetProjectFrame( project );
auto isSyncLocked = settings.IsSyncLocked();
selectionState.HandleListSelection(
tracks, viewInfo, *t,
shift, ctrl, isSyncLocked );
if (! ctrl )
trackPanel.SetFocusedTrack(t);
window.Refresh(false);
if (modifyState)
ProjectHistory::Get( project ).ModifyState(true);
}
void DoSelectAll(AudacityProject &project)
{
DoSelectTimeAndTracks( project, true, true );
}
void DoSelectAllAudio(AudacityProject &project)
{
DoSelectTimeAndAudioTracks( project, true, true );
}
// This function selects all tracks if no tracks selected,
// and all time if no time selected.
// There is an argument for making it just count wave tracks,
// However you could then not select a label and cut it,
// without this function selecting all tracks.
void DoSelectSomething(AudacityProject &project)
{
auto &tracks = TrackList::Get( project );
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
bool bTime = selectedRegion.isPoint();
bool bTracks = tracks.Selected().empty();
if( bTime || bTracks )
DoSelectTimeAndTracks( project, bTime, bTracks );
}
// Menu handler functions
@ -579,7 +459,7 @@ struct Handler
void OnSelectAll(const CommandContext &context)
{
DoSelectAll( context.project );
SelectUtilities::DoSelectAll( context.project );
}
void OnSelectNone(const CommandContext &context)
@ -588,14 +468,14 @@ void OnSelectNone(const CommandContext &context)
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
selectedRegion.collapseToT0();
SelectNone( project );
SelectUtilities::SelectNone( project );
ProjectHistory::Get( project ).ModifyState(false);
}
void OnSelectAllTracks(const CommandContext &context)
{
auto &project = context.project;
DoSelectTimeAndTracks( project, false, true );
SelectUtilities::DoSelectTimeAndTracks( project, false, true );
}
void OnSelectSyncLockSel(const CommandContext &context)
@ -1145,7 +1025,7 @@ void OnSeekRightLong(const CommandContext &context)
void OnSelectAllTime(const CommandContext &context)
{
auto &project = context.project;
DoSelectTimeAndTracks( project, true, false );
SelectUtilities::DoSelectTimeAndTracks( project, true, false );
}
#endif

View File

@ -14,6 +14,7 @@
#include "../ProjectSettings.h"
#include "../PluginManager.h"
#include "../ProjectWindow.h"
#include "../SelectUtilities.h"
#include "../ShuttleGui.h"
#include "../TimeTrack.h"
#include "../TrackPanel.h"
@ -822,7 +823,7 @@ void OnNewWaveTrack(const CommandContext &context)
auto rate = settings.GetRate();
auto t = tracks.Add( trackFactory.NewWaveTrack( defaultFormat, rate ) );
SelectActions::SelectNone( project );
SelectUtilities::SelectNone( project );
t->SetSelected(true);
@ -845,7 +846,7 @@ void OnNewStereoTrack(const CommandContext &context)
auto defaultFormat = settings.GetDefaultFormat();
auto rate = settings.GetRate();
SelectActions::SelectNone( project );
SelectUtilities::SelectNone( project );
auto left = tracks.Add( trackFactory.NewWaveTrack( defaultFormat, rate ) );
left->SetSelected(true);
@ -872,7 +873,7 @@ void OnNewLabelTrack(const CommandContext &context)
auto t = tracks.Add( trackFactory.NewLabelTrack() );
SelectActions::SelectNone( project );
SelectUtilities::SelectNone( project );
t->SetSelected(true);
@ -898,7 +899,7 @@ void OnNewTimeTrack(const CommandContext &context)
auto t = tracks.AddToHead( trackFactory.NewTimeTrack() );
SelectActions::SelectNone( project );
SelectUtilities::SelectNone( project );
t->SetSelected(true);

View File

@ -18,7 +18,6 @@ Paul Licameli split from TrackPanel.cpp
#include "../../AColor.h"
#include "../../FreqWindow.h"
#include "../../Menus.h"
#include "../../NumberScale.h"
#include "../../Project.h"
#include "../../ProjectAudioIO.h"
@ -26,6 +25,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../ProjectSettings.h"
#include "../../ProjectWindow.h"
#include "../../RefreshCode.h"
#include "../../SelectUtilities.h"
#include "../../SelectionState.h"
#include "../../TrackPanel.h"
#include "../../TrackPanelMouseEvent.h"
@ -547,7 +547,7 @@ UIHandle::Result SelectHandle::Click
// text boxes.
bool bShift = event.ShiftDown();
bool unsafe = ProjectAudioIO::Get( *pProject ).IsAudioActive();
SelectActions::DoListSelection(
SelectUtilities::DoListSelection(
*pProject, pTrack, bShift, true, !unsafe);
return true;
} )

View File

@ -15,6 +15,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../Project.h"
#include "../../ProjectAudioIO.h"
#include "../../ProjectHistory.h"
#include "../../SelectUtilities.h"
#include "../../RefreshCode.h"
#include "../../Track.h"
#include "../../TrackInfo.h"
@ -97,7 +98,7 @@ UIHandle::Result SelectButtonHandle::CommitChanges
if (pTrack)
{
const bool unsafe = ProjectAudioIO::Get( *pProject ).IsAudioActive();
SelectActions::DoListSelection(*pProject,
SelectUtilities::DoListSelection(*pProject,
pTrack.get(), event.ShiftDown(), event.ControlDown(), !unsafe);
// return RefreshAll ;
}

View File

@ -12,11 +12,11 @@ Paul Licameli split from TrackPanel.cpp
#include "TrackSelectHandle.h"
#include "TrackView.h"
#include "../../Menus.h"
#include "../../Project.h"
#include "../../ProjectAudioIO.h"
#include "../../ProjectHistory.h"
#include "../../RefreshCode.h"
#include "../../SelectUtilities.h"
#include "../../TrackPanel.h"
#include "../../TrackPanelMouseEvent.h"
#include "../../WaveTrack.h"
@ -100,7 +100,7 @@ UIHandle::Result TrackSelectHandle::Click
CalculateRearrangingThresholds(event);
}
SelectActions::DoListSelection(*pProject,
SelectUtilities::DoListSelection(*pProject,
pTrack.get(), event.ShiftDown(), event.ControlDown(), !unsafe);
mClicked = true;