diff --git a/source/clog-gui.lisp b/source/clog-gui.lisp index dce33c0..ce9103b 100644 --- a/source/clog-gui.lisp +++ b/source/clog-gui.lisp @@ -842,7 +842,8 @@ the browser.")) (defmethod window-close ((obj clog-gui-window)) (let ((app (connection-data-item obj "clog-gui"))) (remhash (format nil "~A" (html-id obj)) (windows app)) - (destroy (window-select-item obj)) + (when (window-select app) + (destroy (window-select-item obj))) (remove-from-dom obj) (fire-on-window-change nil app) (fire-on-window-close obj))) @@ -1356,7 +1357,7 @@ Calls on-input with t if confirmed or nil if canceled." (unless left (setf (left win) (unit :px (- (/ (inner-width (window body)) 2.0) (/ (width win) 2.0))))) - (setf (visible win) t) + (setf (visiblep win) t) (when modal (window-make-modal win)) (set-on-click cancel (lambda (obj) diff --git a/tutorial/23-tutorial.lisp b/tutorial/23-tutorial.lisp index 04e8742..0092b35 100644 --- a/tutorial/23-tutorial.lisp +++ b/tutorial/23-tutorial.lisp @@ -5,16 +5,20 @@ (in-package :clog-user) ;; This is a simple demo using semaphores to wait for user input +;; ask demonstrates the mechanics in general and the modal dialog +;; example show a more practical example. (defun ask (obj) (let ((result nil) (hold (bordeaux-threads:make-semaphore)) (q-box (create-div obj))) (set-on-click (create-button q-box :content "Yes") (lambda (obj) + (declare (ignore obj)) (setf result :yes) (bordeaux-threads:signal-semaphore hold))) (set-on-click (create-button q-box :content "No") (lambda (obj) + (declare (ignore obj)) (setf result :no) (bordeaux-threads:signal-semaphore hold))) (bordeaux-threads:wait-on-semaphore hold :timeout 10) @@ -22,10 +26,26 @@ result)) (defun on-new-window (body) + ;; clog-gui can be mixed in to non-desktop environments, but + ;; to use you must call first clog-gui-initialize + (clog-gui-initialize body) (set-on-click (create-button body :content "Click for my question. You have 10 seconds to answer.") (lambda (obj) - (create-div body :content (ask body)))) + (declare (ignore obj)) + ;; ask returns once an answer is given or times out + (create-div body :content (ask body)) + ;; once ask returns with its answer (yes no or nil for timeout) + ;; the next statment is processed to open a dialog + (let ((hold (bordeaux-threads:make-semaphore))) + (confirm-dialog body "Are you sure?" + (lambda (answer) + (if answer + (create-div body :content "Great!") + (create-div body :content "Next time be sure!")) + (bordeaux-threads:signal-semaphore hold))) + (bordeaux-threads:wait-on-semaphore hold :timeout 60) + (create-div body :content "Thank you for answering!")))) (run body)) (defun start-tutorial ()