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.

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