MCPcopy Create free account
hub / github.com/audacity/audacity / OpenProjectFile

Method OpenProjectFile

src/ProjectFileManager.cpp:1103–1174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1101}
1102
1103AudacityProject *ProjectFileManager::OpenProjectFile(
1104 const FilePath &fileName, bool addtohistory)
1105{
1106 // Allow extensions to update the project before opening it.
1107 if (ProjectFileIOExtensionRegistry::OnOpen(
1108 mProject, audacity::ToUTF8(fileName)) == OnOpenAction::Cancel)
1109 return nullptr;
1110
1111 auto &project = mProject;
1112 auto &history = ProjectHistory::Get( project );
1113 auto &tracks = TrackList::Get( project );
1114 auto &trackPanel = TrackPanel::Get( project );
1115 auto &projectFileIO = ProjectFileIO::Get( project );
1116 auto &viewport = Viewport::Get( project );
1117
1118 auto results = ReadProjectFile( fileName );
1119 const bool bParseSuccess = results.parseSuccess;
1120 const auto &errorStr = results.errorString;
1121 const bool err = results.trackError;
1122
1123 if (bParseSuccess && !err) {
1124 Viewport::Get(project).ReinitScrollbars();
1125
1126 ProjectHistory::Get( project ).InitialState();
1127 TrackFocus::Get(project).Set(*tracks.begin());
1128 viewport.HandleResize();
1129 trackPanel.Refresh(false);
1130
1131 // ? Old rationale in this comment no longer applies in 3.0.0, with no
1132 // more on-demand loading:
1133 trackPanel.Update(); // force any repaint to happen now,
1134 // else any asynch calls into the blockfile code will not have
1135 // finished logging errors (if any) before the call to ProjectFSCK()
1136
1137 if (addtohistory)
1138 FileHistory::Global().Append(fileName);
1139 }
1140
1141 if (bParseSuccess && !err) {
1142 if (projectFileIO.IsRecovered())
1143 {
1144 // PushState calls AutoSave(), so no longer need to do so here.
1145 history.PushState(XO("Project was recovered"), XO("Recover"));
1146 }
1147 return &project;
1148 }
1149 else {
1150 // Vaughan, 2011-10-30:
1151 // See first topic at http://bugzilla.audacityteam.org/show_bug.cgi?id=451#c16.
1152 // Calling mTracks->Clear() with deleteTracks true results in data loss.
1153
1154 // PRL 2014-12-19:
1155 // I made many changes for wave track memory management, but only now
1156 // read the above comment. I may have invalidated the fix above (which
1157 // may have spared the files at the expense of leaked memory). But
1158 // here is a better way to accomplish the intent, doing like what happens
1159 // when the project closes:
1160 for (auto pTrack : tracks.Any<WaveTrack>())

Callers 1

OpenFileMethod · 0.80

Calls 15

OnOpenFunction · 0.85
ToUTF8Function · 0.85
GetFunction · 0.85
ProjectFramePlacementFunction · 0.85
InitialStateMethod · 0.80
IsRecoveredMethod · 0.80
ShowErrorMethod · 0.80
SetMethod · 0.45
beginMethod · 0.45
HandleResizeMethod · 0.45
RefreshMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected