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.

283 lines
12KB

  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. const String getDocumentTitle();
  36. const String loadDocument (const File& file);
  37. const String saveDocument (const File& file);
  38. String saveResourcesOnly (const File& file);
  39. const File getLastDocumentOpened();
  40. void setLastDocumentOpened (const File& file);
  41. void setTitle (const String& newTitle);
  42. //==============================================================================
  43. ValueTree getProjectRoot() const { return projectRoot; }
  44. Value getProjectName() { return getMainGroup().getNameValue(); }
  45. String getProjectFilenameRoot() { return File::createLegalFileName (getDocumentTitle()); }
  46. String getProjectUID() const { return projectRoot [ComponentBuilder::idProperty]; }
  47. //==============================================================================
  48. template <class FileType>
  49. bool shouldBeAddedToBinaryResourcesByDefault (const FileType& file)
  50. {
  51. return ! file.hasFileExtension (sourceOrHeaderFileExtensions);
  52. }
  53. File resolveFilename (String filename) const;
  54. String getRelativePathForFile (const File& file) const;
  55. //==============================================================================
  56. // Creates editors for the project settings
  57. void createPropertyEditors (PropertyListBuilder&);
  58. //==============================================================================
  59. // project types
  60. const ProjectType& getProjectType() const;
  61. Value getProjectTypeValue() { return getProjectValue (Ids::projectType); }
  62. String getProjectTypeString() const { return projectRoot [Ids::projectType]; }
  63. Value getVersionValue() { return getProjectValue (Ids::version); }
  64. String getVersionString() const { return projectRoot [Ids::version]; }
  65. String getVersionAsHex() const;
  66. Value getBundleIdentifier() { return getProjectValue (Ids::bundleIdentifier); }
  67. void setBundleIdentifierToDefault() { getBundleIdentifier() = "com.yourcompany." + CodeHelpers::makeValidIdentifier (getProjectName().toString(), false, true, false); }
  68. Value getCompanyName() { return getProjectValue (Ids::companyName); }
  69. //==============================================================================
  70. Value getProjectValue (const Identifier& name) { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  71. Value getProjectPreprocessorDefs() { return getProjectValue (Ids::defines); }
  72. StringPairArray getPreprocessorDefs() const;
  73. //==============================================================================
  74. File getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  75. File getGeneratedCodeFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  76. //==============================================================================
  77. String getAmalgamatedHeaderFileName() const { return "juce_amalgamated.h"; }
  78. String getAmalgamatedMMFileName() const { return "juce_amalgamated.mm"; }
  79. String getAmalgamatedCppFileName() const { return "juce_amalgamated.cpp"; }
  80. String getAppConfigFilename() const { return "AppConfig.h"; }
  81. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  82. int getNumSeparateAmalgamatedFiles() const { return 4; }
  83. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  84. //==============================================================================
  85. class Item
  86. {
  87. public:
  88. //==============================================================================
  89. Item (Project& project, const ValueTree& itemNode);
  90. Item (const Item& other);
  91. static Item createGroup (Project& project, const String& name, const String& uid);
  92. void initialiseMissingProperties();
  93. //==============================================================================
  94. bool isValid() const { return state.isValid(); }
  95. bool operator== (const Item& other) const { return state == other.state && &project == &other.project; }
  96. bool operator!= (const Item& other) const { return ! operator== (other); }
  97. //==============================================================================
  98. bool isFile() const;
  99. bool isGroup() const;
  100. bool isMainGroup() const;
  101. bool isImageFile() const;
  102. String getID() const;
  103. void setID (const String& newID);
  104. Item findItemWithID (const String& targetId) const; // (recursive search)
  105. String getImageFileID() const;
  106. Image loadAsImageFile() const;
  107. //==============================================================================
  108. Value getNameValue();
  109. String getName() const;
  110. File getFile() const;
  111. String getFilePath() const;
  112. void setFile (const File& file);
  113. void setFile (const RelativePath& file);
  114. File determineGroupFolder() const;
  115. bool renameFile (const File& newFile);
  116. bool shouldBeAddedToTargetProject() const;
  117. bool shouldBeCompiled() const;
  118. Value getShouldCompileValue();
  119. bool shouldBeAddedToBinaryResources() const;
  120. Value getShouldAddToResourceValue();
  121. Value getShouldInhibitWarningsValue();
  122. bool shouldInhibitWarnings() const;
  123. Value getShouldUseStdCallValue();
  124. bool shouldUseStdCall() const;
  125. //==============================================================================
  126. bool canContain (const Item& child) const;
  127. int getNumChildren() const { return state.getNumChildren(); }
  128. Item getChild (int index) const { return Item (project, state.getChild (index)); }
  129. Item addNewSubGroup (const String& name, int insertIndex);
  130. Item getOrCreateSubGroup (const String& name);
  131. void addChild (const Item& newChild, int insertIndex);
  132. bool addFile (const File& file, int insertIndex, bool shouldCompile);
  133. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  134. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  135. void removeItemFromProject();
  136. void sortAlphabetically (bool keepGroupsAtStart);
  137. Item findItemForFile (const File& file) const;
  138. bool containsChildForFile (const RelativePath& file) const;
  139. Item getParent() const;
  140. Item createCopy();
  141. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  142. const Drawable* getIcon() const;
  143. Project& project;
  144. ValueTree state;
  145. private:
  146. Item& operator= (const Item&);
  147. };
  148. Item getMainGroup();
  149. void findAllImageItems (OwnedArray<Item>& items);
  150. //==============================================================================
  151. ValueTree getExporters();
  152. int getNumExporters();
  153. ProjectExporter* createExporter (int index);
  154. void addNewExporter (const String& exporterName);
  155. void deleteExporter (int index);
  156. void createDefaultExporters();
  157. struct ExporterIterator
  158. {
  159. ExporterIterator (Project& project);
  160. ~ExporterIterator();
  161. bool next();
  162. ProjectExporter& operator*() const { return *exporter; }
  163. ProjectExporter* operator->() const { return exporter; }
  164. ScopedPointer<ProjectExporter> exporter;
  165. int index;
  166. private:
  167. Project& project;
  168. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterIterator);
  169. };
  170. //==============================================================================
  171. struct ConfigFlag
  172. {
  173. String symbol, description, sourceModuleID;
  174. Value value; // 1 = true, 2 = false, anything else = use default
  175. };
  176. static const char* const configFlagDefault;
  177. static const char* const configFlagEnabled;
  178. static const char* const configFlagDisabled;
  179. Value getConfigFlag (const String& name);
  180. bool isConfigFlagEnabled (const String& name) const;
  181. //==============================================================================
  182. bool isModuleEnabled (const String& moduleID) const;
  183. Value shouldShowAllModuleFilesInProject (const String& moduleID);
  184. Value shouldCopyModuleFilesLocally (const String& moduleID);
  185. void addModule (const String& moduleID, bool shouldCopyFilesLocally);
  186. void removeModule (const String& moduleID);
  187. int getNumModules() const;
  188. String getModuleID (int index) const;
  189. void addDefaultModules (bool shouldCopyFilesLocally);
  190. void createRequiredModules (const ModuleList& availableModules, OwnedArray<LibraryModule>& modules) const;
  191. //==============================================================================
  192. String getFileTemplate (const String& templateName);
  193. //==============================================================================
  194. void valueTreePropertyChanged (ValueTree& tree, const Identifier& property);
  195. void valueTreeChildAdded (ValueTree& parentTree, ValueTree& childWhichHasBeenAdded);
  196. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree& childWhichHasBeenRemoved);
  197. void valueTreeChildOrderChanged (ValueTree& parentTree);
  198. void valueTreeParentChanged (ValueTree& tree);
  199. //==============================================================================
  200. UndoManager* getUndoManagerFor (const ValueTree&) const { return nullptr; }
  201. //==============================================================================
  202. static const char* projectFileExtension;
  203. private:
  204. friend class Item;
  205. ValueTree projectRoot;
  206. static File lastDocumentOpened;
  207. DrawableImage mainProjectIcon;
  208. void updateProjectSettings();
  209. void sanitiseConfigFlags();
  210. void setMissingDefaultValues();
  211. ValueTree getConfigurations() const;
  212. ValueTree getConfigNode();
  213. ValueTree getModulesNode();
  214. void updateOldStyleConfigList();
  215. void moveOldPropertyFromProjectToAllExporters (Identifier name);
  216. void removeDefunctExporters();
  217. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project);
  218. };
  219. #endif // __JUCER_PROJECT_JUCEHEADER__