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.

202 lines
6.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. class GroupItem : public ProjectTreeItemBase
  18. {
  19. public:
  20. GroupItem (const Project::Item& projectItem)
  21. : ProjectTreeItemBase (projectItem)
  22. {
  23. }
  24. bool isRoot() const override { return item.isMainGroup(); }
  25. bool acceptsFileDrop (const StringArray&) const override { return true; }
  26. void addNewGroup()
  27. {
  28. Project::Item newGroup (item.addNewSubGroup ("New Group", 0));
  29. triggerAsyncRename (newGroup);
  30. }
  31. bool acceptsDragItems (const OwnedArray<Project::Item>& selectedNodes) override
  32. {
  33. for (int i = selectedNodes.size(); --i >= 0;)
  34. if (item.canContain (*selectedNodes.getUnchecked(i)))
  35. return true;
  36. return false;
  37. }
  38. void addFilesAtIndex (const StringArray& files, int insertIndex) override
  39. {
  40. for (int i = 0; i < files.size(); ++i)
  41. {
  42. const File file (files[i]);
  43. if (item.addFileAtIndex (file, insertIndex, true))
  44. ++insertIndex;
  45. }
  46. }
  47. void addFilesRetainingSortOrder (const StringArray& files) override
  48. {
  49. for (int i = files.size(); --i >= 0;)
  50. item.addFileRetainingSortOrder (files[i], true);
  51. }
  52. void moveSelectedItemsTo (OwnedArray<Project::Item>& selectedNodes, int insertIndex) override
  53. {
  54. moveItems (selectedNodes, item, insertIndex);
  55. }
  56. void checkFileStatus() override
  57. {
  58. for (int i = 0; i < getNumSubItems(); ++i)
  59. if (ProjectTreeItemBase* p = dynamic_cast<ProjectTreeItemBase*> (getSubItem(i)))
  60. p->checkFileStatus();
  61. }
  62. ProjectTreeItemBase* createSubItem (const Project::Item& child) override
  63. {
  64. if (child.isGroup()) return new GroupItem (child);
  65. if (child.isFile()) return new SourceFileItem (child);
  66. jassertfalse;
  67. return nullptr;
  68. }
  69. void showDocument() override
  70. {
  71. if (ProjectContentComponent* pcc = getProjectContentComponent())
  72. pcc->setEditorComponent (new GroupInformationComponent (item), nullptr);
  73. }
  74. static void openOrCloseAllSubGroups (TreeViewItem& item, bool shouldOpen)
  75. {
  76. item.setOpen (shouldOpen);
  77. for (int i = item.getNumSubItems(); --i >= 0;)
  78. if (TreeViewItem* sub = item.getSubItem(i))
  79. openOrCloseAllSubGroups (*sub, shouldOpen);
  80. }
  81. static void setFilesToCompile (Project::Item item, const bool shouldCompile)
  82. {
  83. if (item.isFile())
  84. item.getShouldCompileValue() = shouldCompile;
  85. for (int i = item.getNumChildren(); --i >= 0;)
  86. setFilesToCompile (item.getChild (i), shouldCompile);
  87. }
  88. void showPopupMenu() override
  89. {
  90. PopupMenu m;
  91. addCreateFileMenuItems (m);
  92. m.addSeparator();
  93. if (! isRoot())
  94. {
  95. if (isOpen())
  96. m.addItem (1, "Collapse all Sub-groups");
  97. else
  98. m.addItem (2, "Expand all Sub-groups");
  99. }
  100. m.addSeparator();
  101. m.addItem (3, "Enable compiling of all enclosed files");
  102. m.addItem (4, "Disable compiling of all enclosed files");
  103. m.addSeparator();
  104. m.addItem (5, "Sort Items Alphabetically");
  105. m.addItem (6, "Sort Items Alphabetically (Groups first)");
  106. m.addSeparator();
  107. if (! isRoot())
  108. {
  109. m.addItem (7, "Rename...");
  110. m.addItem (8, "Delete");
  111. }
  112. launchPopupMenu (m);
  113. }
  114. void showPlusMenu() override
  115. {
  116. PopupMenu m;
  117. addCreateFileMenuItems (m);
  118. launchPopupMenu (m);
  119. }
  120. void handlePopupMenuResult (int resultCode) override
  121. {
  122. switch (resultCode)
  123. {
  124. case 1: openOrCloseAllSubGroups (*this, false); break;
  125. case 2: openOrCloseAllSubGroups (*this, true); break;
  126. case 3: setFilesToCompile (item, true); break;
  127. case 4: setFilesToCompile (item, false); break;
  128. case 5: item.sortAlphabetically (false, false); break;
  129. case 6: item.sortAlphabetically (true, false); break;
  130. case 7: triggerAsyncRename (item); break;
  131. case 8: deleteAllSelectedItems(); break;
  132. default: processCreateFileMenuItem (resultCode); break;
  133. }
  134. }
  135. void addCreateFileMenuItems (PopupMenu& m)
  136. {
  137. m.addItem (1001, "Add New Group");
  138. m.addItem (1002, "Add Existing Files...");
  139. m.addSeparator();
  140. NewFileWizard().addWizardsToMenu (m);
  141. }
  142. void processCreateFileMenuItem (int menuID)
  143. {
  144. switch (menuID)
  145. {
  146. case 1001: addNewGroup(); break;
  147. case 1002: browseToAddExistingFiles(); break;
  148. default:
  149. jassert (getProject() != nullptr);
  150. NewFileWizard().runWizardFromMenu (menuID, *getProject(), item);
  151. break;
  152. }
  153. }
  154. Project* getProject()
  155. {
  156. if (TreeView* tv = getOwnerView())
  157. if (ProjectContentComponent* pcc = tv->findParentComponentOfClass<ProjectContentComponent>())
  158. return pcc->getProject();
  159. return nullptr;
  160. }
  161. };