mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-18 00:50:05 +02:00
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.
|
// FIXME:? TRAP_ERR This should return a result that is checked.
|
||||||
// See comment in AudacityApp::MRUOpen().
|
// 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 &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 );
|
auto &window = ProjectWindow::Get( project );
|
||||||
|
|
||||||
// On Win32, we may be given a short (DOS-compatible) file name on rare
|
// 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"
|
XO("Project resides on FAT formatted drive.\n"
|
||||||
"Copy it to another drive to open it.")))
|
"Copy it to another drive to open it.")))
|
||||||
{
|
{
|
||||||
return;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure it isn't already open.
|
// 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,
|
// 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!
|
// but is not really part of that bug. Anyway, prevent it!
|
||||||
if (IsAlreadyOpen(fileName))
|
if (IsAlreadyOpen(fileName))
|
||||||
return;
|
return nullptr;
|
||||||
|
|
||||||
// Data loss may occur if users mistakenly try to open ".aup3.bak" files
|
// 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.
|
// 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"),
|
XO("Warning - Backup File Detected"),
|
||||||
wxOK | wxCENTRE,
|
wxOK | wxCENTRE,
|
||||||
&window);
|
&window);
|
||||||
return;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!::wxFileExists(fileName)) {
|
if (!::wxFileExists(fileName)) {
|
||||||
@ -915,9 +912,10 @@ void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory
|
|||||||
XO("Error Opening File"),
|
XO("Error Opening File"),
|
||||||
wxOK | wxCENTRE,
|
wxOK | wxCENTRE,
|
||||||
&window);
|
&window);
|
||||||
return;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Following block covers cases other than a project file:
|
||||||
{
|
{
|
||||||
wxFFile ff(fileName, wxT("rb"));
|
wxFFile ff(fileName, wxT("rb"));
|
||||||
|
|
||||||
@ -935,7 +933,7 @@ void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory
|
|||||||
XO("Error opening file"),
|
XO("Error opening file"),
|
||||||
wxOK | wxCENTRE,
|
wxOK | wxCENTRE,
|
||||||
&window);
|
&window);
|
||||||
return;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[7];
|
char buf[7];
|
||||||
@ -946,39 +944,55 @@ void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory
|
|||||||
XO("Error Opening File or Project"),
|
XO("Error Opening File or Project"),
|
||||||
wxOK | wxCENTRE,
|
wxOK | wxCENTRE,
|
||||||
&window);
|
&window);
|
||||||
return;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wxStrncmp(buf, "SQLite", 6) != 0)
|
if (wxStrncmp(buf, "SQLite", 6) != 0)
|
||||||
{
|
{
|
||||||
|
// Not a database
|
||||||
#ifdef EXPERIMENTAL_DRAG_DROP_PLUG_INS
|
#ifdef EXPERIMENTAL_DRAG_DROP_PLUG_INS
|
||||||
// Is it a plug-in?
|
// Is it a plug-in?
|
||||||
if (PluginManager::Get().DropFile(fileName))
|
if (PluginManager::Get().DropFile(fileName)) {
|
||||||
{
|
|
||||||
MenuCreator::RebuildAllMenuBars();
|
MenuCreator::RebuildAllMenuBars();
|
||||||
|
// Plug-in installation happened, not really opening of a file,
|
||||||
|
// so return null
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_MIDI
|
#ifdef USE_MIDI
|
||||||
if (FileNames::IsMidi(fileName))
|
if (FileNames::IsMidi(fileName)) {
|
||||||
{
|
// If this succeeds, indo history is incremented, and it also does
|
||||||
DoImportMIDI(project, fileName);
|
// ZoomAfterImport:
|
||||||
|
if(DoImportMIDI(project, fileName))
|
||||||
|
return &project;
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
{
|
// Undo history is incremented inside this:
|
||||||
Import(fileName);
|
if (Import(fileName)) {
|
||||||
}
|
|
||||||
// Bug 2743: Don't zoom with lof.
|
// Bug 2743: Don't zoom with lof.
|
||||||
if (!fileName.AfterLast('.').IsSameAs(wxT("lof"), false))
|
if (!fileName.AfterLast('.').IsSameAs(wxT("lof"), false))
|
||||||
window.ZoomAfterImport(nullptr);
|
window.ZoomAfterImport(nullptr);
|
||||||
|
return &project;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
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 );
|
auto results = ReadProjectFile( fileName );
|
||||||
|
|
||||||
const bool bParseSuccess = results.parseSuccess;
|
const bool bParseSuccess = results.parseSuccess;
|
||||||
const auto &errorStr = results.errorString;
|
const auto &errorStr = results.errorString;
|
||||||
const bool err = results.trackError;
|
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.
|
// PushState calls AutoSave(), so no longer need to do so here.
|
||||||
history.PushState(XO("Project was recovered"), XO("Recover"));
|
history.PushState(XO("Project was recovered"), XO("Recover"));
|
||||||
}
|
}
|
||||||
|
return &project;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Vaughan, 2011-10-30:
|
// Vaughan, 2011-10-30:
|
||||||
@ -1044,6 +1059,8 @@ void ProjectFileManager::OpenFile(const FilePath &fileNameArg, bool addtohistory
|
|||||||
XO("Error Opening Project"),
|
XO("Error Opening Project"),
|
||||||
errorStr,
|
errorStr,
|
||||||
results.helpUrl);
|
results.helpUrl);
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1292,7 +1309,7 @@ bool ProjectFileManager::Import(
|
|||||||
|
|
||||||
history.PushState(XO("Imported '%s'").Format( fileName ), XO("Import"));
|
history.PushState(XO("Imported '%s'").Format( fileName ), XO("Import"));
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PRL: Undo history is incremented inside this:
|
// PRL: Undo history is incremented inside this:
|
||||||
|
@ -43,16 +43,6 @@ public:
|
|||||||
ProjectFileManager &operator=( const ProjectFileManager & ) PROHIBITED;
|
ProjectFileManager &operator=( const ProjectFileManager & ) PROHIBITED;
|
||||||
~ProjectFileManager();
|
~ProjectFileManager();
|
||||||
|
|
||||||
struct ReadProjectResults
|
|
||||||
{
|
|
||||||
bool parseSuccess;
|
|
||||||
bool trackError;
|
|
||||||
const TranslatableString errorString;
|
|
||||||
wxString helpUrl;
|
|
||||||
};
|
|
||||||
ReadProjectResults ReadProjectFile(
|
|
||||||
const FilePath &fileName, bool discardAutosave = false );
|
|
||||||
|
|
||||||
bool OpenProject();
|
bool OpenProject();
|
||||||
void CloseProject();
|
void CloseProject();
|
||||||
bool OpenNewProject();
|
bool OpenNewProject();
|
||||||
@ -91,7 +81,14 @@ public:
|
|||||||
|
|
||||||
static bool IsAlreadyOpen(const FilePath &projPathName);
|
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 Import(const FilePath &fileName,
|
||||||
bool addToHistory = true);
|
bool addToHistory = true);
|
||||||
@ -105,6 +102,24 @@ public:
|
|||||||
void SetMenuClose(bool value) { mMenuClose = value; }
|
void SetMenuClose(bool value) { mMenuClose = value; }
|
||||||
|
|
||||||
private:
|
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);
|
bool DoSave(const FilePath & fileName, bool fromSaveAs);
|
||||||
|
|
||||||
AudacityProject &mProject;
|
AudacityProject &mProject;
|
||||||
|
@ -838,18 +838,16 @@ void ProjectManager::OnCloseWindow(wxCloseEvent & event)
|
|||||||
|
|
||||||
// PRL: I preserve this handler function for an event that was never sent, but
|
// PRL: I preserve this handler function for an event that was never sent, but
|
||||||
// I don't know the intention.
|
// I don't know the intention.
|
||||||
|
|
||||||
void ProjectManager::OnOpenAudioFile(wxCommandEvent & event)
|
void ProjectManager::OnOpenAudioFile(wxCommandEvent & event)
|
||||||
{
|
{
|
||||||
auto &project = mProject;
|
|
||||||
auto &window = GetProjectFrame( project );
|
|
||||||
const wxString &cmd = event.GetString();
|
const wxString &cmd = event.GetString();
|
||||||
|
if (!cmd.empty()) {
|
||||||
if (!cmd.empty())
|
if (auto project = ProjectFileManager::Get( mProject ).OpenFile(cmd)) {
|
||||||
ProjectFileManager::Get( mProject ).OpenFile(cmd);
|
auto &window = GetProjectFrame( *project );
|
||||||
|
|
||||||
window.RequestUserAttention();
|
window.RequestUserAttention();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// static method, can be called outside of a project
|
// static method, can be called outside of a project
|
||||||
void ProjectManager::OpenFiles(AudacityProject *proj)
|
void ProjectManager::OpenFiles(AudacityProject *proj)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user