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.

230 lines
7.9KB

  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. #ifndef JUCER_NEWPROJECTWIZARD_H_INCLUDED
  18. #define JUCER_NEWPROJECTWIZARD_H_INCLUDED
  19. //==============================================================================
  20. static ComboBox& createFileCreationOptionComboBox (Component& setupComp,
  21. OwnedArray<Component>& itemsCreated,
  22. const StringArray& fileOptions)
  23. {
  24. ComboBox* c = new ComboBox();
  25. itemsCreated.add (c);
  26. setupComp.addChildAndSetID (c, "filesToCreate");
  27. c->addItemList (fileOptions, 1);
  28. c->setSelectedId (1, dontSendNotification);
  29. Label* l = new Label (String(), TRANS("Files to Auto-Generate") + ":");
  30. l->attachToComponent (c, true);
  31. itemsCreated.add (l);
  32. c->setBounds ("parent.width / 2 + 160, 30, parent.width - 30, top + 22");
  33. return *c;
  34. }
  35. static int getFileCreationComboResult (WizardComp& setupComp)
  36. {
  37. if (ComboBox* cb = dynamic_cast<ComboBox*> (setupComp.findChildWithID ("filesToCreate")))
  38. return cb->getSelectedItemIndex();
  39. jassertfalse;
  40. return 0;
  41. }
  42. static void setExecutableNameForAllTargets (Project& project, const String& exeName)
  43. {
  44. for (Project::ExporterIterator exporter (project); exporter.next();)
  45. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  46. config->getTargetBinaryName() = exeName;
  47. }
  48. static Project::Item createSourceGroup (Project& project)
  49. {
  50. return project.getMainGroup().addNewSubGroup ("Source", 0);
  51. }
  52. static File& getLastWizardFolder()
  53. {
  54. #if JUCE_WINDOWS
  55. static File lastFolder (File::getSpecialLocation (File::userDocumentsDirectory));
  56. #else
  57. static File lastFolder (File::getSpecialLocation (File::userHomeDirectory));
  58. #endif
  59. return lastFolder;
  60. }
  61. //==============================================================================
  62. struct NewProjectWizard
  63. {
  64. NewProjectWizard() {}
  65. virtual ~NewProjectWizard() {}
  66. //==============================================================================
  67. virtual String getName() const = 0;
  68. virtual String getDescription() const = 0;
  69. virtual const char* getIcon() const = 0;
  70. virtual void addSetupItems (Component&, OwnedArray<Component>&) {}
  71. virtual Result processResultsFromSetupItems (WizardComp&) { return Result::ok(); }
  72. virtual bool initialiseProject (Project& project) = 0;
  73. virtual StringArray getDefaultModules()
  74. {
  75. static const char* mods[] =
  76. {
  77. "juce_core",
  78. "juce_events",
  79. "juce_graphics",
  80. "juce_data_structures",
  81. "juce_gui_basics",
  82. "juce_gui_extra",
  83. "juce_cryptography",
  84. "juce_video",
  85. "juce_opengl",
  86. "juce_audio_basics",
  87. "juce_audio_devices",
  88. "juce_audio_formats",
  89. "juce_audio_processors",
  90. nullptr
  91. };
  92. return StringArray (mods);
  93. }
  94. String appTitle;
  95. File targetFolder, projectFile, modulesFolder;
  96. WizardComp* ownerWizardComp;
  97. StringArray failedFiles;
  98. bool selectJuceFolder()
  99. {
  100. return ModulesFolderPathBox::selectJuceFolder (modulesFolder);
  101. }
  102. //==============================================================================
  103. Project* runWizard (WizardComp& wc,
  104. const String& projectName,
  105. const File& target)
  106. {
  107. ownerWizardComp = &wc;
  108. appTitle = projectName;
  109. targetFolder = target;
  110. if (! targetFolder.exists())
  111. {
  112. if (! targetFolder.createDirectory())
  113. failedFiles.add (targetFolder.getFullPathName());
  114. }
  115. else if (FileHelpers::containsAnyNonHiddenFiles (targetFolder))
  116. {
  117. if (! AlertWindow::showOkCancelBox (AlertWindow::InfoIcon,
  118. TRANS("New JUCE Project"),
  119. TRANS("You chose the folder:\n\nXFLDRX\n\n").replace ("XFLDRX", targetFolder.getFullPathName())
  120. + TRANS("This folder isn't empty - are you sure you want to create the project there?")
  121. + "\n\n"
  122. + TRANS("Any existing files with the same names may be overwritten by the new files.")))
  123. return nullptr;
  124. }
  125. projectFile = targetFolder.getChildFile (File::createLegalFileName (appTitle))
  126. .withFileExtension (Project::projectFileExtension);
  127. ScopedPointer<Project> project (new Project (projectFile));
  128. if (failedFiles.size() == 0)
  129. {
  130. project->setFile (projectFile);
  131. project->setTitle (appTitle);
  132. project->getBundleIdentifier() = project->getDefaultBundleIdentifier();
  133. if (! initialiseProject (*project))
  134. return nullptr;
  135. addExporters (*project, wc);
  136. addDefaultModules (*project, false);
  137. if (project->save (false, true) != FileBasedDocument::savedOk)
  138. return nullptr;
  139. project->setChangedFlag (false);
  140. }
  141. if (failedFiles.size() > 0)
  142. {
  143. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  144. TRANS("Errors in Creating Project!"),
  145. TRANS("The following files couldn't be written:")
  146. + "\n\n"
  147. + failedFiles.joinIntoString ("\n", 0, 10));
  148. return nullptr;
  149. }
  150. return project.release();
  151. }
  152. //==============================================================================
  153. File getSourceFilesFolder() const
  154. {
  155. return projectFile.getSiblingFile ("Source");
  156. }
  157. void createSourceFolder()
  158. {
  159. if (! getSourceFilesFolder().createDirectory())
  160. failedFiles.add (getSourceFilesFolder().getFullPathName());
  161. }
  162. void addDefaultModules (Project& project, bool areModulesCopiedLocally)
  163. {
  164. StringArray mods (getDefaultModules());
  165. ModuleList list;
  166. list.addAllModulesInFolder (modulesFolder);
  167. for (int i = 0; i < mods.size(); ++i)
  168. if (const ModuleDescription* info = list.getModuleWithID (mods[i]))
  169. project.getModules().addModule (info->moduleFolder, areModulesCopiedLocally);
  170. }
  171. void addExporters (Project& project, WizardComp& wizardComp)
  172. {
  173. StringArray types (wizardComp.platformTargets.getSelectedPlatforms());
  174. for (int i = 0; i < types.size(); ++i)
  175. project.addNewExporter (types[i]);
  176. if (project.getNumExporters() == 0)
  177. project.createExporterForCurrentPlatform();
  178. }
  179. };
  180. #endif // JUCER_NEWPROJECTWIZARD_H_INCLUDED