mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-23 17:30:17 +01:00
Move SaveWindowSize to Project.cpp & it no longer needs AudacityApp.h
This commit is contained in:
@@ -99,7 +99,6 @@ scroll information. It also has some status flags.
|
||||
#include "FreqWindow.h"
|
||||
#include "effects/Contrast.h"
|
||||
#include "AutoRecovery.h"
|
||||
#include "AudacityApp.h"
|
||||
#include "AColor.h"
|
||||
#include "AudioIO.h"
|
||||
#include "BatchProcessDialog.h"
|
||||
@@ -174,10 +173,13 @@ scroll information. It also has some status flags.
|
||||
#endif
|
||||
|
||||
bool AllProjects::sbClosing = false;
|
||||
bool AllProjects::sbWindowRectAlreadySaved = false;
|
||||
|
||||
bool AllProjects::Close( bool force )
|
||||
{
|
||||
ValueRestorer<bool> cleanup{ sbClosing, true };
|
||||
if (gAudacityProjects.size())
|
||||
SaveWindowSize();
|
||||
while (gAudacityProjects.size())
|
||||
{
|
||||
// Closing the project has global side-effect
|
||||
@@ -195,6 +197,84 @@ bool AllProjects::Close( bool force )
|
||||
return true;
|
||||
}
|
||||
|
||||
void AllProjects::SaveWindowSize()
|
||||
{
|
||||
if (sbWindowRectAlreadySaved)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool validWindowForSaveWindowSize = FALSE;
|
||||
AudacityProject * validProject = NULL;
|
||||
bool foundIconizedProject = FALSE;
|
||||
size_t numProjects = gAudacityProjects.size();
|
||||
for (size_t i = 0; i < numProjects; i++)
|
||||
{
|
||||
if (!gAudacityProjects[i]->IsIconized()) {
|
||||
validWindowForSaveWindowSize = TRUE;
|
||||
validProject = gAudacityProjects[i].get();
|
||||
i = numProjects;
|
||||
}
|
||||
else
|
||||
foundIconizedProject = TRUE;
|
||||
|
||||
}
|
||||
if (validWindowForSaveWindowSize)
|
||||
{
|
||||
wxRect windowRect = validProject->GetRect();
|
||||
wxRect normalRect = validProject->GetNormalizedWindowState();
|
||||
bool wndMaximized = validProject->IsMaximized();
|
||||
gPrefs->Write(wxT("/Window/X"), windowRect.GetX());
|
||||
gPrefs->Write(wxT("/Window/Y"), windowRect.GetY());
|
||||
gPrefs->Write(wxT("/Window/Width"), windowRect.GetWidth());
|
||||
gPrefs->Write(wxT("/Window/Height"), windowRect.GetHeight());
|
||||
gPrefs->Write(wxT("/Window/Maximized"), wndMaximized);
|
||||
gPrefs->Write(wxT("/Window/Normal_X"), normalRect.GetX());
|
||||
gPrefs->Write(wxT("/Window/Normal_Y"), normalRect.GetY());
|
||||
gPrefs->Write(wxT("/Window/Normal_Width"), normalRect.GetWidth());
|
||||
gPrefs->Write(wxT("/Window/Normal_Height"), normalRect.GetHeight());
|
||||
gPrefs->Write(wxT("/Window/Iconized"), FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (foundIconizedProject) {
|
||||
validProject = gAudacityProjects[0].get();
|
||||
bool wndMaximized = validProject->IsMaximized();
|
||||
wxRect normalRect = validProject->GetNormalizedWindowState();
|
||||
// store only the normal rectangle because the itemized rectangle
|
||||
// makes no sense for an opening project window
|
||||
gPrefs->Write(wxT("/Window/X"), normalRect.GetX());
|
||||
gPrefs->Write(wxT("/Window/Y"), normalRect.GetY());
|
||||
gPrefs->Write(wxT("/Window/Width"), normalRect.GetWidth());
|
||||
gPrefs->Write(wxT("/Window/Height"), normalRect.GetHeight());
|
||||
gPrefs->Write(wxT("/Window/Maximized"), wndMaximized);
|
||||
gPrefs->Write(wxT("/Window/Normal_X"), normalRect.GetX());
|
||||
gPrefs->Write(wxT("/Window/Normal_Y"), normalRect.GetY());
|
||||
gPrefs->Write(wxT("/Window/Normal_Width"), normalRect.GetWidth());
|
||||
gPrefs->Write(wxT("/Window/Normal_Height"), normalRect.GetHeight());
|
||||
gPrefs->Write(wxT("/Window/Iconized"), TRUE);
|
||||
}
|
||||
else {
|
||||
// this would be a very strange case that might possibly occur on the Mac
|
||||
// Audacity would have to be running with no projects open
|
||||
// in this case we are going to write only the default values
|
||||
wxRect defWndRect;
|
||||
GetDefaultWindowRect(&defWndRect);
|
||||
gPrefs->Write(wxT("/Window/X"), defWndRect.GetX());
|
||||
gPrefs->Write(wxT("/Window/Y"), defWndRect.GetY());
|
||||
gPrefs->Write(wxT("/Window/Width"), defWndRect.GetWidth());
|
||||
gPrefs->Write(wxT("/Window/Height"), defWndRect.GetHeight());
|
||||
gPrefs->Write(wxT("/Window/Maximized"), FALSE);
|
||||
gPrefs->Write(wxT("/Window/Normal_X"), defWndRect.GetX());
|
||||
gPrefs->Write(wxT("/Window/Normal_Y"), defWndRect.GetY());
|
||||
gPrefs->Write(wxT("/Window/Normal_Width"), defWndRect.GetWidth());
|
||||
gPrefs->Write(wxT("/Window/Normal_Height"), defWndRect.GetHeight());
|
||||
gPrefs->Write(wxT("/Window/Iconized"), FALSE);
|
||||
}
|
||||
}
|
||||
gPrefs->Flush();
|
||||
sbWindowRectAlreadySaved = true;
|
||||
}
|
||||
|
||||
ODLock &AudacityProject::AllProjectDeleteMutex()
|
||||
{
|
||||
static ODLock theMutex;
|
||||
@@ -2581,7 +2661,7 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event)
|
||||
//
|
||||
// LL: Save before doing anything else to the window that might make
|
||||
// its size change.
|
||||
SaveWindowSize();
|
||||
AllProjects::SaveWindowSize();
|
||||
|
||||
mIsDeleting = true;
|
||||
|
||||
@@ -2707,7 +2787,8 @@ void AudacityProject::OnCloseWindow(wxCloseEvent & event)
|
||||
QuitAudacity();
|
||||
}
|
||||
else {
|
||||
wxGetApp().SetWindowRectAlreadySaved(FALSE);
|
||||
AllProjects::Reset();
|
||||
// For non-Mac, always keep at least one project window open
|
||||
CreateNewAudacityProject();
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user