ActionGroup.h 1.1 KB

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