1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-24 16:38:07 +02:00

ProjectWindow does not depend on ProjectFileIO

This commit is contained in:
Paul Licameli 2019-06-05 07:23:08 -04:00
parent 2f9322e7f7
commit 236b188d6b
5 changed files with 56 additions and 55 deletions

View File

@ -39,6 +39,48 @@ Paul Licameli split from AudacityProject.cpp
#include "xml/XMLFileReader.h"
#include "xml/XMLWriter.h"
static void RefreshAllTitles(bool bShowProjectNumbers )
{
for ( auto pProject : AllProjects{} ) {
if ( !GetProjectFrame( *pProject ).IsIconized() ) {
ProjectFileIO::Get( *pProject ).SetProjectTitle(
bShowProjectNumbers ? pProject->GetProjectNumber() : -1 );
}
}
}
TitleRestorer::TitleRestorer(
wxTopLevelWindow &window, AudacityProject &project )
{
if( window.IsIconized() )
window.Restore();
window.Raise(); // May help identifying the window on Mac
// Construct this project's name and number.
sProjName = project.GetProjectName();
if ( sProjName.empty() ) {
sProjName = _("<untitled>");
UnnamedCount = std::count_if(
AllProjects{}.begin(), AllProjects{}.end(),
[]( const AllProjects::value_type &ptr ){
return ptr->GetProjectName().empty();
}
);
if ( UnnamedCount > 1 ) {
sProjNumber.Printf(
"[Project %02i] ", project.GetProjectNumber() + 1 );
RefreshAllTitles( true );
}
}
else
UnnamedCount = 0;
}
TitleRestorer::~TitleRestorer() {
if( UnnamedCount > 1 )
RefreshAllTitles( false );
}
static const AudacityProject::AttachedObjects::RegisteredFactory sFileIOKey{
[]( AudacityProject &parent ){
auto result = std::make_shared< ProjectFileIO >( parent );
@ -1108,7 +1150,7 @@ bool ProjectFileIO::SaveAs(bool bWantSaveCopy /*= false*/, bool bLossless /*= fa
{
auto &project = mProject;
auto &window = ProjectWindow::Get( project );
TitleRestorer Restorer( &window ); // RAII
TitleRestorer Restorer( window, project ); // RAII
bool bHasPath = true;
wxFileName filename{ project.GetFileName() };
// Save a copy of the project with 32-bit float tracks.

View File

@ -113,4 +113,16 @@ private:
bool mImportedDependencies{ false };
};
class wxTopLevelWindow;
// TitleRestorer restores project window titles to what they were, in its destructor.
class TitleRestorer{
public:
TitleRestorer( wxTopLevelWindow &window, AudacityProject &project );
~TitleRestorer();
wxString sProjNumber;
wxString sProjName;
size_t UnnamedCount;
};
#endif

View File

@ -700,7 +700,7 @@ void ProjectManager::OnCloseWindow(wxCloseEvent & event)
// project is now empty.
if (event.CanVeto() && (settings.EmptyCanBeDirty() || bHasTracks)) {
if ( UndoManager::Get( project ).UnsavedChanges() ) {
TitleRestorer Restorer( &window );// RAII
TitleRestorer Restorer( window, project );// RAII
/* i18n-hint: The first %s numbers the project, the second %s is the project name.*/
wxString Title = wxString::Format(_("%sSave changes to %s?"), Restorer.sProjNumber, Restorer.sProjName);
wxString Message = _("Save project before closing?");

View File

@ -16,7 +16,6 @@ Paul Licameli split from AudacityProject.cpp
#include "Menus.h"
#include "Project.h"
#include "ProjectAudioIO.h"
#include "ProjectFileIO.h"
#include "TrackPanel.h"
#include "ViewInfo.h"
#include "WaveClip.h"
@ -39,48 +38,6 @@ Paul Licameli split from AudacityProject.cpp
#include "../images/AudacityLogoAlpha.xpm"
#endif
static void RefreshAllTitles(bool bShowProjectNumbers )
{
for ( auto pProject : AllProjects{} ) {
if ( !GetProjectFrame( *pProject ).IsIconized() ) {
ProjectFileIO::Get( *pProject ).SetProjectTitle(
bShowProjectNumbers ? pProject->GetProjectNumber() : -1 );
}
}
}
TitleRestorer::TitleRestorer(ProjectWindow * pWindow )
{
auto &window = *pWindow;
if( window.IsIconized() )
window.Restore();
window.Raise(); // May help identifying the window on Mac
// Construct this projects name and number.
auto p = &pWindow->GetProject();
sProjName = p->GetProjectName();
if (sProjName.empty()){
sProjName = _("<untitled>");
UnnamedCount = std::count_if(
AllProjects{}.begin(), AllProjects{}.end(),
[]( const AllProjects::value_type &ptr ){
return ptr->GetProjectName().empty();
}
);
if( UnnamedCount > 1 ){
sProjNumber.Printf( "[Project %02i] ", p->GetProjectNumber()+1 );
RefreshAllTitles( true );
}
} else {
UnnamedCount = 0;
}
}
TitleRestorer::~TitleRestorer() {
if( UnnamedCount > 1 )
RefreshAllTitles( false );
}
// Returns the screen containing a rectangle, or -1 if none does.
int ScreenContaining( wxRect & r ){
unsigned int n = wxDisplay::GetCount();

View File

@ -190,14 +190,4 @@ private:
void GetDefaultWindowRect(wxRect *defRect);
void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized);
// TitleRestorer restores project window titles to what they were, in its destructor.
class TitleRestorer{
public:
TitleRestorer(ProjectWindow * pWindow );
~TitleRestorer();
wxString sProjNumber;
wxString sProjName;
size_t UnnamedCount;
};
#endif