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.

301 lines
13KB

  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_PROJECT_H_INCLUDED
  18. #define JUCER_PROJECT_H_INCLUDED
  19. #include "../jucer_Headers.h"
  20. class ProjectExporter;
  21. class ProjectType;
  22. class LibraryModule;
  23. class EnabledModuleList;
  24. //==============================================================================
  25. class Project : public FileBasedDocument,
  26. public ValueTree::Listener
  27. {
  28. public:
  29. //==============================================================================
  30. Project (const File& file);
  31. ~Project();
  32. //==============================================================================
  33. // FileBasedDocument stuff..
  34. String getDocumentTitle() override;
  35. Result loadDocument (const File& file) override;
  36. Result saveDocument (const File& file) override;
  37. Result saveProject (const File& file, bool isCommandLineApp);
  38. Result saveResourcesOnly (const File& file);
  39. File getLastDocumentOpened() override;
  40. void setLastDocumentOpened (const File& file) override;
  41. void setTitle (const String& newTitle);
  42. //==============================================================================
  43. File getProjectFolder() const { return getFile().getParentDirectory(); }
  44. ValueTree getProjectRoot() const { return projectRoot; }
  45. String getTitle() const;
  46. Value getProjectNameValue() { return getMainGroup().getNameValue(); }
  47. String getProjectFilenameRoot() { return File::createLegalFileName (getDocumentTitle()); }
  48. String getProjectUID() const { return projectRoot [Ids::ID]; }
  49. //==============================================================================
  50. template <class FileType>
  51. bool shouldBeAddedToBinaryResourcesByDefault (const FileType& file)
  52. {
  53. return ! file.hasFileExtension (sourceOrHeaderFileExtensions);
  54. }
  55. File resolveFilename (String filename) const;
  56. String getRelativePathForFile (const File& file) const;
  57. //==============================================================================
  58. // Creates editors for the project settings
  59. void createPropertyEditors (PropertyListBuilder&);
  60. //==============================================================================
  61. // project types
  62. const ProjectType& getProjectType() const;
  63. Value getProjectTypeValue() { return getProjectValue (Ids::projectType); }
  64. String getProjectTypeString() const { return projectRoot [Ids::projectType]; }
  65. Value getVersionValue() { return getProjectValue (Ids::version); }
  66. String getVersionString() const { return projectRoot [Ids::version]; }
  67. String getVersionAsHex() const;
  68. int getVersionAsHexInteger() const;
  69. Value getBundleIdentifier() { return getProjectValue (Ids::bundleIdentifier); }
  70. String getDefaultBundleIdentifier() { return "com.yourcompany." + CodeHelpers::makeValidIdentifier (getTitle(), false, true, false); }
  71. Value getAAXIdentifier() { return getProjectValue (Ids::aaxIdentifier); }
  72. String getDefaultAAXIdentifier() { return getDefaultBundleIdentifier(); }
  73. Value getCompanyName() { return getProjectValue (Ids::companyName); }
  74. Value getCompanyWebsite() { return getProjectValue (Ids::companyWebsite); }
  75. Value getCompanyEmail() { return getProjectValue (Ids::companyEmail); }
  76. //==============================================================================
  77. Value getProjectValue (const Identifier& name) { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  78. Value getProjectPreprocessorDefs() { return getProjectValue (Ids::defines); }
  79. StringPairArray getPreprocessorDefs() const;
  80. Value getProjectUserNotes() { return getProjectValue (Ids::userNotes); }
  81. //==============================================================================
  82. File getGeneratedCodeFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  83. File getSourceFilesFolder() const { return getProjectFolder().getChildFile ("Source"); }
  84. File getLocalModulesFolder() const { return getGeneratedCodeFolder().getChildFile ("modules"); }
  85. File getLocalModuleFolder (const String& moduleID) const { return getLocalModulesFolder().getChildFile (moduleID); }
  86. File getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  87. File getBinaryDataCppFile (int index) const;
  88. File getBinaryDataHeaderFile() const { return getBinaryDataCppFile (0).withFileExtension (".h"); }
  89. Value getMaxBinaryFileSize() { return getProjectValue (Ids::maxBinaryFileSize); }
  90. Value shouldIncludeBinaryInAppConfig() { return getProjectValue (Ids::includeBinaryInAppConfig); }
  91. //==============================================================================
  92. String getAmalgamatedHeaderFileName() const { return "juce_amalgamated.h"; }
  93. String getAmalgamatedMMFileName() const { return "juce_amalgamated.mm"; }
  94. String getAmalgamatedCppFileName() const { return "juce_amalgamated.cpp"; }
  95. String getAppConfigFilename() const { return "AppConfig.h"; }
  96. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  97. int getNumSeparateAmalgamatedFiles() const { return 4; }
  98. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  99. //==============================================================================
  100. class Item
  101. {
  102. public:
  103. //==============================================================================
  104. Item (Project& project, const ValueTree& itemNode);
  105. Item (const Item& other);
  106. static Item createGroup (Project& project, const String& name, const String& uid);
  107. void initialiseMissingProperties();
  108. //==============================================================================
  109. bool isValid() const { return state.isValid(); }
  110. bool operator== (const Item& other) const { return state == other.state && &project == &other.project; }
  111. bool operator!= (const Item& other) const { return ! operator== (other); }
  112. //==============================================================================
  113. bool isFile() const;
  114. bool isGroup() const;
  115. bool isMainGroup() const;
  116. bool isImageFile() const;
  117. String getID() const;
  118. void setID (const String& newID);
  119. Item findItemWithID (const String& targetId) const; // (recursive search)
  120. String getImageFileID() const;
  121. Drawable* loadAsImageFile() const;
  122. //==============================================================================
  123. Value getNameValue();
  124. String getName() const;
  125. File getFile() const;
  126. String getFilePath() const;
  127. void setFile (const File& file);
  128. void setFile (const RelativePath& file);
  129. File determineGroupFolder() const;
  130. bool renameFile (const File& newFile);
  131. bool shouldBeAddedToTargetProject() const;
  132. bool shouldBeCompiled() const;
  133. Value getShouldCompileValue();
  134. bool shouldBeAddedToBinaryResources() const;
  135. Value getShouldAddToBinaryResourcesValue();
  136. bool shouldBeAddedToXcodeResources() const;
  137. Value getShouldAddToXcodeResourcesValue();
  138. Value getShouldInhibitWarningsValue();
  139. bool shouldInhibitWarnings() const;
  140. Value getShouldUseStdCallValue();
  141. bool shouldUseStdCall() const;
  142. //==============================================================================
  143. bool canContain (const Item& child) const;
  144. int getNumChildren() const { return state.getNumChildren(); }
  145. Item getChild (int index) const { return Item (project, state.getChild (index)); }
  146. Item addNewSubGroup (const String& name, int insertIndex);
  147. Item getOrCreateSubGroup (const String& name);
  148. void addChild (const Item& newChild, int insertIndex);
  149. bool addFileAtIndex (const File& file, int insertIndex, bool shouldCompile);
  150. bool addFileRetainingSortOrder (const File& file, bool shouldCompile);
  151. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  152. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  153. void removeItemFromProject();
  154. void sortAlphabetically (bool keepGroupsAtStart);
  155. Item findItemForFile (const File& file) const;
  156. bool containsChildForFile (const RelativePath& file) const;
  157. Item getParent() const;
  158. Item createCopy();
  159. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  160. Icon getIcon() const;
  161. bool isIconCrossedOut() const;
  162. Project& project;
  163. ValueTree state;
  164. private:
  165. Item& operator= (const Item&);
  166. };
  167. Item getMainGroup();
  168. void findAllImageItems (OwnedArray<Item>& items);
  169. //==============================================================================
  170. ValueTree getExporters();
  171. int getNumExporters();
  172. ProjectExporter* createExporter (int index);
  173. void addNewExporter (const String& exporterName);
  174. void createExporterForCurrentPlatform();
  175. struct ExporterIterator
  176. {
  177. ExporterIterator (Project& project);
  178. ~ExporterIterator();
  179. bool next();
  180. ProjectExporter& operator*() const { return *exporter; }
  181. ProjectExporter* operator->() const { return exporter; }
  182. ScopedPointer<ProjectExporter> exporter;
  183. int index;
  184. private:
  185. Project& project;
  186. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterIterator)
  187. };
  188. //==============================================================================
  189. struct ConfigFlag
  190. {
  191. String symbol, description, sourceModuleID;
  192. Value value; // 1 = true, 2 = false, anything else = use default
  193. };
  194. static const char* const configFlagDefault;
  195. static const char* const configFlagEnabled;
  196. static const char* const configFlagDisabled;
  197. Value getConfigFlag (const String& name);
  198. bool isConfigFlagEnabled (const String& name) const;
  199. //==============================================================================
  200. EnabledModuleList& getModules();
  201. //==============================================================================
  202. String getFileTemplate (const String& templateName);
  203. //==============================================================================
  204. PropertiesFile& getStoredProperties() const;
  205. //==============================================================================
  206. void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
  207. void valueTreeChildAdded (ValueTree&, ValueTree&) override;
  208. void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override;
  209. void valueTreeChildOrderChanged (ValueTree&, int, int) override;
  210. void valueTreeParentChanged (ValueTree&) override;
  211. //==============================================================================
  212. UndoManager* getUndoManagerFor (const ValueTree&) const { return nullptr; }
  213. //==============================================================================
  214. static const char* projectFileExtension;
  215. private:
  216. friend class Item;
  217. ValueTree projectRoot;
  218. ScopedPointer<EnabledModuleList> enabledModulesList;
  219. bool isSaving;
  220. void updateProjectSettings();
  221. void sanitiseConfigFlags();
  222. void setMissingDefaultValues();
  223. ValueTree getConfigurations() const;
  224. ValueTree getConfigNode();
  225. void updateOldStyleConfigList();
  226. void moveOldPropertyFromProjectToAllExporters (Identifier name);
  227. void removeDefunctExporters();
  228. void updateOldModulePaths();
  229. void warnAboutOldIntrojucerVersion();
  230. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project)
  231. };
  232. #endif // JUCER_PROJECT_H_INCLUDED