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.

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