mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-26 09:28:07 +02:00
ProjectWindow does not depend on ProjectFileIO
This commit is contained in:
parent
2f9322e7f7
commit
236b188d6b
@ -39,6 +39,48 @@ Paul Licameli split from AudacityProject.cpp
|
|||||||
#include "xml/XMLFileReader.h"
|
#include "xml/XMLFileReader.h"
|
||||||
#include "xml/XMLWriter.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{
|
static const AudacityProject::AttachedObjects::RegisteredFactory sFileIOKey{
|
||||||
[]( AudacityProject &parent ){
|
[]( AudacityProject &parent ){
|
||||||
auto result = std::make_shared< ProjectFileIO >( 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 &project = mProject;
|
||||||
auto &window = ProjectWindow::Get( project );
|
auto &window = ProjectWindow::Get( project );
|
||||||
TitleRestorer Restorer( &window ); // RAII
|
TitleRestorer Restorer( window, project ); // RAII
|
||||||
bool bHasPath = true;
|
bool bHasPath = true;
|
||||||
wxFileName filename{ project.GetFileName() };
|
wxFileName filename{ project.GetFileName() };
|
||||||
// Save a copy of the project with 32-bit float tracks.
|
// Save a copy of the project with 32-bit float tracks.
|
||||||
|
@ -113,4 +113,16 @@ private:
|
|||||||
bool mImportedDependencies{ false };
|
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
|
#endif
|
||||||
|
@ -700,7 +700,7 @@ void ProjectManager::OnCloseWindow(wxCloseEvent & event)
|
|||||||
// project is now empty.
|
// project is now empty.
|
||||||
if (event.CanVeto() && (settings.EmptyCanBeDirty() || bHasTracks)) {
|
if (event.CanVeto() && (settings.EmptyCanBeDirty() || bHasTracks)) {
|
||||||
if ( UndoManager::Get( project ).UnsavedChanges() ) {
|
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.*/
|
/* 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 Title = wxString::Format(_("%sSave changes to %s?"), Restorer.sProjNumber, Restorer.sProjName);
|
||||||
wxString Message = _("Save project before closing?");
|
wxString Message = _("Save project before closing?");
|
||||||
|
@ -16,7 +16,6 @@ Paul Licameli split from AudacityProject.cpp
|
|||||||
#include "Menus.h"
|
#include "Menus.h"
|
||||||
#include "Project.h"
|
#include "Project.h"
|
||||||
#include "ProjectAudioIO.h"
|
#include "ProjectAudioIO.h"
|
||||||
#include "ProjectFileIO.h"
|
|
||||||
#include "TrackPanel.h"
|
#include "TrackPanel.h"
|
||||||
#include "ViewInfo.h"
|
#include "ViewInfo.h"
|
||||||
#include "WaveClip.h"
|
#include "WaveClip.h"
|
||||||
@ -39,48 +38,6 @@ Paul Licameli split from AudacityProject.cpp
|
|||||||
#include "../images/AudacityLogoAlpha.xpm"
|
#include "../images/AudacityLogoAlpha.xpm"
|
||||||
#endif
|
#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.
|
// Returns the screen containing a rectangle, or -1 if none does.
|
||||||
int ScreenContaining( wxRect & r ){
|
int ScreenContaining( wxRect & r ){
|
||||||
unsigned int n = wxDisplay::GetCount();
|
unsigned int n = wxDisplay::GetCount();
|
||||||
|
@ -190,14 +190,4 @@ private:
|
|||||||
void GetDefaultWindowRect(wxRect *defRect);
|
void GetDefaultWindowRect(wxRect *defRect);
|
||||||
void GetNextWindowPlacement(wxRect *nextRect, bool *pMaximized, bool *pIconized);
|
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
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user