Add AppContext::dispatch_action and use it for app menu actions

Co-Authored-By: Marshall <marshall@zed.dev>
Co-Authored-By: Julia <julia@zed.dev>
This commit is contained in:
Nathan Sobo 2023-12-05 15:49:06 -07:00
parent 631e264e3c
commit 79567d1c87
5 changed files with 73 additions and 33 deletions

View file

@ -53,14 +53,14 @@ pub enum OsAction {
}
pub(crate) fn init(platform: &dyn Platform, cx: &mut AppContext) {
platform.on_will_open_menu(Box::new({
platform.on_will_open_app_menu(Box::new({
let cx = cx.to_async();
move || {
cx.update(|cx| cx.clear_pending_keystrokes()).ok();
}
}));
platform.on_validate_menu_command(Box::new({
platform.on_validate_app_menu_command(Box::new({
let cx = cx.to_async();
move |action| {
cx.update(|cx| cx.is_action_available(action))
@ -68,29 +68,10 @@ pub(crate) fn init(platform: &dyn Platform, cx: &mut AppContext) {
}
}));
platform.on_menu_command(Box::new({
platform.on_app_menu_action(Box::new({
let cx = cx.to_async();
move |action| {
cx.update(|cx| {
// if let Some(main_window) = cx.active_window() {
// let dispatched = main_window
// .update(&mut *cx, |cx| {
// if let Some(view_id) = cx.focused_view_id() {
// cx.dispatch_action(Some(view_id), action);
// true
// } else {
// false
// }
// })
// .unwrap_or(false);
// if dispatched {
// return;
// }
// }
// cx.dispatch_global_action_any(action);
})
.log_err();
cx.update(|cx| cx.dispatch_action(action)).log_err();
}
}));
}