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.

107 lines
2.7KB

  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. struct ActivityList : public ChangeBroadcaster
  18. {
  19. ActivityList() {}
  20. void setList (const StringArray& newList)
  21. {
  22. checkThread();
  23. if (activities != newList)
  24. {
  25. const bool wasEmpty = isEmpty();
  26. activities = newList;
  27. sendChangeMessage();
  28. if (wasEmpty != isEmpty())
  29. ProjucerApplication::getCommandManager().commandStatusChanged();
  30. }
  31. }
  32. void clear()
  33. {
  34. setList (StringArray());
  35. }
  36. StringArray getActivities() const
  37. {
  38. checkThread();
  39. StringArray s;
  40. for (auto a : activities)
  41. s.add (a.upToFirstOccurrenceOf ("|||", false, false));
  42. return s;
  43. }
  44. bool isEmpty() const noexcept
  45. {
  46. return activities.size() == 0;
  47. }
  48. int getNumActivities() const
  49. {
  50. checkThread();
  51. return activities.size();
  52. }
  53. struct Listener
  54. {
  55. virtual ~Listener() {}
  56. virtual void classListChanged (const ClassDatabase::ClassList&) = 0;
  57. };
  58. void addListener (Listener* l)
  59. {
  60. checkThread();
  61. listeners.add (l);
  62. }
  63. void removeListener (Listener* l)
  64. {
  65. checkThread();
  66. listeners.remove (l);
  67. }
  68. void sendClassListChangedMessage (const ClassDatabase::ClassList& newList)
  69. {
  70. checkThread();
  71. listeners.call (&ActivityList::Listener::classListChanged, newList);
  72. }
  73. private:
  74. StringArray activities;
  75. ListenerList<Listener> listeners;
  76. static void checkThread()
  77. {
  78. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  79. }
  80. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ActivityList)
  81. };