1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-21 16:37:12 +01:00

Bug 137 (P3) - Unreliable project re-opening with orphaned and missing blockfile errors

At bottom of http://bugzilla.audacityteam.org/show_bug.cgi?id=137#c17: 

> I noticed that although when we open the same project a second time with File >
> Open or File > Recent Files we show an error "is already open in another
> window", there is no block on executing the .aup from your file manager and
> opening as many copies of the project as you like. I had not done that when
> Audacity moved the files around in error the first time, but can we block this
> anyway?

This is a different bug from Bug 137, repeatable, and I think lower priority. But I went ahead and fixed it with this commit.

Also fixed previously unnoted bug where AudacityApp::MRUOpen() returned true when it actually failed to open the file. Also removed AudacityApp::OnMRUProject() cruft.

Unfortunately, it still creates a new, empty project window on Win Explorer open whereas Open and Recent Files commands do not. I think that constitutes a new, separate P5 bug. 

Overall, this is another aspect of what I was talking about in http://bugzilla.audacityteam.org/show_bug.cgi?id=322#c26. Opening files vs projects got conflated for convenience, but this code is hacked in some regards, rather than being a good design, and that's why this type of bug shows up.
This commit is contained in:
v.audacity
2011-03-26 01:41:22 +00:00
parent 0bd3f11f41
commit 6bbbf5faa9
3 changed files with 54 additions and 60 deletions

View File

@@ -701,7 +701,7 @@ void AudacityApp::OnMacOpenFile(wxCommandEvent & event)
while (ofqueue.GetCount()) {
wxString name(ofqueue[0]);
ofqueue.RemoveAt(0);
MRUOpen(name);
MRUOpen(name); // FIX-ME: Check the return result?
}
}
#endif //__WXMAC__
@@ -735,7 +735,7 @@ BEGIN_EVENT_TABLE(AudacityApp, wxApp)
EVT_APP_COMMAND(wxID_ANY, AudacityApp::OnReceiveCommand)
END_EVENT_TABLE()
// Backend for OnMRUFile and OnMRUProject
// backend for OnMRUFile
bool AudacityApp::MRUOpen(wxString fullPathStr) {
// Most of the checks below are copied from AudacityProject::OpenFiles.
// - some rationalisation might be possible.
@@ -749,18 +749,12 @@ bool AudacityApp::MRUOpen(wxString fullPathStr) {
{
gPrefs->Write(wxT("/DefaultOpenPath"), wxPathOnly(fullPathStr));
// Make sure it isn't already open
wxFileName newFileName(fullPathStr);
size_t numProjects = gAudacityProjects.Count();
for (size_t i = 0; i < numProjects; i++) {
if (newFileName.SameAs(gAudacityProjects[i]->GetFileName())) {
wxMessageBox(wxString::Format(_("%s is already open in another window."),
newFileName.GetName().c_str()),
_("Error opening project"),
wxOK | wxCENTRE);
return(true);
}
}
// Make sure it isn't already open.
// Test here even though AudacityProject::OpenFile() also now checks, because
// that method does not return the bad result.
// That itself may be a FIX-ME.
if (AudacityProject::IsAlreadyOpen(fullPathStr))
return false;
// DMM: If the project is dirty, that means it's been touched at
// all, and it's not safe to open a new project directly in its
@@ -795,40 +789,22 @@ void AudacityApp::OnMRUClear(wxCommandEvent& event)
mRecentFiles->Clear();
}
//vvv Basically, anything from Recent Files is treated as a .aup, until proven otherwise,
// then it tries to Import(). Very questionable handling, imo.
// Better, for example, to check the file type early on.
void AudacityApp::OnMRUFile(wxCommandEvent& event) {
int n = event.GetId() - ID_RECENT_FIRST;
wxString fullPathStr = mRecentFiles->GetHistoryFile(n);
bool opened = MRUOpen(fullPathStr);
if(!opened) {
// Try to open only if not already open.
// Test IsAlreadyOpen() here even though AudacityProject::MRUOpen() also now checks,
// because we don't want to RemoveFileFromHistory() just because it already exists,
// and AudacityApp::OnMacOpenFile() calls MRUOpen() directly.
// that method does not return the bad result.
if (!AudacityProject::IsAlreadyOpen(fullPathStr) && !MRUOpen(fullPathStr))
mRecentFiles->RemoveFileFromHistory(n);
}
}
#if 0
//FIX-ME: Was this OnMRUProject lost in an edit?? Should we have it back?
//vvv I think it was removed on purpose, but I don't know why it's still here.
// Basically, anything from Recent Files is treated as a .aup, until proven otherwise,
// then it tries to Import(). Very questionable handling, imo.
// Better, for example, to check the file type early on.
//
void AudacityApp::OnMRUProject(wxCommandEvent& event) {
AudacityProject *proj = GetActiveProject();
int n = event.GetId() - 6050;//FIX-ME: Use correct ID name.
wxString fullPathStr = proj->GetRecentProjects()->GetHistoryFile(n);
bool opened = MRUOpen(fullPathStr);
if(!opened) {
proj->GetRecentProjects()->RemoveFileFromHistory(n);
gPrefs->SetPath("/RecentProjects");
proj->GetRecentProjects()->Save(*gPrefs);
gPrefs->SetPath("..");
}
}
#endif
void AudacityApp::InitLang( const wxString & lang )
{
if( mLocale )