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.

105 lines
2.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. #pragma once
  14. //==============================================================================
  15. struct ActivityList : public ChangeBroadcaster
  16. {
  17. ActivityList() {}
  18. void setList (const StringArray& newList)
  19. {
  20. checkThread();
  21. if (activities != newList)
  22. {
  23. const bool wasEmpty = isEmpty();
  24. activities = newList;
  25. sendChangeMessage();
  26. if (wasEmpty != isEmpty())
  27. ProjucerApplication::getCommandManager().commandStatusChanged();
  28. }
  29. }
  30. void clear()
  31. {
  32. setList (StringArray());
  33. }
  34. StringArray getActivities() const
  35. {
  36. checkThread();
  37. StringArray s;
  38. for (auto a : activities)
  39. s.add (a.upToFirstOccurrenceOf ("|||", false, false));
  40. return s;
  41. }
  42. bool isEmpty() const noexcept
  43. {
  44. return activities.size() == 0;
  45. }
  46. int getNumActivities() const
  47. {
  48. checkThread();
  49. return activities.size();
  50. }
  51. struct Listener
  52. {
  53. virtual ~Listener() {}
  54. virtual void classListChanged (const ClassDatabase::ClassList&) = 0;
  55. };
  56. void addListener (Listener* l)
  57. {
  58. checkThread();
  59. listeners.add (l);
  60. }
  61. void removeListener (Listener* l)
  62. {
  63. checkThread();
  64. listeners.remove (l);
  65. }
  66. void sendClassListChangedMessage (const ClassDatabase::ClassList& newList)
  67. {
  68. checkThread();
  69. listeners.call ([&] (Listener& l) { l.classListChanged (newList); });
  70. }
  71. private:
  72. StringArray activities;
  73. ListenerList<Listener> listeners;
  74. static void checkThread()
  75. {
  76. JUCE_ASSERT_MESSAGE_THREAD
  77. }
  78. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ActivityList)
  79. };