Audacity  3.0.3
ActiveProject.cpp
Go to the documentation of this file.
1 /*!********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  @file ActiveProject.cpp
6 
7  Paul Licameli split from Project.cpp
8 
9  **********************************************************************/
10 
11 #include "ActiveProject.h"
12 #include "KeyboardCapture.h"
13 #include "Project.h"
14 #include "ProjectWindows.h"
15 
16 #include <wx/app.h>
17 #include <wx/frame.h>
18 
19 wxDEFINE_EVENT(EVT_PROJECT_ACTIVATION, wxCommandEvent);
20 
21 //This is a pointer to the currently-active project.
22 static std::weak_ptr<AudacityProject> gActiveProject;
23 
24 AUDACITY_DLL_API std::weak_ptr<AudacityProject> GetActiveProject()
25 {
26  return gActiveProject;
27 }
28 
30 {
31  auto pProject = project ? project->shared_from_this() : nullptr;
32  if ( gActiveProject.lock() != pProject ) {
33  gActiveProject = pProject;
34  KeyboardCapture::Capture( nullptr );
35  wxTheApp->QueueEvent( safenew wxCommandEvent{ EVT_PROJECT_ACTIVATION } );
36  }
37  wxTheApp->SetTopWindow( FindProjectFrame( project ) );
38 }
gActiveProject
static std::weak_ptr< AudacityProject > gActiveProject
Definition: ActiveProject.cpp:22
Project.h
KeyboardCapture.h
GetActiveProject
AUDACITY_DLL_API std::weak_ptr< AudacityProject > GetActiveProject()
Definition: ActiveProject.cpp:24
wxDEFINE_EVENT
wxDEFINE_EVENT(EVT_PROJECT_ACTIVATION, wxCommandEvent)
KeyboardCapture::Capture
void Capture(wxWindow *handler)
Definition: KeyboardCapture.cpp:70
ProjectWindows.h
accessors for certain important windows associated with each project
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
SetActiveProject
void SetActiveProject(AudacityProject *project)
Definition: ActiveProject.cpp:29
ActiveProject.h
Handle changing of active project and keep global project pointer.
FindProjectFrame
wxFrame * FindProjectFrame(AudacityProject *project)
Get a pointer to the window associated with a project, or null if the given pointer is null,...
Definition: ProjectWindows.cpp:88
safenew
#define safenew
Definition: MemoryX.h:10