Audacity  3.0.3
ProjectStatus.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 ProjectStatus.h
6 
7 Paul Licameli
8 
9 **********************************************************************/
10 
11 #include "ProjectStatus.h"
12 
13 #include "Project.h"
14 
16  : wxEvent{ -1, EVT_PROJECT_STATUS_UPDATE }
17  , mField{ field }
18 {}
19 
21 
22 wxEvent *ProjectStatusEvent::Clone() const
23 {
24  return safenew ProjectStatusEvent{*this};
25 }
26 
27 wxDEFINE_EVENT(EVT_PROJECT_STATUS_UPDATE, ProjectStatusEvent);
28 
30  []( AudacityProject &parent ){
31  return std::make_shared< ProjectStatus >( parent );
32  }
33 };
34 
36 {
37  return project.AttachedObjects::Get< ProjectStatus >( key );
38 }
39 
41 {
42  return Get( const_cast< AudacityProject & >( project ) );
43 }
44 
46  : mProject{ project }
47 {
48 }
49 
51 
52 namespace
53 {
55  {
56  static ProjectStatus::StatusWidthFunctions theFunctions;
57  return theFunctions;
58  }
59 }
60 
62  const StatusWidthFunction &function )
63 {
64  statusWidthFunctions().emplace_back( function );
65 }
66 
68 {
69  return statusWidthFunctions();
70 }
71 
73 {
74  return mLastStatusMessages[ field - 1 ];
75 }
76 
78 {
79  auto &project = mProject;
80  auto &lastMessage = mLastStatusMessages[ field - 1 ];
81  // compare full translations not msgids!
82  if ( msg.Translation() != lastMessage.Translation() ) {
83  lastMessage = msg;
85  project.ProcessEvent( evt );
86  }
87 }
88 
90 {
91  auto &project = mProject;
92  for (auto field = 1; field <= nStatusBarFields; field++) {
94  project.ProcessEvent( evt );
95  }
96 }
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
field
#define field(n, t)
Definition: ImportAUP.cpp:167
ProjectStatus.h
ProjectStatus::mProject
AudacityProject & mProject
Definition: ProjectStatus.h:82
Project.h
ProjectStatusEvent
Definition: ProjectStatus.h:32
StatusBarField
StatusBarField
Definition: ProjectStatus.h:24
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: ProjectStatus.cpp:29
ProjectStatusEvent::ProjectStatusEvent
ProjectStatusEvent(StatusBarField field)
Definition: ProjectStatus.cpp:15
ProjectStatus::mLastStatusMessages
TranslatableString mLastStatusMessages[nStatusBarFields]
Definition: ProjectStatus.h:83
ProjectStatusEvent::~ProjectStatusEvent
~ProjectStatusEvent() override
ProjectStatus::GetStatusWidthFunctions
static const StatusWidthFunctions & GetStatusWidthFunctions()
Definition: ProjectStatus.cpp:67
anonymous_namespace{ProjectStatus.cpp}::statusWidthFunctions
ProjectStatus::StatusWidthFunctions & statusWidthFunctions()
Definition: ProjectStatus.cpp:54
ClientData::Site::RegisteredFactory
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:266
ProjectStatusEvent::Clone
wxEvent * Clone() const override
Definition: ProjectStatus.cpp:22
ProjectStatus::Set
void Set(const TranslatableString &msg, StatusBarField field=mainStatusBarField)
Definition: ProjectStatus.cpp:77
ProjectStatus::StatusWidthFunctions
std::vector< StatusWidthFunction > StatusWidthFunctions
Definition: ProjectStatus.h:63
ProjectStatus
Definition: ProjectStatus.h:46
ProjectStatus::StatusWidthFunction
std::function< StatusWidthResult(const AudacityProject &, StatusBarField) > StatusWidthFunction
Definition: ProjectStatus.h:62
wxDEFINE_EVENT
wxDEFINE_EVENT(EVT_PROJECT_STATUS_UPDATE, ProjectStatusEvent)
ProjectStatus::Get
static ProjectStatus & Get(AudacityProject &project)
Definition: ProjectStatus.cpp:35
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
ProjectStatus::~ProjectStatus
~ProjectStatus() override
TranslatableString::Translation
wxString Translation() const
Definition: TranslatableString.h:79
ProjectStatus::RegisteredStatusWidthFunction::RegisteredStatusWidthFunction
RegisteredStatusWidthFunction(const StatusWidthFunction &function)
Definition: ProjectStatus.cpp:61
ProjectStatus::UpdatePrefs
void UpdatePrefs() override
Definition: ProjectStatus.cpp:89
ProjectStatus::ProjectStatus
ProjectStatus(AudacityProject &project)
Definition: ProjectStatus.cpp:45
safenew
#define safenew
Definition: MemoryX.h:10
nStatusBarFields
@ nStatusBarFields
Definition: ProjectStatus.h:29