Make macOS application menu aware of which key bindings are disabled (#2735)

Follow-up of https://github.com/zed-industries/zed/pull/2678
Deals with https://github.com/zed-industries/community/issues/772

Refreshes macOs menu panel on keymap file change and properly ignore
disabled actions.

Release Notes:

- Fixes a bug when disabled actions from macOs menu were still working
This commit is contained in:
Max Brunsfeld 2023-07-17 11:20:41 -07:00 committed by GitHub
commit fef73ae921
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 395 additions and 73 deletions

View file

@ -517,11 +517,7 @@ pub fn handle_keymap_file_changes(
let mut settings_subscription = None;
while let Some(user_keymap_content) = user_keymap_file_rx.next().await {
if let Ok(keymap_content) = KeymapFile::parse(&user_keymap_content) {
cx.update(|cx| {
cx.clear_bindings();
load_default_keymap(cx);
keymap_content.clone().add_to_cx(cx).log_err();
});
cx.update(|cx| reload_keymaps(cx, &keymap_content));
let mut old_base_keymap = cx.read(|cx| *settings::get::<BaseKeymap>(cx));
drop(settings_subscription);
@ -530,10 +526,7 @@ pub fn handle_keymap_file_changes(
let new_base_keymap = *settings::get::<BaseKeymap>(cx);
if new_base_keymap != old_base_keymap {
old_base_keymap = new_base_keymap.clone();
cx.clear_bindings();
load_default_keymap(cx);
keymap_content.clone().add_to_cx(cx).log_err();
reload_keymaps(cx, &keymap_content);
}
})
.detach();
@ -544,6 +537,13 @@ pub fn handle_keymap_file_changes(
.detach();
}
fn reload_keymaps(cx: &mut AppContext, keymap_content: &KeymapFile) {
cx.clear_bindings();
load_default_keymap(cx);
keymap_content.clone().add_to_cx(cx).log_err();
cx.set_menus(menus::menus());
}
fn open_local_settings_file(
workspace: &mut Workspace,
_: &OpenLocalSettings,