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.

719 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. if ((hasSuffix (file, "_OSX") && ! exporter.isOSX())
  208. || (hasSuffix (file, "_iOS") && ! exporter.isiOS())
  209. || (hasSuffix (file, "_Windows") && ! exporter.isWindows())
  210. || (hasSuffix (file, "_Linux") && ! exporter.isLinux())
  211. || (hasSuffix (file, "_Android") && ! exporter.isAndroid()))
  212. return false;
  213. auto targetType = Project::getTargetTypeFromFilePath (file, false);
  214. if (targetType != build_tools::ProjectType::Target::unspecified && ! exporter.shouldBuildTargetType (targetType))
  215. return false;
  216. return exporter.usesMMFiles() ? isCompiledForObjC
  217. : isCompiledForNonObjC;
  218. }
  219. String LibraryModule::CompileUnit::getFilenameForProxyFile() const
  220. {
  221. return "include_" + file.getFileName();
  222. }
  223. bool LibraryModule::CompileUnit::hasSuffix (const File& f, const char* suffix)
  224. {
  225. auto fileWithoutSuffix = f.getFileNameWithoutExtension() + ".";
  226. return fileWithoutSuffix.containsIgnoreCase (suffix + String ("."))
  227. || fileWithoutSuffix.containsIgnoreCase (suffix + String ("_"));
  228. }
  229. Array<LibraryModule::CompileUnit> LibraryModule::getAllCompileUnits (build_tools::ProjectType::Target::Type forTarget) const
  230. {
  231. auto files = getFolder().findChildFiles (File::findFiles, false);
  232. FileSorter sorter;
  233. files.sort (sorter);
  234. Array<LibraryModule::CompileUnit> units;
  235. for (auto& file : files)
  236. {
  237. if (file.getFileName().startsWithIgnoreCase (getID())
  238. && file.hasFileExtension (sourceFileExtensions))
  239. {
  240. if (forTarget == build_tools::ProjectType::Target::unspecified
  241. || forTarget == Project::getTargetTypeFromFilePath (file, true))
  242. {
  243. CompileUnit cu;
  244. cu.file = file;
  245. units.add (std::move (cu));
  246. }
  247. }
  248. }
  249. for (auto& cu : units)
  250. {
  251. cu.isCompiledForObjC = true;
  252. cu.isCompiledForNonObjC = ! cu.file.hasFileExtension ("mm;m;metal");
  253. if (cu.isCompiledForNonObjC)
  254. if (cu.file.withFileExtension ("mm").existsAsFile())
  255. cu.isCompiledForObjC = false;
  256. jassert (cu.isCompiledForObjC || cu.isCompiledForNonObjC);
  257. }
  258. return units;
  259. }
  260. void LibraryModule::findAndAddCompiledUnits (ProjectExporter& exporter,
  261. ProjectSaver* projectSaver,
  262. Array<File>& result,
  263. build_tools::ProjectType::Target::Type forTarget) const
  264. {
  265. for (auto& cu : getAllCompileUnits (forTarget))
  266. {
  267. if (cu.isNeededForExporter (exporter))
  268. {
  269. auto localFile = exporter.getProject().getGeneratedCodeFolder()
  270. .getChildFile (cu.getFilenameForProxyFile());
  271. result.add (localFile);
  272. if (projectSaver != nullptr)
  273. projectSaver->addFileToGeneratedGroup (localFile);
  274. }
  275. }
  276. }
  277. void LibraryModule::addBrowseableCode (ProjectExporter& exporter, const Array<File>& compiled, const File& localModuleFolder) const
  278. {
  279. if (sourceFiles.isEmpty())
  280. findBrowseableFiles (localModuleFolder, sourceFiles);
  281. auto sourceGroup = Project::Item::createGroup (exporter.getProject(), getID(), "__mainsourcegroup" + getID(), false);
  282. auto moduleFromProject = exporter.getModuleFolderRelativeToProject (getID());
  283. auto moduleHeader = moduleDescription.getHeader();
  284. auto& project = exporter.getProject();
  285. if (project.getEnabledModules().shouldCopyModuleFilesLocally (getID()))
  286. moduleHeader = project.getLocalModuleFolder (getID()).getChildFile (moduleHeader.getFileName());
  287. auto isModuleHeader = [&] (const File& f) { return f.getFileName() == moduleHeader.getFileName(); };
  288. for (auto& sourceFile : sourceFiles)
  289. {
  290. auto pathWithinModule = build_tools::getRelativePathFrom (sourceFile, localModuleFolder);
  291. // (Note: in exporters like MSVC we have to avoid adding the same file twice, even if one of those instances
  292. // is flagged as being excluded from the build, because this overrides the other and it fails to compile)
  293. if ((exporter.canCopeWithDuplicateFiles() || ! compiled.contains (sourceFile)) && ! isModuleHeader (sourceFile))
  294. addFileWithGroups (sourceGroup, moduleFromProject.getChildFile (pathWithinModule), pathWithinModule);
  295. }
  296. sourceGroup.sortAlphabetically (true, true);
  297. sourceGroup.addFileAtIndex (moduleHeader, -1, false);
  298. exporter.getModulesGroup().state.appendChild (sourceGroup.state.createCopy(), nullptr);
  299. }
  300. //==============================================================================
  301. EnabledModulesList::EnabledModulesList (Project& p, const ValueTree& s)
  302. : project (p), state (s)
  303. {
  304. }
  305. StringArray EnabledModulesList::getAllModules() const
  306. {
  307. StringArray moduleIDs;
  308. for (int i = 0; i < getNumModules(); ++i)
  309. moduleIDs.add (getModuleID (i));
  310. return moduleIDs;
  311. }
  312. void EnabledModulesList::createRequiredModules (OwnedArray<LibraryModule>& modules)
  313. {
  314. for (int i = 0; i < getNumModules(); ++i)
  315. modules.add (new LibraryModule (getModuleInfo (getModuleID (i))));
  316. }
  317. void EnabledModulesList::sortAlphabetically()
  318. {
  319. struct ModuleTreeSorter
  320. {
  321. static int compareElements (const ValueTree& m1, const ValueTree& m2)
  322. {
  323. return m1[Ids::ID].toString().compareIgnoreCase (m2[Ids::ID]);
  324. }
  325. };
  326. ModuleTreeSorter sorter;
  327. const ScopedLock sl (stateLock);
  328. state.sort (sorter, getUndoManager(), false);
  329. }
  330. File EnabledModulesList::getDefaultModulesFolder() const
  331. {
  332. File globalPath (getAppSettings().getStoredPath (Ids::defaultJuceModulePath, TargetOS::getThisOS()).get().toString());
  333. if (globalPath.exists())
  334. return globalPath;
  335. for (auto& exporterPathModule : project.getExporterPathsModulesList().getAllModules())
  336. {
  337. auto f = exporterPathModule.second;
  338. if (f.isDirectory())
  339. return f.getParentDirectory();
  340. }
  341. return File::getCurrentWorkingDirectory();
  342. }
  343. ModuleDescription EnabledModulesList::getModuleInfo (const String& moduleID) const
  344. {
  345. return ModuleDescription (project.getModuleWithID (moduleID).second);
  346. }
  347. bool EnabledModulesList::isModuleEnabled (const String& moduleID) const
  348. {
  349. const ScopedLock sl (stateLock);
  350. return state.getChildWithProperty (Ids::ID, moduleID).isValid();
  351. }
  352. static void getDependencies (Project& project, const String& moduleID, StringArray& dependencies)
  353. {
  354. auto info = project.getEnabledModules().getModuleInfo (moduleID);
  355. for (auto uid : info.getDependencies())
  356. {
  357. if (! dependencies.contains (uid, true))
  358. {
  359. dependencies.add (uid);
  360. getDependencies (project, uid, dependencies);
  361. }
  362. }
  363. }
  364. StringArray EnabledModulesList::getExtraDependenciesNeeded (const String& moduleID) const
  365. {
  366. StringArray dependencies, extraDepsNeeded;
  367. getDependencies (project, moduleID, dependencies);
  368. for (auto dep : dependencies)
  369. if (dep != moduleID && ! isModuleEnabled (dep))
  370. extraDepsNeeded.add (dep);
  371. return extraDepsNeeded;
  372. }
  373. bool EnabledModulesList::tryToFixMissingDependencies (const String& moduleID)
  374. {
  375. auto copyLocally = areMostModulesCopiedLocally();
  376. auto useGlobalPath = areMostModulesUsingGlobalPath();
  377. StringArray missing;
  378. for (auto missingModule : getExtraDependenciesNeeded (moduleID))
  379. {
  380. auto mod = project.getModuleWithID (missingModule);
  381. if (mod.second != File())
  382. addModule (mod.second, copyLocally, useGlobalPath);
  383. else
  384. missing.add (missingModule);
  385. }
  386. return (missing.size() == 0);
  387. }
  388. bool EnabledModulesList::doesModuleHaveHigherCppStandardThanProject (const String& moduleID) const
  389. {
  390. auto projectCppStandard = project.getCppStandardString();
  391. if (projectCppStandard == Project::getCppStandardVars().getLast().toString())
  392. return false;
  393. auto moduleCppStandard = getModuleInfo (moduleID).getMinimumCppStandard();
  394. return (moduleCppStandard.getIntValue() > projectCppStandard.getIntValue());
  395. }
  396. bool EnabledModulesList::shouldUseGlobalPath (const String& moduleID) const
  397. {
  398. const ScopedLock sl (stateLock);
  399. return (bool) shouldUseGlobalPathValue (moduleID).getValue();
  400. }
  401. Value EnabledModulesList::shouldUseGlobalPathValue (const String& moduleID) const
  402. {
  403. const ScopedLock sl (stateLock);
  404. return state.getChildWithProperty (Ids::ID, moduleID)
  405. .getPropertyAsValue (Ids::useGlobalPath, getUndoManager());
  406. }
  407. bool EnabledModulesList::shouldShowAllModuleFilesInProject (const String& moduleID) const
  408. {
  409. return (bool) shouldShowAllModuleFilesInProjectValue (moduleID).getValue();
  410. }
  411. Value EnabledModulesList::shouldShowAllModuleFilesInProjectValue (const String& moduleID) const
  412. {
  413. const ScopedLock sl (stateLock);
  414. return state.getChildWithProperty (Ids::ID, moduleID)
  415. .getPropertyAsValue (Ids::showAllCode, getUndoManager());
  416. }
  417. bool EnabledModulesList::shouldCopyModuleFilesLocally (const String& moduleID) const
  418. {
  419. return (bool) shouldCopyModuleFilesLocallyValue (moduleID).getValue();
  420. }
  421. Value EnabledModulesList::shouldCopyModuleFilesLocallyValue (const String& moduleID) const
  422. {
  423. const ScopedLock sl (stateLock);
  424. return state.getChildWithProperty (Ids::ID, moduleID)
  425. .getPropertyAsValue (Ids::useLocalCopy, getUndoManager());
  426. }
  427. bool EnabledModulesList::areMostModulesUsingGlobalPath() const
  428. {
  429. int numYes = 0, numNo = 0;
  430. for (auto i = getNumModules(); --i >= 0;)
  431. {
  432. if (shouldUseGlobalPath (getModuleID (i)))
  433. ++numYes;
  434. else
  435. ++numNo;
  436. }
  437. return numYes > numNo;
  438. }
  439. bool EnabledModulesList::areMostModulesCopiedLocally() const
  440. {
  441. int numYes = 0, numNo = 0;
  442. for (auto i = getNumModules(); --i >= 0;)
  443. {
  444. if (shouldCopyModuleFilesLocally (getModuleID (i)))
  445. ++numYes;
  446. else
  447. ++numNo;
  448. }
  449. return numYes > numNo;
  450. }
  451. StringArray EnabledModulesList::getModulesWithHigherCppStandardThanProject() const
  452. {
  453. StringArray list;
  454. for (auto& module : getAllModules())
  455. if (doesModuleHaveHigherCppStandardThanProject (module))
  456. list.add (module);
  457. return list;
  458. }
  459. StringArray EnabledModulesList::getModulesWithMissingDependencies() const
  460. {
  461. StringArray list;
  462. for (auto& module : getAllModules())
  463. if (getExtraDependenciesNeeded (module).size() > 0)
  464. list.add (module);
  465. return list;
  466. }
  467. String EnabledModulesList::getHighestModuleCppStandard() const
  468. {
  469. auto highestCppStandard = Project::getCppStandardVars()[0].toString();
  470. for (auto& mod : getAllModules())
  471. {
  472. auto moduleCppStandard = getModuleInfo (mod).getMinimumCppStandard();
  473. if (moduleCppStandard == "latest")
  474. return moduleCppStandard;
  475. if (moduleCppStandard.getIntValue() > highestCppStandard.getIntValue())
  476. highestCppStandard = moduleCppStandard;
  477. }
  478. return highestCppStandard;
  479. }
  480. void EnabledModulesList::addModule (const File& moduleFolder, bool copyLocally, bool useGlobalPath)
  481. {
  482. ModuleDescription info (moduleFolder);
  483. if (info.isValid())
  484. {
  485. auto moduleID = info.getID();
  486. if (! isModuleEnabled (moduleID))
  487. {
  488. ValueTree module (Ids::MODULE);
  489. module.setProperty (Ids::ID, moduleID, getUndoManager());
  490. {
  491. const ScopedLock sl (stateLock);
  492. state.appendChild (module, getUndoManager());
  493. }
  494. sortAlphabetically();
  495. shouldShowAllModuleFilesInProjectValue (moduleID) = true;
  496. shouldCopyModuleFilesLocallyValue (moduleID) = copyLocally;
  497. shouldUseGlobalPathValue (moduleID) = useGlobalPath;
  498. build_tools::RelativePath path (moduleFolder.getParentDirectory(),
  499. project.getProjectFolder(),
  500. build_tools::RelativePath::projectFolder);
  501. for (Project::ExporterIterator exporter (project); exporter.next();)
  502. exporter->getPathForModuleValue (moduleID) = path.toUnixStyle();
  503. if (! useGlobalPath)
  504. project.rescanExporterPathModules (false);
  505. }
  506. }
  507. }
  508. void EnabledModulesList::addModuleInteractive (const String& moduleID)
  509. {
  510. auto f = project.getModuleWithID (moduleID).second;
  511. if (f != File())
  512. {
  513. addModule (f, areMostModulesCopiedLocally(), areMostModulesUsingGlobalPath());
  514. return;
  515. }
  516. addModuleFromUserSelectedFile();
  517. }
  518. void EnabledModulesList::addModuleFromUserSelectedFile()
  519. {
  520. chooser = std::make_unique<FileChooser> ("Select a module to add...", getDefaultModulesFolder(), "");
  521. auto flags = FileBrowserComponent::openMode | FileBrowserComponent::canSelectDirectories;
  522. chooser->launchAsync (flags, [this] (const FileChooser& fc)
  523. {
  524. if (fc.getResult() == File{})
  525. return;
  526. addModuleOfferingToCopy (fc.getResult(), true);
  527. });
  528. }
  529. void EnabledModulesList::addModuleOfferingToCopy (const File& f, bool isFromUserSpecifiedFolder)
  530. {
  531. ModuleDescription m (f);
  532. if (! m.isValid())
  533. {
  534. AlertWindow::showMessageBoxAsync (MessageBoxIconType::InfoIcon,
  535. "Add Module", "This wasn't a valid module folder!");
  536. return;
  537. }
  538. if (isModuleEnabled (m.getID()))
  539. {
  540. AlertWindow::showMessageBoxAsync (MessageBoxIconType::InfoIcon,
  541. "Add Module", "The project already contains this module!");
  542. return;
  543. }
  544. addModule (m.getModuleFolder(), areMostModulesCopiedLocally(),
  545. isFromUserSpecifiedFolder ? false : areMostModulesUsingGlobalPath());
  546. }
  547. void EnabledModulesList::removeModule (String moduleID) // must be pass-by-value, and not a const ref!
  548. {
  549. {
  550. const ScopedLock sl (stateLock);
  551. for (auto i = state.getNumChildren(); --i >= 0;)
  552. if (state.getChild(i) [Ids::ID] == moduleID)
  553. state.removeChild (i, getUndoManager());
  554. }
  555. for (Project::ExporterIterator exporter (project); exporter.next();)
  556. exporter->removePathForModule (moduleID);
  557. }