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.

124 lines
5.6KB

  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. struct GUIAppWizard : public NewProjectWizard
  18. {
  19. GUIAppWizard() {}
  20. String getName() const override { return TRANS("GUI Application"); }
  21. String getDescription() const override { return TRANS("Creates a blank JUCE application with a single window component."); }
  22. const char* getIcon() const override { return BinaryData::wizard_GUI_svg; }
  23. void addSetupItems (Component& setupComp, OwnedArray<Component>& itemsCreated) override
  24. {
  25. const String fileOptions[] = { TRANS("Create a Main.cpp file"),
  26. TRANS("Create a Main.cpp file and a basic window"),
  27. TRANS("Don't create any files") };
  28. createFileCreationOptionComboBox (setupComp, itemsCreated,
  29. StringArray (fileOptions, numElementsInArray (fileOptions)))
  30. .setSelectedId (2);
  31. }
  32. Result processResultsFromSetupItems (WizardComp& setupComp) override
  33. {
  34. createMainCpp = createWindow = false;
  35. switch (getFileCreationComboResult (setupComp))
  36. {
  37. case 0: createMainCpp = true; break;
  38. case 1: createMainCpp = createWindow = true; break;
  39. case 2: break;
  40. default: jassertfalse; break;
  41. }
  42. return Result::ok();
  43. }
  44. bool initialiseProject (Project& project) override
  45. {
  46. createSourceFolder();
  47. File mainCppFile = getSourceFilesFolder().getChildFile ("Main.cpp");
  48. File contentCompCpp = getSourceFilesFolder().getChildFile ("MainComponent.cpp");
  49. File contentCompH = contentCompCpp.withFileExtension (".h");
  50. String contentCompName = "MainContentComponent";
  51. project.getProjectTypeValue() = ProjectType_GUIApp::getTypeName();
  52. Project::Item sourceGroup (createSourceGroup (project));
  53. setExecutableNameForAllTargets (project, File::createLegalFileName (appTitle));
  54. String appHeaders (CodeHelpers::createIncludeStatement (project.getAppIncludeFile(), mainCppFile));
  55. if (createWindow)
  56. {
  57. appHeaders << newLine << CodeHelpers::createIncludeStatement (contentCompH, mainCppFile);
  58. String windowH = project.getFileTemplate ("jucer_ContentCompTemplate_h")
  59. .replace ("INCLUDE_JUCE", CodeHelpers::createIncludeStatement (project.getAppIncludeFile(), contentCompH), false)
  60. .replace ("CONTENTCOMPCLASS", contentCompName, false)
  61. .replace ("HEADERGUARD", CodeHelpers::makeHeaderGuardName (contentCompH), false);
  62. String windowCpp = project.getFileTemplate ("jucer_ContentCompTemplate_cpp")
  63. .replace ("INCLUDE_JUCE", CodeHelpers::createIncludeStatement (project.getAppIncludeFile(), contentCompCpp), false)
  64. .replace ("INCLUDE_CORRESPONDING_HEADER", CodeHelpers::createIncludeStatement (contentCompH, contentCompCpp), false)
  65. .replace ("CONTENTCOMPCLASS", contentCompName, false);
  66. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (contentCompH, windowH))
  67. failedFiles.add (contentCompH.getFullPathName());
  68. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (contentCompCpp, windowCpp))
  69. failedFiles.add (contentCompCpp.getFullPathName());
  70. sourceGroup.addFileAtIndex (contentCompCpp, -1, true);
  71. sourceGroup.addFileAtIndex (contentCompH, -1, false);
  72. }
  73. if (createMainCpp)
  74. {
  75. String mainCpp = project.getFileTemplate (createWindow ? "jucer_MainTemplate_Window_cpp"
  76. : "jucer_MainTemplate_NoWindow_cpp")
  77. .replace ("APPHEADERS", appHeaders, false)
  78. .replace ("APPCLASSNAME", CodeHelpers::makeValidIdentifier (appTitle + "Application", false, true, false), false)
  79. .replace ("APPNAME", CppTokeniserFunctions::addEscapeChars (appTitle), false)
  80. .replace ("CONTENTCOMPCLASS", contentCompName, false)
  81. .replace ("ALLOWMORETHANONEINSTANCE", "true", false);
  82. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (mainCppFile, mainCpp))
  83. failedFiles.add (mainCppFile.getFullPathName());
  84. sourceGroup.addFileAtIndex (mainCppFile, -1, true);
  85. }
  86. return true;
  87. }
  88. private:
  89. bool createMainCpp, createWindow;
  90. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GUIAppWizard)
  91. };