-
Notifications
You must be signed in to change notification settings - Fork 1
/
keybinding.rkt
46 lines (40 loc) · 1.28 KB
/
keybinding.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#lang s-exp framework/keybinding-lang
(define (menu-bind key menu-item)
(keybinding
key
(λ (ed evt)
(define canvas (send ed get-canvas))
(when canvas
(define menu-bar (find-menu-bar canvas))
(when menu-bar
(define item (find-item menu-bar menu-item))
(when item
(define menu-evt
(new control-event%
[event-type 'menu]
[time-stamp
(send evt get-time-stamp)]))
(send item command menu-evt)))))))
(define/contract (find-menu-bar c)
(-> (is-a?/c area<%>) (or/c #f (is-a?/c menu-bar%)))
(let loop ([c c])
(cond
[(is-a? c frame%) (send c get-menu-bar)]
[(is-a? c area<%>) (loop (send c get-parent))]
[else #f])))
(define/contract (find-item menu-bar label)
(-> (is-a?/c menu-bar%)
string?
(or/c (is-a?/c selectable-menu-item<%>) #f))
(let loop ([o menu-bar])
(cond
[(is-a? o selectable-menu-item<%>)
(and (equal? (send o get-plain-label) label)
o)]
[(is-a? o menu-item-container<%>)
(for/or ([i (in-list (send o get-items))])
(loop i))]
[else #f])))
(menu-bind "c:a" "Run")
(menu-bind "c:/" "Comment Out with Semicolons")
(menu-bind "c:\\" "Uncomment")