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.

86 lines
2.8KB

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