Browse Source

LibGUI: Add Menu::set_children_actions_enabled() helper

This adds a helper function to Menu that allows us to set all the
children enabled/disabled.
Marcus Nilsson 3 năm trước cách đây
mục cha
commit
708ec90bba
2 tập tin đã thay đổi với 10 bổ sung0 xóa
  1. 8 0
      Userland/Libraries/LibGUI/Menu.cpp
  2. 2 0
      Userland/Libraries/LibGUI/Menu.h

+ 8 - 0
Userland/Libraries/LibGUI/Menu.cpp

@@ -164,6 +164,14 @@ Action* Menu::action_at(size_t index)
     return m_items[index].action();
 }
 
+void Menu::set_children_actions_enabled(bool enabled)
+{
+    for (auto& item : m_items) {
+        if (item.action())
+            item.action()->set_enabled(enabled);
+    }
+}
+
 void Menu::visibility_did_change(Badge<WindowServerConnection>, bool visible)
 {
     if (m_visible == visible)

+ 2 - 0
Userland/Libraries/LibGUI/Menu.h

@@ -45,6 +45,8 @@ public:
 
     void visibility_did_change(Badge<WindowServerConnection>, bool visible);
 
+    void set_children_actions_enabled(bool enabled);
+
     Function<void(bool)> on_visibility_change;
 
     bool is_visible() const { return m_visible; }