MCPcopy Create free account
hub / github.com/VCVRack/Rack / saveAsDialog

Method saveAsDialog

src/patch.cpp:162–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160
161
162void Manager::saveAsDialog(bool setPath) {
163 std::string dir;
164 std::string filename;
165 if (this->path != "") {
166 dir = system::getDirectory(this->path);
167 filename = system::getFilename(this->path);
168 }
169
170 // Use fallback lastPatchDirectory
171 if (dir == "" || !system::isDirectory(dir)) {
172 dir = settings::lastPatchDirectory;
173
174 // Use fallback <Rack user dir>/patches
175 if (dir == "" || !system::isDirectory(dir)) {
176 dir = asset::user("patches");
177 system::createDirectory(dir);
178 }
179 }
180
181 // Use fallback filename
182 if (filename == "") {
183 filename = "Untitled.vcv";
184 }
185
186 osdialog_filters* filters = osdialog_filters_parse(PATCH_FILTERS);
187 DEFER({osdialog_filters_free(filters);});
188
189 char* pathC = osdialog_file(OSDIALOG_SAVE, dir.c_str(), filename.c_str(), filters);
190 if (!pathC) {
191 // Cancel silently
192 return;
193 }
194 std::string path = pathC;
195 std::free(pathC);
196
197 // Automatically append .vcv extension
198 if (system::getExtension(path) != ".vcv") {
199 path += ".vcv";
200 }
201
202 try {
203 save(path);
204 }
205 catch (Exception& e) {
206 std::string message = string::f(string::translate("patch.saveFailed"), e.what());
207 osdialog_message(OSDIALOG_WARNING, OSDIALOG_OK, message.c_str());
208 return;
209 }
210
211 // Commit patch path
212 APP->history->setSaved();
213 if (setPath) {
214 this->path = path;
215 settings::lastPatchDirectory = system::getDirectory(path);
216 pushRecentPath(path);
217 }
218}
219

Callers 2

onHoverKeyMethod · 0.80
onActionMethod · 0.80

Calls 11

getDirectoryFunction · 0.85
getFilenameFunction · 0.85
isDirectoryFunction · 0.85
userFunction · 0.85
createDirectoryFunction · 0.85
getExtensionFunction · 0.85
saveFunction · 0.85
translateFunction · 0.85
whatMethod · 0.80
setSavedMethod · 0.80
fFunction · 0.70

Tested by

no test coverage detected