Audio plugin host https://kx.studio/carla
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.

85 lines
2.6KB

  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. MenuBarModel::MenuBarModel() noexcept
  18. : manager (nullptr)
  19. {
  20. }
  21. MenuBarModel::~MenuBarModel()
  22. {
  23. setApplicationCommandManagerToWatch (nullptr);
  24. }
  25. //==============================================================================
  26. void MenuBarModel::menuItemsChanged()
  27. {
  28. triggerAsyncUpdate();
  29. }
  30. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) noexcept
  31. {
  32. if (manager != newManager)
  33. {
  34. if (manager != nullptr)
  35. manager->removeListener (this);
  36. manager = newManager;
  37. if (manager != nullptr)
  38. manager->addListener (this);
  39. }
  40. }
  41. void MenuBarModel::addListener (Listener* const newListener) noexcept
  42. {
  43. listeners.add (newListener);
  44. }
  45. void MenuBarModel::removeListener (Listener* const listenerToRemove) noexcept
  46. {
  47. // Trying to remove a listener that isn't on the list!
  48. // If this assertion happens because this object is a dangling pointer, make sure you've not
  49. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  50. jassert (listeners.contains (listenerToRemove));
  51. listeners.remove (listenerToRemove);
  52. }
  53. //==============================================================================
  54. void MenuBarModel::handleAsyncUpdate()
  55. {
  56. listeners.call (&MenuBarModel::Listener::menuBarItemsChanged, this);
  57. }
  58. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  59. {
  60. listeners.call (&MenuBarModel::Listener::menuCommandInvoked, this, info);
  61. }
  62. void MenuBarModel::applicationCommandListChanged()
  63. {
  64. menuItemsChanged();
  65. }