mirror of
https://github.com/cookiengineer/audacity
synced 2025-12-03 15:20:17 +01:00
Bug2570 residual: Compact should not change last saved state...
... So that if you save, edit, compact, close without saving, then reopen, you recover the saved state as expected, not the compacted state. Implications: Do not push an undo state for compaction. Discard redo states instead. Do not purge undo states after the last saved. The database still needs them. So we might reclaim less space than before.
This commit is contained in:
@@ -1231,15 +1231,23 @@ void ProjectFileManager::Compact()
|
|||||||
// Purpose of this is to remove the -wal file.
|
// Purpose of this is to remove the -wal file.
|
||||||
projectFileIO.ReopenProject();
|
projectFileIO.ReopenProject();
|
||||||
|
|
||||||
auto currentTracks = TrackList::Create( nullptr );
|
auto savedState = undoManager.GetSavedState();
|
||||||
auto &tracks = TrackList::Get( project );
|
if (savedState < 0) {
|
||||||
for (auto t : tracks.Any())
|
undoManager.StateSaved();
|
||||||
{
|
savedState = undoManager.GetSavedState();
|
||||||
currentTracks->Add(t->Duplicate());
|
if (savedState < 0) {
|
||||||
|
wxASSERT(false);
|
||||||
|
savedState = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
std::vector<const TrackList*> trackLists;
|
||||||
|
undoManager.VisitStates(
|
||||||
|
[&](auto& elem){ trackLists.push_back(elem.state.tracks.get()); },
|
||||||
|
savedState,
|
||||||
|
undoManager.GetCurrentState() + 1);
|
||||||
|
|
||||||
int64_t total = projectFileIO.GetTotalUsage();
|
int64_t total = projectFileIO.GetTotalUsage();
|
||||||
int64_t used = projectFileIO.GetCurrentUsage({currentTracks.get()});
|
int64_t used = projectFileIO.GetCurrentUsage(trackLists);
|
||||||
|
|
||||||
auto before = wxFileName::GetSize(projectFileIO.GetFileName());
|
auto before = wxFileName::GetSize(projectFileIO.GetFileName());
|
||||||
|
|
||||||
@@ -1256,27 +1264,21 @@ void ProjectFileManager::Compact()
|
|||||||
Internat::FormatSize(total - used)));
|
Internat::FormatSize(total - used)));
|
||||||
if (isBatch || dlg.ShowModal() == wxYES)
|
if (isBatch || dlg.ShowModal() == wxYES)
|
||||||
{
|
{
|
||||||
// Want to do this before removing the states so that it becomes the
|
// We can remove redo states.
|
||||||
// current state.
|
undoManager.AbandonRedo();
|
||||||
ProjectHistory::Get(project)
|
|
||||||
.PushState(XO("Compacted project file"), XO("Compact"), UndoPush::CONSOLIDATE);
|
|
||||||
|
|
||||||
// Now we can remove all previous states.
|
// We can remove all states before the last saved.
|
||||||
auto numStates = undoManager.GetNumStates();
|
undoManager.RemoveStates(0, savedState);
|
||||||
undoManager.RemoveStates(0, numStates - 1);
|
|
||||||
|
|
||||||
// And clear the clipboard, if needed
|
// And clear the clipboard, if needed
|
||||||
if (&mProject == clipboard.Project().lock().get())
|
if (&mProject == clipboard.Project().lock().get())
|
||||||
clipboard.Clear();
|
clipboard.Clear();
|
||||||
|
|
||||||
// This may also decrease some reference counts on blocks
|
|
||||||
mLastSavedTracks.reset();
|
|
||||||
|
|
||||||
// Refresh the before space usage since it may have changed due to the
|
// Refresh the before space usage since it may have changed due to the
|
||||||
// above actions.
|
// above actions.
|
||||||
auto before = wxFileName::GetSize(projectFileIO.GetFileName());
|
auto before = wxFileName::GetSize(projectFileIO.GetFileName());
|
||||||
|
|
||||||
projectFileIO.Compact( { currentTracks.get() }, true);
|
projectFileIO.Compact(trackLists, true);
|
||||||
|
|
||||||
auto after = wxFileName::GetSize(projectFileIO.GetFileName());
|
auto after = wxFileName::GetSize(projectFileIO.GetFileName());
|
||||||
|
|
||||||
@@ -1288,6 +1290,4 @@ void ProjectFileManager::Compact()
|
|||||||
XO("Compact Project"));
|
XO("Compact Project"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mLastSavedTracks = currentTracks;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -321,11 +321,7 @@ void UndoManager::PushState(const TrackList * l,
|
|||||||
|
|
||||||
mayConsolidate = true;
|
mayConsolidate = true;
|
||||||
|
|
||||||
// Abandon redo states
|
AbandonRedo();
|
||||||
if (saved >= current) {
|
|
||||||
saved = -1;
|
|
||||||
}
|
|
||||||
RemoveStates( current + 1, stack.size() );
|
|
||||||
|
|
||||||
// Assume tags was duplicated before any changes.
|
// Assume tags was duplicated before any changes.
|
||||||
// Just save a NEW shared_ptr to it.
|
// Just save a NEW shared_ptr to it.
|
||||||
@@ -343,6 +339,14 @@ void UndoManager::PushState(const TrackList * l,
|
|||||||
mProject.QueueEvent( safenew wxCommandEvent{ EVT_UNDO_PUSHED } );
|
mProject.QueueEvent( safenew wxCommandEvent{ EVT_UNDO_PUSHED } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UndoManager::AbandonRedo()
|
||||||
|
{
|
||||||
|
if (saved > current) {
|
||||||
|
saved = -1;
|
||||||
|
}
|
||||||
|
RemoveStates( current + 1, stack.size() );
|
||||||
|
}
|
||||||
|
|
||||||
void UndoManager::SetStateTo(unsigned int n, const Consumer &consumer)
|
void UndoManager::SetStateTo(unsigned int n, const Consumer &consumer)
|
||||||
{
|
{
|
||||||
wxASSERT(n < stack.size());
|
wxASSERT(n < stack.size());
|
||||||
@@ -438,6 +442,11 @@ void UndoManager::StateSaved()
|
|||||||
saved = current;
|
saved = current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int UndoManager::GetSavedState() const
|
||||||
|
{
|
||||||
|
return saved;
|
||||||
|
}
|
||||||
|
|
||||||
// currently unused
|
// currently unused
|
||||||
//void UndoManager::Debug()
|
//void UndoManager::Debug()
|
||||||
//{
|
//{
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ class AUDACITY_DLL_API UndoManager final
|
|||||||
UndoPush flags = UndoPush::NONE);
|
UndoPush flags = UndoPush::NONE);
|
||||||
void ModifyState(const TrackList * l,
|
void ModifyState(const TrackList * l,
|
||||||
const SelectedRegion &selectedRegion, const std::shared_ptr<Tags> &tags);
|
const SelectedRegion &selectedRegion, const std::shared_ptr<Tags> &tags);
|
||||||
|
void AbandonRedo();
|
||||||
void ClearStates();
|
void ClearStates();
|
||||||
void RemoveStates(
|
void RemoveStates(
|
||||||
size_t begin, //!< inclusive start of range
|
size_t begin, //!< inclusive start of range
|
||||||
@@ -183,6 +184,7 @@ class AUDACITY_DLL_API UndoManager final
|
|||||||
bool RedoAvailable();
|
bool RedoAvailable();
|
||||||
|
|
||||||
bool UnsavedChanges() const;
|
bool UnsavedChanges() const;
|
||||||
|
int GetSavedState() const;
|
||||||
void StateSaved();
|
void StateSaved();
|
||||||
|
|
||||||
// Return value must first be calculated by CalculateSpaceUsage():
|
// Return value must first be calculated by CalculateSpaceUsage():
|
||||||
|
|||||||
Reference in New Issue
Block a user