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.

291 lines
13KB

  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_PROJECT_JUCEHEADER__
  18. #define __JUCER_PROJECT_JUCEHEADER__
  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 getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  84. File getBinaryDataCppFile (int index) const;
  85. File getBinaryDataHeaderFile() const { return getBinaryDataCppFile (0).withFileExtension (".h"); }
  86. Value getMaxBinaryFileSize() { return getProjectValue (Ids::maxBinaryFileSize); }
  87. Value shouldIncludeBinaryInAppConfig() { return getProjectValue (Ids::includeBinaryInAppConfig); }
  88. //==============================================================================
  89. String getAmalgamatedHeaderFileName() const { return "juce_amalgamated.h"; }
  90. String getAmalgamatedMMFileName() const { return "juce_amalgamated.mm"; }
  91. String getAmalgamatedCppFileName() const { return "juce_amalgamated.cpp"; }
  92. String getAppConfigFilename() const { return "AppConfig.h"; }
  93. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  94. int getNumSeparateAmalgamatedFiles() const { return 4; }
  95. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  96. //==============================================================================
  97. class Item
  98. {
  99. public:
  100. //==============================================================================
  101. Item (Project& project, const ValueTree& itemNode);
  102. Item (const Item& other);
  103. static Item createGroup (Project& project, const String& name, const String& uid);
  104. void initialiseMissingProperties();
  105. //==============================================================================
  106. bool isValid() const { return state.isValid(); }
  107. bool operator== (const Item& other) const { return state == other.state && &project == &other.project; }
  108. bool operator!= (const Item& other) const { return ! operator== (other); }
  109. //==============================================================================
  110. bool isFile() const;
  111. bool isGroup() const;
  112. bool isMainGroup() const;
  113. bool isImageFile() const;
  114. String getID() const;
  115. void setID (const String& newID);
  116. Item findItemWithID (const String& targetId) const; // (recursive search)
  117. String getImageFileID() const;
  118. Drawable* loadAsImageFile() const;
  119. //==============================================================================
  120. Value getNameValue();
  121. String getName() const;
  122. File getFile() const;
  123. String getFilePath() const;
  124. void setFile (const File& file);
  125. void setFile (const RelativePath& file);
  126. File determineGroupFolder() const;
  127. bool renameFile (const File& newFile);
  128. bool shouldBeAddedToTargetProject() const;
  129. bool shouldBeCompiled() const;
  130. Value getShouldCompileValue();
  131. bool shouldBeAddedToBinaryResources() const;
  132. Value getShouldAddToResourceValue();
  133. Value getShouldInhibitWarningsValue();
  134. bool shouldInhibitWarnings() const;
  135. Value getShouldUseStdCallValue();
  136. bool shouldUseStdCall() const;
  137. //==============================================================================
  138. bool canContain (const Item& child) const;
  139. int getNumChildren() const { return state.getNumChildren(); }
  140. Item getChild (int index) const { return Item (project, state.getChild (index)); }
  141. Item addNewSubGroup (const String& name, int insertIndex);
  142. Item getOrCreateSubGroup (const String& name);
  143. void addChild (const Item& newChild, int insertIndex);
  144. bool addFile (const File& file, int insertIndex, bool shouldCompile);
  145. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  146. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  147. void removeItemFromProject();
  148. void sortAlphabetically (bool keepGroupsAtStart);
  149. Item findItemForFile (const File& file) const;
  150. bool containsChildForFile (const RelativePath& file) const;
  151. Item getParent() const;
  152. Item createCopy();
  153. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  154. Icon getIcon() const;
  155. bool isIconCrossedOut() const;
  156. Project& project;
  157. ValueTree state;
  158. private:
  159. Item& operator= (const Item&);
  160. };
  161. Item getMainGroup();
  162. void findAllImageItems (OwnedArray<Item>& items);
  163. //==============================================================================
  164. ValueTree getExporters();
  165. int getNumExporters();
  166. ProjectExporter* createExporter (int index);
  167. void addNewExporter (const String& exporterName);
  168. void createExporterForCurrentPlatform();
  169. struct ExporterIterator
  170. {
  171. ExporterIterator (Project& project);
  172. ~ExporterIterator();
  173. bool next();
  174. ProjectExporter& operator*() const { return *exporter; }
  175. ProjectExporter* operator->() const { return exporter; }
  176. ScopedPointer<ProjectExporter> exporter;
  177. int index;
  178. private:
  179. Project& project;
  180. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterIterator)
  181. };
  182. //==============================================================================
  183. struct ConfigFlag
  184. {
  185. String symbol, description, sourceModuleID;
  186. Value value; // 1 = true, 2 = false, anything else = use default
  187. };
  188. static const char* const configFlagDefault;
  189. static const char* const configFlagEnabled;
  190. static const char* const configFlagDisabled;
  191. Value getConfigFlag (const String& name);
  192. bool isConfigFlagEnabled (const String& name) const;
  193. //==============================================================================
  194. EnabledModuleList& getModules();
  195. //==============================================================================
  196. String getFileTemplate (const String& templateName);
  197. //==============================================================================
  198. PropertiesFile& getStoredProperties() const;
  199. //==============================================================================
  200. void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
  201. void valueTreeChildAdded (ValueTree&, ValueTree&) override;
  202. void valueTreeChildRemoved (ValueTree&, ValueTree&) override;
  203. void valueTreeChildOrderChanged (ValueTree&) override;
  204. void valueTreeParentChanged (ValueTree&) override;
  205. //==============================================================================
  206. UndoManager* getUndoManagerFor (const ValueTree&) const { return nullptr; }
  207. //==============================================================================
  208. static const char* projectFileExtension;
  209. private:
  210. friend class Item;
  211. ValueTree projectRoot;
  212. ScopedPointer<EnabledModuleList> enabledModulesList;
  213. void updateProjectSettings();
  214. void sanitiseConfigFlags();
  215. void setMissingDefaultValues();
  216. ValueTree getConfigurations() const;
  217. ValueTree getConfigNode();
  218. void updateOldStyleConfigList();
  219. void moveOldPropertyFromProjectToAllExporters (Identifier name);
  220. void removeDefunctExporters();
  221. void updateOldModulePaths();
  222. void warnAboutOldIntrojucerVersion();
  223. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project)
  224. };
  225. #endif // __JUCER_PROJECT_JUCEHEADER__