The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

722 lines
24KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #include "../../Application/jucer_Headers.h"
  19. #include "../../ProjectSaving/jucer_ProjectSaver.h"
  20. #include "../../ProjectSaving/jucer_ProjectExport_Xcode.h"
  21. #include "../../Application/jucer_Application.h"
  22. //==============================================================================
  23. LibraryModule::LibraryModule (const ModuleDescription& d)
  24. : moduleDescription (d)
  25. {
  26. }
  27. void LibraryModule::writeIncludes (ProjectSaver& projectSaver, OutputStream& out)
  28. {
  29. auto& project = projectSaver.getProject();
  30. auto& modules = project.getEnabledModules();
  31. auto moduleID = getID();
  32. if (modules.shouldCopyModuleFilesLocally (moduleID))
  33. {
  34. auto juceModuleFolder = moduleDescription.getFolder();
  35. auto localModuleFolder = project.getLocalModuleFolder (moduleID);
  36. localModuleFolder.createDirectory();
  37. projectSaver.copyFolder (juceModuleFolder, localModuleFolder);
  38. }
  39. out << "#include <" << moduleDescription.getModuleFolder().getFileName() << "/"
  40. << moduleDescription.getHeader().getFileName()
  41. << ">" << newLine;
  42. }
  43. void LibraryModule::addSearchPathsToExporter (ProjectExporter& exporter) const
  44. {
  45. auto moduleRelativePath = exporter.getModuleFolderRelativeToProject (getID());
  46. exporter.addToExtraSearchPaths (moduleRelativePath.getParentDirectory());
  47. const auto libDirPlatform = [&]() -> String
  48. {
  49. if (exporter.isLinux())
  50. return "Linux";
  51. if (exporter.isCodeBlocks() && exporter.isWindows())
  52. return "MinGW";
  53. return exporter.getTypeInfoForExporter (exporter.getExporterIdentifier()).targetFolder;
  54. }();
  55. auto libSubdirPath = moduleRelativePath.toUnixStyle() + "/libs/" + libDirPlatform;
  56. auto moduleLibDir = exporter.getProject().resolveFilename (libSubdirPath);
  57. if (moduleLibDir.exists())
  58. exporter.addToModuleLibPaths ({ libSubdirPath, moduleRelativePath.getRoot() });
  59. auto extraInternalSearchPaths = moduleDescription.getExtraSearchPaths().trim();
  60. if (extraInternalSearchPaths.isNotEmpty())
  61. {
  62. auto paths = StringArray::fromTokens (extraInternalSearchPaths, true);
  63. for (auto& path : paths)
  64. exporter.addToExtraSearchPaths (moduleRelativePath.getChildFile (path.unquoted()));
  65. }
  66. }
  67. void LibraryModule::addDefinesToExporter (ProjectExporter& exporter) const
  68. {
  69. auto extraDefs = moduleDescription.getPreprocessorDefs().trim();
  70. if (extraDefs.isNotEmpty())
  71. exporter.getExporterPreprocessorDefsValue() = exporter.getExporterPreprocessorDefsString() + "\n" + extraDefs;
  72. }
  73. void LibraryModule::addCompileUnitsToExporter (ProjectExporter& exporter, ProjectSaver& projectSaver) const
  74. {
  75. auto& project = exporter.getProject();
  76. auto& modules = project.getEnabledModules();
  77. auto moduleID = getID();
  78. auto localModuleFolder = modules.shouldCopyModuleFilesLocally (moduleID) ? project.getLocalModuleFolder (moduleID)
  79. : moduleDescription.getFolder();
  80. Array<File> compiled;
  81. findAndAddCompiledUnits (exporter, &projectSaver, compiled);
  82. if (modules.shouldShowAllModuleFilesInProject (moduleID))
  83. addBrowseableCode (exporter, compiled, localModuleFolder);
  84. }
  85. void LibraryModule::addLibsToExporter (ProjectExporter& exporter) const
  86. {
  87. auto parseAndAddLibsToList = [] (StringArray& libList, const String& libs)
  88. {
  89. libList.addTokens (libs, ", ", {});
  90. libList.trim();
  91. libList.removeDuplicates (false);
  92. };
  93. auto& project = exporter.getProject();
  94. auto moduleInfo = moduleDescription.getModuleInfo();
  95. if (exporter.isXcode())
  96. {
  97. auto& xcodeExporter = dynamic_cast<XcodeProjectExporter&> (exporter);
  98. if (project.isAUPluginHost())
  99. {
  100. xcodeExporter.xcodeFrameworks.add ("CoreAudioKit");
  101. if (xcodeExporter.isOSX())
  102. xcodeExporter.xcodeFrameworks.add ("AudioUnit");
  103. }
  104. auto frameworks = moduleInfo[xcodeExporter.isOSX() ? "OSXFrameworks" : "iOSFrameworks"].toString();
  105. xcodeExporter.xcodeFrameworks.addTokens (frameworks, ", ", {});
  106. auto weakFrameworks = moduleInfo[xcodeExporter.isOSX() ? "WeakOSXFrameworks" : "WeakiOSFrameworks"].toString();
  107. xcodeExporter.xcodeWeakFrameworks.addTokens (weakFrameworks, ", ", {});
  108. parseAndAddLibsToList (xcodeExporter.xcodeLibs, moduleInfo[exporter.isOSX() ? "OSXLibs" : "iOSLibs"].toString());
  109. }
  110. else if (exporter.isLinux())
  111. {
  112. parseAndAddLibsToList (exporter.linuxLibs, moduleInfo["linuxLibs"].toString());
  113. parseAndAddLibsToList (exporter.linuxPackages, moduleInfo["linuxPackages"].toString());
  114. }
  115. else if (exporter.isWindows())
  116. {
  117. if (exporter.isCodeBlocks())
  118. parseAndAddLibsToList (exporter.mingwLibs, moduleInfo["mingwLibs"].toString());
  119. else
  120. parseAndAddLibsToList (exporter.windowsLibs, moduleInfo["windowsLibs"].toString());
  121. }
  122. else if (exporter.isAndroid())
  123. {
  124. parseAndAddLibsToList (exporter.androidLibs, moduleInfo["androidLibs"].toString());
  125. }
  126. }
  127. void LibraryModule::addSettingsForModuleToExporter (ProjectExporter& exporter, ProjectSaver& projectSaver) const
  128. {
  129. addSearchPathsToExporter (exporter);
  130. addDefinesToExporter (exporter);
  131. addCompileUnitsToExporter (exporter, projectSaver);
  132. addLibsToExporter (exporter);
  133. }
  134. void LibraryModule::getConfigFlags (Project& project, OwnedArray<Project::ConfigFlag>& flags) const
  135. {
  136. auto header = moduleDescription.getHeader();
  137. jassert (header.exists());
  138. StringArray lines;
  139. header.readLines (lines);
  140. for (int i = 0; i < lines.size(); ++i)
  141. {
  142. auto line = lines[i].trim();
  143. if (line.startsWith ("/**") && line.containsIgnoreCase ("Config:"))
  144. {
  145. auto config = std::make_unique<Project::ConfigFlag>();
  146. config->sourceModuleID = getID();
  147. config->symbol = line.fromFirstOccurrenceOf (":", false, false).trim();
  148. if (config->symbol.length() > 2)
  149. {
  150. ++i;
  151. while (! (lines[i].contains ("*/") || lines[i].contains ("@see")))
  152. {
  153. if (lines[i].trim().isNotEmpty())
  154. config->description = config->description.trim() + " " + lines[i].trim();
  155. ++i;
  156. }
  157. config->description = config->description.upToFirstOccurrenceOf ("*/", false, false);
  158. config->value = project.getConfigFlag (config->symbol);
  159. i += 2;
  160. if (lines[i].contains ("#define " + config->symbol))
  161. {
  162. auto value = lines[i].fromFirstOccurrenceOf ("#define " + config->symbol, false, true).trim();
  163. config->value.setDefault (value == "0" ? false : true);
  164. }
  165. auto currentValue = config->value.get().toString();
  166. if (currentValue == "enabled") config->value = true;
  167. else if (currentValue == "disabled") config->value = false;
  168. flags.add (std::move (config));
  169. }
  170. }
  171. }
  172. }
  173. static void addFileWithGroups (Project::Item& group, const build_tools::RelativePath& file, const String& path)
  174. {
  175. auto slash = path.indexOfChar (File::getSeparatorChar());
  176. if (slash >= 0)
  177. {
  178. auto topLevelGroup = path.substring (0, slash);
  179. auto remainingPath = path.substring (slash + 1);
  180. auto newGroup = group.getOrCreateSubGroup (topLevelGroup);
  181. addFileWithGroups (newGroup, file, remainingPath);
  182. }
  183. else
  184. {
  185. if (! group.containsChildForFile (file))
  186. group.addRelativeFile (file, -1, false);
  187. }
  188. }
  189. struct FileSorter
  190. {
  191. static int compareElements (const File& f1, const File& f2)
  192. {
  193. return f1.getFileName().compareNatural (f2.getFileName());
  194. }
  195. };
  196. void LibraryModule::findBrowseableFiles (const File& folder, Array<File>& filesFound) const
  197. {
  198. Array<File> tempList;
  199. FileSorter sorter;
  200. for (const auto& iter : RangedDirectoryIterator (folder, true, "*", File::findFiles))
  201. if (! iter.isHidden() && iter.getFile().hasFileExtension (browseableFileExtensions))
  202. tempList.addSorted (sorter, iter.getFile());
  203. filesFound.addArray (tempList);
  204. }
  205. bool LibraryModule::CompileUnit::isNeededForExporter (ProjectExporter& exporter) const
  206. {
  207. const auto trimmedFileNameLowercase = file.getFileNameWithoutExtension().toLowerCase();
  208. const std::tuple<const char*, bool> shouldBuildForSuffix[] { { "_android", exporter.isAndroid() },
  209. { "_ios", exporter.isiOS() },
  210. { "_linux", exporter.isLinux() },
  211. { "_mac", exporter.isOSX() },
  212. { "_osx", exporter.isOSX() },
  213. { "_windows", exporter.isWindows() } };
  214. for (const auto& [suffix, shouldBuild] : shouldBuildForSuffix)
  215. if (trimmedFileNameLowercase.endsWith (suffix))
  216. return shouldBuild;
  217. const auto targetType = Project::getTargetTypeFromFilePath (file, false);
  218. if (targetType != build_tools::ProjectType::Target::unspecified && ! exporter.shouldBuildTargetType (targetType))
  219. return false;
  220. return exporter.usesMMFiles() ? isCompiledForObjC
  221. : isCompiledForNonObjC;
  222. }
  223. String LibraryModule::CompileUnit::getFilenameForProxyFile() const
  224. {
  225. return "include_" + file.getFileName();
  226. }
  227. Array<LibraryModule::CompileUnit> LibraryModule::getAllCompileUnits (build_tools::ProjectType::Target::Type forTarget) const
  228. {
  229. auto files = getFolder().findChildFiles (File::findFiles, false);
  230. FileSorter sorter;
  231. files.sort (sorter);
  232. Array<LibraryModule::CompileUnit> units;
  233. for (auto& file : files)
  234. {
  235. if (file.getFileName().startsWithIgnoreCase (getID())
  236. && file.hasFileExtension (sourceFileExtensions))
  237. {
  238. if (forTarget == build_tools::ProjectType::Target::unspecified
  239. || forTarget == Project::getTargetTypeFromFilePath (file, true))
  240. {
  241. CompileUnit cu;
  242. cu.file = file;
  243. units.add (std::move (cu));
  244. }
  245. }
  246. }
  247. for (auto& cu : units)
  248. {
  249. cu.isCompiledForObjC = true;
  250. cu.isCompiledForNonObjC = ! cu.file.hasFileExtension ("mm;m;metal");
  251. if (cu.isCompiledForNonObjC)
  252. if (cu.file.withFileExtension ("mm").existsAsFile())
  253. cu.isCompiledForObjC = false;
  254. jassert (cu.isCompiledForObjC || cu.isCompiledForNonObjC);
  255. }
  256. return units;
  257. }
  258. void LibraryModule::findAndAddCompiledUnits (ProjectExporter& exporter,
  259. ProjectSaver* projectSaver,
  260. Array<File>& result,
  261. build_tools::ProjectType::Target::Type forTarget) const
  262. {
  263. for (auto& cu : getAllCompileUnits (forTarget))
  264. {
  265. if (cu.isNeededForExporter (exporter))
  266. {
  267. auto localFile = exporter.getProject().getGeneratedCodeFolder()
  268. .getChildFile (cu.getFilenameForProxyFile());
  269. result.add (localFile);
  270. if (projectSaver != nullptr)
  271. projectSaver->addFileToGeneratedGroup (localFile);
  272. }
  273. }
  274. }
  275. void LibraryModule::addBrowseableCode (ProjectExporter& exporter, const Array<File>& compiled, const File& localModuleFolder) const
  276. {
  277. if (sourceFiles.isEmpty())
  278. findBrowseableFiles (localModuleFolder, sourceFiles);
  279. auto sourceGroup = Project::Item::createGroup (exporter.getProject(), getID(), "__mainsourcegroup" + getID(), false);
  280. auto moduleFromProject = exporter.getModuleFolderRelativeToProject (getID());
  281. auto moduleHeader = moduleDescription.getHeader();
  282. auto& project = exporter.getProject();
  283. if (project.getEnabledModules().shouldCopyModuleFilesLocally (getID()))
  284. moduleHeader = project.getLocalModuleFolder (getID()).getChildFile (moduleHeader.getFileName());
  285. auto isModuleHeader = [&] (const File& f) { return f.getFileName() == moduleHeader.getFileName(); };
  286. for (auto& sourceFile : sourceFiles)
  287. {
  288. auto pathWithinModule = build_tools::getRelativePathFrom (sourceFile, localModuleFolder);
  289. // (Note: in exporters like MSVC we have to avoid adding the same file twice, even if one of those instances
  290. // is flagged as being excluded from the build, because this overrides the other and it fails to compile)
  291. if ((exporter.canCopeWithDuplicateFiles() || ! compiled.contains (sourceFile)) && ! isModuleHeader (sourceFile))
  292. addFileWithGroups (sourceGroup, moduleFromProject.getChildFile (pathWithinModule), pathWithinModule);
  293. }
  294. sourceGroup.sortAlphabetically (true, true);
  295. sourceGroup.addFileAtIndex (moduleHeader, -1, false);
  296. exporter.getModulesGroup().state.appendChild (sourceGroup.state.createCopy(), nullptr);
  297. }
  298. //==============================================================================
  299. EnabledModulesList::EnabledModulesList (Project& p, const ValueTree& s)
  300. : project (p), state (s)
  301. {
  302. }
  303. StringArray EnabledModulesList::getAllModules() const
  304. {
  305. StringArray moduleIDs;
  306. for (int i = 0; i < getNumModules(); ++i)
  307. moduleIDs.add (getModuleID (i));
  308. return moduleIDs;
  309. }
  310. void EnabledModulesList::createRequiredModules (OwnedArray<LibraryModule>& modules)
  311. {
  312. for (int i = 0; i < getNumModules(); ++i)
  313. modules.add (new LibraryModule (getModuleInfo (getModuleID (i))));
  314. }
  315. void EnabledModulesList::sortAlphabetically()
  316. {
  317. struct ModuleTreeSorter
  318. {
  319. static int compareElements (const ValueTree& m1, const ValueTree& m2)
  320. {
  321. return m1[Ids::ID].toString().compareIgnoreCase (m2[Ids::ID]);
  322. }
  323. };
  324. ModuleTreeSorter sorter;
  325. const ScopedLock sl (stateLock);
  326. state.sort (sorter, getUndoManager(), false);
  327. }
  328. File EnabledModulesList::getDefaultModulesFolder() const
  329. {
  330. File globalPath (getAppSettings().getStoredPath (Ids::defaultJuceModulePath, TargetOS::getThisOS()).get().toString());
  331. if (globalPath.exists())
  332. return globalPath;
  333. for (auto& exporterPathModule : project.getExporterPathsModulesList().getAllModules())
  334. {
  335. auto f = exporterPathModule.second;
  336. if (f.isDirectory())
  337. return f.getParentDirectory();
  338. }
  339. return File::getCurrentWorkingDirectory();
  340. }
  341. ModuleDescription EnabledModulesList::getModuleInfo (const String& moduleID) const
  342. {
  343. return ModuleDescription (project.getModuleWithID (moduleID).second);
  344. }
  345. bool EnabledModulesList::isModuleEnabled (const String& moduleID) const
  346. {
  347. const ScopedLock sl (stateLock);
  348. return state.getChildWithProperty (Ids::ID, moduleID).isValid();
  349. }
  350. static void getDependencies (Project& project, const String& moduleID, StringArray& dependencies)
  351. {
  352. auto info = project.getEnabledModules().getModuleInfo (moduleID);
  353. for (auto uid : info.getDependencies())
  354. {
  355. if (! dependencies.contains (uid, true))
  356. {
  357. dependencies.add (uid);
  358. getDependencies (project, uid, dependencies);
  359. }
  360. }
  361. }
  362. StringArray EnabledModulesList::getExtraDependenciesNeeded (const String& moduleID) const
  363. {
  364. StringArray dependencies, extraDepsNeeded;
  365. getDependencies (project, moduleID, dependencies);
  366. for (auto dep : dependencies)
  367. if (dep != moduleID && ! isModuleEnabled (dep))
  368. extraDepsNeeded.add (dep);
  369. return extraDepsNeeded;
  370. }
  371. bool EnabledModulesList::tryToFixMissingDependencies (const String& moduleID)
  372. {
  373. auto copyLocally = areMostModulesCopiedLocally();
  374. auto useGlobalPath = areMostModulesUsingGlobalPath();
  375. StringArray missing;
  376. for (auto missingModule : getExtraDependenciesNeeded (moduleID))
  377. {
  378. auto mod = project.getModuleWithID (missingModule);
  379. if (mod.second != File())
  380. addModule (mod.second, copyLocally, useGlobalPath);
  381. else
  382. missing.add (missingModule);
  383. }
  384. return (missing.size() == 0);
  385. }
  386. bool EnabledModulesList::doesModuleHaveHigherCppStandardThanProject (const String& moduleID) const
  387. {
  388. auto projectCppStandard = project.getCppStandardString();
  389. if (projectCppStandard == Project::getCppStandardVars().getLast().toString())
  390. return false;
  391. auto moduleCppStandard = getModuleInfo (moduleID).getMinimumCppStandard();
  392. return (moduleCppStandard.getIntValue() > projectCppStandard.getIntValue());
  393. }
  394. bool EnabledModulesList::shouldUseGlobalPath (const String& moduleID) const
  395. {
  396. const ScopedLock sl (stateLock);
  397. return (bool) shouldUseGlobalPathValue (moduleID).getValue();
  398. }
  399. Value EnabledModulesList::shouldUseGlobalPathValue (const String& moduleID) const
  400. {
  401. const ScopedLock sl (stateLock);
  402. return state.getChildWithProperty (Ids::ID, moduleID)
  403. .getPropertyAsValue (Ids::useGlobalPath, getUndoManager());
  404. }
  405. bool EnabledModulesList::shouldShowAllModuleFilesInProject (const String& moduleID) const
  406. {
  407. return (bool) shouldShowAllModuleFilesInProjectValue (moduleID).getValue();
  408. }
  409. Value EnabledModulesList::shouldShowAllModuleFilesInProjectValue (const String& moduleID) const
  410. {
  411. const ScopedLock sl (stateLock);
  412. return state.getChildWithProperty (Ids::ID, moduleID)
  413. .getPropertyAsValue (Ids::showAllCode, getUndoManager());
  414. }
  415. bool EnabledModulesList::shouldCopyModuleFilesLocally (const String& moduleID) const
  416. {
  417. return (bool) shouldCopyModuleFilesLocallyValue (moduleID).getValue();
  418. }
  419. Value EnabledModulesList::shouldCopyModuleFilesLocallyValue (const String& moduleID) const
  420. {
  421. const ScopedLock sl (stateLock);
  422. return state.getChildWithProperty (Ids::ID, moduleID)
  423. .getPropertyAsValue (Ids::useLocalCopy, getUndoManager());
  424. }
  425. bool EnabledModulesList::areMostModulesUsingGlobalPath() const
  426. {
  427. int numYes = 0, numNo = 0;
  428. for (auto i = getNumModules(); --i >= 0;)
  429. {
  430. if (shouldUseGlobalPath (getModuleID (i)))
  431. ++numYes;
  432. else
  433. ++numNo;
  434. }
  435. return numYes > numNo;
  436. }
  437. bool EnabledModulesList::areMostModulesCopiedLocally() const
  438. {
  439. int numYes = 0, numNo = 0;
  440. for (auto i = getNumModules(); --i >= 0;)
  441. {
  442. if (shouldCopyModuleFilesLocally (getModuleID (i)))
  443. ++numYes;
  444. else
  445. ++numNo;
  446. }
  447. return numYes > numNo;
  448. }
  449. StringArray EnabledModulesList::getModulesWithHigherCppStandardThanProject() const
  450. {
  451. StringArray list;
  452. for (auto& module : getAllModules())
  453. if (doesModuleHaveHigherCppStandardThanProject (module))
  454. list.add (module);
  455. return list;
  456. }
  457. StringArray EnabledModulesList::getModulesWithMissingDependencies() const
  458. {
  459. StringArray list;
  460. for (auto& module : getAllModules())
  461. if (getExtraDependenciesNeeded (module).size() > 0)
  462. list.add (module);
  463. return list;
  464. }
  465. String EnabledModulesList::getHighestModuleCppStandard() const
  466. {
  467. auto highestCppStandard = Project::getCppStandardVars()[0].toString();
  468. for (auto& mod : getAllModules())
  469. {
  470. auto moduleCppStandard = getModuleInfo (mod).getMinimumCppStandard();
  471. if (moduleCppStandard == "latest")
  472. return moduleCppStandard;
  473. if (moduleCppStandard.getIntValue() > highestCppStandard.getIntValue())
  474. highestCppStandard = moduleCppStandard;
  475. }
  476. return highestCppStandard;
  477. }
  478. void EnabledModulesList::addModule (const File& moduleFolder, bool copyLocally, bool useGlobalPath)
  479. {
  480. ModuleDescription info (moduleFolder);
  481. if (info.isValid())
  482. {
  483. auto moduleID = info.getID();
  484. if (! isModuleEnabled (moduleID))
  485. {
  486. ValueTree module (Ids::MODULE);
  487. module.setProperty (Ids::ID, moduleID, getUndoManager());
  488. {
  489. const ScopedLock sl (stateLock);
  490. state.appendChild (module, getUndoManager());
  491. }
  492. sortAlphabetically();
  493. shouldShowAllModuleFilesInProjectValue (moduleID) = true;
  494. shouldCopyModuleFilesLocallyValue (moduleID) = copyLocally;
  495. shouldUseGlobalPathValue (moduleID) = useGlobalPath;
  496. build_tools::RelativePath path (moduleFolder.getParentDirectory(),
  497. project.getProjectFolder(),
  498. build_tools::RelativePath::projectFolder);
  499. for (Project::ExporterIterator exporter (project); exporter.next();)
  500. exporter->getPathForModuleValue (moduleID) = path.toUnixStyle();
  501. if (! useGlobalPath)
  502. project.rescanExporterPathModules (false);
  503. }
  504. }
  505. }
  506. void EnabledModulesList::addModuleInteractive (const String& moduleID)
  507. {
  508. auto f = project.getModuleWithID (moduleID).second;
  509. if (f != File())
  510. {
  511. addModule (f, areMostModulesCopiedLocally(), areMostModulesUsingGlobalPath());
  512. return;
  513. }
  514. addModuleFromUserSelectedFile();
  515. }
  516. void EnabledModulesList::addModuleFromUserSelectedFile()
  517. {
  518. chooser = std::make_unique<FileChooser> ("Select a module to add...", getDefaultModulesFolder(), "");
  519. auto flags = FileBrowserComponent::openMode | FileBrowserComponent::canSelectDirectories;
  520. chooser->launchAsync (flags, [this] (const FileChooser& fc)
  521. {
  522. if (fc.getResult() == File{})
  523. return;
  524. addModuleOfferingToCopy (fc.getResult(), true);
  525. });
  526. }
  527. void EnabledModulesList::addModuleOfferingToCopy (const File& f, bool isFromUserSpecifiedFolder)
  528. {
  529. ModuleDescription m (f);
  530. if (! m.isValid())
  531. {
  532. auto options = MessageBoxOptions::makeOptionsOk (MessageBoxIconType::InfoIcon,
  533. "Add Module",
  534. "This wasn't a valid module folder!");
  535. messageBox = AlertWindow::showScopedAsync (options, nullptr);
  536. return;
  537. }
  538. if (isModuleEnabled (m.getID()))
  539. {
  540. auto options = MessageBoxOptions::makeOptionsOk (MessageBoxIconType::InfoIcon,
  541. "Add Module",
  542. "The project already contains this module!");
  543. messageBox = AlertWindow::showScopedAsync (options, nullptr);
  544. return;
  545. }
  546. addModule (m.getModuleFolder(),
  547. areMostModulesCopiedLocally(),
  548. isFromUserSpecifiedFolder ? false : areMostModulesUsingGlobalPath());
  549. }
  550. void EnabledModulesList::removeModule (String moduleID) // must be pass-by-value, and not a const ref!
  551. {
  552. {
  553. const ScopedLock sl (stateLock);
  554. for (auto i = state.getNumChildren(); --i >= 0;)
  555. if (state.getChild (i) [Ids::ID] == moduleID)
  556. state.removeChild (i, getUndoManager());
  557. }
  558. for (Project::ExporterIterator exporter (project); exporter.next();)
  559. exporter->removePathForModule (moduleID);
  560. }