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)
 
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)
 

Private Member Functions

void OnAudioIO (wxCommandEvent &evt)
 
void DoUpdate ()
 
void UpdateLevels ()
 
void OnSize (wxSizeEvent &event)
 
void OnCloseWindow (wxCloseEvent &WXUNUSED(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(), 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->Bind(wxEVT_KEY_DOWN,
99  // ignore it
100  [](wxEvent&){});
101  S.AddVariableText( {} )->Hide();
102 
103  mAvail = S.Id(ID_AVAIL).AddTextBox(_("&Undo Levels Available"), wxT("0"), 10);
104  mAvail->Bind(wxEVT_KEY_DOWN,
105  // ignore it
106  [](wxEvent&){});
107  S.AddVariableText( {} )->Hide();
108 
109  S.AddPrompt(_("&Levels To Discard"));
110  mLevels = safenew wxSpinCtrl(this,
111  ID_LEVELS,
112  wxT("1"),
113  wxDefaultPosition,
114  wxDefaultSize,
115  wxSP_ARROW_KEYS,
116  0,
117  mManager->GetCurrentState() - 1,
118  0);
119  S.AddWindow(mLevels);
120  /* i18n-hint: (verb)*/
121  mDiscard = S.Id(ID_DISCARD).AddButton(_("&Discard"));
122 
123  mClipboard = S.AddTextBox(_("Clipboard space used"), wxT("0"), 10);
124  mClipboard->Bind(wxEVT_KEY_DOWN,
125  // ignore it
126  [](wxEvent&){});
127  S.Id(ID_DISCARD_CLIPBOARD).AddButton(_("Discard"));
128  }
129  S.EndMultiColumn();
130  }
131  S.EndStatic();
132 
133  S.StartHorizontalLay(wxALIGN_RIGHT, false);
134  {
135  S.SetBorder(10);
136  S.Id(wxID_OK).AddButton(_("&OK"))->SetDefault();
137  }
138  S.EndHorizontalLay();
139  }
140  S.EndVerticalLay();
141  // ----------------------- End of main section --------------
142 
143  DoUpdate();
144  mList->SetMinSize(mList->GetSize());
145  Fit();
146  SetMinSize(GetSize());
147  mList->SetColumnWidth(0, mList->GetClientSize().x - mList->GetColumnWidth(1));
148  mList->SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
149 
150  wxTheApp->Bind(EVT_AUDIOIO_PLAYBACK,
152  this);
153 
154  wxTheApp->Bind(EVT_AUDIOIO_CAPTURE,
156  this);
157 }
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
unsigned int GetCurrentState()
wxListCtrl * mList
Definition: HistoryWindow.h:47
wxTextCtrl * mAvail
Definition: HistoryWindow.h:50
wxSpinCtrl * mLevels
Definition: HistoryWindow.h:51
#define safenew
Definition: Audacity.h:230
AudacityProject * mProject
Definition: HistoryWindow.h:45
wxButton * mDiscard
Definition: HistoryWindow.h:52
wxTextCtrl * mClipboard
Definition: HistoryWindow.h:49
_("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 OnAudioIO(wxCommandEvent &evt)
wxTextCtrl * mTotal
Definition: HistoryWindow.h:48
UndoManager * mManager
Definition: HistoryWindow.h:46

Member Function Documentation

void HistoryWindow::DoUpdate ( )
private

Definition at line 177 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().

178 {
179  int i;
180 
182 
183  mList->DeleteAllItems();
184 
185  wxLongLong_t total = 0;
187  for (i = 0; i < (int)mManager->GetNumStates(); i++) {
188  wxString desc, size;
189 
190  total += mManager->GetLongDescription(i + 1, &desc, &size);
191  mList->InsertItem(i, desc, i == mSelected ? 1 : 0);
192  mList->SetItem(i, 1, size);
193  }
194 
195  mTotal->SetValue(Internat::FormatSize(total));
196 
197  auto clipboardUsage = mManager->GetClipboardSpaceUsage();
198  mClipboard->SetValue(Internat::FormatSize(clipboardUsage));
199  FindWindowById(ID_DISCARD_CLIPBOARD)->Enable(clipboardUsage > 0);
200 
201  mList->EnsureVisible(mSelected);
202 
203  mList->SetItemState(mSelected,
204  wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED,
205  wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
206 
207  UpdateLevels();
208 }
static wxString FormatSize(wxLongLong size)
Convert a number to a string while formatting it in bytes, KB, MB, GB.
Definition: Internat.cpp:191
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:47
void CalculateSpaceUsage()
wxLongLong_t GetLongDescription(unsigned int n, wxString *desc, wxString *size)
wxTextCtrl * mClipboard
Definition: HistoryWindow.h:49
wxTextCtrl * mTotal
Definition: HistoryWindow.h:48
UndoManager * mManager
Definition: HistoryWindow.h:46
void HistoryWindow::OnAudioIO ( wxCommandEvent &  evt)
private

Definition at line 159 of file HistoryWindow.cpp.

References mAudioIOBusy, and mDiscard.

Referenced by HistoryWindow().

160 {
161  evt.Skip();
162 
163  if (evt.GetInt() != 0)
164  mAudioIOBusy = true;
165  else
166  mAudioIOBusy = false;
167 
168  mDiscard->Enable(!mAudioIOBusy);
169 }
wxButton * mDiscard
Definition: HistoryWindow.h:52
void HistoryWindow::OnCloseWindow ( wxCloseEvent &  WXUNUSEDevent)
private

Definition at line 289 of file HistoryWindow.cpp.

290 {
291  this->Show(false);
292 }
void HistoryWindow::OnDiscard ( wxCommandEvent &  event)
private

Definition at line 237 of file HistoryWindow.cpp.

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

238 {
239  int i = mLevels->GetValue();
240 
241  mSelected -= i;
244 
245  while(--i >= 0)
246  mList->DeleteItem(i);
247 
248  DoUpdate();
249 }
wxListCtrl * mList
Definition: HistoryWindow.h:47
void RemoveStates(int num)
wxSpinCtrl * mLevels
Definition: HistoryWindow.h:51
AudacityProject * mProject
Definition: HistoryWindow.h:45
void SetStateTo(unsigned int n)
Definition: Project.cpp:4714
UndoManager * mManager
Definition: HistoryWindow.h:46
void HistoryWindow::OnDiscardClipboard ( wxCommandEvent &  event)
private

Definition at line 251 of file HistoryWindow.cpp.

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

252 {
254  DoUpdate();
255 }
static void ClearClipboard()
Definition: Project.cpp:4800
void HistoryWindow::OnItemSelected ( wxListEvent &  event)
private

Definition at line 257 of file HistoryWindow.cpp.

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

258 {
259  if (mAudioIOBusy) {
260  mList->SetItemState(mSelected,
261  wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED,
262  wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED);
263  return;
264  }
265 
266  int selected = event.GetIndex();
267  int i;
268 
269  for (i = 0; i < mList->GetItemCount(); i++) {
270  mList->SetItemImage(i, 0);
271  if (i > selected)
272  mList->SetItemTextColour(i, *wxLIGHT_GREY);
273  else
274  mList->SetItemTextColour(i, mList->GetTextColour());
275  }
276  mList->SetItemImage(selected, 1);
277 
278  // Do not do a SetStateTo() if we're not actually changing the selected
279  // entry. Doing so can cause unnecessary delays upon initial load or while
280  // clicking the same entry over and over.
281  if (selected != mSelected) {
282  mProject->SetStateTo(selected + 1);
283  }
284  mSelected = selected;
285 
286  UpdateLevels();
287 }
wxListCtrl * mList
Definition: HistoryWindow.h:47
AudacityProject * mProject
Definition: HistoryWindow.h:45
void SetStateTo(unsigned int n)
Definition: Project.cpp:4714
void HistoryWindow::OnSize ( wxSizeEvent &  event)
private

Definition at line 294 of file HistoryWindow.cpp.

References mList, and mSelected.

295 {
296  Layout();
297  mList->SetColumnWidth(0, mList->GetClientSize().x - mList->GetColumnWidth(1));
298  if (mList->GetItemCount() > 0)
299  mList->EnsureVisible(mSelected);
300 }
wxListCtrl * mList
Definition: HistoryWindow.h:47
void HistoryWindow::UpdateDisplay ( )
void HistoryWindow::UpdateLevels ( )
private

Definition at line 210 of file HistoryWindow.cpp.

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

Referenced by DoUpdate(), and OnItemSelected().

211 {
212  wxWindow *focus;
213  int value = mLevels->GetValue();
214 
215  if (value > mSelected) {
216  value = mSelected;
217  }
218 
219  if (value == 0) {
220  value = 1;
221  }
222 
223  mLevels->SetValue(value);
224  mLevels->SetRange(1, mSelected);
225 
226  mAvail->SetValue(wxString::Format(wxT("%d"), mSelected));
227 
228  focus = FindFocus();
229  if ((focus == mDiscard || focus == mLevels) && mSelected == 0) {
230  mList->SetFocus();
231  }
232 
233  mLevels->Enable(mSelected > 0);
234  mDiscard->Enable(!mAudioIOBusy && mSelected > 0);
235 }
wxListCtrl * mList
Definition: HistoryWindow.h:47
wxTextCtrl * mAvail
Definition: HistoryWindow.h:50
wxSpinCtrl * mLevels
Definition: HistoryWindow.h:51
wxButton * mDiscard
Definition: HistoryWindow.h:52

Member Data Documentation

bool HistoryWindow::mAudioIOBusy
private

Definition at line 55 of file HistoryWindow.h.

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

wxTextCtrl* HistoryWindow::mAvail
private

Definition at line 50 of file HistoryWindow.h.

Referenced by UpdateLevels().

wxTextCtrl* HistoryWindow::mClipboard
private

Definition at line 49 of file HistoryWindow.h.

Referenced by DoUpdate().

wxButton* HistoryWindow::mDiscard
private

Definition at line 52 of file HistoryWindow.h.

Referenced by OnAudioIO(), and UpdateLevels().

wxSpinCtrl* HistoryWindow::mLevels
private

Definition at line 51 of file HistoryWindow.h.

Referenced by OnDiscard(), and UpdateLevels().

wxListCtrl* HistoryWindow::mList
private

Definition at line 47 of file HistoryWindow.h.

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

UndoManager* HistoryWindow::mManager
private

Definition at line 46 of file HistoryWindow.h.

Referenced by DoUpdate(), and OnDiscard().

AudacityProject* HistoryWindow::mProject
private

Definition at line 45 of file HistoryWindow.h.

Referenced by OnDiscard(), and OnItemSelected().

int HistoryWindow::mSelected
private

Definition at line 54 of file HistoryWindow.h.

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

wxTextCtrl* HistoryWindow::mTotal
private

Definition at line 48 of file HistoryWindow.h.

Referenced by DoUpdate().


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