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.

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