ESC cancels command
This commit is contained in:
parent
0f9d93630e
commit
3fac6a2601
17
command.fnl
17
command.fnl
@ -139,14 +139,22 @@
|
||||
)))
|
||||
|
||||
|
||||
(fn activate [{: state : entry : prompt}]
|
||||
(fn activate [{: state : entry : prompt &as self}]
|
||||
(tset state :active true)
|
||||
(set entry.sensitive true)
|
||||
(set entry.text "")
|
||||
(set prompt.label (or state.this-param "Command" ""))
|
||||
(update-widget-state
|
||||
self
|
||||
{:active true
|
||||
:prompt (or state.this-param "Command" "")
|
||||
})
|
||||
(entry:grab_focus)
|
||||
state)
|
||||
|
||||
(fn deactivate [{: state : entry : prompt &as self}]
|
||||
(doto state
|
||||
(lume.clear)
|
||||
(tset :active false))
|
||||
(update-widget-state self {:active false}))
|
||||
|
||||
(fn invoke-interactively [self name params]
|
||||
(let [c (find-command name)
|
||||
supplied-params (collect [k v (pairs params)]
|
||||
@ -175,6 +183,7 @@
|
||||
self {
|
||||
:state default-state
|
||||
: activate
|
||||
: deactivate
|
||||
:active? (fn [self] self.state.active)
|
||||
: on-input
|
||||
: on-activate
|
||||
|
@ -45,6 +45,10 @@
|
||||
(match (recogniser:accept-event event)
|
||||
[name params] (commander:invoke-interactively name params)
|
||||
(nil prompt) (print "prompted" prompt)))
|
||||
(when (and (commander:active?)
|
||||
(= (Gdk.keyval_name event.keyval) "Escape"))
|
||||
(commander:deactivate))
|
||||
|
||||
(when (and event.state.MOD1_MASK
|
||||
(= event.keyval (string.byte "x")))
|
||||
(commander:activate))))
|
||||
|
Loading…
Reference in New Issue
Block a user