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.

116 lines
2.9KB

  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 ErrorList : public ChangeBroadcaster
  18. {
  19. ErrorList() : warningsEnabled (true) {}
  20. void takeCopy (Array<DiagnosticMessage>& dest) const
  21. {
  22. checkThread();
  23. if (warningsEnabled)
  24. {
  25. dest = messages;
  26. }
  27. else
  28. {
  29. for (DiagnosticMessage& d : messages)
  30. if (d.isError())
  31. dest.add (d);
  32. }
  33. }
  34. void resetToError (const String& message)
  35. {
  36. DiagnosticMessage m;
  37. m.message = message;
  38. m.type = DiagnosticMessage::error;
  39. DiagnosticList list;
  40. list.add (m);
  41. setList (list.toValueTree());
  42. }
  43. void setList (const ValueTree& newList)
  44. {
  45. checkThread();
  46. messages.clear();
  47. for (int i = 0; i < newList.getNumChildren(); ++i)
  48. messages.add (DiagnosticMessage::fromValueTree (newList.getChild(i)));
  49. sendChangeMessage();
  50. }
  51. bool isEmpty() const noexcept { return messages.size() == 0; }
  52. int getNumErrors() const
  53. {
  54. checkThread();
  55. int num = 0;
  56. for (const auto& m : messages)
  57. if (m.isError())
  58. ++num;
  59. return num;
  60. }
  61. int getNumWarnings() const
  62. {
  63. checkThread();
  64. int num = 0;
  65. for (const auto& m : messages)
  66. if (m.isWarning())
  67. ++num;
  68. return num;
  69. }
  70. void setWarningsEnabled (bool enabled)
  71. {
  72. if (warningsEnabled != enabled)
  73. {
  74. warningsEnabled = enabled;
  75. if (messages.size() > 0)
  76. sendChangeMessage();
  77. }
  78. }
  79. private:
  80. Array<DiagnosticMessage> messages;
  81. bool warningsEnabled;
  82. static void checkThread()
  83. {
  84. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  85. }
  86. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ErrorList)
  87. };