1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-15 15:49:36 +02:00

static SelectionState::Get()...

... not member functions of AudacityProject
This commit is contained in:
Paul Licameli 2019-01-22 12:06:46 -05:00
parent c1c0030013
commit 68e25f3b7d
10 changed files with 39 additions and 15 deletions

View File

@ -120,6 +120,7 @@ scroll information. It also has some status flags.
#include "NoteTrack.h"
#include "Prefs.h"
#include "ProjectFSCK.h"
#include "SelectionState.h"
#include "Sequence.h"
#include "Snap.h"
#include "Tags.h"
@ -4162,7 +4163,7 @@ bool AudacityProject::SaveCopyWaveTracks(const FilePath & strProjectPathName,
wxFileName uniqueTrackFileName;
for (auto pTrack : (trackRange + &Track::IsLeader))
{
SelectionStateChanger changer{ GetSelectionState(), tracks };
SelectionStateChanger changer{ SelectionState::Get( project ), tracks };
auto channels = TrackList::Channels(pTrack);
for (auto channel : channels)

View File

@ -24,7 +24,6 @@
#include "ClientData.h"
#include "Prefs.h"
#include "SelectionState.h"
#include "commands/CommandManagerWindowClasses.h"
#include "TrackPanelListener.h"
@ -304,7 +303,6 @@ public:
wxPanel *GetTopPanel() { return mTopPanel; }
TrackPanel * GetTrackPanel() {return mTrackPanel;}
const TrackPanel * GetTrackPanel() const {return mTrackPanel;}
SelectionState &GetSelectionState() { return mSelectionState; }
bool GetTracksFitVerticallyZoomed() { return mTracksFitVerticallyZoomed; } //lda
void SetTracksFitVerticallyZoomed(bool flag) { mTracksFitVerticallyZoomed = flag; } //lda
@ -557,7 +555,6 @@ private:
AdornedRulerPanel *mRuler{};
wxPanel *mTopPanel{};
TrackPanel *mTrackPanel{};
SelectionState mSelectionState{};
wxWindow * mMainPage;
wxPanel * mMainPanel;
wxScrollBar *mHsbar;

View File

@ -11,6 +11,21 @@
#include "ViewInfo.h"
#include "Track.h"
#include "Project.h"
static const AudacityProject::AttachedObjects::RegisteredFactory key{
[](AudacityProject &){ return std::make_shared< SelectionState >(); }
};
SelectionState &SelectionState::Get( AudacityProject &project )
{
return project.AttachedObjects::Get< SelectionState >( key );
}
const SelectionState &SelectionState::Get( const AudacityProject &project )
{
return Get( const_cast< AudacityProject & >( project ) );
}
// Set selection length to the length of a track -- but if sync-lock is turned
// on, use the largest possible selection in the sync-lock group.

View File

@ -9,16 +9,22 @@
#ifndef __AUDACITY_SELECTION_STATE__
#define __AUDACITY_SELECTION_STATE__
class AudacityProject;
class Track;
class TrackList;
class ViewInfo;
#include "ClientData.h"
#include "MemoryX.h"
#include <vector>
// State relating to the set of selected tracks
class SelectionState
class SelectionState final
: public ClientData::Base
{
public:
static SelectionState &Get( AudacityProject &project );
static const SelectionState &Get( const AudacityProject &project );
static void SelectTrackLength
( ViewInfo &viewInfo, Track &track, bool syncLocked );

View File

@ -44,6 +44,7 @@
#include "../LabelTrack.h"
#include "../Project.h"
#include "../Prefs.h"
#include "../SelectionState.h"
#include "../ShuttleGui.h"
#include "../Tags.h"
#include "../WaveTrack.h"
@ -127,7 +128,7 @@ END_EVENT_TABLE()
ExportMultiple::ExportMultiple(AudacityProject *project)
: wxDialogWrapper(project, wxID_ANY, wxString(_("Export Multiple")))
, mSelectionState{ project->GetSelectionState() }
, mSelectionState{ SelectionState::Get( *project ) }
{
SetName(GetTitle());

View File

@ -4,6 +4,7 @@
#include "../Prefs.h"
#include "../Project.h"
#include "../Track.h"
#include "../SelectionState.h"
#include "../TrackPanel.h"
#include "../TrackPanelAx.h"
#include "../commands/CommandContext.h"
@ -85,7 +86,7 @@ void DoPrevTrack(
{
auto trackPanel = project.GetTrackPanel();
auto &tracks = TrackList::Get( project );
auto &selectionState = project.GetSelectionState();
auto &selectionState = SelectionState::Get( project );
Track* t = trackPanel->GetFocusedTrack();
if( t == NULL ) // if there isn't one, focus on last
@ -195,7 +196,7 @@ void DoNextTrack(
{
auto trackPanel = project.GetTrackPanel();
auto &tracks = TrackList::Get( project );
auto &selectionState = project.GetSelectionState();
auto &selectionState = SelectionState::Get( project );
auto t = trackPanel->GetFocusedTrack(); // Get currently focused track
if( t == NULL ) // if there isn't one, focus on first
@ -507,7 +508,7 @@ void OnToggle(const CommandContext &context)
{
auto &project = context.project;
auto trackPanel = project.GetTrackPanel();
auto &selectionState = project.GetSelectionState();
auto &selectionState = SelectionState::Get( project );
Track *t;

View File

@ -7,6 +7,7 @@
#include "../Menus.h" // for PrefsListener
#include "../Prefs.h"
#include "../Project.h"
#include "../SelectionState.h"
#include "../TimeDialog.h"
#include "../TrackPanel.h"
#include "../ViewInfo.h"
@ -509,7 +510,7 @@ void DoListSelection
{
auto &tracks = TrackList::Get( project );
auto trackPanel = project.GetTrackPanel();
auto &selectionState = project.GetSelectionState();
auto &selectionState = SelectionState::Get( project );
auto &viewInfo = ViewInfo::Get( project );
auto isSyncLocked = project.IsSyncLocked();

View File

@ -17,6 +17,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../../LabelTrack.h"
#include "../../../Project.h"
#include "../../../RefreshCode.h"
#include "../../../SelectionState.h"
#include "../../../TrackPanelMouseEvent.h"
#include "../../../ViewInfo.h"
#include "../../../images/Cursors.h"
@ -74,7 +75,7 @@ UIHandle::Result LabelTextHandle::Click
auto result = LabelDefaultClickHandle::Click( evt, pProject );
auto &selectionState = pProject->GetSelectionState();
auto &selectionState = SelectionState::Get( *pProject );
auto &tracks = TrackList::Get( *pProject );
mChanger =
std::make_shared< SelectionStateChanger >( selectionState, tracks );

View File

@ -12,8 +12,8 @@ Paul Licameli split from TrackPanel.cpp
#include "BackgroundCell.h"
#include "../../HitTestResult.h"
#include "../../Project.h"
#include "../../RefreshCode.h"
#include "../../SelectionState.h"
#include "../../Track.h"
#include "../../TrackPanelMouseEvent.h"
#include "../../UIHandle.h"
@ -51,7 +51,7 @@ public:
// AS: If the user clicked outside all tracks, make nothing
// selected.
if ((event.ButtonDown() || event.ButtonDClick())) {
pProject->GetSelectionState().SelectNone(
SelectionState::Get( *pProject ).SelectNone(
TrackList::Get( *pProject ) );
result |= RefreshAll;
}

View File

@ -22,6 +22,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../NumberScale.h"
#include "../../Project.h"
#include "../../RefreshCode.h"
#include "../../SelectionState.h"
#include "../../TrackPanel.h"
#include "../../TrackPanelMouseEvent.h"
#include "../../ViewInfo.h"
@ -552,7 +553,7 @@ UIHandle::Result SelectHandle::Click
// Do not start a drag
return RefreshAll | Cancelled;
auto &selectionState = pProject->GetSelectionState();
auto &selectionState = SelectionState::Get( *pProject );
if (event.LeftDClick() && !event.ShiftDown()) {
auto &trackList = TrackList::Get( *pProject );
@ -835,7 +836,7 @@ UIHandle::Result SelectHandle::Drag
Track *eTrack = clickedTrack.get();
auto &trackList = TrackList::Get( *pProject );
if ( sTrack && eTrack && !event.ControlDown() ) {
auto &selectionState = pProject->GetSelectionState();
auto &selectionState = SelectionState::Get( *pProject );
selectionState.SelectRangeOfTracks( trackList, *sTrack, *eTrack );
}