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.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. //==============================================================================
  15. struct GUIAppWizard : public NewProjectWizard
  16. {
  17. GUIAppWizard() {}
  18. String getName() const override { return TRANS("GUI Application"); }
  19. String getDescription() const override { return TRANS("Creates a blank JUCE application with a single window component."); }
  20. const char* getIcon() const override { return BinaryData::wizard_GUI_svg; }
  21. StringArray getFileCreationOptions() override
  22. {
  23. return { "Create a Main.cpp file with header and implementation files",
  24. "Create a Main.cpp file with header file only",
  25. "Create a Main.cpp file only",
  26. "Don't create any files" };
  27. }
  28. Result processResultsFromSetupItems (WizardComp& setupComp) override
  29. {
  30. createMainCpp = createWindow = createCppFile = false;
  31. switch (setupComp.getFileCreationComboID())
  32. {
  33. case 0: createMainCpp = createWindow = createCppFile = true; break;
  34. case 1: createMainCpp = createWindow = true; break;
  35. case 2: createMainCpp = true; break;
  36. case 3: break;
  37. default: jassertfalse; break;
  38. }
  39. return Result::ok();
  40. }
  41. bool initialiseProject (Project& project) override
  42. {
  43. createSourceFolder();
  44. File mainCppFile = getSourceFilesFolder().getChildFile ("Main.cpp");
  45. File contentCompCpp = getSourceFilesFolder().getChildFile ("MainComponent.cpp");
  46. File contentCompH = contentCompCpp.withFileExtension (".h");
  47. String contentCompName = "MainComponent";
  48. project.setProjectType (build_tools::ProjectType_GUIApp::getTypeName());
  49. Project::Item sourceGroup (createSourceGroup (project));
  50. setExecutableNameForAllTargets (project, File::createLegalFileName (appTitle));
  51. auto juceHeaderInclude = CodeHelpers::createIncludePathIncludeStatement (Project::getJuceSourceHFilename());
  52. auto appHeaders = juceHeaderInclude;
  53. if (createWindow)
  54. {
  55. appHeaders << newLine << CodeHelpers::createIncludeStatement (contentCompH, mainCppFile);
  56. String windowH = project.getFileTemplate (createCppFile ? "jucer_ContentCompTemplate_h"
  57. : "jucer_ContentCompSimpleTemplate_h")
  58. .replace ("%%include_juce%%", juceHeaderInclude)
  59. .replace ("%%content_component_class%%", contentCompName, false);
  60. if (!build_tools::overwriteFileWithNewDataIfDifferent (contentCompH, windowH))
  61. failedFiles.add (contentCompH.getFullPathName());
  62. sourceGroup.addFileAtIndex (contentCompH, -1, false);
  63. if (createCppFile)
  64. {
  65. String windowCpp = project.getFileTemplate ("jucer_ContentCompTemplate_cpp")
  66. .replace ("%%include_juce%%", juceHeaderInclude)
  67. .replace ("%%include_corresponding_header%%", CodeHelpers::createIncludeStatement (contentCompH, contentCompCpp), false)
  68. .replace ("%%content_component_class%%", contentCompName, false);
  69. if (!build_tools::overwriteFileWithNewDataIfDifferent (contentCompCpp, windowCpp))
  70. failedFiles.add (contentCompCpp.getFullPathName());
  71. sourceGroup.addFileAtIndex (contentCompCpp, -1, true);
  72. }
  73. }
  74. if (createMainCpp)
  75. {
  76. String mainCpp = project.getFileTemplate (createWindow ? "jucer_MainTemplate_Window_cpp"
  77. : "jucer_MainTemplate_NoWindow_cpp")
  78. .replace ("%%app_headers%%", appHeaders, false)
  79. .replace ("%%app_class_name%%", build_tools::makeValidIdentifier (appTitle + "Application", false, true, false), false)
  80. .replace ("%%content_component_class%%", contentCompName, false)
  81. .replace ("%%allow_more_than_one_instance%%", "true", false);
  82. if (!build_tools::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, createCppFile;
  90. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GUIAppWizard)
  91. };