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) 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. 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)
  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. }
  31. Result processResultsFromSetupItems (WizardComp& setupComp)
  32. {
  33. createMainCpp = createWindow = false;
  34. switch (getFileCreationComboResult (setupComp))
  35. {
  36. case 0: createMainCpp = true; break;
  37. case 1: createMainCpp = createWindow = true; break;
  38. case 2: break;
  39. default: jassertfalse; break;
  40. }
  41. return Result::ok();
  42. }
  43. bool initialiseProject (Project& project)
  44. {
  45. createSourceFolder();
  46. File mainCppFile = getSourceFilesFolder().getChildFile ("Main.cpp");
  47. File contentCompCpp = getSourceFilesFolder().getChildFile ("MainComponent.cpp");
  48. File contentCompH = contentCompCpp.withFileExtension (".h");
  49. String contentCompName = "MainContentComponent";
  50. project.getProjectTypeValue() = ProjectType::getGUIAppTypeName();
  51. Project::Item sourceGroup (createSourceGroup (project));
  52. setExecutableNameForAllTargets (project, File::createLegalFileName (appTitle));
  53. String appHeaders (CodeHelpers::createIncludeStatement (project.getAppIncludeFile(), mainCppFile));
  54. if (createWindow)
  55. {
  56. appHeaders << newLine << CodeHelpers::createIncludeStatement (contentCompH, mainCppFile);
  57. String windowH = project.getFileTemplate ("jucer_ContentCompTemplate_h")
  58. .replace ("INCLUDE_JUCE", CodeHelpers::createIncludeStatement (project.getAppIncludeFile(), contentCompH), false)
  59. .replace ("CONTENTCOMPCLASS", contentCompName, false)
  60. .replace ("HEADERGUARD", CodeHelpers::makeHeaderGuardName (contentCompH), false);
  61. String windowCpp = project.getFileTemplate ("jucer_ContentCompTemplate_cpp")
  62. .replace ("INCLUDE_JUCE", CodeHelpers::createIncludeStatement (project.getAppIncludeFile(), contentCompCpp), false)
  63. .replace ("INCLUDE_CORRESPONDING_HEADER", CodeHelpers::createIncludeStatement (contentCompH, contentCompCpp), false)
  64. .replace ("CONTENTCOMPCLASS", contentCompName, false);
  65. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (contentCompH, windowH))
  66. failedFiles.add (contentCompH.getFullPathName());
  67. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (contentCompCpp, windowCpp))
  68. failedFiles.add (contentCompCpp.getFullPathName());
  69. sourceGroup.addFile (contentCompCpp, -1, true);
  70. sourceGroup.addFile (contentCompH, -1, false);
  71. }
  72. if (createMainCpp)
  73. {
  74. String mainCpp = project.getFileTemplate (createWindow ? "jucer_MainTemplate_Window_cpp"
  75. : "jucer_MainTemplate_NoWindow_cpp")
  76. .replace ("APPHEADERS", appHeaders, false)
  77. .replace ("APPCLASSNAME", CodeHelpers::makeValidIdentifier (appTitle + "Application", false, true, false), false)
  78. .replace ("APPNAME", CppTokeniserFunctions::addEscapeChars (appTitle), false)
  79. .replace ("CONTENTCOMPCLASS", contentCompName, false)
  80. .replace ("ALLOWMORETHANONEINSTANCE", "true", false);
  81. if (! FileHelpers::overwriteFileWithNewDataIfDifferent (mainCppFile, mainCpp))
  82. failedFiles.add (mainCppFile.getFullPathName());
  83. sourceGroup.addFile (mainCppFile, -1, true);
  84. }
  85. return true;
  86. }
  87. private:
  88. bool createMainCpp, createWindow;
  89. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GUIAppWizard)
  90. };