(in-package :clim-user)

;(defvar *items*)

(define-application-frame items-from-list ()
  ((exit-command :accessor exit-command)
   (items :accessor items :initform nil :initarg :items))
  (:menu-bar t)
  (:panes
   (list (make-pane 'list-pane
                    :mode :nonexclusive
;                    :items *items*
                    :items (items *application-frame*)
		    )))
  (:layouts
   (default
    (scrolling (:scroll-bar :vertical)
      list))))

(macrolet ((frob (command)
             `(define-items-from-list-command (,command :name t :menu t) ()
                (setf (exit-command *application-frame*) ',command)
                (frame-exit *application-frame*))))
  (frob com-ok)
  (frob com-cancel))

(defun prompt-for-items-from-list (items)
  (flet ((get-list-pane (frame)
           (find-pane-named frame 'list)))
    (let* (;(*items* items)
           (frame (make-application-frame 'items-from-list :items items)))
      (run-frame-top-level frame)
      (ecase (exit-command frame)
        (com-ok
         (values (gadget-value (get-list-pane frame))
                 t))
        (com-cancel
         (values nil
                 nil))))))

;; (prompt-for-items-from-list '(1 2 3 4))
