void LibraryModule::addBrowseableCode (ProjectExporter& exporter, const Array<File>& compiled, const File& localModuleFolder) const { if (sourceFiles.size() == 0) findBrowseableFiles (localModuleFolder, sourceFiles); Project::Item sourceGroup (Project::Item::createGroup (exporter.getProject(), getID(), "__mainsourcegroup" + getID())); const RelativePath moduleFromProject (exporter.getModuleFolderRelativeToProject (getID())); for (int i = 0; i < sourceFiles.size(); ++i) { const String pathWithinModule (FileHelpers::getRelativePathFrom (sourceFiles.getReference(i), localModuleFolder)); // (Note: in exporters like MSVC we have to avoid adding the same file twice, even if one of those instances // is flagged as being excluded from the build, because this overrides the other and it fails to compile) if (exporter.canCopeWithDuplicateFiles() || ! compiled.contains (sourceFiles.getReference(i))) addFileWithGroups (sourceGroup, moduleFromProject.getChildFile (pathWithinModule), pathWithinModule); } sourceGroup.addFileAtIndex (localModuleFolder.getChildFile (FileHelpers::getRelativePathFrom (moduleInfo.manifestFile, moduleInfo.getFolder())), -1, false); sourceGroup.addFileAtIndex (getModuleHeaderFile (localModuleFolder), -1, false); exporter.getModulesGroup().state.addChild (sourceGroup.state.createCopy(), -1, nullptr); }
void LibraryModule::findAndAddCompiledUnits (ProjectExporter& exporter, ProjectSaver* projectSaver, const File& localModuleFolder, Array<File>& result) const { const var compileArray (moduleInfo.moduleInfo ["compile"]); // careful to keep this alive while the array is in use! if (const Array<var>* const files = compileArray.getArray()) { for (int i = 0; i < files->size(); ++i) { const var& file = files->getReference(i); const String filename (file ["file"].toString()); if (filename.isNotEmpty() && fileShouldBeCompiled (exporter, file)) { const File compiledFile (localModuleFolder.getChildFile (filename)); result.add (compiledFile); if (projectSaver != nullptr) { Project::Item item (projectSaver->addFileToGeneratedGroup (compiledFile)); if (file ["warnings"].toString().equalsIgnoreCase ("disabled")) item.getShouldInhibitWarningsValue() = true; if (file ["stdcall"]) item.getShouldUseStdCallValue() = true; } } } } }
static void findImages (const Project::Item& item, OwnedArray<Project::Item>& found) { if (item.isImageFile()) { found.add (new Project::Item (item)); } else if (item.isGroup()) { for (int i = 0; i < item.getNumChildren(); ++i) findImages (item.getChild (i), found); } }
//============================================================================== void ResourceFile::addResourcesFromProjectItem (const Project::Item& projectItem) { if (projectItem.isGroup()) { for (int i = 0; i < projectItem.getNumChildren(); ++i) addResourcesFromProjectItem (projectItem.getChild(i)); } else { if (projectItem.shouldBeAddedToBinaryResources()) addFile (projectItem.getFile()); } }
void SourceFileTreeViewItem::setName (const String& newName) { if (newName != File::createLegalFileName (newName)) { AlertWindow::showMessageBox (AlertWindow::WarningIcon, "File Rename", "That filename contained some illegal characters!"); triggerAsyncRename (item); return; } File oldFile (getFile()); File newFile (oldFile.getSiblingFile (newName)); File correspondingFile (findCorrespondingHeaderOrCpp (oldFile)); if (correspondingFile.exists() && newFile.hasFileExtension (oldFile.getFileExtension())) { Project::Item correspondingItem (item.project.getMainGroup().findItemForFile (correspondingFile)); if (correspondingItem.isValid()) { if (AlertWindow::showOkCancelBox (AlertWindow::NoIcon, "File Rename", "Do you also want to rename the corresponding file \"" + correspondingFile.getFileName() + "\" to match?")) { if (! item.renameFile (newFile)) { AlertWindow::showMessageBox (AlertWindow::WarningIcon, "File Rename", "Failed to rename \"" + oldFile.getFullPathName() + "\"!\n\nCheck your file permissions!"); return; } if (! correspondingItem.renameFile (newFile.withFileExtension (correspondingFile.getFileExtension()))) { AlertWindow::showMessageBox (AlertWindow::WarningIcon, "File Rename", "Failed to rename \"" + correspondingFile.getFullPathName() + "\"!\n\nCheck your file permissions!"); } } } } if (! item.renameFile (newFile)) { AlertWindow::showMessageBox (AlertWindow::WarningIcon, "File Rename", "Failed to rename the file!\n\nCheck your file permissions!"); } }
static void addFileWithGroups (Project::Item& group, const RelativePath& file, const String& path) { const int slash = path.indexOfChar (File::separator); if (slash >= 0) { const String topLevelGroup (path.substring (0, slash)); const String remainingPath (path.substring (slash + 1)); Project::Item newGroup (group.getOrCreateSubGroup (topLevelGroup)); addFileWithGroups (newGroup, file, remainingPath); } else { if (! group.containsChildForFile (file)) group.addRelativeFile (file, -1, false); } }
static void addFileWithGroups (Project::Item& group, const RelativePath& file, const String& path) { auto slash = path.indexOfChar (File::getSeparatorChar()); if (slash >= 0) { auto topLevelGroup = path.substring (0, slash); auto remainingPath = path.substring (slash + 1); auto newGroup = group.getOrCreateSubGroup (topLevelGroup); addFileWithGroups (newGroup, file, remainingPath); } else { if (! group.containsChildForFile (file)) group.addRelativeFile (file, -1, false); } }
void ProjectTreeViewBase::moveItems (OwnedArray <Project::Item>& selectedNodes, Project::Item destNode, int insertIndex) { for (int i = selectedNodes.size(); --i >= 0;) { Project::Item* const n = selectedNodes.getUnchecked(i); if (destNode == *n || destNode.state.isAChildOf (n->state)) // Check for recursion. return; if (! destNode.canContain (*n)) selectedNodes.remove (i); } // Don't include any nodes that are children of other selected nodes.. for (int i = selectedNodes.size(); --i >= 0;) { Project::Item* const n = selectedNodes.getUnchecked(i); for (int j = selectedNodes.size(); --j >= 0;) { if (j != i && n->state.isAChildOf (selectedNodes.getUnchecked(j)->state)) { selectedNodes.remove (i); break; } } } // Remove and re-insert them one at a time.. for (int i = 0; i < selectedNodes.size(); ++i) { Project::Item* selectedNode = selectedNodes.getUnchecked(i); if (selectedNode->state.getParent() == destNode.state && indexOfNode (destNode.state, selectedNode->state) < insertIndex) --insertIndex; selectedNode->removeItemFromProject(); destNode.addChild (*selectedNode, insertIndex++); } }
static bool create (Project::Item parent, const File& newFile, const char* templateName) { if (fillInNewCppFileTemplate (newFile, parent, templateName)) { parent.addFile (newFile, 0, true); return true; } showFailedToWriteMessage (newFile); return false; }
void createNewFile (Project::Item parent) override { const File newFile (askUserToChooseNewFile (String (defaultClassName) + ".h", "*.h;*.cpp", parent)); if (newFile != File::nonexistent) { const File headerFile (newFile.withFileExtension (".h")); const File cppFile (newFile.withFileExtension (".cpp")); headerFile.replaceWithText (String::empty); cppFile.replaceWithText (String::empty); OpenDocumentManager& odm = IntrojucerApp::getApp().openDocumentManager; if (SourceCodeDocument* cpp = dynamic_cast <SourceCodeDocument*> (odm.openFile (nullptr, cppFile))) { if (SourceCodeDocument* header = dynamic_cast <SourceCodeDocument*> (odm.openFile (nullptr, headerFile))) { ScopedPointer<JucerDocument> jucerDoc (new ComponentDocument (cpp)); if (jucerDoc != nullptr) { jucerDoc->setClassName (newFile.getFileNameWithoutExtension()); jucerDoc->flushChangesToDocuments(); jucerDoc = nullptr; cpp->save(); header->save(); odm.closeDocument (cpp, true); odm.closeDocument (header, true); parent.addFile (headerFile, 0, true); parent.addFile (cppFile, 0, true); } } } } }
void createNewFile (Project& project, Project::Item parent) override { auto newFile = askUserToChooseNewFile (String (defaultClassName) + ".h", "*.h;*.cpp", parent); if (newFile != File()) { auto headerFile = newFile.withFileExtension (".h"); auto cppFile = newFile.withFileExtension (".cpp"); headerFile.replaceWithText (String()); cppFile.replaceWithText (String()); auto& odm = ProjucerApplication::getApp().openDocumentManager; if (auto* cpp = dynamic_cast<SourceCodeDocument*> (odm.openFile (nullptr, cppFile))) { if (auto* header = dynamic_cast<SourceCodeDocument*> (odm.openFile (nullptr, headerFile))) { std::unique_ptr<JucerDocument> jucerDoc (new ComponentDocument (cpp)); if (jucerDoc != nullptr) { jucerDoc->setClassName (newFile.getFileNameWithoutExtension()); jucerDoc->flushChangesToDocuments (&project); jucerDoc.reset(); cpp->save(); header->save(); odm.closeDocument (cpp, true); odm.closeDocument (header, true); parent.addFileRetainingSortOrder (headerFile, true); parent.addFileRetainingSortOrder (cppFile, true); } } } } }
File NewFileWizard::Type::askUserToChooseNewFile (const String& suggestedFilename, const String& wildcard, const Project::Item& projectGroupToAddTo) { FileChooser fc ("Select File to Create", projectGroupToAddTo.determineGroupFolder() .getChildFile (suggestedFilename) .getNonexistentSibling(), wildcard); if (fc.browseForFileToSave (true)) return fc.getResult(); return File::nonexistent; }
static bool create (const String& className, Project::Item parent, const File& newFile, const char* templateName) { String content = fillInBasicTemplateFields (newFile, parent, templateName) .replace ("COMPONENTCLASS", className) .replace ("INCLUDE_JUCE", CodeHelpers::createIncludeStatement (parent.project.getAppIncludeFile(), newFile)); if (FileHelpers::overwriteFileWithNewDataIfDifferent (newFile, content)) { parent.addFile (newFile, 0, true); return true; } showFailedToWriteMessage (newFile); return false; }
bool initialiseProject (Project& project) { if (! getSourceFilesFolder().createDirectory()) failedFiles.add (getSourceFilesFolder().getFullPathName()); File mainCppFile = getSourceFilesFolder().getChildFile ("Main.cpp"); File mainWindowCpp = getSourceFilesFolder().getChildFile ("MainWindow.cpp"); File mainWindowH = mainWindowCpp.withFileExtension (".h"); String windowClassName = "MainAppWindow"; project.getProjectTypeValue() = ProjectType::getGUIAppTypeName(); Project::Item sourceGroup (project.getMainGroup().addNewSubGroup ("Source", 0)); setExecutableNameForAllTargets (project, File::createLegalFileName (appTitle)); String appHeaders (CodeHelpers::createIncludeStatement (project.getAppIncludeFile(), mainCppFile)); String initCode, shutdownCode, anotherInstanceStartedCode, privateMembers, memberInitialisers; if (createWindow) { appHeaders << newLine << CodeHelpers::createIncludeStatement (mainWindowH, mainCppFile); initCode = "mainWindow = new " + windowClassName + "();"; shutdownCode = "mainWindow = 0;"; privateMembers = "ScopedPointer <" + windowClassName + "> mainWindow;"; String windowH = project.getFileTemplate ("jucer_WindowTemplate_h") .replace ("INCLUDES", CodeHelpers::createIncludeStatement (project.getAppIncludeFile(), mainWindowH), false) .replace ("WINDOWCLASS", windowClassName, false) .replace ("HEADERGUARD", CodeHelpers::makeHeaderGuardName (mainWindowH), false); String windowCpp = project.getFileTemplate ("jucer_WindowTemplate_cpp") .replace ("INCLUDES", CodeHelpers::createIncludeStatement (mainWindowH, mainWindowCpp), false) .replace ("WINDOWCLASS", windowClassName, false); if (! FileHelpers::overwriteFileWithNewDataIfDifferent (mainWindowH, windowH)) failedFiles.add (mainWindowH.getFullPathName()); if (! FileHelpers::overwriteFileWithNewDataIfDifferent (mainWindowCpp, windowCpp)) failedFiles.add (mainWindowCpp.getFullPathName()); sourceGroup.addFile (mainWindowCpp, -1, true); sourceGroup.addFile (mainWindowH, -1, false); } if (createMainCpp) { String mainCpp = project.getFileTemplate ("jucer_MainTemplate_cpp") .replace ("APPHEADERS", appHeaders, false) .replace ("APPCLASSNAME", CodeHelpers::makeValidIdentifier (appTitle + "Application", false, true, false), false) .replace ("MEMBERINITIALISERS", memberInitialisers, false) .replace ("APPINITCODE", initCode, false) .replace ("APPSHUTDOWNCODE", shutdownCode, false) .replace ("APPNAME", CodeHelpers::addEscapeChars (appTitle), false) .replace ("APPVERSION", "1.0", false) .replace ("ALLOWMORETHANONEINSTANCE", "true", false) .replace ("ANOTHERINSTANCECODE", anotherInstanceStartedCode, false) .replace ("PRIVATEMEMBERS", privateMembers, false); if (! FileHelpers::overwriteFileWithNewDataIfDifferent (mainCppFile, mainCpp)) failedFiles.add (mainCppFile.getFullPathName()); sourceGroup.addFile (mainCppFile, -1, true); } project.createDefaultExporters(); return true; }
bool initialiseProject (Project& project) { if (! getSourceFilesFolder().createDirectory()) failedFiles.add (getSourceFilesFolder().getFullPathName()); String filterClassName = CodeHelpers::makeValidIdentifier (appTitle, true, true, false) + "AudioProcessor"; filterClassName = filterClassName.substring (0, 1).toUpperCase() + filterClassName.substring (1); String editorClassName = filterClassName + "Editor"; File filterCppFile = getSourceFilesFolder().getChildFile ("PluginProcessor.cpp"); File filterHFile = filterCppFile.withFileExtension (".h"); File editorCppFile = getSourceFilesFolder().getChildFile ("PluginEditor.cpp"); File editorHFile = editorCppFile.withFileExtension (".h"); project.getProjectTypeValue() = ProjectType::getAudioPluginTypeName(); project.addModule ("juce_audio_plugin_client", true); Project::Item sourceGroup (project.getMainGroup().addNewSubGroup ("Source", 0)); project.getConfigFlag ("JUCE_QUICKTIME") = Project::configFlagDisabled; // disabled because it interferes with RTAS build on PC setExecutableNameForAllTargets (project, File::createLegalFileName (appTitle)); String appHeaders (CodeHelpers::createIncludeStatement (project.getAppIncludeFile(), filterCppFile)); String filterCpp = project.getFileTemplate ("jucer_AudioPluginFilterTemplate_cpp") .replace ("FILTERHEADERS", CodeHelpers::createIncludeStatement (filterHFile, filterCppFile) + newLine + CodeHelpers::createIncludeStatement (editorHFile, filterCppFile), false) .replace ("FILTERCLASSNAME", filterClassName, false) .replace ("EDITORCLASSNAME", editorClassName, false); String filterH = project.getFileTemplate ("jucer_AudioPluginFilterTemplate_h") .replace ("APPHEADERS", appHeaders, false) .replace ("FILTERCLASSNAME", filterClassName, false) .replace ("HEADERGUARD", CodeHelpers::makeHeaderGuardName (filterHFile), false); String editorCpp = project.getFileTemplate ("jucer_AudioPluginEditorTemplate_cpp") .replace ("EDITORCPPHEADERS", CodeHelpers::createIncludeStatement (filterHFile, filterCppFile) + newLine + CodeHelpers::createIncludeStatement (editorHFile, filterCppFile), false) .replace ("FILTERCLASSNAME", filterClassName, false) .replace ("EDITORCLASSNAME", editorClassName, false); String editorH = project.getFileTemplate ("jucer_AudioPluginEditorTemplate_h") .replace ("EDITORHEADERS", appHeaders + newLine + CodeHelpers::createIncludeStatement (filterHFile, filterCppFile), false) .replace ("FILTERCLASSNAME", filterClassName, false) .replace ("EDITORCLASSNAME", editorClassName, false) .replace ("HEADERGUARD", CodeHelpers::makeHeaderGuardName (editorHFile), false); if (! FileHelpers::overwriteFileWithNewDataIfDifferent (filterCppFile, filterCpp)) failedFiles.add (filterCppFile.getFullPathName()); if (! FileHelpers::overwriteFileWithNewDataIfDifferent (filterHFile, filterH)) failedFiles.add (filterHFile.getFullPathName()); if (! FileHelpers::overwriteFileWithNewDataIfDifferent (editorCppFile, editorCpp)) failedFiles.add (editorCppFile.getFullPathName()); if (! FileHelpers::overwriteFileWithNewDataIfDifferent (editorHFile, editorH)) failedFiles.add (editorHFile.getFullPathName()); sourceGroup.addFile (filterCppFile, -1, true); sourceGroup.addFile (filterHFile, -1, false); sourceGroup.addFile (editorCppFile, -1, true); sourceGroup.addFile (editorHFile, -1, false); return true; }
bool initialiseProject (Project& project) { if (! getSourceFilesFolder().createDirectory()) failedFiles.add (getSourceFilesFolder().getFullPathName()); File mainCppFile = getSourceFilesFolder().getChildFile ("Main.cpp"); File contentCompCpp = getSourceFilesFolder().getChildFile ("MainComponent.cpp"); File contentCompH = contentCompCpp.withFileExtension (".h"); String contentCompName = "MainContentComponent"; project.getProjectTypeValue() = ProjectType::getGUIAppTypeName(); Project::Item sourceGroup (project.getMainGroup().addNewSubGroup ("Source", 0)); setExecutableNameForAllTargets (project, File::createLegalFileName (appTitle)); String appHeaders (CodeHelpers::createIncludeStatement (project.getAppIncludeFile(), mainCppFile)); if (createWindow) { appHeaders << newLine << CodeHelpers::createIncludeStatement (contentCompH, mainCppFile); String windowH = project.getFileTemplate ("jucer_ContentCompTemplate_h") .replace ("INCLUDE_JUCE", CodeHelpers::createIncludeStatement (project.getAppIncludeFile(), contentCompH), false) .replace ("CONTENTCOMPCLASS", contentCompName, false) .replace ("HEADERGUARD", CodeHelpers::makeHeaderGuardName (contentCompH), false); String windowCpp = project.getFileTemplate ("jucer_ContentCompTemplate_cpp") .replace ("INCLUDE_JUCE", CodeHelpers::createIncludeStatement (project.getAppIncludeFile(), contentCompCpp), false) .replace ("INCLUDE_CORRESPONDING_HEADER", CodeHelpers::createIncludeStatement (contentCompH, contentCompCpp), false) .replace ("CONTENTCOMPCLASS", contentCompName, false); if (! FileHelpers::overwriteFileWithNewDataIfDifferent (contentCompH, windowH)) failedFiles.add (contentCompH.getFullPathName()); if (! FileHelpers::overwriteFileWithNewDataIfDifferent (contentCompCpp, windowCpp)) failedFiles.add (contentCompCpp.getFullPathName()); sourceGroup.addFile (contentCompCpp, -1, true); sourceGroup.addFile (contentCompH, -1, false); } if (createMainCpp) { String mainCpp = project.getFileTemplate (createWindow ? "jucer_MainTemplate_Window_cpp" : "jucer_MainTemplate_NoWindow_cpp") .replace ("APPHEADERS", appHeaders, false) .replace ("APPCLASSNAME", CodeHelpers::makeValidIdentifier (appTitle + "Application", false, true, false), false) .replace ("APPNAME", CodeHelpers::addEscapeChars (appTitle), false) .replace ("CONTENTCOMPCLASS", contentCompName, false) .replace ("ALLOWMORETHANONEINSTANCE", "true", false); if (! FileHelpers::overwriteFileWithNewDataIfDifferent (mainCppFile, mainCpp)) failedFiles.add (mainCppFile.getFullPathName()); sourceGroup.addFile (mainCppFile, -1, true); } project.createExporterForCurrentPlatform(); return true; }