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.

173 lines
5.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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 addFiles (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.addFile (file, insertIndex, true))
  44. ++insertIndex;
  45. }
  46. }
  47. void moveSelectedItemsTo (OwnedArray<Project::Item>& selectedNodes, int insertIndex) override
  48. {
  49. moveItems (selectedNodes, item, insertIndex);
  50. }
  51. void checkFileStatus() override
  52. {
  53. for (int i = 0; i < getNumSubItems(); ++i)
  54. if (ProjectTreeItemBase* p = dynamic_cast<ProjectTreeItemBase*> (getSubItem(i)))
  55. p->checkFileStatus();
  56. }
  57. ProjectTreeItemBase* createSubItem (const Project::Item& child) override
  58. {
  59. if (child.isGroup()) return new GroupItem (child);
  60. if (child.isFile()) return new SourceFileItem (child);
  61. jassertfalse;
  62. return nullptr;
  63. }
  64. void showDocument() override
  65. {
  66. if (ProjectContentComponent* pcc = getProjectContentComponent())
  67. pcc->setEditorComponent (new GroupInformationComponent (item), nullptr);
  68. }
  69. static void openOrCloseAllSubGroups (TreeViewItem& item, bool shouldOpen)
  70. {
  71. item.setOpen (shouldOpen);
  72. for (int i = item.getNumSubItems(); --i >= 0;)
  73. if (TreeViewItem* sub = item.getSubItem(i))
  74. openOrCloseAllSubGroups (*sub, shouldOpen);
  75. }
  76. static void setFilesToCompile (Project::Item item, const bool shouldCompile)
  77. {
  78. if (item.isFile())
  79. item.getShouldCompileValue() = shouldCompile;
  80. for (int i = item.getNumChildren(); --i >= 0;)
  81. setFilesToCompile (item.getChild (i), shouldCompile);
  82. }
  83. void showPopupMenu() override
  84. {
  85. PopupMenu m;
  86. addCreateFileMenuItems (m);
  87. m.addSeparator();
  88. if (isOpen())
  89. m.addItem (1, "Collapse all Sub-groups");
  90. else
  91. m.addItem (2, "Expand all Sub-groups");
  92. m.addSeparator();
  93. m.addItem (3, "Enable compiling of all enclosed files");
  94. m.addItem (4, "Disable compiling of all enclosed files");
  95. m.addSeparator();
  96. m.addItem (5, "Sort Items Alphabetically");
  97. m.addItem (6, "Sort Items Alphabetically (Groups first)");
  98. m.addSeparator();
  99. m.addItem (7, "Rename...");
  100. if (! isRoot())
  101. m.addItem (8, "Delete");
  102. launchPopupMenu (m);
  103. }
  104. void handlePopupMenuResult (int resultCode) override
  105. {
  106. switch (resultCode)
  107. {
  108. case 1: openOrCloseAllSubGroups (*this, false); break;
  109. case 2: openOrCloseAllSubGroups (*this, true); break;
  110. case 3: setFilesToCompile (item, true); break;
  111. case 4: setFilesToCompile (item, false); break;
  112. case 5: item.sortAlphabetically (false); break;
  113. case 6: item.sortAlphabetically (true); break;
  114. case 7: triggerAsyncRename (item); break;
  115. case 8: deleteAllSelectedItems(); break;
  116. default: processCreateFileMenuItem (resultCode); break;
  117. }
  118. }
  119. void addCreateFileMenuItems (PopupMenu& m)
  120. {
  121. m.addItem (1001, "Add New Group");
  122. m.addItem (1002, "Add Existing Files...");
  123. m.addSeparator();
  124. NewFileWizard().addWizardsToMenu (m);
  125. }
  126. void processCreateFileMenuItem (int menuID)
  127. {
  128. switch (menuID)
  129. {
  130. case 1001: addNewGroup(); break;
  131. case 1002: browseToAddExistingFiles(); break;
  132. default:
  133. NewFileWizard().runWizardFromMenu (menuID, item);
  134. break;
  135. }
  136. }
  137. };