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 (unless (eq (find-package :cl
)
43 (symbol-package type
))
44 (find-class (intern name
(symbol-package type
)) nil
))
45 (find-class (intern name
) nil
)
46 (find-class (intern name
:lol
) nil
)
47 'string-attribute-editor
))))))
49 (defclass attribute-editor
()
50 ((class :initarg
:class
)
53 :accessor attribute-editor-type
)
54 (parser :initarg
:parse-using
56 :accessor attribute-editor-parsing-function
)
57 (attributes :initarg
:attributes
59 :accessor attribute-editor-attributes
)
60 (prompt :initarg
:prompt
63 :initarg
:unbound-value
68 (defclass string-attribute-editor
(attribute-editor) ())
69 (defclass text-attribute-editor
(string-attribute-editor) ())
71 (deftype password
() 'string
)
73 (defclass password-attribute-editor
(string-attribute-editor) ())
75 (defclass number-attribute-editor
(attribute-editor) ()
77 :parse-using
'parse-number
:PARSE-NUMBER
80 (defun parse-attribute-value (attribute value
)
81 (funcall (attribute-editor-parsing-function
82 (attribute-editor attribute
))
85 (define-layered-function display-attribute-editor
(attribute)
87 (setf (attribute-value attribute
)
88 (funcall (attribute-editor-parsing-function
89 (attribute-editor attribute
))
92 (define-description T
()
93 ((editp :label
"Edit by Default?"
99 (:in-description editable
))
101 (define-layered-method (setf attribute-value-using-object
)
102 :in-layer
#.
(defining-description 'editable
)(value object attribute
)
104 (let ((setter (attribute-setter attribute
)))
106 (funcall setter value object
)
107 (error "No setter in ~A for ~A" attribute object
))))
110 (define-layered-function attribute-editp
(attribute)
111 (:method
(attribute) nil
))
113 (define-layered-method attribute-editp
114 :in-layer
#.
(defining-description 'editable
)
115 ((attribute standard-attribute
))
116 (let ((value (attribute-value attribute
)))
117 (unless (or (unbound-slot-value-p value
)
119 (attribute-editor-type
120 (attribute-editor attribute
))))
121 (return-from attribute-editp nil
)))
122 (let ((edit?
(call-next-method)))
123 (if (eq :inherit edit?
)
124 (attribute-value (find-attribute
125 (attribute-description attribute
)
130 (define-layered-method display-attribute-value
131 :in-layer
#.
(defining-description 'editable
)
132 ((attribute standard-attribute
))
133 (if (attribute-editp attribute
)
134 (display-attribute-editor attribute
)