1 (in-package :lisp-on-lines
)
3 (define-description editable
()
7 (define-layered-class standard-attribute
8 :in-layer
#.
(defining-description 'editable
)
12 :layered-accessor attribute-editp
18 :accessor attribute-setter
23 :accessor attribute-editor
24 :initform
(make-instance 'attribute-editor
)
25 :documentation
"This ones a bit odd")))
27 (defmethod shared-initialize :after
((object standard-attribute
)
28 slots
&rest args
&key input
&allow-other-keys
)
31 (setf (attribute-editor object
)
32 (apply #'make-instance
(find-editor-class input
)
36 (defun find-editor-class (spec)
37 (let ((class (getf spec
:class
))
38 (type (getf spec
:type
)))
40 (and type
(symbolp type
))
41 (let ((name (format nil
"~A-~A" type
'attribute-editor
)))
42 (or (find-class (intern name
(symbol-package type
)) nil
)
43 (find-class (intern name
) nil
)
44 'string-attribute-editor
))))))
46 (defclass attribute-editor
()
47 ((class :initarg
:class
)
50 :accessor attribute-editor-type
)
51 (parser :initarg
:parse-using
53 :accessor attribute-editor-parsing-function
)
54 (prompt :initarg
:prompt
57 :initarg
:unbound-value
62 (defclass string-attribute-editor
(attribute-editor) ())
63 (defclass text-attribute-editor
(string-attribute-editor) ())
65 (deftype password
() 'string
)
67 (defclass password-attribute-editor
(string-attribute-editor) ())
69 (defclass number-attribute-editor
(attribute-editor) ()
71 :parse-using
'parse-number
:PARSE-NUMBER
74 (defun parse-attribute-value (attribute value
)
75 (funcall (attribute-editor-parsing-function
76 (attribute-editor attribute
))
79 (define-layered-function display-attribute-editor
(attribute)
81 (setf (attribute-value attribute
)
82 (funcall (attribute-editor-parsing-function
83 (attribute-editor attribute
))
86 (define-description T
()
87 ((editp :label
"Edit by Default?"
93 (:in-description editable
))
95 (define-layered-method (setf attribute-value-using-object
)
96 :in-layer
#.
(defining-description 'editable
)(value object attribute
)
98 (let ((setter (attribute-setter attribute
)))
100 (funcall setter value object
)
101 (error "No setter in ~A for ~A" attribute object
))))
104 (define-layered-function attribute-editp
(attribute)
105 (:method
(attribute) nil
))
107 (define-layered-method attribute-editp
108 :in-layer
#.
(defining-description 'editable
)
109 ((attribute standard-attribute
))
110 (let ((value (attribute-value attribute
)))
111 (unless (or (unbound-slot-value-p value
)
113 (attribute-editor-type
114 (attribute-editor attribute
))))
115 (return-from attribute-editp nil
)))
116 (let ((edit?
(call-next-method)))
117 (if (eq :inherit edit?
)
118 (attribute-value (find-attribute
119 (attribute-description attribute
)
124 (define-layered-method display-attribute-value
125 :in-layer
#.
(defining-description 'editable
)
126 ((attribute standard-attribute
))
127 (if (attribute-editp attribute
)
128 (display-attribute-editor attribute
)