Audacity  2.2.2
HistoryWindow.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  HistoryWindow.cpp
6 
7  Joshua Haberman
8  Leland Lucius
9 
10 *******************************************************************//*******************************************************************/
18 
19 #include "Audacity.h"
20 
21 #include <wx/app.h>
22 #include <wx/defs.h>
23 #include <wx/button.h>
24 #include <wx/dialog.h>
25 #include <wx/event.h>
26 #include <wx/imaglist.h>
27 #include <wx/intl.h>
28 #include <wx/listctrl.h>
29 #include <wx/settings.h>
30 #include <wx/stattext.h>
31 #include <wx/textctrl.h>
32 
33 #include "AudioIO.h"
34 #include "../images/Arrow.xpm"
35 #include "../images/Empty9x16.xpm"
36 #include "HistoryWindow.h"
37 #include "UndoManager.h"
38 #include "Project.h"
39 #include "ShuttleGui.h"
40 #include "Track.h"
41 
42 enum {
43  ID_AVAIL = 1000,
48 };
49 
50 BEGIN_EVENT_TABLE(HistoryWindow, wxDialogWrapper)
51  EVT_SIZE(HistoryWindow::OnSize)
52  EVT_CLOSE(HistoryWindow::OnCloseWindow)
53  EVT_LIST_ITEM_SELECTED(wxID_ANY, HistoryWindow::OnItemSelected)
55  EVT_BUTTON(ID_DISCARD_CLIPBOARD, HistoryWindow::OnDiscardClipboard)
57 
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 }
158 
159 void HistoryWindow::OnAudioIO(wxCommandEvent& evt)
160 {
161  evt.Skip();
162 
163  if (evt.GetInt() != 0)
164  mAudioIOBusy = true;
165  else
166  mAudioIOBusy = false;
167 
168  mDiscard->Enable(!mAudioIOBusy);
169 }
170 
172 {
173  if(IsShown())
174  DoUpdate();
175 }
176 
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 }
209 
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 }
236 
237 void HistoryWindow::OnDiscard(wxCommandEvent & WXUNUSED(event))
238 {
239  int i = mLevels->GetValue();
240 
241  mSelected -= i;
244 
245  while(--i >= 0)
246  mList->DeleteItem(i);
247 
248  DoUpdate();
249 }
250 
251 void HistoryWindow::OnDiscardClipboard(wxCommandEvent & WXUNUSED(event))
252 {
254  DoUpdate();
255 }
256 
257 void HistoryWindow::OnItemSelected(wxListEvent &event)
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 }
288 
289 void HistoryWindow::OnCloseWindow(wxCloseEvent & WXUNUSED(event))
290 {
291  this->Show(false);
292 }
293 
294 void HistoryWindow::OnSize(wxSizeEvent & WXUNUSED(event))
295 {
296  Layout();
297  mList->SetColumnWidth(0, mList->GetClientSize().x - mList->GetColumnWidth(1));
298  if (mList->GetItemCount() > 0)
299  mList->EnsureVisible(mSelected);
300 }
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
void OnDiscardClipboard(wxCommandEvent &event)
unsigned int GetNumStates()
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: HistoryWindow.h:27
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
wxWindow * AddWindow(wxWindow *pWindow, int Flags=wxALIGN_CENTRE|wxALL)
Definition: ShuttleGui.cpp:288
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 * mAvail
Definition: HistoryWindow.h:50
void EndMultiColumn()
void RemoveStates(int num)
wxSpinCtrl * mLevels
Definition: HistoryWindow.h:51
void OnItemSelected(wxListEvent &event)
#define safenew
Definition: Audacity.h:230
void OnCloseWindow(wxCloseEvent &WXUNUSED(event))
void EndHorizontalLay()
void AddPrompt(const wxString &Prompt)
Right aligned text string.
Definition: ShuttleGui.cpp:239
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
void EndVerticalLay()
wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:540
void OnSize(wxSizeEvent &event)
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
wxListCtrl * AddListControlReportMode()
Definition: ShuttleGui.cpp:689
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
AudacityProject * mProject
Definition: HistoryWindow.h:45
static void ClearClipboard()
Definition: Project.cpp:4893
ShuttleGui & Id(int id)
void OnDiscard(wxCommandEvent &event)
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
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)
wxStaticText * AddVariableText(const wxString &Str, bool bCenter=false, int PositionFlags=0)
Definition: ShuttleGui.cpp:414
wxStaticBox * StartStatic(const wxString &Str, int iProp=0)
Definition: ShuttleGui.cpp:763
Works with HistoryWindow to provide the Undo functionality.
Definition: UndoManager.h:93
END_EVENT_TABLE()
void SetBorder(int Border)
Definition: ShuttleGui.h:286
wxTextCtrl * mTotal
Definition: HistoryWindow.h:48
wxButton * AddButton(const wxString &Text, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:341
void SetStateTo(unsigned int n)
Definition: Project.cpp:4807
UndoManager * mManager
Definition: HistoryWindow.h:46
EVT_LIST_ITEM_SELECTED(CurvesListID, EditCurvesDialog::OnListSelectionChange) EVT_LIST_ITEM_DESELECTED(CurvesListID
Constructor.
void StartVerticalLay(int iProp=1)