ActionGroup.h 1023 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/HashTable.h>
  8. #include <AK/Weakable.h>
  9. #include <LibGUI/Forward.h>
  10. namespace GUI {
  11. class ActionGroup : public Weakable<ActionGroup> {
  12. public:
  13. ActionGroup() { }
  14. ~ActionGroup() { }
  15. void add_action(Action&);
  16. void remove_action(Action&);
  17. bool is_exclusive() const { return m_exclusive; }
  18. void set_exclusive(bool exclusive) { m_exclusive = exclusive; }
  19. bool is_unchecking_allowed() const { return m_unchecking_allowed; }
  20. void set_unchecking_allowed(bool unchecking_allowed) { m_unchecking_allowed = unchecking_allowed; }
  21. template<typename C>
  22. void for_each_action(C callback)
  23. {
  24. for (auto& it : m_actions) {
  25. if (callback(*it) == IterationDecision::Break)
  26. break;
  27. }
  28. }
  29. private:
  30. HashTable<Action*> m_actions;
  31. bool m_exclusive { false };
  32. bool m_unchecking_allowed { false };
  33. };
  34. }