annotate lisp/w3/widget-edit.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; widget-edit.el --- Functions for creating and using widgets.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: help, extensions, faces, hypermedia
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Version: 0.4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; See `widget.el'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 (require 'widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 (require 'cl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; Compatibility.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 (or (fboundp 'event-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; XEmacs function missing in Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 (defun event-point (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 "Return the character position of the given mouse-motion, button-press,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 or button-release event. If the event did not occur over a window, or did
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 not occur over text, then this returns nil. Otherwise, it returns an index
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 into the buffer visible in the event's window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (posn-point (event-start event))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (or (fboundp 'set-keymap-parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; Xemacs function missing in Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; Definition stolen from `lucid.el'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (defun set-keymap-parent (keymap new-parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (let ((tail keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (while (and tail (cdr tail) (not (eq (car (cdr tail)) 'keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (setq tail (cdr tail)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (if tail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (setcdr tail new-parent)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; Customization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; These should be specified with the custom package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (defvar widget-button-face 'bold)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defvar widget-mouse-face 'highlight)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (defvar widget-field-face 'italic)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; Utility functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; These are not really widget specific.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (defun widget-plist-member (plist prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; Return non-nil if PLIST has the property PROP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; PLIST is a property list, which is a list of the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; (PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; Unlike `plist-get', this allows you to distinguish between a missing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; property and a property with the value nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; The value is actually the tail of PLIST whose car is PROP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (while (and plist (not (eq (car plist) prop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (setq plist (cdr (cdr plist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defun widget-princ-to-string (object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; Return string representation of OBJECT, any Lisp object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; No quoting characters are used; no delimiters are printed around
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; the contents of strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (set-buffer (get-buffer-create " *widget-tmp*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (let ((standard-output (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (princ object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (buffer-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (defun widget-clear-undo ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 "Clear all undo information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (buffer-disable-undo (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (buffer-enable-undo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;; Widget text specifications.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; These functions are for specifying text properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (defun widget-specify-none (from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; Clear all text properties between FROM and TO.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (set-text-properties from to nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (defun widget-specify-text (from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; Default properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (add-text-properties from to (list 'read-only t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 'front-sticky t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 'rear-nonsticky nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (defun widget-specify-field (widget from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; Specify editable button for WIDGET between FROM and TO.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (widget-specify-field-update widget from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; Make it possible to edit both end of the field.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (add-text-properties (1- from) from (list 'rear-nonsticky t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 'end-open t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 'invisible t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (add-text-properties to (1+ to) (list 'font-sticky nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 'start-open t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (defun widget-specify-field-update (widget from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; Specify editable button for WIDGET between FROM and TO.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (let ((map (widget-get widget :keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (face (or (widget-get widget :value-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 widget-field-face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (add-text-properties from to (list 'field widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 'read-only nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 'local-map map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 'keymap map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 'face widget-field-face))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (defun widget-specify-button (widget from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; Specify button for WIDGET between FROM and TO.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (let ((face (or (widget-get widget :button-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 widget-button-face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (add-text-properties from to (list 'button widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 'mouse-face widget-mouse-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 'face face))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (defun widget-specify-doc (widget from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;; Specify documentation for WIDGET between FROM and TO.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (put-text-property from to 'widget-doc widget))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (defmacro widget-specify-insert (&rest form)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;; Execute FORM without inheriting any text properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 `(save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (let ((inhibit-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 after-change-functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (insert "<>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (narrow-to-region (- (point) 2) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (widget-specify-none (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (goto-char (1+ (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (setq result (progn ,@form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (delete-region (point-min) (1+ (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (delete-region (1- (point-max)) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;; Widget Properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (defun widget-put (widget property value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 "In WIDGET set PROPERTY to VALUE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 The value can later be retrived with `widget-get'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (setcdr widget (plist-put (cdr widget) property value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (defun widget-get (widget property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 "In WIDGET, get the value of PROPERTY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 The value could either be specified when the widget was created, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 later with `widget-put'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (cond ((widget-plist-member (cdr widget) property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (plist-get (cdr widget) property))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ((car widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (widget-get (get (car widget) 'widget-type) property))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (defun widget-member (widget property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 "Non-nil iff there is a definition in WIDGET for PROPERTY."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (cond ((widget-plist-member (cdr widget) property)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ((car widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (widget-member (get (car widget) 'widget-type) property))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (defun widget-apply (widget property &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 "Apply the value of WIDGET's PROPERTY to the widget itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ARGS are passed as extra argments to the function."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (apply (widget-get widget property) widget args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (defun widget-value (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 "Extract the current value of WIDGET."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (widget-apply widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 :value-to-external (widget-apply widget :value-get)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (defun widget-value-set (widget value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 "Set the current value of WIDGET to VALUE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (widget-apply widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 :value-set (widget-apply widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 :value-to-internal value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (defun widget-match-inline (widget values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;; Match the head of values.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (cond ((widget-get widget :inline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (widget-apply widget :match-inline values))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ((widget-apply widget :match (car values))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (cons (list (car values)) (cdr values)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;;; Creating Widgets.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (defun widget-create (type &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 "Create widget of TYPE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 The optional ARGS are additional keyword arguments."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (let ((widget (apply 'widget-convert type args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (widget-apply widget :create)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 widget))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (defun widget-delete (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 "Delete WIDGET."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (widget-apply widget :delete))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (defun widget-convert (type &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 "Convert TYPE to a widget without inserting it in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 The optional ARGS are additional keyword arguments."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;; Don't touch the type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (let* ((widget (if (symbolp type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (list type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (copy-list type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (current widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (keys args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;; First set the :args keyword.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (while (cdr current) ;Look in the type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (let ((next (car (cdr current))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (setq current (cdr (cdr current)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (setcdr current (list :args (cdr current)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (setq current nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (while args ;Look in the args.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (let ((next (nth 0 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (setq args (nthcdr 2 args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (widget-put widget :args args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (setq args nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ;; Then Convert the widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (setq type widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (while type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (let ((convert-widget (widget-get type :convert-widget)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (if convert-widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (setq widget (funcall convert-widget widget))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (setq type (get (car type) 'widget-type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ;; Finally set the keyword args.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (while keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (let ((next (nth 0 keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (if (and (symbolp next) (eq (aref (symbol-name next) 0) ?:))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (widget-put widget next (nth 1 keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (setq keys (nthcdr 2 keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (setq keys nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 ;; Return the newly create widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 widget))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (defun widget-insert (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 "Call `insert' with ARGS and make the text read only."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (let ((inhibit-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 after-change-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (from (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (apply 'insert args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (widget-specify-text from (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ;;; Keymap and Comands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (defvar widget-keymap nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 "Keymap containing useful binding for buffers containing widgets.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 Recommended as a parent keymap for modes using widgets.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (if widget-keymap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (setq widget-keymap (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (set-keymap-parent widget-keymap global-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (define-key widget-keymap "\t" 'widget-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (define-key widget-keymap "\M-\t" 'widget-backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (define-key widget-keymap [(shift tab)] 'widget-backward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (if (string-match "XEmacs" (emacs-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (define-key widget-keymap [button2] 'widget-button-click)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (define-key widget-keymap [mouse-2] 'widget-button-click))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (define-key widget-keymap "\C-m" 'widget-button-press))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (defvar widget-global-map global-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 "Keymap used for events the widget does not handle themselves.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (make-variable-buffer-local 'widget-global-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (defun widget-button-click (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 "Activate button below mouse pointer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (interactive "@e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (widget-button-press (event-point event) event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (defun widget-button-press (pos &optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 "Activate button at POS."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (interactive "@d")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (let* ((button (get-text-property pos 'button)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (if button
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (widget-apply button :action event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (call-interactively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (lookup-key widget-global-map (this-command-keys))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (defun widget-forward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 "Move point to the next field or button.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 With optional ARG, move across that many fields."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (setq arg (1- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (let ((next (cond ((get-text-property (point) 'button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (next-single-property-change (point) 'button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ((get-text-property (point) 'field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (next-single-property-change (point) 'field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (if (null next) ; Widget extends to end. of buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (setq next (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (let ((button (next-single-property-change next 'button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (field (next-single-property-change next 'field)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (cond ((or (get-text-property next 'button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (get-text-property next 'field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (goto-char next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 ((and button field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (goto-char (min button field)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (button (goto-char button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (field (goto-char field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (let ((button (next-single-property-change (point-min) 'button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (field (next-single-property-change (point-min) 'field)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (cond ((and button field) (goto-char (min button field)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (button (goto-char button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (field (goto-char field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (error "No buttons or fields found")))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (while (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (if (= (point-min) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (setq arg (1+ arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (let ((previous (cond ((get-text-property (1- (point)) 'button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (previous-single-property-change (point) 'button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 ((get-text-property (1- (point)) 'field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (previous-single-property-change (point) 'field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (if (null previous) ; Widget extends to beg. of buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (setq previous (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (let ((button (previous-single-property-change previous 'button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (field (previous-single-property-change previous 'field)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (cond ((and button field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (goto-char (max button field)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (button (goto-char button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (field (goto-char field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (let ((button (previous-single-property-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (point-max) 'button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (field (previous-single-property-change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (point-max) 'field)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (cond ((and button field) (goto-char (max button field)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (button (goto-char button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (field (goto-char field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (error "No buttons or fields found"))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (let ((button (previous-single-property-change (point) 'button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (field (previous-single-property-change (point) 'field)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (cond ((and button field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (goto-char (max button field)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (button (goto-char button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (field (goto-char field)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (let ((help-echo (or (get-text-property (point) 'button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (get-text-property (point) 'field))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (if (and help-echo (setq help-echo (widget-get help-echo :help-echo)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (message "%s" help-echo))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (defun widget-backward (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 "Move point to the previous field or button.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 With optional ARG, move across that many fields."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (widget-forward (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 ;;; Setting up the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (defvar widget-field-new nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 ;; List of all newly created editable fields in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (make-variable-buffer-local 'widget-field-new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (defvar widget-field-list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 ;; List of all editable fields in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (make-variable-buffer-local 'widget-field-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (defun widget-setup ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 "Setup current buffer so editing string widgets works."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (let ((inhibit-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (while widget-field-new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (setq field (car widget-field-new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 widget-field-new (cdr widget-field-new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 widget-field-list (cons field widget-field-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (let ((from (widget-get field :value-from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (to (widget-get field :value-to)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (widget-specify-field field from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (move-marker from (1- from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (move-marker to (1+ to)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (widget-clear-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 ;; We need to maintain text properties and size of the editing fields.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (make-local-variable 'after-change-functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (if widget-field-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (setq after-change-functions '(widget-after-change))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (setq after-change-functions nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (defvar widget-field-last nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 ;; Last field containing point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (make-variable-buffer-local 'widget-field-last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (defvar widget-field-was nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 ;; The widget data before the change.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (make-variable-buffer-local 'widget-field-was)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (defun widget-field-find (pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 ;; Find widget whose editing field is located at POS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 ;; Return nil if POS is not inside and editing field.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 ;; This is only used in `widget-field-modified', since ordinarily
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 ;; you would just test the field property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (let ((fields widget-field-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 field found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (while fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (setq field (car fields)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 fields (cdr fields))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (let ((from (widget-get field :value-from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (to (widget-get field :value-to)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (if (and from to (< from pos) (> to pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (setq fields nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 found field))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (defun widget-after-change (from to old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 ;; Adjust field size and text properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (let ((field (widget-field-find from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (inhibit-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (cond ((null field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 ((not (eq field (widget-field-find to)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (message "Error: `widget-after-change' called on two fields"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (let ((size (widget-get field :size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (if size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (let ((begin (1+ (widget-get field :value-from)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (end (1- (widget-get field :value-to))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (widget-specify-field-update field begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (cond ((< (- end begin) size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 ;; Field too small.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (insert-char ?\ (- (+ begin size) end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 ((> (- end begin) size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 ;; Field too large and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (if (or (< (point) (+ begin size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (> (point) end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ;; Point is outside extra space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (setq begin (+ begin size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 ;; Point is within the extra space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (setq begin (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (while (and (eq (preceding-char) ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (> (point) begin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (delete-backward-char 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (widget-specify-field-update field from to)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (widget-apply field :notify field))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (error (debug))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ;;; The `default' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (define-widget 'default nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 "Basic widget other widgets are derived from."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 :value-to-internal (lambda (widget value) value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 :value-to-external (lambda (widget value) value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 :create 'widget-default-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 :format-handler 'widget-default-format-handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 :delete 'widget-default-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 :value-set 'widget-default-value-set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 :value-inline 'widget-default-value-inline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 :menu-tag-get 'widget-default-menu-tag-get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 :validate (lambda (widget) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 :action 'widget-default-action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 :notify 'widget-default-notify)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (defun widget-default-create (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 "Create WIDGET at point in the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (widget-specify-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (let ((from (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (tag (widget-get widget :tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (doc (widget-get widget :doc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 button-begin button-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 doc-begin doc-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 value-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (insert (widget-get widget :format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ;; Parse % escapes in format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (while (re-search-forward "%\\(.\\)" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (let ((escape (aref (match-string 1) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (replace-match "" t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (cond ((eq escape ?%)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (insert "%"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ((eq escape ?\[)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (setq button-begin (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ((eq escape ?\])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (setq button-end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 ((eq escape ?t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (if tag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (insert tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (let ((standard-output (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (princ (widget-get widget :value)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 ((eq escape ?d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (when doc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (setq doc-begin (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (insert doc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (while (eq (preceding-char) ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (delete-backward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (setq doc-end (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 ((eq escape ?v)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (if (and button-begin (not button-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (widget-apply widget :value-create)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (setq value-pos (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (widget-apply widget :format-handler escape)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ;; Specify button and doc, and insert value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (and button-begin button-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (widget-specify-button widget button-begin button-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (and doc-begin doc-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (widget-specify-doc widget doc-begin doc-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (when value-pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (goto-char value-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (widget-apply widget :value-create)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (let ((from (copy-marker (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (to (copy-marker (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (widget-specify-text from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (set-marker-insertion-type from t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (set-marker-insertion-type to nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (widget-put widget :from from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (widget-put widget :to to))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (defun widget-default-format-handler (widget escape)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 ;; By default unknown escapes are errors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (error "Unknown escape `%c'" escape))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (defun widget-default-delete (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ;; Remove widget from the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (let ((from (widget-get widget :from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (to (widget-get widget :to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (inhibit-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 after-change-functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (widget-apply widget :value-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (delete-region from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (set-marker from nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (set-marker to nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (defun widget-default-value-set (widget value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 ;; Recreate widget with new value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (goto-char (widget-get widget :from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (widget-apply widget :delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (widget-put widget :value value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (widget-apply widget :create)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (defun widget-default-value-inline (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 ;; Wrap value in a list unless it is inline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (if (widget-get widget :inline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (widget-value widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (list (widget-value widget))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (defun widget-default-menu-tag-get (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 ;; Use tag or value for menus.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (or (widget-get widget :menu-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (widget-get widget :tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (widget-princ-to-string (widget-get widget :value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (defun widget-default-action (widget &optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 ;; Notify the parent when a widget change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (let ((parent (widget-get widget :parent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (when parent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (widget-apply parent :notify widget event))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (defun widget-default-notify (widget child &optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 ;; Pass notification to parent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (widget-default-action widget event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 ;;; The `item' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (define-widget 'item 'default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 "Constant items for inclusion in other widgets."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 :convert-widget 'widget-item-convert-widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 :value-create 'widget-item-value-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 :value-delete 'ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 :value-get 'widget-item-value-get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 :match 'widget-item-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 :match-inline 'widget-item-match-inline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 :action 'widget-item-action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 :format "%t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (defun widget-item-convert-widget (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 ;; Initialize :value and :tag from :args in WIDGET.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (let ((args (widget-get widget :args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (when args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (widget-put widget :value (car args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (widget-put widget :args nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (defun widget-item-value-create (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 ;; Insert the printed representation of the value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (let ((standard-output (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (princ (widget-get widget :value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (defun widget-item-match (widget value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 ;; Match if the value is the same.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (equal (widget-get widget :value) value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (defun widget-item-match-inline (widget values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 ;; Match if the value is the same.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (let ((value (widget-get widget :value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (and (listp value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (<= (length value) (length values))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (let ((head (subseq values 0 (length value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (and (equal head value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (cons head (subseq values (length value))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (defun widget-item-action (widget &optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 ;; Just notify itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (widget-apply widget :notify widget event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (defun widget-item-value-get (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 ;; Items are simple.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (widget-get widget :value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 ;;; The `push' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (define-widget 'push 'item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 "A pushable button."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 :format "%[[%t]%]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 ;;; The `link' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (define-widget 'link 'item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 "An embedded link."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 :format "%[_%t_%]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 ;;; The `field' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (define-widget 'field 'default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 "An editable text field."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 :convert-widget 'widget-item-convert-widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 :format "%v"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 :value ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 :tag "field"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 :value-create 'widget-field-value-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 :value-delete 'widget-field-value-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 :value-get 'widget-field-value-get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 :match 'widget-field-match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (defun widget-field-value-create (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 ;; Create an editable text field.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (insert " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (let ((size (widget-get widget :size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (value (widget-get widget :value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (from (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (if (null size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (insert value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (insert value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (if (< (length value) size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (insert-char ?\ (- size (length value)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (unless (memq widget widget-field-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (setq widget-field-new (cons widget widget-field-new)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (widget-put widget :value-from (copy-marker from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (set-marker-insertion-type (widget-get widget :value-from) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (widget-put widget :value-to (copy-marker (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (set-marker-insertion-type (widget-get widget :value-to) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (if (null size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (insert ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (insert ?\ ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (defun widget-field-value-delete (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 ;; Remove the widget from the list of active editing fields.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (setq widget-field-list (delq widget widget-field-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (set-marker (widget-get widget :value-from) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (set-marker (widget-get widget :value-to) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (defun widget-field-value-get (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 ;; Return current text in editing field.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (let ((from (widget-get widget :value-from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (to (widget-get widget :value-to)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (if (and from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (setq from (1+ from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 to (1- to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (while (and (> to from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (eq (char-after (1- to)) ?\ ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (setq to (1- to)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (buffer-substring-no-properties from to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (widget-get widget :value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (defun widget-field-match (widget value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 ;; Match any string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (stringp value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 ;;; The `choice' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (define-widget 'choice 'default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 "A menu of options."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 :convert-widget 'widget-choice-convert-widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 :format "%[%t%]: %v"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 :tag "choice"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 :inline t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 :void '(item "void")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 :value-create 'widget-choice-value-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 :value-delete 'widget-radio-value-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 :value-get 'widget-choice-value-get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 :value-inline 'widget-choice-value-inline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 :action 'widget-choice-action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 :error "Make a choice"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 :validate 'widget-choice-validate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 :match 'widget-choice-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 :match-inline 'widget-choice-match-inline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (defun widget-choice-convert-widget (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 ;; Expand type args into widget objects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (widget-put widget :args (mapcar 'widget-convert (widget-get widget :args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (defun widget-choice-value-create (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 ;; Insert the first choice that matches the value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (let ((value (widget-get widget :value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (args (widget-get widget :args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (while args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (setq current (car args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 args (cdr args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (when (widget-apply current :match value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (widget-put widget :children (list (widget-create current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 :parent widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 :value value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (widget-put widget :choice current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (setq args nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 current nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (when current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (let ((void (widget-get widget :void)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (widget-put widget :children (list (widget-create void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 :parent widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 :value value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (widget-put widget :choice void)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (defun widget-choice-value-get (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 ;; Get value of the child widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (widget-value (car (widget-get widget :children))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (defun widget-choice-value-inline (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 ;; Get value of the child widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (widget-apply (car (widget-get widget :children)) :value-inline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (defun widget-choice-action (widget &optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 ;; Make a choice.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (let ((args (widget-get widget :args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (old (widget-get widget :choice))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (tag (widget-apply widget :menu-tag-get))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 current choices)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (setq current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (cond ((= (length args) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 ((= (length args) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (nth 0 args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 ((and (= (length args) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (memq old args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (if (eq old (nth 0 args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (nth 1 args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (nth 0 args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (while args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (setq current (car args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 args (cdr args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (setq choices
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (cons (cons (widget-apply current :menu-tag-get)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 choices)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 ((and event (fboundp 'x-popup-menu) window-system)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 ;; We are in Emacs-19, pressed by the mouse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (x-popup-menu event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (list tag (cons "" (reverse choices)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 ((and event (fboundp 'popup-menu) window-system)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 ;; We are in XEmacs, pressed by the mouse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (let ((val (get-popup-menu-response
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (cons ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (vector (car x) (list (car x)) t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (reverse choices))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (setq val (and val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (listp (event-object val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (stringp (car-safe (event-object val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (car (event-object val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (cdr (assoc val choices))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (cdr (assoc (completing-read (concat tag ": ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 choices nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 choices)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (when current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (widget-value-set widget (widget-value current))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (widget-setup)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 ;; Notify parent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (widget-apply widget :notify widget event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 (widget-clear-undo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (defun widget-choice-validate (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 ;; Valid if we have made a valid choice.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (let ((void (widget-get widget :void))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (choice (widget-get widget :choice))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (child (car (widget-get widget :children))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (if (eq void choice)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (widget-apply child :validate))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (defun widget-choice-match (widget value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 ;; Matches if one of the choices matches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (let ((args (widget-get widget :args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 current found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (while (and args (not found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (setq current (car args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 args (cdr args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 found (widget-apply current :match value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (defun widget-choice-match-inline (widget values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 ;; Matches if one of the choices matches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (let ((args (widget-get widget :args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 current found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (while (and args (null found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (setq current (car args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 args (cdr args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 found (widget-match-inline current values)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 ;;; The `toggle' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (define-widget 'toggle 'choice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 "Toggle between two states."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 :convert-widget 'widget-toggle-convert-widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 :format "%[%v%]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 :on "on"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 :off "off")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (defun widget-toggle-convert-widget (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 ;; Create the types representing the `on' and `off' states.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (let ((args (widget-get widget :args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (on-type (widget-get widget :on-type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (off-type (widget-get widget :off-type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (unless on-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (setq on-type (list 'item :value t :tag (widget-get widget :on))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (unless off-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (setq off-type (list 'item :value nil :tag (widget-get widget :off))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (widget-put widget :args (list on-type off-type)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 ;;; The `checkbox' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (define-widget 'checkbox 'toggle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 "A checkbox toggle."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 :convert-widget 'widget-item-convert-widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 :on-type '(item :format "[X]" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 :off-type '(item :format "[ ]" nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 ;;; The `checklist' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (define-widget 'checklist 'default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 "A multiple choice widget."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 :convert-widget 'widget-choice-convert-widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 :format "%v"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 :entry-format "%b %v"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 :menu-tag "checklist"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 :value-create 'widget-checklist-value-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 :value-delete 'widget-radio-value-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 :value-get 'widget-checklist-value-get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 :validate 'widget-checklist-validate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 :match 'widget-checklist-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 :match-inline 'widget-checklist-match-inline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (defun widget-checklist-value-create (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 ;; Insert all values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (let ((alist (widget-checklist-match-find widget (widget-get widget :value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (args (widget-get widget :args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (while args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (widget-checklist-add-item widget (car args) (assq (car args) alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (setq args (cdr args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (widget-put widget :children (nreverse (widget-get widget :children)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (defun widget-checklist-add-item (widget type chosen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 ;; Create checklist item in WIDGET of type TYPE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 ;; If the item is checked, CHOSEN is a cons whose cdr is the value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (widget-specify-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (let* ((children (widget-get widget :children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (buttons (widget-get widget :buttons))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (from (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 child button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (insert (widget-get widget :entry-format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 ;; Parse % escapes in format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (while (re-search-forward "%\\([bv%]\\)" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (let ((escape (aref (match-string 1) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (replace-match "" t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (cond ((eq escape ?%)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (insert "%"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 ((eq escape ?b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (setq button (widget-create 'checkbox
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 :parent widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 :value (not (null chosen)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 ((eq escape ?v)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (setq child
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (cond ((not chosen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (widget-create type :parent widget))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 ((widget-get type :inline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (widget-create type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 :parent widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 :value (cdr chosen)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (widget-create type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 :parent widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 :value (car (cdr chosen)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (error "Unknown escape `%c'" escape)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 ;; Update properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (and button child (widget-put child :button button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (and button (widget-put widget :buttons (cons button buttons)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (and child (widget-put widget :children (cons child children))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (defun widget-checklist-match (widget values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 ;; All values must match a type in the checklist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (and (listp values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (null (cdr (widget-checklist-match-inline widget values)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (defun widget-checklist-match-inline (widget values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 ;; Find the values which match a type in the checklist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (let ((greedy (widget-get widget :greedy))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (args (copy-list (widget-get widget :args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 found rest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (while values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (let ((answer (widget-checklist-match-up args values)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (cond (answer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (let ((vals (widget-match-inline answer values)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (setq found (append found (car vals))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 values (cdr vals)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 args (delq answer args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (greedy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (setq rest (append rest (list (car values)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 values (cdr values)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (setq rest (append rest values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 values nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (cons found rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 (defun widget-checklist-match-find (widget values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 ;; Find the values which match a type in the checklist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 ;; Return an alist of (TYPE MATCH).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (let ((greedy (widget-get widget :greedy))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (args (copy-list (widget-get widget :args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (while values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (let ((answer (widget-checklist-match-up args values)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (cond (answer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (let ((vals (widget-match-inline answer values)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (setq found (cons (cons answer (car vals)) found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 values (cdr vals)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 args (delq answer args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (greedy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (setq values (cdr values)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (setq values nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (defun widget-checklist-match-up (args values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 ;; Rerturn the first type from ARGS that matches VALUES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (let (current found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (while (and args (null found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (setq current (car args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 args (cdr args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 found (widget-match-inline current values)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (and found current)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (defun widget-checklist-value-get (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 ;; The values of all selected items.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 (let ((children (widget-get widget :children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 child result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (while children
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (setq child (car children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 children (cdr children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (if (widget-value (widget-get child :button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (setq result (append result (widget-apply child :value-inline)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (defun widget-checklist-validate (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 ;; Ticked chilren must be valid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (let ((children (widget-get widget :children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 child button found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (while (and children (not found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (setq child (car children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 children (cdr children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 button (widget-get child :button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 found (and (widget-value button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (widget-apply child :validate))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 ;;; The `option' Widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (define-widget 'option 'checklist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 "An widget with an optional item."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 :inline t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 ;;; The `choice-item' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (define-widget 'choice-item 'item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 "Button items that delegate action events to their parents."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 :action 'widget-choice-item-action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 :format "%[%t%]\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 (defun widget-choice-item-action (widget &optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 ;; Tell parent what happened.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (widget-apply (widget-get widget :parent) :action event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 ;;; The `radio-button' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (define-widget 'radio-button 'toggle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 "A radio button for use in the `radio' widget."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 :format "%v"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 :notify 'widget-radio-button-notify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 :on-type '(choice-item :format "%[(*)%]" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 :off-type '(choice-item :format "%[( )%]" nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (defun widget-radio-button-notify (widget child &optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 ;; Notify the parent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (widget-apply (widget-get widget :parent) :action widget event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 ;;; The `radio' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (define-widget 'radio 'default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 "Select one of multiple options."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 :convert-widget 'widget-choice-convert-widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 :format "%v"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 :entry-format "%b %v"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 :menu-tag "radio"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 :value-create 'widget-radio-value-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 :value-delete 'widget-radio-value-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 :value-get 'widget-radio-value-get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 :value-inline 'widget-radio-value-inline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 :value-set 'widget-radio-value-set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 :error "You must push one of the buttons"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 :validate 'widget-radio-validate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 :match 'widget-choice-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 :match-inline 'widget-choice-match-inline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 :action 'widget-radio-action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (defun widget-radio-value-create (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 ;; Insert all values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (let ((args (widget-get widget :args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (indent (widget-get widget :indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (while args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (setq arg (car args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 args (cdr args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (widget-radio-add-item widget arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 (and indent args (insert-char ?\ indent)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (defun widget-radio-add-item (widget type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 "Add to radio widget WIDGET a new radio button item of type TYPE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (setq type (widget-convert type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 (widget-specify-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (let* ((value (widget-get widget :value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (children (widget-get widget :children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (buttons (widget-get widget :buttons))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (from (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 (chosen (and (null (widget-get widget :choice))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 (widget-apply type :match value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 child button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (insert (widget-get widget :entry-format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 ;; Parse % escapes in format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (while (re-search-forward "%\\([bv%]\\)" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 (let ((escape (aref (match-string 1) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (replace-match "" t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (cond ((eq escape ?%)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (insert "%"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 ((eq escape ?b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 (setq button (widget-create 'radio-button
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 :parent widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 :value (not (null chosen)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 ((eq escape ?v)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (setq child (if chosen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (widget-create type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 :parent widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 :value value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (widget-create type :parent widget))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (error "Unknown escape `%c'" escape)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 ;; Update properties.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (when chosen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (widget-put widget :choice type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (when button
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (widget-put child :button button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (widget-put widget :buttons (nconc buttons (list button))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (when child
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (widget-put widget :children (nconc children (list child))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 child)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (defun widget-radio-value-delete (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 ;; Delete the child widgets.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (mapcar 'widget-delete (widget-get widget :children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (widget-put widget :children nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (mapcar 'widget-delete (widget-get widget :buttons))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (widget-put widget :buttons nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (defun widget-radio-value-get (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 ;; Get value of the child widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (let ((chosen (widget-radio-chosen widget)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (and chosen (widget-value chosen))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (defun widget-radio-chosen (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 "Return the widget representing the chosen radio button."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (let ((children (widget-get widget :children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 current found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (while children
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (setq current (car children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 children (cdr children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (let* ((button (widget-get current :button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 (value (widget-apply button :value-get)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (when value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 (setq found current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 children nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (defun widget-radio-value-inline (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 ;; Get value of the child widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (let ((children (widget-get widget :children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 current found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (while children
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (setq current (car children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 children (cdr children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (let* ((button (widget-get current :button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (value (widget-apply button :value-get)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (when value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 (setq found (widget-apply current :value-inline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 children nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (defun widget-radio-value-set (widget value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 ;; We can't just delete and recreate a radio widget, since children
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 ;; can be added after the original creation and won't be recreated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 ;; by `:create'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 (let ((children (widget-get widget :children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 current found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (while children
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (setq current (car children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 children (cdr children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (let* ((button (widget-get current :button))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (match (and (not found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (widget-apply current :match value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (widget-value-set button match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (if match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (widget-value-set current value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (setq found (or found match))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 (defun widget-radio-validate (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 ;; Valid if we have made a valid choice.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (let ((children (widget-get widget :children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 current found button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (while (and children (not found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 (setq current (car children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 children (cdr children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 button (widget-get current :button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 found (widget-apply button :value-get)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (if found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (widget-apply current :validate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 widget)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 (defun widget-radio-action (widget child event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 ;; Check if a radio button was pressed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (let ((children (widget-get widget :children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (buttons (widget-get widget :buttons))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (when (memq child buttons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (while children
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 (setq current (car children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 children (cdr children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (let* ((button (widget-get current :button)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (cond ((eq child button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (widget-value-set button t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 ((widget-value button)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (widget-value-set button nil)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 ;; Pass notification to parent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (widget-apply widget :notify child event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 ;;; The `insert-button' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (define-widget 'insert-button 'push
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 "An insert button for the `repeat' widget."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 :tag "INS"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 :action 'widget-insert-button-action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (defun widget-insert-button-action (widget &optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 ;; Ask the parent to insert a new item.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (widget-apply (widget-get widget :parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 :insert-before (widget-get widget :widget)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 ;;; The `delete-button' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (define-widget 'delete-button 'push
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 "A delete button for the `repeat' widget."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 :tag "DEL"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 :action 'widget-delete-button-action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 (defun widget-delete-button-action (widget &optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 ;; Ask the parent to insert a new item.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 (widget-apply (widget-get widget :parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 :delete-at (widget-get widget :widget)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 ;;; The `repeat' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 (define-widget 'repeat 'default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 "A variable list of widgets of the same type."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 :convert-widget 'widget-choice-convert-widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 :format "%v%i\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 :format-handler 'widget-repeat-format-handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 :entry-format "%i %d %v"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 :menu-tag "repeat"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 :value-create 'widget-repeat-value-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 :value-delete 'widget-radio-value-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 :value-get 'widget-repeat-value-get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 :validate 'widget-repeat-validate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 :match 'widget-repeat-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 :match-inline 'widget-repeat-match-inline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 :insert-before 'widget-repeat-insert-before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 :delete-at 'widget-repeat-delete-at)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 (defun widget-repeat-format-handler (widget escape)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 ;; We recognize the insert button.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 (cond ((eq escape ?i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (insert " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 (let* ((from (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 (button (widget-create (list 'insert-button
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 :parent widget))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (widget-specify-button button from (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 (widget-default-format-handler widget escape))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 (defun widget-repeat-value-create (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 ;; Insert all values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 (let* ((value (widget-get widget :value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 (type (nth 0 (widget-get widget :args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (inlinep (widget-get type :inline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 (widget-put widget :value-pos (copy-marker (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 (set-marker-insertion-type (widget-get widget :value-pos) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (while value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 (let ((answer (widget-match-inline type value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 (if answer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 (setq children (cons (widget-repeat-entry-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 widget (if inlinep
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (car answer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (car (car answer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 value (cdr answer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 (setq value nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 (widget-put widget :children (nreverse children))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (defun widget-repeat-value-get (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 ;; Get value of the child widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 (apply 'append (mapcar (lambda (child) (widget-apply child :value-inline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 (widget-get widget :children))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 (defun widget-repeat-validate (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 ;; All the chilren must be valid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 (let ((children (widget-get widget :children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 child found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (while (and children (not found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (setq child (car children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 children (cdr children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 found (widget-apply child :validate)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (defun widget-repeat-match (widget value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 ;; Value must be a list and all the members must match the repeat type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 (and (listp value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 (null (cdr (widget-repeat-match-inline widget value)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 (defun widget-repeat-match-inline (widget value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 (let ((type (nth 0 (widget-get widget :args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 (ok t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 (while (and value ok)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (let ((answer (widget-match-inline type value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 (if answer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (setq found (append found (car answer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 value (cdr answer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 (setq ok nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (cons found value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 (defun widget-repeat-insert-before (widget before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 ;; Insert a new child in the list of children.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 (let ((children (widget-get widget :children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 (inhibit-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 after-change-functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 (cond (before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 (goto-char (widget-get before :from)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 (goto-char (widget-get widget :value-pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 (let ((child (widget-repeat-entry-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 widget (widget-get (nth 0 (widget-get widget :args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 :value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 (widget-specify-text (widget-get child :from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 (widget-get child :to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 (if (eq (car children) before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (widget-put widget :children (cons child children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (while (not (eq (car (cdr children)) before))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (setq children (cdr children)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (setcdr children (cons child (cdr children)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (widget-setup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 (widget-apply widget :notify widget))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 (defun widget-repeat-delete-at (widget child)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 ;; Delete child from list of children.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 (let ((buttons (copy-list (widget-get widget :buttons)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 button
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 (inhibit-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 after-change-functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 (while buttons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 (setq button (car buttons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 buttons (cdr buttons))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (when (eq (widget-get button :widget) child)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 (widget-put widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 :buttons (delq button (widget-get widget :buttons)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 (widget-delete button))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 (widget-delete child)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 (widget-put widget :children (delq child (widget-get widget :children))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 (widget-setup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 (widget-apply widget :notify widget))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 (defun widget-repeat-entry-create (widget value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 ;; Create a new entry to the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (let ((type (nth 0 (widget-get widget :args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 (indent (widget-get widget :indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 child delete insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 (widget-specify-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 (insert (widget-get widget :entry-format))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (if indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (insert-char ?\ indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 ;; Parse % escapes in format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (while (re-search-forward "%\\(.\\)" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (let ((escape (aref (match-string 1) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 (replace-match "" t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (cond ((eq escape ?%)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (insert "%"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 ((eq escape ?i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 (setq insert (widget-create 'insert-button
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 :parent widget)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 ((eq escape ?d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (setq delete (widget-create 'delete-button
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 :parent widget)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 ((eq escape ?v)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 (setq child (widget-create type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 :parent widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 :value value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (error "Unknown escape `%c'" escape)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (widget-put widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 :buttons (cons delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 (cons insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (widget-get widget :buttons))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 (move-marker (widget-get child :from) (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 (move-marker (widget-get child :to) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 (widget-put insert :widget child)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 (widget-put delete :widget child)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 child))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 ;;; The `group' Widget.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (define-widget 'group 'default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 "A widget which group other widgets inside."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 :convert-widget 'widget-choice-convert-widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 :format "%v"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 :value-create 'widget-group-value-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 :value-delete 'widget-radio-value-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 :value-get 'widget-repeat-value-get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 :validate 'widget-repeat-validate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 :match 'widget-group-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 :match-inline 'widget-group-match-inline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (defun widget-group-value-create (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 ;; Create each component.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 (let ((args (widget-get widget :args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (value (widget-get widget :value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (indent (widget-get widget :indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 arg answer children)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (while args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 (setq arg (car args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 args (cdr args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 answer (widget-match-inline arg value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 value (cdr answer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 children (cons (cond ((null answer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (widget-create arg :parent widget))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 ((widget-get arg :inline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 (widget-create arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 :parent widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 :value (car answer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (widget-create arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 :parent widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 :value (car (car answer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 children))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 (and args indent (insert-char ?\ indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 (widget-put widget :children (nreverse children))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 (defun widget-group-match (widget values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 ;; Match if the components match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 (and (listp values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (null (cdr (widget-group-match-inline widget values)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (defun widget-group-match-inline (widget values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 ;; Match if the components match.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (let ((args (widget-get widget :args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (match t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 arg answer found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (while args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (setq arg (car args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 args (cdr args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 answer (widget-match-inline arg values))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 (if answer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 (setq values (cdr answer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 found (append found (car answer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 (setq values nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 (if answer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 (cons found values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 ;;; The Sexp Widgets.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 (define-widget 'const 'item
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 :format "%t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (define-widget 'string 'field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (define-widget 'file 'string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 :format "%[%t%]:%v"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 :tag "File"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 :action 'widget-file-action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 (defun widget-file-action (widget &optional event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 ;; Read a file name from the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 (widget-value-set widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (read-file-name (widget-apply widget :menu-tag-get)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (widget-get widget :directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (widget-value widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (widget-get widget :must-match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 (widget-get widget :initial))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 (define-widget 'directory 'file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 :tag "Directory")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 (define-widget 'symbol 'string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 :match (lambda (widget value) (symbolp value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 :value-to-internal (lambda (widget value) (symbol-name value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 :value-to-external (lambda (widget value) (intern value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 (define-widget 'sexp 'string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 :validate 'widget-sexp-validate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 :match (lambda (widget value) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 :value-to-internal (lambda (widget value) (pp-to-string value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 :value-to-external (lambda (widget value) (read value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 (defun widget-sexp-validate (widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 ;; Valid if we can read the string and there is no junk left after it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 (set-buffer (get-buffer-create " *Widget Scratch*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 (insert (widget-apply :value-get widget))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 (condition-case data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 (let ((value (read (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 (if (widget-apply widget :match value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 (widget-put widget :error (widget-get widget :type-error))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 (widget-put widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 :error (format "Junk at end of expression: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 (buffer-substring (point) (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 (error (widget-put widget :error (error-message-string data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 (define-widget 'integer 'sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 :type-error "This field should contain an integer"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 :match (lambda (widget value) (integerp value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 (define-widget 'number 'sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 :type-error "This field should contain a number"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 :match (lambda (widget value) (numberp value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 (define-widget 'list 'group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 (define-widget 'vector 'group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 :match 'widget-vector-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 :value-to-internal (lambda (widget value) (append value nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 :value-to-external (lambda (widget value) (apply 'vector value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 (defun widget-vector-match (widget value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 (and (vectorp value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 (widget-group-match widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 (widget-apply :value-to-internal widget value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 (define-widget 'cons 'group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 :match 'widget-cons-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 :value-to-internal (lambda (widget value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 (list (car value) (cdr value)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 :value-to-external (lambda (widget value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 (cons (nth 0 value) (nth 1 value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (defun widget-cons-match (widget value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (and (consp value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 (widget-group-match widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 (widget-apply :value-to-internal widget value))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 ;;; The End:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 (provide 'widget-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 ;; widget-edit.el ends here