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.

712 lines
24KB

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