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.

289 lines
13KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_PROJECT_JUCEHEADER__
  19. #define __JUCER_PROJECT_JUCEHEADER__
  20. #include "../jucer_Headers.h"
  21. class ProjectExporter;
  22. class ProjectType;
  23. class ModuleList;
  24. class LibraryModule;
  25. //==============================================================================
  26. class Project : public FileBasedDocument,
  27. public ValueTree::Listener
  28. {
  29. public:
  30. //==============================================================================
  31. Project (const File& file);
  32. ~Project();
  33. //==============================================================================
  34. // FileBasedDocument stuff..
  35. String getDocumentTitle();
  36. Result loadDocument (const File& file);
  37. Result saveDocument (const File& file);
  38. Result saveProject (const File& file, bool isCommandLineApp);
  39. Result saveResourcesOnly (const File& file);
  40. File getLastDocumentOpened();
  41. void setLastDocumentOpened (const File& file);
  42. void setTitle (const String& newTitle);
  43. //==============================================================================
  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 [ComponentBuilder::idProperty]; }
  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. 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. //==============================================================================
  74. Value getProjectValue (const Identifier& name) { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  75. Value getProjectPreprocessorDefs() { return getProjectValue (Ids::defines); }
  76. StringPairArray getPreprocessorDefs() const;
  77. //==============================================================================
  78. File getGeneratedCodeFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  79. File getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  80. File getBinaryDataCppFile() const { return getGeneratedCodeFolder().getChildFile ("BinaryData.cpp"); }
  81. File getBinaryDataHeaderFile() const { return getBinaryDataCppFile().withFileExtension (".h"); }
  82. //==============================================================================
  83. String getAmalgamatedHeaderFileName() const { return "juce_amalgamated.h"; }
  84. String getAmalgamatedMMFileName() const { return "juce_amalgamated.mm"; }
  85. String getAmalgamatedCppFileName() const { return "juce_amalgamated.cpp"; }
  86. String getAppConfigFilename() const { return "AppConfig.h"; }
  87. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  88. int getNumSeparateAmalgamatedFiles() const { return 4; }
  89. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  90. //==============================================================================
  91. class Item
  92. {
  93. public:
  94. //==============================================================================
  95. Item (Project& project, const ValueTree& itemNode);
  96. Item (const Item& other);
  97. static Item createGroup (Project& project, const String& name, const String& uid);
  98. void initialiseMissingProperties();
  99. //==============================================================================
  100. bool isValid() const { return state.isValid(); }
  101. bool operator== (const Item& other) const { return state == other.state && &project == &other.project; }
  102. bool operator!= (const Item& other) const { return ! operator== (other); }
  103. //==============================================================================
  104. bool isFile() const;
  105. bool isGroup() const;
  106. bool isMainGroup() const;
  107. bool isImageFile() const;
  108. String getID() const;
  109. void setID (const String& newID);
  110. Item findItemWithID (const String& targetId) const; // (recursive search)
  111. String getImageFileID() const;
  112. Image loadAsImageFile() const;
  113. //==============================================================================
  114. Value getNameValue();
  115. String getName() const;
  116. File getFile() const;
  117. String getFilePath() const;
  118. void setFile (const File& file);
  119. void setFile (const RelativePath& file);
  120. File determineGroupFolder() const;
  121. bool renameFile (const File& newFile);
  122. bool shouldBeAddedToTargetProject() const;
  123. bool shouldBeCompiled() const;
  124. Value getShouldCompileValue();
  125. bool shouldBeAddedToBinaryResources() const;
  126. Value getShouldAddToResourceValue();
  127. Value getShouldInhibitWarningsValue();
  128. bool shouldInhibitWarnings() const;
  129. Value getShouldUseStdCallValue();
  130. bool shouldUseStdCall() const;
  131. //==============================================================================
  132. bool canContain (const Item& child) const;
  133. int getNumChildren() const { return state.getNumChildren(); }
  134. Item getChild (int index) const { return Item (project, state.getChild (index)); }
  135. Item addNewSubGroup (const String& name, int insertIndex);
  136. Item getOrCreateSubGroup (const String& name);
  137. void addChild (const Item& newChild, int insertIndex);
  138. bool addFile (const File& file, int insertIndex, bool shouldCompile);
  139. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  140. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  141. void removeItemFromProject();
  142. void sortAlphabetically (bool keepGroupsAtStart);
  143. Item findItemForFile (const File& file) const;
  144. bool containsChildForFile (const RelativePath& file) const;
  145. Item getParent() const;
  146. Item createCopy();
  147. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  148. Icon getIcon() const;
  149. Project& project;
  150. ValueTree state;
  151. private:
  152. Item& operator= (const Item&);
  153. };
  154. Item getMainGroup();
  155. void findAllImageItems (OwnedArray<Item>& items);
  156. //==============================================================================
  157. ValueTree getExporters();
  158. int getNumExporters();
  159. ProjectExporter* createExporter (int index);
  160. void addNewExporter (const String& exporterName);
  161. void createExporterForCurrentPlatform();
  162. struct ExporterIterator
  163. {
  164. ExporterIterator (Project& project);
  165. ~ExporterIterator();
  166. bool next();
  167. ProjectExporter& operator*() const { return *exporter; }
  168. ProjectExporter* operator->() const { return exporter; }
  169. ScopedPointer<ProjectExporter> exporter;
  170. int index;
  171. private:
  172. Project& project;
  173. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterIterator);
  174. };
  175. //==============================================================================
  176. struct ConfigFlag
  177. {
  178. String symbol, description, sourceModuleID;
  179. Value value; // 1 = true, 2 = false, anything else = use default
  180. };
  181. static const char* const configFlagDefault;
  182. static const char* const configFlagEnabled;
  183. static const char* const configFlagDisabled;
  184. Value getConfigFlag (const String& name);
  185. bool isConfigFlagEnabled (const String& name) const;
  186. //==============================================================================
  187. bool isModuleEnabled (const String& moduleID) const;
  188. Value shouldShowAllModuleFilesInProject (const String& moduleID);
  189. Value shouldCopyModuleFilesLocally (const String& moduleID);
  190. void addModule (const String& moduleID, bool shouldCopyFilesLocally);
  191. void removeModule (const String& moduleID);
  192. int getNumModules() const;
  193. String getModuleID (int index) const;
  194. void addDefaultModules (bool shouldCopyFilesLocally);
  195. bool isAudioPluginModuleMissing() const;
  196. void createRequiredModules (const ModuleList& availableModules, OwnedArray<LibraryModule>& modules) const;
  197. //==============================================================================
  198. String getFileTemplate (const String& templateName);
  199. //==============================================================================
  200. void valueTreePropertyChanged (ValueTree& tree, const Identifier& property);
  201. void valueTreeChildAdded (ValueTree& parentTree, ValueTree& childWhichHasBeenAdded);
  202. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree& childWhichHasBeenRemoved);
  203. void valueTreeChildOrderChanged (ValueTree& parentTree);
  204. void valueTreeParentChanged (ValueTree& tree);
  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. void updateProjectSettings();
  213. void sanitiseConfigFlags();
  214. void setMissingDefaultValues();
  215. ValueTree getConfigurations() const;
  216. ValueTree getConfigNode();
  217. ValueTree getModulesNode();
  218. void updateOldStyleConfigList();
  219. void moveOldPropertyFromProjectToAllExporters (Identifier name);
  220. void removeDefunctExporters();
  221. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project);
  222. };
  223. #endif // __JUCER_PROJECT_JUCEHEADER__