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.

261 lines
8.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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 inline void 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::empty, 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. }
  34. static inline int getFileCreationComboResult (Component& setupComp)
  35. {
  36. if (ComboBox* cb = dynamic_cast<ComboBox*> (setupComp.findChildWithID ("filesToCreate")))
  37. return cb->getSelectedItemIndex();
  38. jassertfalse;
  39. return 0;
  40. }
  41. static inline 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 inline Project::Item createSourceGroup (Project& project)
  48. {
  49. return project.getMainGroup().addNewSubGroup ("Source", 0);
  50. }
  51. static inline 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. static bool isJuceModulesFolder (const File& f)
  61. {
  62. return f.isDirectory()
  63. && f.getChildFile ("juce_core").isDirectory();
  64. }
  65. static File findDefaultModulesFolder (bool mustContainJuceCoreModule = true)
  66. {
  67. const MainWindowList& windows = IntrojucerApp::getApp().mainWindowList;
  68. for (int i = windows.windows.size(); --i >= 0;)
  69. {
  70. if (Project* p = windows.windows.getUnchecked (i)->getProject())
  71. {
  72. const File f (EnabledModuleList::findDefaultModulesFolder (*p));
  73. if (isJuceModulesFolder (f) || (f.isDirectory() && ! mustContainJuceCoreModule))
  74. return f;
  75. }
  76. }
  77. if (mustContainJuceCoreModule)
  78. return findDefaultModulesFolder (false);
  79. return File::nonexistent;
  80. }
  81. //==============================================================================
  82. struct NewProjectWizard
  83. {
  84. NewProjectWizard() {}
  85. virtual ~NewProjectWizard() {}
  86. //==============================================================================
  87. virtual String getName() = 0;
  88. virtual String getDescription() = 0;
  89. virtual void addSetupItems (Component&, OwnedArray<Component>&) {}
  90. virtual Result processResultsFromSetupItems (Component&) { return Result::ok(); }
  91. virtual bool initialiseProject (Project& project) = 0;
  92. virtual StringArray getDefaultModules()
  93. {
  94. static const char* mods[] =
  95. {
  96. "juce_core",
  97. "juce_events",
  98. "juce_graphics",
  99. "juce_data_structures",
  100. "juce_gui_basics",
  101. "juce_gui_extra",
  102. "juce_cryptography",
  103. "juce_video",
  104. "juce_opengl",
  105. "juce_audio_basics",
  106. "juce_audio_devices",
  107. "juce_audio_formats",
  108. "juce_audio_processors",
  109. nullptr
  110. };
  111. return StringArray (mods);
  112. }
  113. String appTitle;
  114. File targetFolder, projectFile, modulesFolder;
  115. Component* ownerWindow;
  116. StringArray failedFiles;
  117. //==============================================================================
  118. Project* runWizard (Component* window,
  119. const String& projectName,
  120. const File& target)
  121. {
  122. ownerWindow = window;
  123. appTitle = projectName;
  124. targetFolder = target;
  125. if (! targetFolder.exists())
  126. {
  127. if (! targetFolder.createDirectory())
  128. failedFiles.add (targetFolder.getFullPathName());
  129. }
  130. else if (FileHelpers::containsAnyNonHiddenFiles (targetFolder))
  131. {
  132. if (! AlertWindow::showOkCancelBox (AlertWindow::InfoIcon,
  133. TRANS("New Juce Project"),
  134. TRANS("The folder you chose isn't empty - are you sure you want to create the project there?")
  135. + "\n\n"
  136. + TRANS("Any existing files with the same names may be overwritten by the new files.")))
  137. return nullptr;
  138. }
  139. projectFile = targetFolder.getChildFile (File::createLegalFileName (appTitle))
  140. .withFileExtension (Project::projectFileExtension);
  141. ScopedPointer<Project> project (new Project (projectFile));
  142. if (failedFiles.size() == 0)
  143. {
  144. project->setFile (projectFile);
  145. project->setTitle (appTitle);
  146. project->getBundleIdentifier() = project->getDefaultBundleIdentifier();
  147. if (! initialiseProject (*project))
  148. return nullptr;
  149. addDefaultModules (*project);
  150. if (project->save (false, true) != FileBasedDocument::savedOk)
  151. return nullptr;
  152. project->setChangedFlag (false);
  153. }
  154. if (failedFiles.size() > 0)
  155. {
  156. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  157. TRANS("Errors in Creating Project!"),
  158. TRANS("The following files couldn't be written:")
  159. + "\n\n"
  160. + failedFiles.joinIntoString ("\n", 0, 10));
  161. return nullptr;
  162. }
  163. return project.release();
  164. }
  165. bool selectJuceFolder()
  166. {
  167. for (;;)
  168. {
  169. FileChooser fc ("Select your JUCE modules folder...",
  170. findDefaultModulesFolder(),
  171. "*");
  172. if (! fc.browseForDirectory())
  173. return false;
  174. if (isJuceModulesFolder (fc.getResult()))
  175. {
  176. modulesFolder = fc.getResult();
  177. return true;
  178. }
  179. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  180. "Not a valid JUCE modules folder!",
  181. "Please select the folder containing your juce_* modules!\n\n"
  182. "This is required so that the new project can be given some essential core modules.");
  183. }
  184. }
  185. //==============================================================================
  186. File getSourceFilesFolder() const
  187. {
  188. return projectFile.getSiblingFile ("Source");
  189. }
  190. void createSourceFolder()
  191. {
  192. if (! getSourceFilesFolder().createDirectory())
  193. failedFiles.add (getSourceFilesFolder().getFullPathName());
  194. }
  195. void addDefaultModules (Project& project)
  196. {
  197. StringArray mods (getDefaultModules());
  198. ModuleList list;
  199. list.addAllModulesInFolder (modulesFolder);
  200. for (int i = 0; i < mods.size(); ++i)
  201. if (const ModuleDescription* info = list.getModuleWithID (mods[i]))
  202. project.getModules().addModule (info->manifestFile, true);
  203. }
  204. };
  205. #endif // JUCER_NEWPROJECTWIZARD_H_INCLUDED