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.

290 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. Value getProjectName() { return getMainGroup().getNameValue(); }
  46. String getProjectFilenameRoot() { return File::createLegalFileName (getDocumentTitle()); }
  47. String getProjectUID() const { return projectRoot [ComponentBuilder::idProperty]; }
  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. Value getBundleIdentifier() { return getProjectValue (Ids::bundleIdentifier); }
  68. String getDefaultBundleIdentifier() { return "com.yourcompany." + CodeHelpers::makeValidIdentifier (getProjectName().toString(), false, true, false); }
  69. Value getAAXIdentifier() { return getProjectValue (Ids::aaxIdentifier); }
  70. String getDefaultAAXIdentifier() { return getDefaultBundleIdentifier(); }
  71. Value getCompanyName() { return getProjectValue (Ids::companyName); }
  72. //==============================================================================
  73. Value getProjectValue (const Identifier& name) { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  74. Value getProjectPreprocessorDefs() { return getProjectValue (Ids::defines); }
  75. StringPairArray getPreprocessorDefs() const;
  76. //==============================================================================
  77. File getGeneratedCodeFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  78. File getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  79. File getBinaryDataCppFile() const { return getGeneratedCodeFolder().getChildFile ("BinaryData.cpp"); }
  80. File getBinaryDataHeaderFile() const { return getBinaryDataCppFile().withFileExtension (".h"); }
  81. //==============================================================================
  82. String getAmalgamatedHeaderFileName() const { return "juce_amalgamated.h"; }
  83. String getAmalgamatedMMFileName() const { return "juce_amalgamated.mm"; }
  84. String getAmalgamatedCppFileName() const { return "juce_amalgamated.cpp"; }
  85. String getAppConfigFilename() const { return "AppConfig.h"; }
  86. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  87. int getNumSeparateAmalgamatedFiles() const { return 4; }
  88. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  89. //==============================================================================
  90. class Item
  91. {
  92. public:
  93. //==============================================================================
  94. Item (Project& project, const ValueTree& itemNode);
  95. Item (const Item& other);
  96. static Item createGroup (Project& project, const String& name, const String& uid);
  97. void initialiseMissingProperties();
  98. //==============================================================================
  99. bool isValid() const { return state.isValid(); }
  100. bool operator== (const Item& other) const { return state == other.state && &project == &other.project; }
  101. bool operator!= (const Item& other) const { return ! operator== (other); }
  102. //==============================================================================
  103. bool isFile() const;
  104. bool isGroup() const;
  105. bool isMainGroup() const;
  106. bool isImageFile() const;
  107. String getID() const;
  108. void setID (const String& newID);
  109. Item findItemWithID (const String& targetId) const; // (recursive search)
  110. String getImageFileID() const;
  111. Image loadAsImageFile() const;
  112. //==============================================================================
  113. Value getNameValue();
  114. String getName() const;
  115. File getFile() const;
  116. String getFilePath() const;
  117. void setFile (const File& file);
  118. void setFile (const RelativePath& file);
  119. File determineGroupFolder() const;
  120. bool renameFile (const File& newFile);
  121. bool shouldBeAddedToTargetProject() const;
  122. bool shouldBeCompiled() const;
  123. Value getShouldCompileValue();
  124. bool shouldBeAddedToBinaryResources() const;
  125. Value getShouldAddToResourceValue();
  126. Value getShouldInhibitWarningsValue();
  127. bool shouldInhibitWarnings() const;
  128. Value getShouldUseStdCallValue();
  129. bool shouldUseStdCall() const;
  130. //==============================================================================
  131. bool canContain (const Item& child) const;
  132. int getNumChildren() const { return state.getNumChildren(); }
  133. Item getChild (int index) const { return Item (project, state.getChild (index)); }
  134. Item addNewSubGroup (const String& name, int insertIndex);
  135. Item getOrCreateSubGroup (const String& name);
  136. void addChild (const Item& newChild, int insertIndex);
  137. bool addFile (const File& file, int insertIndex, bool shouldCompile);
  138. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  139. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  140. void removeItemFromProject();
  141. void sortAlphabetically (bool keepGroupsAtStart);
  142. Item findItemForFile (const File& file) const;
  143. bool containsChildForFile (const RelativePath& file) const;
  144. Item getParent() const;
  145. Item createCopy();
  146. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  147. const Drawable* getIcon() const;
  148. Project& project;
  149. ValueTree state;
  150. private:
  151. Item& operator= (const Item&);
  152. };
  153. Item getMainGroup();
  154. void findAllImageItems (OwnedArray<Item>& items);
  155. //==============================================================================
  156. ValueTree getExporters();
  157. int getNumExporters();
  158. ProjectExporter* createExporter (int index);
  159. void addNewExporter (const String& exporterName);
  160. void deleteExporter (int index);
  161. void createDefaultExporters();
  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. DrawableImage mainProjectIcon;
  213. void updateProjectSettings();
  214. void sanitiseConfigFlags();
  215. void setMissingDefaultValues();
  216. ValueTree getConfigurations() const;
  217. ValueTree getConfigNode();
  218. ValueTree getModulesNode();
  219. void updateOldStyleConfigList();
  220. void moveOldPropertyFromProjectToAllExporters (Identifier name);
  221. void removeDefunctExporters();
  222. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project);
  223. };
  224. #endif // __JUCER_PROJECT_JUCEHEADER__