Audacity  2.2.2
CommandContext.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity - A Digital Audio Editor
4  Copyright 1999-2017 Audacity Team
5  License: wxwidgets
6 
7  Dan Horgan
8  James Crook
9 
10 ******************************************************************//*******************************************************************/
22 
23 #include "../Audacity.h"
24 #include "Command.h"
25 #include <map>
26 #include <wx/string.h>
27 #include <wx/variant.h>
28 #include <wx/arrstr.h>
29 
30 #include "../AudacityException.h"
31 #include "Validators.h"
32 #include "CommandType.h"
33 #include "CommandMisc.h"
34 #include "CommandBuilder.h"
35 #include "CommandTargets.h"
36 #include "CommandDirectory.h"
37 
38 //#include "CommandContext.h"
39 #include "CommandContext.h"
40 #include "../Project.h"
41 
44  , const wxEvent *e
45  , int ii
46  , const CommandParameter &param
47  )
48  : project{ p }
49  // No target specified? Use the special interactive one that pops up a dialog.
50  , pOutput( std::make_unique<InteractiveOutputTargets>() )
51  , pEvt{ e }
52  , index{ ii }
53  , parameter{ param }
54 {
55 }
56 
58  AudacityProject &p,
59  std::unique_ptr<CommandOutputTargets> target)
60  : project{ p }
61  // Revisit and use std_unique pointer for pOutput??
62  , pOutput( std::move( target) )
63  , pEvt{ nullptr }
64  , index{ 0 }
65  , parameter{ CommandParameter{}}
66 {
67 }
68 
69 void CommandContext::Status( const wxString & message, bool bFlush ) const
70 {
71  if( pOutput )
72  pOutput->Status( message, bFlush );
73  else
74  {
75  wxLogDebug("Status:%s", message );
76  }
77 }
78 
79 void CommandContext::Error( const wxString & message ) const
80 {
81  if( pOutput )
82  pOutput->Error( message );
83  else
84  {
85  wxLogDebug("Error:%s", message );
86  }
87 }
88 
89 void CommandContext::Progress( double d ) const
90 {
91  if( pOutput )
92  pOutput->Progress( d );
93 }
94 
96 { return (AudacityApp *) wxTheApp;}
97 
99 { return GetActiveProject();}
100 
102 {
103  if( pOutput )
104  pOutput->StartArray();
105 }
107 {
108  if( pOutput )
109  pOutput->EndArray();
110 }
112 {
113  if( pOutput )
114  pOutput->StartStruct();
115 }
117 {
118  if( pOutput )
119  pOutput->EndStruct();
120 }
121 void CommandContext::StartField(const wxString &name) const
122 {
123  if( pOutput )
124  pOutput->StartField(name);
125 }
127 {
128  if( pOutput )
129  pOutput->EndField();
130 }
131 void CommandContext::AddItem(const wxString &value , const wxString &name ) const
132 {
133  if( pOutput )
134  pOutput->AddItem( value, name );
135 }
136 void CommandContext::AddBool(const bool value , const wxString &name ) const
137 {
138  if( pOutput )
139  pOutput->AddItem( value, name );
140 }
141 void CommandContext::AddItem(const double value , const wxString &name ) const
142 {
143  if( pOutput )
144  pOutput->AddItem( value, name );
145 }
146 
147 
148 
149 
AudacityProject * GetProject() const
std::unique_ptr< CommandOutputTargets > pOutput
AudacityApp * GetApp() const
Contains declarations for CommandType class.
CommandContext(AudacityProject &p, const wxEvent *e=nullptr, int ii=0, const CommandParameter &param=CommandParameter{})
Contains declaration of Command base class.
virtual void Status(const wxString &message, bool bFlush=false) const
virtual void Progress(double d) const
void AddItem(const wxString &value, const wxString &name="") const
Contains declarations for CommandDirectory class.
Contains declarations and definitions for Validator, OptionValidator, BoolValidator, DoubleValidator, RangeValidator, IntValidator and AndValidator classes.
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
void StartField(const wxString &name) const
void StartStruct() const
void EndArray() const
AudacityApp is the 'main' class for Audacity.
Definition: AudacityApp.h:59
const wxChar * name
Definition: Distortion.cpp:94
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
virtual void Error(const wxString &message) const
Contains declaration of CommandBuilder class.
void StartArray() const
void EndStruct() const
void AddBool(const bool value, const wxString &name="") const
void EndField() const
wxString CommandParameter