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.

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