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.

92 lines
2.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. BEGIN_JUCE_NAMESPACE
  19. //==============================================================================
  20. MenuBarModel::MenuBarModel() noexcept
  21. : manager (nullptr)
  22. {
  23. }
  24. MenuBarModel::~MenuBarModel()
  25. {
  26. setApplicationCommandManagerToWatch (nullptr);
  27. }
  28. //==============================================================================
  29. void MenuBarModel::menuItemsChanged()
  30. {
  31. triggerAsyncUpdate();
  32. }
  33. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) noexcept
  34. {
  35. if (manager != newManager)
  36. {
  37. if (manager != nullptr)
  38. manager->removeListener (this);
  39. manager = newManager;
  40. if (manager != nullptr)
  41. manager->addListener (this);
  42. }
  43. }
  44. void MenuBarModel::addListener (Listener* const newListener) noexcept
  45. {
  46. listeners.add (newListener);
  47. }
  48. void MenuBarModel::removeListener (Listener* const listenerToRemove) noexcept
  49. {
  50. // Trying to remove a listener that isn't on the list!
  51. // If this assertion happens because this object is a dangling pointer, make sure you've not
  52. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  53. jassert (listeners.contains (listenerToRemove));
  54. listeners.remove (listenerToRemove);
  55. }
  56. //==============================================================================
  57. void MenuBarModel::handleAsyncUpdate()
  58. {
  59. listeners.call (&MenuBarModel::Listener::menuBarItemsChanged, this);
  60. }
  61. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  62. {
  63. listeners.call (&MenuBarModel::Listener::menuCommandInvoked, this, info);
  64. }
  65. void MenuBarModel::applicationCommandListChanged()
  66. {
  67. menuItemsChanged();
  68. }
  69. END_JUCE_NAMESPACE