FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees() { if (! hasChangedSinceSaved()) return savedOk; const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon, TRANS("Closing document..."), TRANS("Do you want to save the changes to \"") + getDocumentTitle() + "\"?", TRANS("save"), TRANS("discard changes"), TRANS("cancel")); if (r == 1) { // save changes return save (true, true); } else if (r == 2) { // discard changes return savedOk; } return userCancelledSave; }
FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile, const bool warnAboutOverwritingExistingFiles, const bool askUserForFileIfNotSpecified, const bool showMessageOnFailure) { if (newFile == File::nonexistent) { if (askUserForFileIfNotSpecified) return saveAsInteractive (true); // can't save to an unspecified file jassertfalse; return failedToWriteToFile; } if (warnAboutOverwritingExistingFiles && newFile.exists() && ! askToOverwriteFile (newFile)) return userCancelledSave; MouseCursor::showWaitCursor(); const File oldFile (documentFile); documentFile = newFile; const Result result (saveDocument (newFile)); if (result.wasOk()) { setChangedFlag (false); MouseCursor::hideWaitCursor(); sendChangeMessage(); // because the filename may have changed return savedOk; } documentFile = oldFile; MouseCursor::hideWaitCursor(); if (showMessageOnFailure) AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, TRANS("Error writing to file..."), TRANS("An error occurred while trying to save \"DCNM\" to the file: FLNM") .replace ("DCNM", getDocumentTitle()) .replace ("FLNM", "\n" + newFile.getFullPathName()) + "\n\n" + result.getErrorMessage()); sendChangeMessage(); // because the filename may have changed return failedToWriteToFile; }
FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles) { File f; if (documentFile.existsAsFile()) f = documentFile; else f = getLastDocumentOpened(); String legalFilename (File::createLegalFileName (getDocumentTitle())); if (legalFilename.isEmpty()) legalFilename = "unnamed"; if (f.existsAsFile() || f.getParentDirectory().isDirectory()) f = f.getSiblingFile (legalFilename); else f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename); f = getSuggestedSaveAsFile (f); FileChooser fc (saveFileDialogTitle, f, fileWildcard); if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles)) { File chosen (fc.getResult()); if (chosen.getFileExtension().isEmpty()) { chosen = chosen.withFileExtension (fileExtension); if (chosen.exists()) { if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon, TRANS("File already exists"), TRANS("There's already a file called:") + "\n\n" + chosen.getFullPathName() + "\n\n" + TRANS("Are you sure you want to overwrite it?"), TRANS("overwrite"), TRANS("cancel"))) { return userCancelledSave; } } } setLastDocumentOpened (chosen); return saveAs (chosen, false, false, true); } return userCancelledSave; }
void Project::setMissingDefaultValues() { if (! projectRoot.hasProperty (ComponentBuilder::idProperty)) projectRoot.setProperty (ComponentBuilder::idProperty, createAlphaNumericUID(), nullptr); // Create main file group if missing if (! projectRoot.getChildWithName (Tags::projectMainGroup).isValid()) { Item mainGroup (*this, ValueTree (Tags::projectMainGroup)); projectRoot.addChild (mainGroup.state, 0, 0); } getMainGroup().initialiseMissingProperties(); if (getDocumentTitle().isEmpty()) setTitle ("Juce Project"); if (! projectRoot.hasProperty (Ids::projectType)) getProjectTypeValue() = ProjectType::getGUIAppTypeName(); if (! projectRoot.hasProperty (Ids::version)) getVersionValue() = "1.0.0"; updateOldStyleConfigList(); moveOldPropertyFromProjectToAllExporters (Ids::bigIcon); moveOldPropertyFromProjectToAllExporters (Ids::smallIcon); for (Project::ExporterIterator exporter (*this); exporter.next();) if (exporter->getNumConfigurations() == 0) exporter->createDefaultConfigs(); if (! projectRoot.getChildWithName (Tags::exporters).isValid()) createDefaultExporters(); getProjectType().setMissingProjectProperties (*this); if (! projectRoot.hasProperty (Ids::bundleIdentifier)) setBundleIdentifierToDefault(); if (! projectRoot.getChildWithName (Tags::modulesGroup).isValid()) addDefaultModules (false); }
void Project::setMissingDefaultValues() { if (! projectRoot.hasProperty (Ids::ID)) projectRoot.setProperty (Ids::ID, createAlphaNumericUID(), nullptr); // Create main file group if missing if (! projectRoot.getChildWithName (Ids::MAINGROUP).isValid()) { Item mainGroup (*this, ValueTree (Ids::MAINGROUP), false); projectRoot.addChild (mainGroup.state, 0, 0); } getMainGroup().initialiseMissingProperties(); if (getDocumentTitle().isEmpty()) setTitle ("JUCE Project"); if (! projectRoot.hasProperty (Ids::projectType)) getProjectTypeValue() = ProjectType_GUIApp::getTypeName(); if (! projectRoot.hasProperty (Ids::version)) getVersionValue() = "1.0.0"; updateOldStyleConfigList(); moveOldPropertyFromProjectToAllExporters (Ids::bigIcon); moveOldPropertyFromProjectToAllExporters (Ids::smallIcon); if (getProjectType().isAudioPlugin()) setMissingAudioPluginDefaultValues(); getModules().sortAlphabetically(); if (getBundleIdentifier().toString().isEmpty()) getBundleIdentifier() = getDefaultBundleIdentifier(); if (shouldIncludeBinaryInAppConfig() == var::null) shouldIncludeBinaryInAppConfig() = true; ProjucerApplication::getApp().updateNewlyOpenedProject (*this); }
FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles) { File f; if (documentFile.existsAsFile()) f = documentFile; else f = getLastDocumentOpened(); String legalFilename (File::createLegalFileName (getDocumentTitle())); if (legalFilename.isEmpty()) legalFilename = "unnamed"; if (f.existsAsFile() || f.getParentDirectory().isDirectory()) f = f.getSiblingFile (legalFilename); else f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename); f = getSuggestedSaveAsFile (f); FileChooser fc (saveFileDialogTitle, f, fileWildcard); if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles)) { File chosen (fc.getResult()); if (chosen.getFileExtension().isEmpty()) { chosen = chosen.withFileExtension (fileExtension); if (chosen.exists() && ! askToOverwriteFile (chosen)) return userCancelledSave; } setLastDocumentOpened (chosen); return saveAs (chosen, false, false, true); } return userCancelledSave; }
void Project::setMissingDefaultValues() { if (! projectRoot.hasProperty (Ids::ID)) projectRoot.setProperty (Ids::ID, createAlphaNumericUID(), nullptr); // Create main file group if missing if (! projectRoot.getChildWithName (Tags::projectMainGroup).isValid()) { Item mainGroup (*this, ValueTree (Tags::projectMainGroup)); projectRoot.addChild (mainGroup.state, 0, 0); } getMainGroup().initialiseMissingProperties(); if (getDocumentTitle().isEmpty()) setTitle ("JUCE Project"); if (! projectRoot.hasProperty (Ids::projectType)) getProjectTypeValue() = ProjectType::getGUIAppTypeName(); if (! projectRoot.hasProperty (Ids::version)) getVersionValue() = "1.0.0"; updateOldStyleConfigList(); moveOldPropertyFromProjectToAllExporters (Ids::bigIcon); moveOldPropertyFromProjectToAllExporters (Ids::smallIcon); getProjectType().setMissingProjectProperties (*this); if (! projectRoot.getChildWithName (Tags::modulesGroup).isValid()) addDefaultModules (false); if (getBundleIdentifier().toString().isEmpty()) getBundleIdentifier() = getDefaultBundleIdentifier(); IntrojucerApp::getApp().updateNewlyOpenedProject (*this); }
void Project::updateProjectSettings() { projectRoot.setProperty (Ids::jucerVersion, ProjectInfo::versionString, nullptr); projectRoot.setProperty (Ids::name, getDocumentTitle(), nullptr); }
void Project::setMissingDefaultValues() { if (! projectRoot.hasProperty (Ids::id_)) projectRoot.setProperty (Ids::id_, createAlphaNumericUID(), 0); // Create main file group if missing if (! projectRoot.getChildWithName (Tags::projectMainGroup).isValid()) { Item mainGroup (*this, ValueTree (Tags::projectMainGroup)); projectRoot.addChild (mainGroup.getNode(), 0, 0); } getMainGroup().initialiseNodeValues(); if (getDocumentTitle().isEmpty()) setTitle ("Juce Project"); if (! projectRoot.hasProperty (Ids::projectType)) getProjectType() = application; if (! projectRoot.hasProperty (Ids::version)) getVersion() = "1.0.0"; if (! projectRoot.hasProperty (Ids::juceLinkage)) getJuceLinkageModeValue() = useAmalgamatedJuceViaMultipleTemplates; const String juceFolderPath (getRelativePathForFile (StoredSettings::getInstance()->getLastKnownJuceFolder())); // Create configs group if (! projectRoot.getChildWithName (Tags::configurations).isValid()) { projectRoot.addChild (ValueTree (Tags::configurations), 0, 0); createDefaultConfigs(); } if (! projectRoot.getChildWithName (Tags::exporters).isValid()) createDefaultExporters(); const String sanitisedProjectName (CodeHelpers::makeValidIdentifier (getProjectName().toString(), false, true, false)); if (! projectRoot.hasProperty (Ids::buildVST)) { shouldBuildVST() = true; shouldBuildRTAS() = false; shouldBuildAU() = true; getPluginName() = getProjectName().toString(); getPluginDesc() = getProjectName().toString(); getPluginManufacturer() = "yourcompany"; getPluginManufacturerCode() = "Manu"; getPluginCode() = "Plug"; getPluginChannelConfigs() = "{1, 1}, {2, 2}"; getPluginIsSynth() = false; getPluginWantsMidiInput() = false; getPluginProducesMidiOut() = false; getPluginSilenceInProducesSilenceOut() = false; getPluginTailLengthSeconds() = 0; getPluginEditorNeedsKeyFocus() = false; getPluginAUExportPrefix() = sanitisedProjectName + "AU"; getPluginAUCocoaViewClassName() = sanitisedProjectName + "AU_V1"; getPluginRTASCategory() = String::empty; } if (! projectRoot.hasProperty (Ids::bundleIdentifier)) setBundleIdentifierToDefault(); }
FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile, const bool warnAboutOverwritingExistingFiles, const bool askUserForFileIfNotSpecified, const bool showMessageOnFailure) { if (newFile == File::nonexistent) { if (askUserForFileIfNotSpecified) { return saveAsInteractive (true); } else { // can't save to an unspecified file jassertfalse; return failedToWriteToFile; } } if (warnAboutOverwritingExistingFiles && newFile.exists()) { if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon, TRANS("File already exists"), TRANS("There's already a file called:\n\n") + newFile.getFullPathName() + TRANS("\n\nAre you sure you want to overwrite it?"), TRANS("overwrite"), TRANS("cancel"))) { return userCancelledSave; } } MouseCursor::showWaitCursor(); const File oldFile (documentFile); documentFile = newFile; String error (saveDocument (newFile)); if (error.isEmpty()) { setChangedFlag (false); MouseCursor::hideWaitCursor(); return savedOk; } documentFile = oldFile; MouseCursor::hideWaitCursor(); if (showMessageOnFailure) { AlertWindow::showMessageBox (AlertWindow::WarningIcon, TRANS("Error writing to file..."), TRANS("An error occurred while trying to save \"") + getDocumentTitle() + TRANS("\" to the file:\n\n") + newFile.getFullPathName() + "\n\n" + error); } return failedToWriteToFile; }