1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-10-14 22:51:11 +02:00

Add button to History dialog to clear the clipboard & space calc

This commit is contained in:
Paul Licameli
2016-11-07 11:25:27 -05:00
parent c439ceba03
commit 93c0b5a92d
5 changed files with 76 additions and 32 deletions

View File

@@ -42,7 +42,8 @@ enum {
ID_AVAIL = 1000, ID_AVAIL = 1000,
ID_TOTAL, ID_TOTAL,
ID_LEVELS, ID_LEVELS,
ID_DISCARD ID_DISCARD,
ID_DISCARD_CLIPBOARD
}; };
BEGIN_EVENT_TABLE(HistoryWindow, wxDialogWrapper) BEGIN_EVENT_TABLE(HistoryWindow, wxDialogWrapper)
@@ -50,6 +51,7 @@ BEGIN_EVENT_TABLE(HistoryWindow, wxDialogWrapper)
EVT_CLOSE(HistoryWindow::OnCloseWindow) EVT_CLOSE(HistoryWindow::OnCloseWindow)
EVT_LIST_ITEM_SELECTED(wxID_ANY, HistoryWindow::OnItemSelected) EVT_LIST_ITEM_SELECTED(wxID_ANY, HistoryWindow::OnItemSelected)
EVT_BUTTON(ID_DISCARD, HistoryWindow::OnDiscard) EVT_BUTTON(ID_DISCARD, HistoryWindow::OnDiscard)
EVT_BUTTON(ID_DISCARD_CLIPBOARD, HistoryWindow::OnDiscardClipboard)
END_EVENT_TABLE() END_EVENT_TABLE()
HistoryWindow::HistoryWindow(AudacityProject *parent, UndoManager *manager): HistoryWindow::HistoryWindow(AudacityProject *parent, UndoManager *manager):
@@ -112,6 +114,10 @@ HistoryWindow::HistoryWindow(AudacityProject *parent, UndoManager *manager):
S.AddWindow(mLevels); S.AddWindow(mLevels);
/* i18n-hint: (verb)*/ /* i18n-hint: (verb)*/
mDiscard = S.Id(ID_DISCARD).AddButton(_("&Discard")); mDiscard = S.Id(ID_DISCARD).AddButton(_("&Discard"));
mClipboard = S.AddTextBox(_("Clipboard space used"), wxT("0"), 10);
mClipboard->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(HistoryWindow::OnChar));
S.Id(ID_DISCARD_CLIPBOARD).AddButton(_("Discard"));
} }
S.EndMultiColumn(); S.EndMultiColumn();
} }
@@ -198,6 +204,10 @@ void HistoryWindow::DoUpdate()
mTotal->SetValue(Internat::FormatSize(total)); mTotal->SetValue(Internat::FormatSize(total));
auto clipboardUsage = mManager->GetClipboardSpaceUsage();
mClipboard->SetValue(Internat::FormatSize(clipboardUsage));
FindWindowById(ID_DISCARD_CLIPBOARD)->Enable(clipboardUsage > 0);
mList->EnsureVisible(mSelected); mList->EnsureVisible(mSelected);
mList->SetItemState(mSelected, mList->SetItemState(mSelected,
@@ -248,6 +258,12 @@ void HistoryWindow::OnDiscard(wxCommandEvent & WXUNUSED(event))
DoUpdate(); DoUpdate();
} }
void HistoryWindow::OnDiscardClipboard(wxCommandEvent & WXUNUSED(event))
{
AudacityProject::ClearClipboard();
DoUpdate();
}
void HistoryWindow::OnItemSelected(wxListEvent &event) void HistoryWindow::OnItemSelected(wxListEvent &event)
{ {
if (mAudioIOBusy) { if (mAudioIOBusy) {

View File

@@ -42,11 +42,13 @@ class HistoryWindow final : public wxDialogWrapper {
void OnChar(wxKeyEvent & event); void OnChar(wxKeyEvent & event);
void OnItemSelected(wxListEvent & event); void OnItemSelected(wxListEvent & event);
void OnDiscard(wxCommandEvent & event); void OnDiscard(wxCommandEvent & event);
void OnDiscardClipboard(wxCommandEvent & event);
AudacityProject *mProject; AudacityProject *mProject;
UndoManager *mManager; UndoManager *mManager;
wxListCtrl *mList; wxListCtrl *mList;
wxTextCtrl *mTotal; wxTextCtrl *mTotal;
wxTextCtrl *mClipboard;
wxTextCtrl *mAvail; wxTextCtrl *mAvail;
wxSpinCtrl *mLevels; wxSpinCtrl *mLevels;
wxButton *mDiscard; wxButton *mDiscard;

View File

@@ -341,6 +341,7 @@ class AUDACITY_DLL_API AudacityProject final : public wxFrame,
// Other commands // Other commands
static TrackList *GetClipboardTracks(); static TrackList *GetClipboardTracks();
static void ClearClipboard();
static void DeleteClipboard(); static void DeleteClipboard();
int GetProjectNumber(){ return mProjectNo;}; int GetProjectNumber(){ return mProjectNo;};
@@ -528,7 +529,6 @@ public:
private: private:
void OnCapture(wxCommandEvent & evt); void OnCapture(wxCommandEvent & evt);
void ClearClipboard();
void InitialState(); void InitialState();
void ModifyState(bool bWantsAutoSave); // if true, writes auto-save file. Should set only if you really want the state change restored after void ModifyState(bool bWantsAutoSave); // if true, writes auto-save file. Should set only if you really want the state change restored after
// a crash, as it can take many seconds for large (eg. 10 track-hours) projects // a crash, as it can take many seconds for large (eg. 10 track-hours) projects

View File

@@ -27,6 +27,7 @@ UndoManager
#include "BlockFile.h" #include "BlockFile.h"
#include "Diags.h" #include "Diags.h"
#include "Internat.h" #include "Internat.h"
#include "Project.h"
#include "Sequence.h" #include "Sequence.h"
#include "WaveTrack.h" // temp #include "WaveTrack.h" // temp
#include "NoteTrack.h" // for Sonify* function declarations #include "NoteTrack.h" // for Sonify* function declarations
@@ -69,11 +70,50 @@ UndoManager::~UndoManager()
ClearStates(); ClearStates();
} }
namespace {
SpaceArray::value_type
CalculateUsage(TrackList *tracks, Set *prev, Set *cur)
{
SpaceArray::value_type result = 0;
//TIMER_START( "CalculateSpaceUsage", space_calc );
TrackListOfKindIterator iter(Track::Wave);
WaveTrack *wt = (WaveTrack *) iter.First(tracks);
while (wt)
{
// Scan all clips within current track
for(const auto &clip : wt->GetAllClips())
{
// Scan all blockfiles within current clip
BlockArray *blocks = clip->GetSequenceBlockArray();
for (const auto &block : *blocks)
{
const auto &file = block.f;
// Accumulate space used by the file if the file didn't exist
// in the previous level
if (!prev || !cur ||
(prev->count( &*file ) == 0 && cur->count( &*file ) == 0))
{
unsigned long long usage{ file->GetSpaceUsage() };
result += usage;
}
// Add file to current set
if (cur)
cur->insert( &*file );
}
}
wt = (WaveTrack *) iter.Next();
}
return result;
}
}
void UndoManager::CalculateSpaceUsage() void UndoManager::CalculateSpaceUsage()
{ {
//TIMER_START( "CalculateSpaceUsage", space_calc );
TrackListOfKindIterator iter(Track::Wave);
space.clear(); space.clear();
space.resize(stack.size(), 0); space.resize(stack.size(), 0);
@@ -90,35 +130,13 @@ void UndoManager::CalculateSpaceUsage()
cur->clear(); cur->clear();
// Scan all tracks at current level // Scan all tracks at current level
WaveTrack *wt = (WaveTrack *) iter.First(stack[i]->state.tracks.get()); auto tracks = stack[i]->state.tracks.get();
while (wt) space[i] = CalculateUsage(tracks, prev, cur);
{
// Scan all clips within current track
for(const auto &clip : wt->GetAllClips())
{
// Scan all blockfiles within current clip
BlockArray *blocks = clip->GetSequenceBlockArray();
for (const auto &block : *blocks)
{
const auto &file = block.f;
// Accumulate space used by the file if the file didn't exist
// in the previous level
if (prev->count( &*file ) == 0 && cur->count( &*file ) == 0)
{
unsigned long long usage{ file->GetSpaceUsage() };
space[i] += usage;
}
// Add file to current set
cur->insert( &*file );
}
}
wt = (WaveTrack *) iter.Next();
}
} }
mClipboardSpaceUsage = CalculateUsage
(AudacityProject::GetClipboardTracks(), nullptr, nullptr);
//TIMER_STOP( space_calc ); //TIMER_STOP( space_calc );
} }

View File

@@ -108,6 +108,7 @@ class AUDACITY_DLL_API UndoManager {
unsigned int GetCurrentState(); unsigned int GetCurrentState();
void GetShortDescription(unsigned int n, wxString *desc); void GetShortDescription(unsigned int n, wxString *desc);
// Return value must first be calculated by CalculateSpaceUsage():
wxLongLong_t GetLongDescription(unsigned int n, wxString *desc, wxString *size); wxLongLong_t GetLongDescription(unsigned int n, wxString *desc, wxString *size);
void SetLongDescription(unsigned int n, const wxString &desc); void SetLongDescription(unsigned int n, const wxString &desc);
@@ -121,6 +122,12 @@ class AUDACITY_DLL_API UndoManager {
bool UnsavedChanges(); bool UnsavedChanges();
void StateSaved(); void StateSaved();
// Return value must first be calculated by CalculateSpaceUsage():
// The clipboard is global, not specific to this project, but it is
// convenient to combine the space usage calculations in one class:
wxLongLong_t GetClipboardSpaceUsage() const
{ return mClipboardSpaceUsage; }
void CalculateSpaceUsage(); void CalculateSpaceUsage();
// void Debug(); // currently unused // void Debug(); // currently unused
@@ -139,6 +146,7 @@ class AUDACITY_DLL_API UndoManager {
int consolidationCount; int consolidationCount;
SpaceArray space; SpaceArray space;
unsigned long long mClipboardSpaceUsage {};
bool mODChanges; bool mODChanges;
ODLock mODChangesMutex;//mODChanges is accessed from many threads. ODLock mODChangesMutex;//mODChanges is accessed from many threads.