1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-28 14:18:41 +02:00

Move SaveWindowSize to Project.cpp & it no longer needs AudacityApp.h

This commit is contained in:
Paul Licameli 2019-04-26 00:14:04 -04:00
parent d4b0fd1b83
commit 187e3be0d6
4 changed files with 87 additions and 91 deletions

View File

@ -292,7 +292,6 @@ void QuitAudacity(bool bForce)
else
/*end+*/
{
SaveWindowSize();
bool closedAll = AllProjects::Close( bForce );
if ( !closedAll )
{
@ -329,84 +328,6 @@ void QuitAudacity()
QuitAudacity(false);
}
void SaveWindowSize()
{
if (wxGetApp().GetWindowRectAlreadySaved())
{
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();
wxGetApp().SetWindowRectAlreadySaved(TRUE);
}
#if defined(__WXGTK__) && defined(HAVE_GTK)
///////////////////////////////////////////////////////////////////////////////
@ -1532,8 +1453,6 @@ bool AudacityApp::OnInit()
ModuleManager::Get().Dispatch(AppInitialized);
mWindowRectAlreadySaved = FALSE;
mTimer.SetOwner(this, kAudacityAppTimerID);
mTimer.Start(200);

View File

@ -39,8 +39,6 @@ class AppCommandEvent;
class AudacityLogger;
class AudacityProject;
void SaveWindowSize();
void QuitAudacity(bool bForce);
void QuitAudacity();
@ -98,9 +96,6 @@ class AudacityApp final : public wxApp {
void AssociateFileTypes();
#endif
bool GetWindowRectAlreadySaved()const {return mWindowRectAlreadySaved;}
void SetWindowRectAlreadySaved(bool alreadySaved) {mWindowRectAlreadySaved = alreadySaved;}
AudacityLogger *GetLogger();
#if defined(EXPERIMENTAL_CRASH_REPORT)
@ -128,8 +123,6 @@ class AudacityApp final : public wxApp {
std::unique_ptr<wxCmdLineParser> ParseCommandLine();
bool mWindowRectAlreadySaved;
#if defined(__WXMSW__)
std::unique_ptr<IPCServ> mIPCServ;
#else

View File

@ -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

View File

@ -157,11 +157,14 @@ public:
// But if return is false, that means the user cancelled close of at least
// one un-saved project.
static bool Close( bool force = false );
static void SaveWindowSize();
static bool Closing() { return sbClosing; }
static void Reset() { sbWindowRectAlreadySaved = false; }
private:
static bool sbClosing;
static bool sbWindowRectAlreadySaved;
};
class EffectPlugs;