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.

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