gpui: Add `is_action_available_in` function (#45029)

Anthony Eid created

This compliments the `window.is_action_available` function that already
exists.

Release Notes:

- N/A

Change summary

crates/gpui/src/window.rs | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

Detailed changes

crates/gpui/src/window.rs 🔗

@@ -1961,7 +1961,7 @@ impl Window {
     }
 
     /// Determine whether the given action is available along the dispatch path to the currently focused element.
-    pub fn is_action_available(&self, action: &dyn Action, cx: &mut App) -> bool {
+    pub fn is_action_available(&self, action: &dyn Action, cx: &App) -> bool {
         let node_id =
             self.focus_node_id_in_rendered_frame(self.focused(cx).map(|handle| handle.id));
         self.rendered_frame
@@ -1969,6 +1969,14 @@ impl Window {
             .is_action_available(action, node_id)
     }
 
+    /// Determine whether the given action is available along the dispatch path to the given focus_handle.
+    pub fn is_action_available_in(&self, action: &dyn Action, focus_handle: &FocusHandle) -> bool {
+        let node_id = self.focus_node_id_in_rendered_frame(Some(focus_handle.id));
+        self.rendered_frame
+            .dispatch_tree
+            .is_action_available(action, node_id)
+    }
+
     /// The position of the mouse relative to the window.
     pub fn mouse_position(&self) -> Point<Pixels> {
         self.mouse_position