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

Works with UndoManager to allow user to see descriptions of and undo previous commands. Also allows you to selectively clear the undo memory so as to free up space. More...

#include <HistoryWindow.h>

Inheritance diagram for HistoryWindow:
wxDialogWrapper wxTabTraversalWrapper< wxDialog >

Public Member Functions

 HistoryWindow (AudacityProject *parent, UndoManager *manager)
 
 ~HistoryWindow ()
 
void UpdateDisplay ()
 
- Public Member Functions inherited from wxDialogWrapper
 wxDialogWrapper ()
 
 wxDialogWrapper (wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const wxString &name=_("Dialog"))
 
bool Create (wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const wxString &name=_("Dialog"))
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxDialog >
 wxTabTraversalWrapper (Args &&...args)
 
 ~wxTabTraversalWrapper ()
 

Private Member Functions

void OnAudioIO (wxCommandEvent &evt)
 
void DoUpdate ()
 
void UpdateLevels ()
 
void OnSize (wxSizeEvent &event)
 
void OnCloseWindow (wxCloseEvent &WXUNUSED(event))
 
void OnChar (wxKeyEvent &event)
 
void OnItemSelected (wxListEvent &event)
 
void OnDiscard (wxCommandEvent &event)
 
void OnDiscardClipboard (wxCommandEvent &event)
 

Private Attributes

AudacityProjectmProject
 
UndoManagermManager
 
wxListCtrl * mList
 
wxTextCtrl * mTotal
 
wxTextCtrl * mClipboard
 
wxTextCtrl * mAvail
 
wxSpinCtrl * mLevels
 
wxButton * mDiscard
 
int mSelected
 
bool mAudioIOBusy
 

Detailed Description

Works with UndoManager to allow user to see descriptions of and undo previous commands. Also allows you to selectively clear the undo memory so as to free up space.

Definition at line 27 of file HistoryWindow.h.

Constructor & Destructor Documentation

HistoryWindow::HistoryWindow ( AudacityProject parent,
UndoManager manager 
)

Definition at line 58 of file HistoryWindow.cpp.

References _(), ShuttleGuiBase::AddButton(), ShuttleGuiBase::AddListControlReportMode(), ShuttleGuiBase::AddPrompt(), ShuttleGuiBase::AddTextBox(), ShuttleGuiBase::AddVariableText(), ShuttleGuiBase::AddWindow(), eIsCreating, ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndMultiColumn(), ShuttleGuiBase::EndStatic(), ShuttleGuiBase::EndVerticalLay(), ShuttleGui::Id(), ID_AVAIL, ID_LEVELS, ID_TOTAL, OnAudioIO(), OnChar(), safenew, ShuttleGuiBase::SetBorder(), ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartMultiColumn(), ShuttleGuiBase::StartStatic(), and ShuttleGuiBase::StartVerticalLay().

58  :
59  wxDialogWrapper((wxWindow*)parent, wxID_ANY, wxString(_("History")),
60  wxDefaultPosition, wxDefaultSize,
61  wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
62 {
63  SetName(GetTitle());
64 
65  mManager = manager;
66  mProject = parent;
67  mSelected = 0;
68  mAudioIOBusy = false;
69 
70  auto imageList = std::make_unique<wxImageList>(9, 16);
71  imageList->Add(wxIcon(empty9x16_xpm));
72  imageList->Add(wxIcon(arrow_xpm));
73 
74  //------------------------- Main section --------------------
75  // Construct the GUI.
76  ShuttleGui S(this, eIsCreating);
77 
78  S.SetBorder(5);
79  S.StartVerticalLay(true);
80  {
81  S.StartStatic(_("&Manage History"), 1);
82  {
83  mList = S.AddListControlReportMode();
84  // Do this BEFORE inserting the columns. On the Mac at least, the
85  // columns are deleted and later InsertItem()s will cause Audacity to crash.
86  mList->SetSingleStyle(wxLC_SINGLE_SEL);
87  mList->InsertColumn(0, _("Action"), wxLIST_FORMAT_LEFT, 260);
88  mList->InsertColumn(1, _("Reclaimable Space"), wxLIST_FORMAT_LEFT, 125);
89 
90  //Assign rather than set the image list, so that it is deleted later.
91  // AssignImageList takes ownership
92  mList->AssignImageList(imageList.release(), wxIMAGE_LIST_SMALL);
93 
94  S.StartMultiColumn(3, wxCENTRE);
95  {
96  // FIXME: Textbox labels have inconsistent capitalization
97  mTotal = S.Id(ID_TOTAL).AddTextBox(_("&Total space used"), wxT("0"), 10);
98  mTotal->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(HistoryWindow::OnChar));
99  S.AddVariableText( {} )->Hide();
100 
101  mAvail = S.Id(ID_AVAIL).AddTextBox(_("&Undo Levels Available"), wxT("0"), 10);
102  mAvail->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(HistoryWindow::OnChar));
103  S.AddVariableText( {} )->Hide();
104 
105  S.AddPrompt(_("&Levels To Discard"));
106  mLevels = safenew wxSpinCtrl(this,
107  ID_LEVELS,
108  wxT("1"),
109  wxDefaultPosition,
110  wxDefaultSize,
111  wxSP_ARROW_KEYS,
112  0,
113  mManager->GetCurrentState() - 1,
114  0);
115  S.AddWindow(mLevels);
116  /* i18n-hint: (verb)*/
117  mDiscard = S.Id(ID_DISCARD).AddButton(_("&Discard"));
118 
119  mClipboard = S.AddTextBox(_("Clipboard space used"), wxT("0"), 10);
120  mClipboard->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(HistoryWindow::OnChar));
121  S.Id(ID_DISCARD_CLIPBOARD).AddButton(_("Discard"));
122  }
123  S.EndMultiColumn();
124  }
125  S.EndStatic();
126 
127  S.StartHorizontalLay(wxALIGN_RIGHT, false);
128  {
129  S.SetBorder(10);
130  S.Id(wxID_OK).AddButton(_("&OK"))->SetDefault();
131  }
132  S.EndHorizontalLay();
133  }
134  S.EndVerticalLay();
135  // ----------------------- End of main section --------------
136 
137  DoUpdate();
138  mList->SetMinSize(mList->GetSize());
139  Fit();
140  SetMinSize(GetSize());
141  mList->SetColumnWidth(0, mList->GetClientSize().x - mList->GetColumnWidth(1));
142  mList->SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
143 
144  wxTheApp->Connect(EVT_AUDIOIO_PLAYBACK,
145  wxCommandEventHandler(HistoryWindow::OnAudioIO),
146  NULL,
147  this);
148 
149  wxTheApp->Connect(EVT_AUDIOIO_CAPTURE,
150  wxCommandEventHandler(HistoryWindow::OnAudioIO),
151  NULL,
152  this);
153 }
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366
unsigned int GetCurrentState()
wxListCtrl * mList
Definition: HistoryWindow.h:49
void OnChar(wxKeyEvent &event)
wxTextCtrl * mAvail
Definition: HistoryWindow.h:52
wxSpinCtrl * mLevels
Definition: HistoryWindow.h:53
#define safenew
Definition: Audacity.h:223
AudacityProject * mProject
Definition: HistoryWindow.h:47
wxButton * mDiscard
Definition: HistoryWindow.h:54
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
wxTextCtrl * mClipboard
Definition: HistoryWindow.h:51
void OnAudioIO(wxCommandEvent &evt)
wxTextCtrl * mTotal
Definition: HistoryWindow.h:50
UndoManager * mManager
Definition: HistoryWindow.h:48
HistoryWindow::~HistoryWindow ( )

Definition at line 155 of file HistoryWindow.cpp.

References mAvail, OnAudioIO(), and OnChar().

156 {
157  wxTheApp->Disconnect(EVT_AUDIOIO_PLAYBACK,
158  wxCommandEventHandler(HistoryWindow::OnAudioIO),
159  NULL,
160  this);
161 
162  wxTheApp->Disconnect(EVT_AUDIOIO_CAPTURE,
163  wxCommandEventHandler(HistoryWindow::OnAudioIO),
164  NULL,
165  this);
166 
167  mAvail->Disconnect(wxEVT_KEY_DOWN, wxKeyEventHandler(HistoryWindow::OnChar));
168 }
void OnChar(wxKeyEvent &event)
wxTextCtrl * mAvail
Definition: HistoryWindow.h:52
void OnAudioIO(wxCommandEvent &evt)

Member Function Documentation

void HistoryWindow::DoUpdate ( )
private

Definition at line 188 of file HistoryWindow.cpp.

References UndoManager::CalculateSpaceUsage(), desc, Internat::FormatSize(), UndoManager::GetClipboardSpaceUsage(), UndoManager::GetCurrentState(), UndoManager::GetLongDescription(), UndoManager::GetNumStates(), ID_DISCARD_CLIPBOARD, mClipboard, mList, mManager, mSelected, mTotal, and UpdateLevels().

Referenced by OnDiscard(), OnDiscardClipboard(), and UpdateDisplay().

189 {
190  int i;
191 
193 
194  mList->DeleteAllItems();
195 
196  wxLongLong_t total = 0;
198  for (i = 0; i < (int)mManager->GetNumStates(); i++) {
199  wxString desc, size;
200 
201  total += mManager->GetLongDescription(i + 1, &desc, &size);
202  mList->InsertItem(i, desc, i == mSelected ? 1 : 0);
203  mList->SetItem(i, 1, size);
204  }
205 
206  mTotal->SetValue(Internat::FormatSize(total));
207 
208  auto clipboardUsage = mManager->GetClipboardSpaceUsage();
209  mClipboard->SetValue(Internat::FormatSize(clipboardUsage));
210  FindWindowById(ID_DISCARD_CLIPBOARD)->Enable(clipboardUsage > 0);
211 
212  mList->EnsureVisible(mSelected);
213 
214  mList->SetItemState(mSelected,
215  wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED,
216  wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
217 
218  UpdateLevels();
219 }
static wxString FormatSize(wxLongLong size)
Convert a number to a string while formatting it in bytes, KB, MB, GB.
Definition: Internat.cpp:190
wxLongLong_t GetClipboardSpaceUsage() const
Definition: UndoManager.h:131
unsigned int GetNumStates()
const wxChar * desc
Definition: ExportPCM.cpp:58
unsigned int GetCurrentState()
wxListCtrl * mList
Definition: HistoryWindow.h:49
void CalculateSpaceUsage()
wxLongLong_t GetLongDescription(unsigned int n, wxString *desc, wxString *size)
wxTextCtrl * mClipboard
Definition: HistoryWindow.h:51
wxTextCtrl * mTotal
Definition: HistoryWindow.h:50
UndoManager * mManager
Definition: HistoryWindow.h:48
void HistoryWindow::OnAudioIO ( wxCommandEvent &  evt)
private

Definition at line 170 of file HistoryWindow.cpp.

References mAudioIOBusy, and mDiscard.

Referenced by HistoryWindow(), and ~HistoryWindow().

171 {
172  evt.Skip();
173 
174  if (evt.GetInt() != 0)
175  mAudioIOBusy = true;
176  else
177  mAudioIOBusy = false;
178 
179  mDiscard->Enable(!mAudioIOBusy);
180 }
wxButton * mDiscard
Definition: HistoryWindow.h:54
void HistoryWindow::OnChar ( wxKeyEvent &  event)
private

Definition at line 313 of file HistoryWindow.cpp.

Referenced by HistoryWindow(), and ~HistoryWindow().

314 {
315  event.Skip(false);
316  return;
317 }
void HistoryWindow::OnCloseWindow ( wxCloseEvent &  WXUNUSEDevent)
private

Definition at line 300 of file HistoryWindow.cpp.

301 {
302  this->Show(false);
303 }
void HistoryWindow::OnDiscard ( wxCommandEvent &  event)
private

Definition at line 248 of file HistoryWindow.cpp.

References DoUpdate(), mLevels, mList, mManager, mProject, mSelected, UndoManager::RemoveStates(), and AudacityProject::SetStateTo().

249 {
250  int i = mLevels->GetValue();
251 
252  mSelected -= i;
255 
256  while(--i >= 0)
257  mList->DeleteItem(i);
258 
259  DoUpdate();
260 }
wxListCtrl * mList
Definition: HistoryWindow.h:49
void RemoveStates(int num)
wxSpinCtrl * mLevels
Definition: HistoryWindow.h:53
AudacityProject * mProject
Definition: HistoryWindow.h:47
void SetStateTo(unsigned int n)
Definition: Project.cpp:4598
UndoManager * mManager
Definition: HistoryWindow.h:48
void HistoryWindow::OnDiscardClipboard ( wxCommandEvent &  event)
private

Definition at line 262 of file HistoryWindow.cpp.

References AudacityProject::ClearClipboard(), and DoUpdate().

263 {
265  DoUpdate();
266 }
static void ClearClipboard()
Definition: Project.cpp:4684
void HistoryWindow::OnItemSelected ( wxListEvent &  event)
private

Definition at line 268 of file HistoryWindow.cpp.

References mAudioIOBusy, mList, mProject, mSelected, AudacityProject::SetStateTo(), and UpdateLevels().

269 {
270  if (mAudioIOBusy) {
271  mList->SetItemState(mSelected,
272  wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED,
273  wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
274  return;
275  }
276 
277  int selected = event.GetIndex();
278  int i;
279 
280  for (i = 0; i < mList->GetItemCount(); i++) {
281  mList->SetItemImage(i, 0);
282  if (i > selected)
283  mList->SetItemTextColour(i, *wxLIGHT_GREY);
284  else
285  mList->SetItemTextColour(i, mList->GetTextColour());
286  }
287  mList->SetItemImage(selected, 1);
288 
289  // Do not do a SetStateTo() if we're not actually changing the selected
290  // entry. Doing so can cause unnecessary delays upon initial load or while
291  // clicking the same entry over and over.
292  if (selected != mSelected) {
293  mProject->SetStateTo(selected + 1);
294  }
295  mSelected = selected;
296 
297  UpdateLevels();
298 }
wxListCtrl * mList
Definition: HistoryWindow.h:49
AudacityProject * mProject
Definition: HistoryWindow.h:47
void SetStateTo(unsigned int n)
Definition: Project.cpp:4598
void HistoryWindow::OnSize ( wxSizeEvent &  event)
private

Definition at line 305 of file HistoryWindow.cpp.

References mList, and mSelected.

306 {
307  Layout();
308  mList->SetColumnWidth(0, mList->GetClientSize().x - mList->GetColumnWidth(1));
309  if (mList->GetItemCount() > 0)
310  mList->EnsureVisible(mSelected);
311 }
wxListCtrl * mList
Definition: HistoryWindow.h:49
void HistoryWindow::UpdateDisplay ( )
void HistoryWindow::UpdateLevels ( )
private

Definition at line 221 of file HistoryWindow.cpp.

References mAudioIOBusy, mAvail, mDiscard, mLevels, mList, and mSelected.

Referenced by DoUpdate(), and OnItemSelected().

222 {
223  wxWindow *focus;
224  int value = mLevels->GetValue();
225 
226  if (value > mSelected) {
227  value = mSelected;
228  }
229 
230  if (value == 0) {
231  value = 1;
232  }
233 
234  mLevels->SetValue(value);
235  mLevels->SetRange(1, mSelected);
236 
237  mAvail->SetValue(wxString::Format(wxT("%d"), mSelected));
238 
239  focus = FindFocus();
240  if ((focus == mDiscard || focus == mLevels) && mSelected == 0) {
241  mList->SetFocus();
242  }
243 
244  mLevels->Enable(mSelected > 0);
245  mDiscard->Enable(!mAudioIOBusy && mSelected > 0);
246 }
wxListCtrl * mList
Definition: HistoryWindow.h:49
wxTextCtrl * mAvail
Definition: HistoryWindow.h:52
wxSpinCtrl * mLevels
Definition: HistoryWindow.h:53
wxButton * mDiscard
Definition: HistoryWindow.h:54

Member Data Documentation

bool HistoryWindow::mAudioIOBusy
private

Definition at line 57 of file HistoryWindow.h.

Referenced by OnAudioIO(), OnItemSelected(), and UpdateLevels().

wxTextCtrl* HistoryWindow::mAvail
private

Definition at line 52 of file HistoryWindow.h.

Referenced by UpdateLevels(), and ~HistoryWindow().

wxTextCtrl* HistoryWindow::mClipboard
private

Definition at line 51 of file HistoryWindow.h.

Referenced by DoUpdate().

wxButton* HistoryWindow::mDiscard
private

Definition at line 54 of file HistoryWindow.h.

Referenced by OnAudioIO(), and UpdateLevels().

wxSpinCtrl* HistoryWindow::mLevels
private

Definition at line 53 of file HistoryWindow.h.

Referenced by OnDiscard(), and UpdateLevels().

wxListCtrl* HistoryWindow::mList
private

Definition at line 49 of file HistoryWindow.h.

Referenced by DoUpdate(), OnDiscard(), OnItemSelected(), OnSize(), and UpdateLevels().

UndoManager* HistoryWindow::mManager
private

Definition at line 48 of file HistoryWindow.h.

Referenced by DoUpdate(), and OnDiscard().

AudacityProject* HistoryWindow::mProject
private

Definition at line 47 of file HistoryWindow.h.

Referenced by OnDiscard(), and OnItemSelected().

int HistoryWindow::mSelected
private

Definition at line 56 of file HistoryWindow.h.

Referenced by DoUpdate(), OnDiscard(), OnItemSelected(), OnSize(), and UpdateLevels().

wxTextCtrl* HistoryWindow::mTotal
private

Definition at line 50 of file HistoryWindow.h.

Referenced by DoUpdate().


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