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.

121 lines
2.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  19. //==============================================================================
  20. struct ErrorList : public ChangeBroadcaster
  21. {
  22. ErrorList() : warningsEnabled (true) {}
  23. void takeCopy (Array<DiagnosticMessage>& dest) const
  24. {
  25. checkThread();
  26. if (warningsEnabled)
  27. {
  28. dest = messages;
  29. }
  30. else
  31. {
  32. for (auto& d : messages)
  33. if (d.isError())
  34. dest.add (d);
  35. }
  36. }
  37. void resetToError (const String& message)
  38. {
  39. DiagnosticMessage m;
  40. m.message = message;
  41. m.type = DiagnosticMessage::error;
  42. DiagnosticList list;
  43. list.add (m);
  44. setList (list.toValueTree());
  45. }
  46. void setList (const ValueTree& newList)
  47. {
  48. checkThread();
  49. messages.clear();
  50. for (int i = 0; i < newList.getNumChildren(); ++i)
  51. messages.add (DiagnosticMessage::fromValueTree (newList.getChild(i)));
  52. sendChangeMessage();
  53. }
  54. bool isEmpty() const noexcept { return messages.size() == 0; }
  55. int getNumErrors() const
  56. {
  57. checkThread();
  58. int num = 0;
  59. for (const auto& m : messages)
  60. if (m.isError())
  61. ++num;
  62. return num;
  63. }
  64. int getNumWarnings() const
  65. {
  66. checkThread();
  67. int num = 0;
  68. for (const auto& m : messages)
  69. if (m.isWarning())
  70. ++num;
  71. return num;
  72. }
  73. void setWarningsEnabled (bool enabled)
  74. {
  75. if (warningsEnabled != enabled)
  76. {
  77. warningsEnabled = enabled;
  78. if (messages.size() > 0)
  79. sendChangeMessage();
  80. }
  81. }
  82. private:
  83. Array<DiagnosticMessage> messages;
  84. bool warningsEnabled;
  85. static void checkThread()
  86. {
  87. JUCE_ASSERT_MESSAGE_THREAD
  88. }
  89. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ErrorList)
  90. };