1 /********************************************************************** 2 3 Audacity: A Digital Audio Editor 4 5 ProjectFileManager.h 6 7 Paul Licameli split from AudacityProject.h 8 9 **********************************************************************/ 10 11 #ifndef __AUDACITY_PROJECT_FILE_MANAGER__ 12 #define __AUDACITY_PROJECT_FILE_MANAGER__ 13 14 #include <functional> 15 #include <memory> 16 #include <vector> 17 18 #include "ClientData.h" // to inherit 19 #include "FileNames.h" // for FileType 20 21 class wxString; 22 class wxFileName; 23 class AudacityProject; 24 class Track; 25 class TrackList; 26 class WaveTrack; 27 class XMLTagHandler; 28 29 using WaveTrackArray = std::vector < std::shared_ptr < WaveTrack > >; 30 using TrackHolders = std::vector< WaveTrackArray >; 31 32 class AUDACITY_DLL_API ProjectFileManager final 33 : public ClientData::Base 34 { 35 public: 36 static ProjectFileManager &Get( AudacityProject &project ); 37 static const ProjectFileManager &Get( const AudacityProject &project ); 38 39 // Open and close a file, invisibly, removing its Autosave blob 40 static void DiscardAutosave(const FilePath &filename); 41 42 explicit ProjectFileManager( AudacityProject &project ); 43 ProjectFileManager( const ProjectFileManager & ) PROHIBITED; 44 ProjectFileManager &operator=( const ProjectFileManager & ) PROHIBITED; 45 ~ProjectFileManager(); 46 47 bool OpenProject(); 48 void CloseProject(); 49 bool OpenNewProject(); 50 51 void CompactProjectOnClose(); 52 53 bool Save(); 54 bool SaveAs(bool allowOverwrite = false); 55 bool SaveAs(const FilePath &newFileName, bool addToHistory = true); 56 // strProjectPathName is full path for aup except extension 57 bool SaveFromTimerRecording( wxFileName fnFile ); 58 bool SaveCopy(const FilePath &fileName = wxT("")); 59 60 /** @brief Show an open dialogue for opening audio files, and possibly other 61 * sorts of files. 62 * 63 * The file type filter will automatically contain: 64 * - "All files" with any extension or none, 65 * - "All supported files" based on the file formats supported in this 66 * build of Audacity, 67 * - All of the individual formats specified by the importer plug-ins which 68 * are built into this build of Audacity, each with the relevant file 69 * extensions for that format. 70 * The dialogue will start in the DefaultOpenPath directory read from the 71 * preferences, failing that the working directory. The file format filter 72 * will be set to the DefaultOpenType from the preferences, failing that 73 * the first format specified in the dialogue. These two parameters will 74 * be saved to the preferences once the user has chosen a file to open. 75 * @param extraType Specify an additional format to allow opening in this 76 * dialogue. 77 * @return Array of file paths which the user selected to open (multiple 78 * selections allowed). 79 */ 80 static wxArrayString ShowOpenDialog(FileNames::Operation op, 81 const FileNames::FileType &extraType = {}); 82 83 static bool IsAlreadyOpen(const FilePath &projPathName); 84 85 //! A function that returns a project to use for opening a file; argument is true if opening a project file 86 using ProjectChooserFn = std::function<AudacityProject&(bool)>; 87 88 /*! 89 Opens files of many kinds. In case of import (sound, MIDI, or .aup), the undo history is pushed. 90 @param chooser told whether opening a project file; decides which project to open into 91 @param fileName the name and contents are examined to decide a type and open appropriately 92 @param addtohistory whether to add .aup3 files to the MRU list (but always done for imports) 93 @return if something was successfully opened, the project containing it; else null 94 */ 95 static AudacityProject *OpenFile( const ProjectChooserFn &chooser, 96 const FilePath &fileName, bool addtohistory = true); 97 98 bool Import(const FilePath &fileName, 99 bool addToHistory = true); 100 101 void Compact(); 102 103 void AddImportedTracks(const FilePath &fileName, 104 TrackHolders &&newTracks); 105 GetMenuClose()106 bool GetMenuClose() const { return mMenuClose; } SetMenuClose(bool value)107 void SetMenuClose(bool value) { mMenuClose = value; } 108 109 private: 110 /*! 111 @param fileName a path assumed to exist and contain an .aup3 project 112 @param addtohistory whether to add the file to the MRU list 113 @return if something was successfully opened, the project containing it; else null 114 */ 115 AudacityProject *OpenProjectFile( 116 const FilePath &fileName, bool addtohistory); 117 118 struct ReadProjectResults 119 { 120 bool parseSuccess; 121 bool trackError; 122 const TranslatableString errorString; 123 wxString helpUrl; 124 }; 125 ReadProjectResults ReadProjectFile( 126 const FilePath &fileName, bool discardAutosave = false ); 127 128 bool DoSave(const FilePath & fileName, bool fromSaveAs); 129 130 AudacityProject &mProject; 131 132 std::shared_ptr<TrackList> mLastSavedTracks; 133 134 // Are we currently closing as the result of a menu command? 135 bool mMenuClose{ false }; 136 }; 137 138 #endif 139