(local { : Gtk : Gdk : WebKit2 : cairo } (require :lgi))

(fn new-buffer [name]
  (let [props {}
        widget (WebKit2.WebView {
                                 ;; :on_decide_policy
                                 ;; (fn [self decision dtype]
                                 ;;   (if (and
                                 ;;        (WebKit2.ResponsePolicyDecision:is_type_of decision)
                                 ;;        (not (decision:is_mime_type_supported)))
                                 ;;       (do
                                 ;;         (download decision.request.uri decision.response.http_headers)
                                 ;;         (decision:ignore)
                                 ;;         true)
                                 ;;       false))
                                 :on_notify
                                 (fn [self pspec]
                                    (when (not (= pspec.name :parent))
                                      (let [val (. self pspec.name)]
                                        (tset props pspec.name val)
                                        ;(listeners:notify pspec.name val)
                                        )))
                                 })]
    {:webview widget
     :visit (fn [self u] (print "visit " u) (widget:load_uri u))
     :properties props}))

(let [buffers {}]
  {
   :new (fn [name]
          (let [b (new-buffer name)]
            (tset buffers name b)
            b))
   :current (fn [] (let [k (next buffers)] (. buffers k)))
   :find (fn [self term] (. buffers term))
   })
