ProjectFileManager::OpenFile returns a pointer to project
This commit is contained in:
parent
c96d5f12bc
commit
1bed51ac80
|
@ -864,13 +864,10 @@ bool ProjectFileManager::IsAlreadyOpen(const FilePath &projPathName)
|
|||
|
||||
// FIXME:? TRAP_ERR This should return a result that is checked.
|
||||
// See comment in AudacityApp::MRUOpen().
|
||||
void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory)
|
||||
AudacityProject *ProjectFileManager::OpenFile(
|
||||
const FilePath &fileNameArg, bool addtohistory)
|
||||
{
|
||||
auto &project = mProject;
|
||||
auto &history = ProjectHistory::Get( project );
|
||||
auto &projectFileIO = ProjectFileIO::Get( project );
|
||||
auto &tracks = TrackList::Get( project );
|
||||
auto &trackPanel = TrackPanel::Get( project );
|
||||
auto &window = ProjectWindow::Get( project );
|
||||
|
||||
// On Win32, we may be given a short (DOS-compatible) file name on rare
|
||||
|
@ -882,7 +879,7 @@ void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory
|
|||
XO("Project resides on FAT formatted drive.\n"
|
||||
"Copy it to another drive to open it.")))
|
||||
{
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Make sure it isn't already open.
|
||||
|
@ -893,7 +890,7 @@ void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory
|
|||
// This was reported in http://bugzilla.audacityteam.org/show_bug.cgi?id=137#c17,
|
||||
// but is not really part of that bug. Anyway, prevent it!
|
||||
if (IsAlreadyOpen(fileName))
|
||||
return;
|
||||
return nullptr;
|
||||
|
||||
// Data loss may occur if users mistakenly try to open ".aup3.bak" files
|
||||
// left over from an unsuccessful save or by previous versions of Audacity.
|
||||
|
@ -906,7 +903,7 @@ void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory
|
|||
XO("Warning - Backup File Detected"),
|
||||
wxOK | wxCENTRE,
|
||||
&window);
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!::wxFileExists(fileName)) {
|
||||
|
@ -915,9 +912,10 @@ void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory
|
|||
XO("Error Opening File"),
|
||||
wxOK | wxCENTRE,
|
||||
&window);
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Following block covers cases other than a project file:
|
||||
{
|
||||
wxFFile ff(fileName, wxT("rb"));
|
||||
|
||||
|
@ -935,7 +933,7 @@ void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory
|
|||
XO("Error opening file"),
|
||||
wxOK | wxCENTRE,
|
||||
&window);
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char buf[7];
|
||||
|
@ -946,39 +944,55 @@ void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory
|
|||
XO("Error Opening File or Project"),
|
||||
wxOK | wxCENTRE,
|
||||
&window);
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (wxStrncmp(buf, "SQLite", 6) != 0)
|
||||
{
|
||||
// Not a database
|
||||
#ifdef EXPERIMENTAL_DRAG_DROP_PLUG_INS
|
||||
// Is it a plug-in?
|
||||
if (PluginManager::Get().DropFile(fileName))
|
||||
{
|
||||
if (PluginManager::Get().DropFile(fileName)) {
|
||||
MenuCreator::RebuildAllMenuBars();
|
||||
// Plug-in installation happened, not really opening of a file,
|
||||
// so return null
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#ifdef USE_MIDI
|
||||
if (FileNames::IsMidi(fileName))
|
||||
{
|
||||
DoImportMIDI(project, fileName);
|
||||
if (FileNames::IsMidi(fileName)) {
|
||||
// If this succeeds, indo history is incremented, and it also does
|
||||
// ZoomAfterImport:
|
||||
if(DoImportMIDI(project, fileName))
|
||||
return &project;
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Import(fileName);
|
||||
// Undo history is incremented inside this:
|
||||
if (Import(fileName)) {
|
||||
// Bug 2743: Don't zoom with lof.
|
||||
if (!fileName.AfterLast('.').IsSameAs(wxT("lof"), false))
|
||||
window.ZoomAfterImport(nullptr);
|
||||
return &project;
|
||||
}
|
||||
// Bug 2743: Don't zoom with lof.
|
||||
if (!fileName.AfterLast('.').IsSameAs(wxT("lof"), false))
|
||||
window.ZoomAfterImport(nullptr);
|
||||
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return OpenProjectFile(fileName, addtohistory);
|
||||
}
|
||||
|
||||
AudacityProject *ProjectFileManager::OpenProjectFile(
|
||||
const FilePath &fileName, bool addtohistory)
|
||||
{
|
||||
auto &project = mProject;
|
||||
auto &history = ProjectHistory::Get( project );
|
||||
auto &tracks = TrackList::Get( project );
|
||||
auto &trackPanel = TrackPanel::Get( project );
|
||||
auto &projectFileIO = ProjectFileIO::Get( project );
|
||||
auto &window = ProjectWindow::Get( project );
|
||||
|
||||
auto results = ReadProjectFile( fileName );
|
||||
|
||||
const bool bParseSuccess = results.parseSuccess;
|
||||
const auto &errorStr = results.errorString;
|
||||
const bool err = results.trackError;
|
||||
|
@ -1020,6 +1034,7 @@ void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory
|
|||
// PushState calls AutoSave(), so no longer need to do so here.
|
||||
history.PushState(XO("Project was recovered"), XO("Recover"));
|
||||
}
|
||||
return &project;
|
||||
}
|
||||
else {
|
||||
// Vaughan, 2011-10-30:
|
||||
|
@ -1044,6 +1059,8 @@ void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory
|
|||
XO("Error Opening Project"),
|
||||
errorStr,
|
||||
results.helpUrl);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1292,7 +1309,7 @@ bool ProjectFileManager::Import(
|
|||
|
||||
history.PushState(XO("Imported '%s'").Format( fileName ), XO("Import"));
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// PRL: Undo history is incremented inside this:
|
||||
|
|
|
@ -43,16 +43,6 @@ public:
|
|||
ProjectFileManager &operator=( const ProjectFileManager & ) PROHIBITED;
|
||||
~ProjectFileManager();
|
||||
|
||||
struct ReadProjectResults
|
||||
{
|
||||
bool parseSuccess;
|
||||
bool trackError;
|
||||
const TranslatableString errorString;
|
||||
wxString helpUrl;
|
||||
};
|
||||
ReadProjectResults ReadProjectFile(
|
||||
const FilePath &fileName, bool discardAutosave = false );
|
||||
|
||||
bool OpenProject();
|
||||
void CloseProject();
|
||||
bool OpenNewProject();
|
||||
|
@ -91,7 +81,14 @@ public:
|
|||
|
||||
static bool IsAlreadyOpen(const FilePath &projPathName);
|
||||
|
||||
void OpenFile(const FilePath &fileName, bool addtohistory = true);
|
||||
/*!
|
||||
Opens files of many kinds. In case of import (sound, MIDI, or .aup), the undo history is pushed.
|
||||
@param fileName the name and contents are examined to decide a type and open appropriately
|
||||
@param addtohistory whether to add .aup3 files to the MRU list (but always done for imports)
|
||||
@return if something was successfully opened, the project containing it; else null
|
||||
*/
|
||||
AudacityProject *OpenFile(
|
||||
const FilePath &fileName, bool addtohistory = true);
|
||||
|
||||
bool Import(const FilePath &fileName,
|
||||
bool addToHistory = true);
|
||||
|
@ -105,6 +102,24 @@ public:
|
|||
void SetMenuClose(bool value) { mMenuClose = value; }
|
||||
|
||||
private:
|
||||
/*!
|
||||
@param fileName a path assumed to exist and contain an .aup3 project
|
||||
@param addtohistory whether to add the file to the MRU list
|
||||
@return if something was successfully opened, the project containing it; else null
|
||||
*/
|
||||
AudacityProject *OpenProjectFile(
|
||||
const FilePath &fileName, bool addtohistory);
|
||||
|
||||
struct ReadProjectResults
|
||||
{
|
||||
bool parseSuccess;
|
||||
bool trackError;
|
||||
const TranslatableString errorString;
|
||||
wxString helpUrl;
|
||||
};
|
||||
ReadProjectResults ReadProjectFile(
|
||||
const FilePath &fileName, bool discardAutosave = false );
|
||||
|
||||
bool DoSave(const FilePath & fileName, bool fromSaveAs);
|
||||
|
||||
AudacityProject &mProject;
|
||||
|
|
|
@ -838,17 +838,15 @@ void ProjectManager::OnCloseWindow(wxCloseEvent & event)
|
|||
|
||||
// PRL: I preserve this handler function for an event that was never sent, but
|
||||
// I don't know the intention.
|
||||
|
||||
void ProjectManager::OnOpenAudioFile(wxCommandEvent & event)
|
||||
{
|
||||
auto &project = mProject;
|
||||
auto &window = GetProjectFrame( project );
|
||||
const wxString &cmd = event.GetString();
|
||||
|
||||
if (!cmd.empty())
|
||||
ProjectFileManager::Get( mProject ).OpenFile(cmd);
|
||||
|
||||
window.RequestUserAttention();
|
||||
if (!cmd.empty()) {
|
||||
if (auto project = ProjectFileManager::Get( mProject ).OpenFile(cmd)) {
|
||||
auto &window = GetProjectFrame( *project );
|
||||
window.RequestUserAttention();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// static method, can be called outside of a project
|
||||
|
|
Loading…
Reference in New Issue