add gtk stuff to show completions as user types
This commit is contained in:
parent
36edd12c6e
commit
e4ed51e137
@ -34,4 +34,9 @@
|
|||||||
(tset buffers name b)
|
(tset buffers name b)
|
||||||
b))
|
b))
|
||||||
:find (fn [term] (. buffers term))
|
:find (fn [term] (. buffers term))
|
||||||
|
;; will rename this to "find" once we've got rid of the
|
||||||
|
;; only remaining call to the existing Buffer.find
|
||||||
|
:match (fn [s] (collect [name buffer (pairs buffers)]
|
||||||
|
(if (string.find name s)
|
||||||
|
(values name buffer))))
|
||||||
})
|
})
|
||||||
|
42
command.fnl
42
command.fnl
@ -23,8 +23,10 @@
|
|||||||
|
|
||||||
(define-command
|
(define-command
|
||||||
"visit-location"
|
"visit-location"
|
||||||
[[:buffer #[$1] (fn [f] f.buffer.name)]
|
[[:buffer
|
||||||
[:url #[$1] #(do "http://www.example.com")]
|
Buffer.match
|
||||||
|
#"main"]
|
||||||
|
[:url #(doto {} (tset $1 $1)) #(do "http://www.example.com")]
|
||||||
]
|
]
|
||||||
(fn [{:url url :buffer buffer}]
|
(fn [{:url url :buffer buffer}]
|
||||||
(let [b (Buffer.find buffer)] (: b :visit url))))
|
(let [b (Buffer.find buffer)] (: b :visit url))))
|
||||||
@ -98,11 +100,30 @@
|
|||||||
:default (and param (param.default self.frame))
|
:default (and param (param.default self.frame))
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(fn update-widget-state [{ : entry : prompt} result]
|
(fn update-widget-state [{ : entry : completions-widget : prompt} result]
|
||||||
(set prompt.label (or result.prompt ""))
|
(set prompt.label (or result.prompt ""))
|
||||||
(set entry.sensitive result.active)
|
(set entry.sensitive result.active)
|
||||||
|
(if (not result.active)
|
||||||
|
(completions-widget:hide))
|
||||||
(set entry.text (or result.default result.error "")))
|
(set entry.text (or result.default result.error "")))
|
||||||
|
|
||||||
|
(fn on-input [self str]
|
||||||
|
(match self.state
|
||||||
|
{:command c :this-param param-name}
|
||||||
|
(let [parent self.completions-widget
|
||||||
|
{ : completer} (. c.params param-name)
|
||||||
|
completions (completer str)]
|
||||||
|
(parent:foreach #(parent:remove $1))
|
||||||
|
(each [text _w (pairs completions)]
|
||||||
|
(parent:add (Gtk.Button {
|
||||||
|
:label text
|
||||||
|
:on_clicked
|
||||||
|
#(update-widget-state self (self:on-activate text))
|
||||||
|
})))
|
||||||
|
(parent:show_all)
|
||||||
|
)))
|
||||||
|
|
||||||
|
|
||||||
(fn activate [{: state : entry : prompt}]
|
(fn activate [{: state : entry : prompt}]
|
||||||
(tset state :active true)
|
(tset state :active true)
|
||||||
(set entry.sensitive true)
|
(set entry.sensitive true)
|
||||||
@ -130,21 +151,32 @@
|
|||||||
(let [entry (Gtk.Entry {:sensitive false })
|
(let [entry (Gtk.Entry {:sensitive false })
|
||||||
prompt (Gtk.Label { :label ""})
|
prompt (Gtk.Label { :label ""})
|
||||||
box (Gtk.Box {
|
box (Gtk.Box {
|
||||||
|
:orientation Gtk.Orientation.VERTICAL
|
||||||
|
})
|
||||||
|
hbox (Gtk.Box {
|
||||||
:orientation Gtk.Orientation.HORIZONTAL
|
:orientation Gtk.Orientation.HORIZONTAL
|
||||||
})
|
})
|
||||||
|
completions (Gtk.FlowBox)
|
||||||
self {
|
self {
|
||||||
:state default-state
|
:state default-state
|
||||||
: activate
|
: activate
|
||||||
:active? (fn [self] self.state.active)
|
:active? (fn [self] self.state.active)
|
||||||
|
: on-input
|
||||||
: on-activate
|
: on-activate
|
||||||
: invoke-interactively
|
: invoke-interactively
|
||||||
: entry
|
: entry
|
||||||
:widget box
|
:widget box
|
||||||
: prompt
|
: prompt
|
||||||
: frame
|
: frame
|
||||||
|
:completions-widget completions
|
||||||
}]
|
}]
|
||||||
(box:pack_start prompt false false 15)
|
(hbox:pack_start prompt false false 15)
|
||||||
(box:pack_start entry true true 5)
|
(hbox:pack_start entry true true 5)
|
||||||
|
(box:pack_start hbox true false 0)
|
||||||
|
(box:pack_start completions true true 0)
|
||||||
|
(tset entry :on_changed
|
||||||
|
(fn [event]
|
||||||
|
(self:on-input event.text)))
|
||||||
(tset entry :on_activate
|
(tset entry :on_activate
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(let [result (self:on-activate event.text)]
|
(let [result (self:on-activate event.text)]
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
(Command.define-command
|
(Command.define-command
|
||||||
"multiply"
|
"multiply"
|
||||||
[[:a #[$1] #(do "3")]
|
[[:a #{$1 $1} #"3"]
|
||||||
[:b #[$1] #(do "2")]]
|
[:b #{$1 $1} #"2"]]
|
||||||
(fn [{: a : b }] (set happened (* (tonumber a) (tonumber b)))))
|
(fn [{: a : b }] (set happened (* (tonumber a) (tonumber b)))))
|
||||||
|
|
||||||
(before)
|
(before)
|
||||||
|
Loading…
Reference in New Issue
Block a user