mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-09 00:50:04 +03:00
Fixed keyboard shortcuts in mac os native panels
co-authored-by: Antonio <antonio@zed.dev>
This commit is contained in:
parent
71d8ead318
commit
4798b72cb8
@ -98,6 +98,31 @@ unsafe fn build_classes() {
|
|||||||
sel!(handleGPUIMenuItem:),
|
sel!(handleGPUIMenuItem:),
|
||||||
handle_menu_item as extern "C" fn(&mut Object, Sel, id),
|
handle_menu_item as extern "C" fn(&mut Object, Sel, id),
|
||||||
);
|
);
|
||||||
|
// Add menu item handlers so that OS save panels have the correct key commands
|
||||||
|
decl.add_method(
|
||||||
|
sel!(cut:),
|
||||||
|
handle_menu_item as extern "C" fn(&mut Object, Sel, id),
|
||||||
|
);
|
||||||
|
decl.add_method(
|
||||||
|
sel!(copy:),
|
||||||
|
handle_menu_item as extern "C" fn(&mut Object, Sel, id),
|
||||||
|
);
|
||||||
|
decl.add_method(
|
||||||
|
sel!(paste:),
|
||||||
|
handle_menu_item as extern "C" fn(&mut Object, Sel, id),
|
||||||
|
);
|
||||||
|
decl.add_method(
|
||||||
|
sel!(selectAll:),
|
||||||
|
handle_menu_item as extern "C" fn(&mut Object, Sel, id),
|
||||||
|
);
|
||||||
|
decl.add_method(
|
||||||
|
sel!(undo:),
|
||||||
|
handle_menu_item as extern "C" fn(&mut Object, Sel, id),
|
||||||
|
);
|
||||||
|
decl.add_method(
|
||||||
|
sel!(redo:),
|
||||||
|
handle_menu_item as extern "C" fn(&mut Object, Sel, id),
|
||||||
|
);
|
||||||
decl.add_method(
|
decl.add_method(
|
||||||
sel!(validateMenuItem:),
|
sel!(validateMenuItem:),
|
||||||
validate_menu_item as extern "C" fn(&mut Object, Sel, id) -> bool,
|
validate_menu_item as extern "C" fn(&mut Object, Sel, id) -> bool,
|
||||||
@ -193,12 +218,25 @@ impl MacForegroundPlatform {
|
|||||||
) -> id {
|
) -> id {
|
||||||
match item {
|
match item {
|
||||||
MenuItem::Separator => NSMenuItem::separatorItem(nil),
|
MenuItem::Separator => NSMenuItem::separatorItem(nil),
|
||||||
MenuItem::Action { name, action, .. } => {
|
MenuItem::Action {
|
||||||
|
name,
|
||||||
|
action,
|
||||||
|
os_action,
|
||||||
|
} => {
|
||||||
// TODO
|
// TODO
|
||||||
let keystrokes = keystroke_matcher
|
let keystrokes = keystroke_matcher
|
||||||
.bindings_for_action_type(action.as_any().type_id())
|
.bindings_for_action_type(action.as_any().type_id())
|
||||||
.find(|binding| binding.action().eq(action.as_ref()))
|
.find(|binding| binding.action().eq(action.as_ref()))
|
||||||
.map(|binding| binding.keystrokes());
|
.map(|binding| binding.keystrokes());
|
||||||
|
let selector = match os_action {
|
||||||
|
Some(crate::OsAction::Cut) => selector("cut:"),
|
||||||
|
Some(crate::OsAction::Copy) => selector("copy:"),
|
||||||
|
Some(crate::OsAction::Paste) => selector("paste:"),
|
||||||
|
Some(crate::OsAction::SelectAll) => selector("selectAll:"),
|
||||||
|
Some(crate::OsAction::Undo) => selector("undo:"),
|
||||||
|
Some(crate::OsAction::Redo) => selector("redo:"),
|
||||||
|
None => selector("handleGPUIMenuItem:"),
|
||||||
|
};
|
||||||
|
|
||||||
let item;
|
let item;
|
||||||
if let Some(keystrokes) = keystrokes {
|
if let Some(keystrokes) = keystrokes {
|
||||||
@ -219,7 +257,7 @@ impl MacForegroundPlatform {
|
|||||||
item = NSMenuItem::alloc(nil)
|
item = NSMenuItem::alloc(nil)
|
||||||
.initWithTitle_action_keyEquivalent_(
|
.initWithTitle_action_keyEquivalent_(
|
||||||
ns_string(name),
|
ns_string(name),
|
||||||
selector("handleGPUIMenuItem:"),
|
selector,
|
||||||
ns_string(key_to_native(&keystroke.key).as_ref()),
|
ns_string(key_to_native(&keystroke.key).as_ref()),
|
||||||
)
|
)
|
||||||
.autorelease();
|
.autorelease();
|
||||||
@ -241,7 +279,7 @@ impl MacForegroundPlatform {
|
|||||||
item = NSMenuItem::alloc(nil)
|
item = NSMenuItem::alloc(nil)
|
||||||
.initWithTitle_action_keyEquivalent_(
|
.initWithTitle_action_keyEquivalent_(
|
||||||
ns_string(&name),
|
ns_string(&name),
|
||||||
selector("handleGPUIMenuItem:"),
|
selector,
|
||||||
ns_string(""),
|
ns_string(""),
|
||||||
)
|
)
|
||||||
.autorelease();
|
.autorelease();
|
||||||
@ -250,7 +288,7 @@ impl MacForegroundPlatform {
|
|||||||
item = NSMenuItem::alloc(nil)
|
item = NSMenuItem::alloc(nil)
|
||||||
.initWithTitle_action_keyEquivalent_(
|
.initWithTitle_action_keyEquivalent_(
|
||||||
ns_string(name),
|
ns_string(name),
|
||||||
selector("handleGPUIMenuItem:"),
|
selector,
|
||||||
ns_string(""),
|
ns_string(""),
|
||||||
)
|
)
|
||||||
.autorelease();
|
.autorelease();
|
||||||
|
Loading…
Reference in New Issue
Block a user