[mcclim-cvs] CVS mcclim/Examples

thenriksen thenriksen at common-lisp.net
Sun Oct 29 23:13:48 UTC 2006


Update of /project/mcclim/cvsroot/mcclim/Examples
In directory clnet:/tmp/cvs-serv3353/Examples

Modified Files:
	views.lisp 
Log Message:
Added a present and accept method so the parameters to command won't
look quite as ugly.


--- /project/mcclim/cvsroot/mcclim/Examples/views.lisp	2006/10/29 15:27:31	1.1
+++ /project/mcclim/cvsroot/mcclim/Examples/views.lisp	2006/10/29 23:13:48	1.2
@@ -50,6 +50,31 @@
         (make-person "Smith" "Eliza" "22, Trafalgar Square" 121212)
         (make-person "Nilsson" "Sven" "Uppsalagatan 33" 98765)))
 
+;;; we define a present method that is called when CLIM is told to
+;;; display a person object to the user.
+(define-presentation-method present ((object person) (type person) 
+                                     stream view &key)
+  (declare (ignore view))
+  (format stream "~A ~A" (first-name object) (last-name object)))
+
+;; we also define an accept method that CLIM uses to convert text
+;; input to a person. Note that the text generated by the present
+;; method is acceptable input for the accept method.
+(define-presentation-method accept ((type person) stream view &key)
+  ;; this means we can have spaces in the input.
+  (with-delimiter-gestures (nil :override t)
+    ;; we just ask for a string and complain if it isn't a known
+    ;; name. We also do not want to show another input prompt, hence
+    ;; the :prompt and :prompt-mode parameters.
+    (let ((name (accept 'string :stream stream :view view
+                        :prompt "" :prompt-mode :raw)))
+      (or (find name *members*
+                :test #'string=
+                :key #'(lambda (person)
+                         (format nil "~A ~A" (first-name person)
+                                             (last-name person))))
+          (simple-parse-error "~A is not a known person" name)))))
+
 ;;; the CLIM view class that corresponds to a list of members, one member
 ;;; per line of text in a CLIM application pane. 
 (defclass members-view (view) ())




More information about the Mcclim-cvs mailing list