Audacity  2.2.2
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
AudacityLogger Class Referencefinal

AudacityLogger is a thread-safe logger class. More...

#include <AudacityLogger.h>

Inheritance diagram for AudacityLogger:

Public Member Functions

 AudacityLogger ()
 
void Show (bool show=true)
 

Protected Member Functions

void Flush () override
 
void DoLogText (const wxString &msg) override
 

Private Member Functions

void OnCloseWindow (wxCloseEvent &e)
 
void OnClose (wxCommandEvent &e)
 
void OnClear (wxCommandEvent &e)
 
void OnSave (wxCommandEvent &e)
 

Private Attributes

Destroy_ptr< wxFrame > mFrame
 
wxTextCtrl * mText
 
wxString mBuffer
 
bool mUpdated
 

Detailed Description

AudacityLogger is a thread-safe logger class.

Provides thread-safe logging based on the wxWidgets log facility.

Definition at line 28 of file AudacityLogger.h.

Constructor & Destructor Documentation

AudacityLogger::AudacityLogger ( )

Definition at line 52 of file AudacityLogger.cpp.

References mText, and mUpdated.

53 : wxEvtHandler(),
54  wxLog()
55 {
56  mText = NULL;
57  mUpdated = false;
58 }
wxTextCtrl * mText

Member Function Documentation

void AudacityLogger::DoLogText ( const wxString &  msg)
overrideprotected

Definition at line 68 of file AudacityLogger.cpp.

References _TS, AUDACITY_VERSION_STRING, Flush(), mBuffer, and mUpdated.

Referenced by OnClear().

69 {
70  if (!wxIsMainThread()) {
71  wxMutexGuiEnter();
72  }
73 
74  if (mBuffer.IsEmpty()) {
75  wxString stamp;
76 
77  TimeStamp(&stamp);
78 
79  mBuffer << stamp << _TS("Audacity ") << AUDACITY_VERSION_STRING << wxT("\n");
80  }
81 
82  mBuffer << str << wxT("\n");
83 
84  mUpdated = true;
85 
86  Flush();
87 
88  if (!wxIsMainThread()) {
89  wxMutexGuiLeave();
90  }
91 }
#define AUDACITY_VERSION_STRING
Definition: Audacity.h:81
#define _TS(s)
Definition: Internat.h:30
void Flush() override
wxString mBuffer
void AudacityLogger::Flush ( )
overrideprotected

Definition at line 60 of file AudacityLogger.cpp.

References mBuffer, mFrame, mText, and mUpdated.

Referenced by DoLogText(), and Show().

61 {
62  if (mUpdated && mFrame && mFrame->IsShown()) {
63  mUpdated = false;
64  mText->ChangeValue(mBuffer);
65  }
66 }
Destroy_ptr< wxFrame > mFrame
wxString mBuffer
wxTextCtrl * mText
void AudacityLogger::OnClear ( wxCommandEvent &  e)
private

Definition at line 224 of file AudacityLogger.cpp.

References DoLogText(), and mBuffer.

Referenced by Show().

225 {
226  mBuffer = wxEmptyString;
227  DoLogText(wxT("Log Cleared."));
228 }
wxString mBuffer
void DoLogText(const wxString &msg) override
void AudacityLogger::OnClose ( wxCommandEvent &  e)
private

Definition at line 218 of file AudacityLogger.cpp.

References OnCloseWindow().

Referenced by Show().

219 {
220  wxCloseEvent dummy;
221  OnCloseWindow(dummy);
222 }
void OnCloseWindow(wxCloseEvent &e)
void AudacityLogger::OnCloseWindow ( wxCloseEvent &  e)
private

Definition at line 206 of file AudacityLogger.cpp.

References mFrame, and Show().

Referenced by OnClose(), and Show().

207 {
208 #if defined(__WXMAC__)
209  // On the Mac, destroy the window rather than hiding it since the
210  // log menu will override the root windows menu if there is no
211  // project window open.
212  mFrame.reset();
213 #else
214  Show(false);
215 #endif
216 }
void Show(bool show=true)
Destroy_ptr< wxFrame > mFrame
void AudacityLogger::OnSave ( wxCommandEvent &  e)
private

Definition at line 230 of file AudacityLogger.cpp.

References _(), AudacityMessageBox(), FileNames::Export, mFrame, mText, and FileNames::SelectFile().

Referenced by Show().

231 {
232  wxString fName = _("log.txt");
233 
235  _("Save log to:"),
236  wxEmptyString,
237  fName,
238  wxT("txt"),
239  wxT("*.txt"),
240  wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxRESIZE_BORDER,
241  mFrame.get());
242 
243  if (fName == wxEmptyString) {
244  return;
245  }
246 
247  if (!mText->SaveFile(fName)) {
249  wxString::Format( _("Couldn't save log to file: %s"), fName ),
250  _("Warning"),
251  wxICON_EXCLAMATION,
252  mFrame.get());
253  return;
254  }
255 }
Destroy_ptr< wxFrame > mFrame
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
wxTextCtrl * mText
static wxString SelectFile(Operation op, const wxString &message, const wxString &default_path, const wxString &default_filename, const wxString &default_extension, const wxString &wildcard, int flags, wxWindow *parent)
Definition: FileNames.cpp:411
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void AudacityLogger::Show ( bool  show = true)

Definition at line 93 of file AudacityLogger.cpp.

References _(), ThemeBase::Bitmap(), eIsCreating, Flush(), LoggerID_Clear, LoggerID_Close, LoggerID_Save, mBuffer, mFrame, mText, OnClear(), OnClose(), OnCloseWindow(), OnSave(), safenew, ShuttleGuiBase::SetStyle(), and theTheme.

Referenced by OnCloseWindow(), and AudacityProject::OnShowLog().

94 {
95  // Hide the frame if created, otherwise do nothing
96  if (!show) {
97  if (mFrame) {
98  mFrame->Show(false);
99  }
100  return;
101  }
102 
103  // If the frame already exists, refresh its contents and show it
104  if (mFrame) {
105  if (!mFrame->IsShown()) {
106  mText->ChangeValue(mBuffer);
107  mText->SetInsertionPointEnd();
108  mText->ShowPosition(mText->GetLastPosition());
109  }
110  mFrame->Show();
111  mFrame->Raise();
112  return;
113  }
114 
115  // This is the first use, so create the frame
117  { safenew wxFrame(NULL, wxID_ANY, _("Audacity Log")) };
118  frame->SetName(frame->GetTitle());
119  frame->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
120 
121  // loads either the XPM or the windows resource, depending on the platform
122  {
123 #if !defined(__WXMAC__) && !defined(__WXX11__)
124 #if defined(__WXMSW__)
125  wxIcon ic{wxICON(AudacityLogo)};
126 #elif defined(__WXGTK__)
127  wxIcon ic{wxICON(AudacityLogoAlpha)};
128 #else
129  wxIcon ic{};
130  ic.CopyFromBitmap(theTheme.Bitmap(bmpAudacityLogo48x48));
131 #endif
132  frame->SetIcon(ic);
133 #endif
134  }
135 
136  // Log text
137  ShuttleGui S(frame.get(), eIsCreating);
138 
139  S.SetStyle(wxNO_BORDER | wxTAB_TRAVERSAL);
140  S.Prop(true).StartPanel();
141  {
142  S.StartVerticalLay(true);
143  {
144  S.SetStyle(wxTE_MULTILINE | wxHSCROLL | wxTE_READONLY);
145  mText = S.AddTextWindow(mBuffer);
146 
147  S.AddSpace(0, 5);
148  S.StartHorizontalLay(wxALIGN_CENTER, 0);
149  {
150  S.AddSpace(10, 0);
151  S.Id(LoggerID_Save).AddButton(_("&Save..."));
152  S.Id(LoggerID_Clear).AddButton(_("Cl&ear"));
153  S.Id(LoggerID_Close).AddButton(_("&Close"));
154  S.AddSpace(10, 0);
155  }
156  S.EndHorizontalLay();
157  S.AddSpace(0, 3);
158  }
159  S.EndVerticalLay();
160  }
161  S.EndPanel();
162 
163  // Give a place for the menu help text to go
164  // frame->CreateStatusBar();
165 
166  frame->Layout();
167 
168  // Hook into the frame events
169  frame->Bind(wxEVT_CLOSE_WINDOW,
170  wxCloseEventHandler(AudacityLogger::OnCloseWindow),
171  this);
172 
173  frame->Bind( wxEVT_COMMAND_MENU_SELECTED,
175  this, LoggerID_Save);
176  frame->Bind( wxEVT_COMMAND_MENU_SELECTED,
178  this, LoggerID_Clear);
179  frame->Bind( wxEVT_COMMAND_MENU_SELECTED,
181  this, LoggerID_Close);
182  frame->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
184  this, LoggerID_Save);
185  frame->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
187  this, LoggerID_Clear);
188  frame->Bind( wxEVT_COMMAND_BUTTON_CLICKED,
190  this, LoggerID_Close);
191 
192  mFrame = std::move( frame );
193 
194  mFrame->Show();
195 
196  Flush();
197 }
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
void OnCloseWindow(wxCloseEvent &e)
void Flush() override
Destroy_ptr< wxFrame > mFrame
#define safenew
Definition: Audacity.h:230
wxString mBuffer
wxBitmap & Bitmap(int iIndex)
Definition: Theme.cpp:1244
void SetStyle(int Style)
Definition: ShuttleGui.h:287
void OnSave(wxCommandEvent &e)
wxTextCtrl * mText
void OnClear(wxCommandEvent &e)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void OnClose(wxCommandEvent &e)
std::unique_ptr< T, Destroyer< T >> Destroy_ptr
Definition: MemoryX.h:433

Member Data Documentation

wxString AudacityLogger::mBuffer
private

Definition at line 50 of file AudacityLogger.h.

Referenced by DoLogText(), Flush(), OnClear(), and Show().

Destroy_ptr<wxFrame> AudacityLogger::mFrame
private

Definition at line 48 of file AudacityLogger.h.

Referenced by Flush(), OnCloseWindow(), OnSave(), and Show().

wxTextCtrl* AudacityLogger::mText
private

Definition at line 49 of file AudacityLogger.h.

Referenced by AudacityLogger(), Flush(), OnSave(), and Show().

bool AudacityLogger::mUpdated
private

Definition at line 51 of file AudacityLogger.h.

Referenced by AudacityLogger(), DoLogText(), and Flush().


The documentation for this class was generated from the following files: