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.

226 lines
7.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. static ComboBox& createFileCreationOptionComboBox (Component& setupComp,
  20. OwnedArray<Component>& itemsCreated,
  21. const StringArray& fileOptions)
  22. {
  23. ComboBox* c = new ComboBox();
  24. itemsCreated.add (c);
  25. setupComp.addChildAndSetID (c, "filesToCreate");
  26. c->addItemList (fileOptions, 1);
  27. c->setSelectedId (1, dontSendNotification);
  28. Label* l = new Label (String(), TRANS("Files to Auto-Generate") + ":");
  29. l->attachToComponent (c, true);
  30. itemsCreated.add (l);
  31. c->setBounds ("parent.width / 2 + 160, 30, parent.width - 30, top + 22");
  32. return *c;
  33. }
  34. static int getFileCreationComboResult (WizardComp& setupComp)
  35. {
  36. if (ComboBox* cb = dynamic_cast<ComboBox*> (setupComp.findChildWithID ("filesToCreate")))
  37. return cb->getSelectedItemIndex();
  38. jassertfalse;
  39. return 0;
  40. }
  41. static void setExecutableNameForAllTargets (Project& project, const String& exeName)
  42. {
  43. for (Project::ExporterIterator exporter (project); exporter.next();)
  44. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  45. config->getTargetBinaryName() = exeName;
  46. }
  47. static Project::Item createSourceGroup (Project& project)
  48. {
  49. return project.getMainGroup().addNewSubGroup ("Source", 0);
  50. }
  51. static File& getLastWizardFolder()
  52. {
  53. #if JUCE_WINDOWS
  54. static File lastFolder (File::getSpecialLocation (File::userDocumentsDirectory));
  55. #else
  56. static File lastFolder (File::getSpecialLocation (File::userHomeDirectory));
  57. #endif
  58. return lastFolder;
  59. }
  60. //==============================================================================
  61. struct NewProjectWizard
  62. {
  63. NewProjectWizard() {}
  64. virtual ~NewProjectWizard() {}
  65. //==============================================================================
  66. virtual String getName() const = 0;
  67. virtual String getDescription() const = 0;
  68. virtual const char* getIcon() const = 0;
  69. virtual void addSetupItems (Component&, OwnedArray<Component>&) {}
  70. virtual Result processResultsFromSetupItems (WizardComp&) { return Result::ok(); }
  71. virtual bool initialiseProject (Project& project) = 0;
  72. virtual StringArray getDefaultModules()
  73. {
  74. static const char* mods[] =
  75. {
  76. "juce_core",
  77. "juce_events",
  78. "juce_graphics",
  79. "juce_data_structures",
  80. "juce_gui_basics",
  81. "juce_gui_extra",
  82. "juce_cryptography",
  83. "juce_video",
  84. "juce_opengl",
  85. "juce_audio_basics",
  86. "juce_audio_devices",
  87. "juce_audio_formats",
  88. "juce_audio_processors",
  89. nullptr
  90. };
  91. return StringArray (mods);
  92. }
  93. String appTitle;
  94. File targetFolder, projectFile, modulesFolder;
  95. WizardComp* ownerWizardComp;
  96. StringArray failedFiles;
  97. bool selectJuceFolder()
  98. {
  99. return ModulesFolderPathBox::selectJuceFolder (modulesFolder);
  100. }
  101. //==============================================================================
  102. Project* runWizard (WizardComp& wc,
  103. const String& projectName,
  104. const File& target)
  105. {
  106. ownerWizardComp = &wc;
  107. appTitle = projectName;
  108. targetFolder = target;
  109. if (! targetFolder.exists())
  110. {
  111. if (! targetFolder.createDirectory())
  112. failedFiles.add (targetFolder.getFullPathName());
  113. }
  114. else if (FileHelpers::containsAnyNonHiddenFiles (targetFolder))
  115. {
  116. if (! AlertWindow::showOkCancelBox (AlertWindow::InfoIcon,
  117. TRANS("New JUCE Project"),
  118. TRANS("You chose the folder:\n\nXFLDRX\n\n").replace ("XFLDRX", targetFolder.getFullPathName())
  119. + TRANS("This folder isn't empty - are you sure you want to create the project there?")
  120. + "\n\n"
  121. + TRANS("Any existing files with the same names may be overwritten by the new files.")))
  122. return nullptr;
  123. }
  124. projectFile = targetFolder.getChildFile (File::createLegalFileName (appTitle))
  125. .withFileExtension (Project::projectFileExtension);
  126. ScopedPointer<Project> project (new Project (projectFile));
  127. if (failedFiles.size() == 0)
  128. {
  129. project->setFile (projectFile);
  130. project->setTitle (appTitle);
  131. project->getBundleIdentifier() = project->getDefaultBundleIdentifier();
  132. if (! initialiseProject (*project))
  133. return nullptr;
  134. addExporters (*project, wc);
  135. addDefaultModules (*project, false);
  136. if (project->save (false, true) != FileBasedDocument::savedOk)
  137. return nullptr;
  138. project->setChangedFlag (false);
  139. }
  140. if (failedFiles.size() > 0)
  141. {
  142. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  143. TRANS("Errors in Creating Project!"),
  144. TRANS("The following files couldn't be written:")
  145. + "\n\n"
  146. + failedFiles.joinIntoString ("\n", 0, 10));
  147. return nullptr;
  148. }
  149. return project.release();
  150. }
  151. //==============================================================================
  152. File getSourceFilesFolder() const
  153. {
  154. return projectFile.getSiblingFile ("Source");
  155. }
  156. void createSourceFolder()
  157. {
  158. if (! getSourceFilesFolder().createDirectory())
  159. failedFiles.add (getSourceFilesFolder().getFullPathName());
  160. }
  161. void addDefaultModules (Project& project, bool areModulesCopiedLocally)
  162. {
  163. StringArray mods (getDefaultModules());
  164. ModuleList list;
  165. list.addAllModulesInFolder (modulesFolder);
  166. for (int i = 0; i < mods.size(); ++i)
  167. if (const ModuleDescription* info = list.getModuleWithID (mods[i]))
  168. project.getModules().addModule (info->moduleFolder, areModulesCopiedLocally);
  169. }
  170. void addExporters (Project& project, WizardComp& wizardComp)
  171. {
  172. StringArray types (wizardComp.platformTargets.getSelectedPlatforms());
  173. for (int i = 0; i < types.size(); ++i)
  174. project.addNewExporter (types[i]);
  175. if (project.getNumExporters() == 0)
  176. project.createExporterForCurrentPlatform();
  177. }
  178. };