mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-02 16:49:41 +02:00
Add button to History dialog to clear the clipboard & space calc
This commit is contained in:
parent
c439ceba03
commit
93c0b5a92d
@ -42,7 +42,8 @@ enum {
|
||||
ID_AVAIL = 1000,
|
||||
ID_TOTAL,
|
||||
ID_LEVELS,
|
||||
ID_DISCARD
|
||||
ID_DISCARD,
|
||||
ID_DISCARD_CLIPBOARD
|
||||
};
|
||||
|
||||
BEGIN_EVENT_TABLE(HistoryWindow, wxDialogWrapper)
|
||||
@ -50,6 +51,7 @@ BEGIN_EVENT_TABLE(HistoryWindow, wxDialogWrapper)
|
||||
EVT_CLOSE(HistoryWindow::OnCloseWindow)
|
||||
EVT_LIST_ITEM_SELECTED(wxID_ANY, HistoryWindow::OnItemSelected)
|
||||
EVT_BUTTON(ID_DISCARD, HistoryWindow::OnDiscard)
|
||||
EVT_BUTTON(ID_DISCARD_CLIPBOARD, HistoryWindow::OnDiscardClipboard)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
HistoryWindow::HistoryWindow(AudacityProject *parent, UndoManager *manager):
|
||||
@ -112,6 +114,10 @@ HistoryWindow::HistoryWindow(AudacityProject *parent, UndoManager *manager):
|
||||
S.AddWindow(mLevels);
|
||||
/* i18n-hint: (verb)*/
|
||||
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();
|
||||
}
|
||||
@ -198,6 +204,10 @@ void HistoryWindow::DoUpdate()
|
||||
|
||||
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->SetItemState(mSelected,
|
||||
@ -248,6 +258,12 @@ void HistoryWindow::OnDiscard(wxCommandEvent & WXUNUSED(event))
|
||||
DoUpdate();
|
||||
}
|
||||
|
||||
void HistoryWindow::OnDiscardClipboard(wxCommandEvent & WXUNUSED(event))
|
||||
{
|
||||
AudacityProject::ClearClipboard();
|
||||
DoUpdate();
|
||||
}
|
||||
|
||||
void HistoryWindow::OnItemSelected(wxListEvent &event)
|
||||
{
|
||||
if (mAudioIOBusy) {
|
||||
|
@ -42,11 +42,13 @@ class HistoryWindow final : public wxDialogWrapper {
|
||||
void OnChar(wxKeyEvent & event);
|
||||
void OnItemSelected(wxListEvent & event);
|
||||
void OnDiscard(wxCommandEvent & event);
|
||||
void OnDiscardClipboard(wxCommandEvent & event);
|
||||
|
||||
AudacityProject *mProject;
|
||||
UndoManager *mManager;
|
||||
wxListCtrl *mList;
|
||||
wxTextCtrl *mTotal;
|
||||
wxTextCtrl *mClipboard;
|
||||
wxTextCtrl *mAvail;
|
||||
wxSpinCtrl *mLevels;
|
||||
wxButton *mDiscard;
|
||||
|
@ -341,6 +341,7 @@ class AUDACITY_DLL_API AudacityProject final : public wxFrame,
|
||||
|
||||
// Other commands
|
||||
static TrackList *GetClipboardTracks();
|
||||
static void ClearClipboard();
|
||||
static void DeleteClipboard();
|
||||
|
||||
int GetProjectNumber(){ return mProjectNo;};
|
||||
@ -528,7 +529,6 @@ public:
|
||||
private:
|
||||
|
||||
void OnCapture(wxCommandEvent & evt);
|
||||
void ClearClipboard();
|
||||
void InitialState();
|
||||
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
|
||||
|
@ -27,6 +27,7 @@ UndoManager
|
||||
#include "BlockFile.h"
|
||||
#include "Diags.h"
|
||||
#include "Internat.h"
|
||||
#include "Project.h"
|
||||
#include "Sequence.h"
|
||||
#include "WaveTrack.h" // temp
|
||||
#include "NoteTrack.h" // for Sonify* function declarations
|
||||
@ -69,11 +70,50 @@ UndoManager::~UndoManager()
|
||||
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()
|
||||
{
|
||||
//TIMER_START( "CalculateSpaceUsage", space_calc );
|
||||
TrackListOfKindIterator iter(Track::Wave);
|
||||
|
||||
space.clear();
|
||||
space.resize(stack.size(), 0);
|
||||
|
||||
@ -90,35 +130,13 @@ void UndoManager::CalculateSpaceUsage()
|
||||
cur->clear();
|
||||
|
||||
// Scan all tracks at current level
|
||||
WaveTrack *wt = (WaveTrack *) iter.First(stack[i]->state.tracks.get());
|
||||
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->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();
|
||||
}
|
||||
auto tracks = stack[i]->state.tracks.get();
|
||||
space[i] = CalculateUsage(tracks, prev, cur);
|
||||
}
|
||||
|
||||
mClipboardSpaceUsage = CalculateUsage
|
||||
(AudacityProject::GetClipboardTracks(), nullptr, nullptr);
|
||||
|
||||
//TIMER_STOP( space_calc );
|
||||
}
|
||||
|
||||
|
@ -108,6 +108,7 @@ class AUDACITY_DLL_API UndoManager {
|
||||
unsigned int GetCurrentState();
|
||||
|
||||
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);
|
||||
void SetLongDescription(unsigned int n, const wxString &desc);
|
||||
|
||||
@ -121,6 +122,12 @@ class AUDACITY_DLL_API UndoManager {
|
||||
bool UnsavedChanges();
|
||||
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 Debug(); // currently unused
|
||||
@ -139,6 +146,7 @@ class AUDACITY_DLL_API UndoManager {
|
||||
int consolidationCount;
|
||||
|
||||
SpaceArray space;
|
||||
unsigned long long mClipboardSpaceUsage {};
|
||||
|
||||
bool mODChanges;
|
||||
ODLock mODChangesMutex;//mODChanges is accessed from many threads.
|
||||
|
Loading…
x
Reference in New Issue
Block a user