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.

114 lines
2.6KB

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