annotate lisp/w3/widget-edit.el @ 9:6f2bbbbbe05a

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