cocoa: avoid infinite loop on re-dispatch of command keys

This commit is contained in:
Matthew Flatt 2010-11-30 20:17:47 -07:00
parent d95e6f35c1
commit e627ccb5ed

View File

@ -35,6 +35,7 @@
"MrEd")) "MrEd"))
(define the-apple-menu #f) (define the-apple-menu #f)
(define recurring-for-command (make-parameter #f))
(define-objc-class MyBarMenu NSMenu (define-objc-class MyBarMenu NSMenu
[] []
@ -44,13 +45,16 @@
(or (and the-apple-menu (or (and the-apple-menu
(tell #:type _BOOL the-apple-menu performKeyEquivalent: evt)) (tell #:type _BOOL the-apple-menu performKeyEquivalent: evt))
;; Explicity send the event to the keyWindow: ;; Explicity send the event to the keyWindow:
(let ([w (tell app keyWindow)]) (and
(and w (not (recurring-for-command))
(let ([r (tell w firstResponder)]) (let ([w (tell app keyWindow)])
(and r (and w
(begin (let ([r (tell w firstResponder)])
(tell r keyDown: evt) (and r
#t)))))))) (begin
(parameterize ([recurring-for-command #t])
(tell r keyDown: evt))
#t)))))))))
(define cocoa-mb (tell (tell MyBarMenu alloc) init)) (define cocoa-mb (tell (tell MyBarMenu alloc) init))
(define current-mb #f) (define current-mb #f)