Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 749 lines (670 sloc) 30.852 kb
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
1 ;;; -*- Mode: Lisp; Package: CLIM-INTERNALS -*-
2
3 ;;; (c) copyright 2003 by Tim Moore (moore@bricoworks.com)
4 ;;; This library is free software; you can redistribute it and/or
5 ;;; modify it under the terms of the GNU Library General Public
6 ;;; License as published by the Free Software Foundation; either
7 ;;; version 2 of the License, or (at your option) any later version.
8 ;;;
9 ;;; This library is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;;; Library General Public License for more details.
13 ;;;
14 ;;; You should have received a copy of the GNU Library General Public
15 ;;; License along with this library; if not, write to the
16 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 ;;; Boston, MA 02111-1307 USA.
56a3553 Added stub for ACCEPTING-VALUES.
Alexey Dejneka authored
18
91cfdcb Back out Andy's fix; accomplish the same thing by calling (setf
Timothy Moore authored
19 #| Random notes:
20
21 An accepting-values stream diverts the calls to accept into calling
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
22 accept-present-default, as described in the spec. The output record
23 produced by accept-present-default, as well as the current value of
24 that query, arguments that were passed to accept, etc. are stored in a
25 query object. The stream stores all the query objects for this
53edf03 Implemented a pop-up-menu-view for displaying the completion
Timothy Moore authored
26 invocation of accepting-values. The record created and returned by
27 accept-present-default must be a subclass of updating-output-record.
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
28
29 After the initial output records are drawn, invoke-accepting-values
53edf03 Implemented a pop-up-menu-view for displaying the completion
Timothy Moore authored
30 blocks accepting commands. The state of the dialog state machine is changed
31 via these commands. The commands currently are:
32
33 COM-SELECT-QUERY query-id -- calls the method select-query with the
34 corresponding query object and output record object. When select-query returns
35 the "next" field, if any, is selected so the user can move from field to field
36 easily.
37
38 COM-CHANGE-QUERY query-id value -- This command is used to directly change the
39 value of a query field that does not need to be selected first for input. For
40 example, a user would click directly on a radio button without selecting the
41 gadget first.
42
43 COM-DESELECT-QUERY -- deselects the currently selected query.
44
45 COM-QUERY-EXIT -- Exits accepting-values
46
47 COM-QUERY-ABORT -- Aborts accepting-values
48
49 These commands are generated in two ways. For query fields that are entirely
50 based on CLIM drawing commands and presentations, these are emitted by
51 presentation translators. There is a presentation type selectable-query that
52 throws com-select-query for the :select gesture. Fields that are based on
53 gadgets have to throw presentations from their callbacks. This can be done
54 using the method on p. 305 of the Franz CLIM user guide, or by using the
55 McCLIM function throw-object-ptype.
56
57 After a command is executed the body of accepting-values is rerun, calling
58 accept-present-default again to update the fields' graphic appearance. [This
59 may be calling these methods too often an may change in the future]. The
60 values returned by the user's calls to accept are come from the query objects.
61
62
63 If a query field is selectable than it should implement the method
64 select-query:
65
66 SELECT-QUERY stream query record -- Make a query field active and do any
67 input. This should change the query object and setf (changedp query). This
68 method might be interrupted at any time if the user selects another field.
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
69
91cfdcb Back out Andy's fix; accomplish the same thing by calling (setf
Timothy Moore authored
70 |#
71
95dff8a make all of the package names passed to in-package be lowercase keywo…
Mike McDonald authored
72 (in-package :clim-internals)
56a3553 Added stub for ACCEPTING-VALUES.
Alexey Dejneka authored
73
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
74 (defclass query ()
75 ((query-identifier :accessor query-identifier :initarg :query-identifier)
76 (ptype :accessor ptype :initarg :ptype)
77 (view :accessor view :initarg :view)
78 (default :accessor default :initarg :default :initform nil)
7945407 Changed STREAM-DESIGNATOR-SYMBOL to take a default value
Timothy Moore authored
79 (default-supplied-p :accessor default-supplied-p
80 :initarg :default-supplied-p :initform nil)
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
81 (value :accessor value :initarg :value :initform nil)
82 (changedp :accessor changedp :initform nil)
83 (record :accessor record :initarg :record)
84 (activation-gestures :accessor activation-gestures
85 :initform *activation-gestures*
86 :documentation "Binding of *activation-gestures* on
87 entry to this accept")
88 (delimeter-gestures :accessor delimiter-gestures
89 :initform *delimiter-gestures*
90 :documentation "Binding of *delimeter-gestures* on entry
91 to this accept")
92 (accept-arguments :accessor accept-arguments :initarg :accept-arguments)
900b913 Don't define an accessor with a reserved name in Common Lisp, per Pau…
Timothy Moore authored
93 (accept-condition :accessor accept-condition :initarg :accept-condition
94 :initform nil
95 :documentation "Condition signalled, if any, during
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
96 accept of this query")))
97
91cfdcb Back out Andy's fix; accomplish the same thing by calling (setf
Timothy Moore authored
98 (defclass accepting-values-record (standard-updating-output-record)
99 ())
100
101 (defclass accepting-values-stream (standard-encapsulating-stream)
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
102 ((queries :accessor queries :initform nil)
45da96f Implemented :ALIGN-PROMPTS in ACCEPTING-VALUES. This was harder than
Timothy Moore authored
103 (selected-query :accessor selected-query :initform nil)
104 (align-prompts :accessor align-prompts :initarg :align-prompts
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
105 :initform nil)
106 (last-pass :accessor last-pass :initform nil
107 :documentation "Flag that indicates the last pass through the
108 body of ACCEPTING-VALUES, after the user has chosen to exit. This controls
109 when conditions will be signalled from calls to ACCEPT.")))
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
110
111 (defmethod stream-default-view ((stream accepting-values-stream))
112 +textual-dialog-view+)
113
114 (define-condition av-exit (condition)
91cfdcb Back out Andy's fix; accomplish the same thing by calling (setf
Timothy Moore authored
115 ())
116
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
117 ;;; The accepting-values state machine is controlled by commands. Each
118 ;;; action (e.g., "select a text field") terminates
119
849c306 Committed patch from Daniel Jensen changing name of ACCEPTING-VALUES
Troels Henriksen authored
120 (define-command-table accept-values) ; :inherit-from nil???
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
121
122 (defvar *default-command* '(accepting-values-default-command))
123
124 ;;; The fields of the query have presentation type query. Fields that
125 ;;; are "selectable", like the default text editor field, have type
126 ;;; selectable-query. The presentation object is the query
127 ;;; identifier.
128
129 (define-presentation-type query () :inherit-from t)
130
131 (define-presentation-type selectable-query () :inherit-from 'query)
132
133 (define-presentation-type exit-button () :inherit-from t)
134
135 (define-presentation-type abort-button () :inherit-from t)
136
137 (defvar *accepting-values-stream* nil)
138
4075d23 Patches to dialog.lisp from Max-Gerd Retzlaff.
Robert Strandh authored
139 (defmacro with-stream-in-own-window ((&optional (stream '*query-io*)
140 &rest further-streams)
6bf2d69 (climi::frame-event-queue *application-frame*) as argument :INPUT-BUFFER
Max-Gerd Retzlaff authored
141 (&optional label)
4075d23 Patches to dialog.lisp from Max-Gerd Retzlaff.
Robert Strandh authored
142 &rest body)
6bf2d69 (climi::frame-event-queue *application-frame*) as argument :INPUT-BUFFER
Max-Gerd Retzlaff authored
143 `(let* ((,stream (open-window-stream :label ,label
144 :input-buffer (climi::frame-event-queue *application-frame*)))
4075d23 Patches to dialog.lisp from Max-Gerd Retzlaff.
Robert Strandh authored
145 ,@(mapcar (lambda (a-stream)
146 (list a-stream stream))
147 further-streams))
148 (unwind-protect
149 (progn
150 ,@body)
151 (close ,stream))))
152
56a3553 Added stub for ACCEPTING-VALUES.
Alexey Dejneka authored
153 (defmacro accepting-values
154 ((&optional (stream t)
155 &rest args
156 &key own-window exit-boxes initially-select-query-identifier
157 modify-initial-query resynchronize-every-pass resize-frame
5416a30 Add new keyword to accepting-values, select-first-query, to automatic…
Andy Hefner authored
158 align-prompts label scroll-bars select-first-query
56a3553 Added stub for ACCEPTING-VALUES.
Alexey Dejneka authored
159 x-position y-position width height command-table frame-class)
160 &body body)
4075d23 Patches to dialog.lisp from Max-Gerd Retzlaff.
Robert Strandh authored
161 (declare (ignorable exit-boxes initially-select-query-identifier
56a3553 Added stub for ACCEPTING-VALUES.
Alexey Dejneka authored
162 modify-initial-query resynchronize-every-pass resize-frame
5416a30 Add new keyword to accepting-values, select-first-query, to automatic…
Andy Hefner authored
163 align-prompts scroll-bars select-first-query
56a3553 Added stub for ACCEPTING-VALUES.
Alexey Dejneka authored
164 x-position y-position width height command-table frame-class))
7945407 Changed STREAM-DESIGNATOR-SYMBOL to take a default value
Timothy Moore authored
165 (setq stream (stream-designator-symbol stream '*standard-input*))
56a3553 Added stub for ACCEPTING-VALUES.
Alexey Dejneka authored
166 (with-gensyms (accepting-values-continuation)
9bf6f78 Do some compile-time analysis to remove unreachable-code warnings at
Troels Henriksen authored
167 (let* ((return-form
168 `(flet ((,accepting-values-continuation (,stream)
169 ,@body))
170 (invoke-accepting-values ,stream
171 #',accepting-values-continuation
172 ,@args)))
173 (true-form `(with-stream-in-own-window (,stream *standard-input* *standard-output*)
174 (,label)
175 ,return-form)))
176 ;; To avoid unreachable-code warnings, if `own-window' is a
177 ;; boolean constant, don't generate the `if' form.
178 (cond ((eq own-window t) true-form)
179 ((eq own-window nil) return-form)
180 (t `(if ,own-window
181 ,true-form
182 ,return-form))))))
56a3553 Added stub for ACCEPTING-VALUES.
Alexey Dejneka authored
183
184 (defun invoke-accepting-values
185 (stream body
870e24f Implement the :INITIALLY-SELECT-QUERY-IDENTIFIER option of
Timothy Moore authored
186 &key own-window exit-boxes
187 (initially-select-query-identifier nil initially-select-p)
5416a30 Add new keyword to accepting-values, select-first-query, to automatic…
Andy Hefner authored
188 select-first-query
56a3553 Added stub for ACCEPTING-VALUES.
Alexey Dejneka authored
189 modify-initial-query resynchronize-every-pass resize-frame
190 align-prompts label scroll-bars
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
191 x-position y-position width height
849c306 Committed patch from Daniel Jensen changing name of ACCEPTING-VALUES
Troels Henriksen authored
192 (command-table 'accept-values)
56a3553 Added stub for ACCEPTING-VALUES.
Alexey Dejneka authored
193 (frame-class 'accept-values))
870e24f Implement the :INITIALLY-SELECT-QUERY-IDENTIFIER option of
Timothy Moore authored
194 (declare (ignore own-window exit-boxes modify-initial-query
45da96f Implemented :ALIGN-PROMPTS in ACCEPTING-VALUES. This was harder than
Timothy Moore authored
195 resize-frame label scroll-bars x-position y-position
4075d23 Patches to dialog.lisp from Max-Gerd Retzlaff.
Robert Strandh authored
196 width height frame-class))
197 (when (and align-prompts ;; t means the same as :right
198 (not (eq align-prompts :left)))
199 (setf align-prompts :right))
85b78a6 Add new :inset border shape. Use this to surround text fields created…
Andy Hefner authored
200 (multiple-value-bind (cx cy) (stream-cursor-position stream)
201 (let* ((*accepting-values-stream*
202 (make-instance 'accepting-values-stream
203 :stream stream
204 :align-prompts align-prompts))
205 (arecord (updating-output (stream
206 :record-type 'accepting-values-record)
207 (if align-prompts
208 (formatting-table (stream)
209 (funcall body *accepting-values-stream*))
210 (funcall body *accepting-values-stream*))
211 (display-exit-boxes *application-frame*
212 stream
213 (stream-default-view
214 *accepting-values-stream*))))
215 (first-time t)
216 (current-command (if initially-select-p
217 `(com-select-query
218 ,initially-select-query-identifier)
219 *default-command*)))
220 (letf (((frame-command-table *application-frame*)
221 (find-command-table command-table)))
222 (unwind-protect
223 (handler-case
224 (loop
225 (if first-time
226 (setq first-time nil)
227 (when resynchronize-every-pass
228 (redisplay arecord stream)))
229 (with-input-context
849c306 Committed patch from Daniel Jensen changing name of ACCEPTING-VALUES
Troels Henriksen authored
230 ('(command :command-table accept-values))
85b78a6 Add new :inset border shape. Use this to surround text fields created…
Andy Hefner authored
231 (object)
232 (progn
5416a30 Add new keyword to accepting-values, select-first-query, to automatic…
Andy Hefner authored
233 (when (and select-first-query
234 (not initially-select-p))
235 (setf current-command
236 `(com-select-query
237 ,(query-identifier
238 (first
239 (queries *accepting-values-stream*))))
240 select-first-query nil))
85b78a6 Add new :inset border shape. Use this to surround text fields created…
Andy Hefner authored
241 (apply (command-name current-command)
242 (command-arguments current-command))
243 ;; If current command returns without throwing a
244 ;; command, go back to the default command
245 (setq current-command *default-command*))
246 (t (setq current-command object)))
247 (redisplay arecord stream))
248 (av-exit ()
249 (finalize-query-records *accepting-values-stream*)
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
250 (setf (last-pass *accepting-values-stream*) t)
85b78a6 Add new :inset border shape. Use this to surround text fields created…
Andy Hefner authored
251 (redisplay arecord stream)))
1b4fa11 Always finalize the input-editing stream used in accepting-values.
Troels Henriksen authored
252 (dolist (query (queries *accepting-values-stream*))
253 (finalize (editing-stream (record query)) nil))
85b78a6 Add new :inset border shape. Use this to surround text fields created…
Andy Hefner authored
254 (erase-output-record arecord stream)
255 (setf (stream-cursor-position stream)
256 (values cx cy)))))))
91cfdcb Back out Andy's fix; accomplish the same thing by calling (setf
Timothy Moore authored
257
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
258 (defgeneric display-exit-boxes (frame stream view))
259
260 (defmethod display-exit-boxes (frame stream (view textual-dialog-view))
261 (declare (ignore frame))
262 (updating-output (stream :unique-id 'buttons :cache-value t)
263 (fresh-line stream)
5416a30 Add new keyword to accepting-values, select-first-query, to automatic…
Andy Hefner authored
264 (formatting-table (stream)
265 (formatting-row (stream)
266 (formatting-cell (stream)
267 (with-output-as-presentation (stream nil 'exit-button)
268 (surrounding-output-with-border
269 (stream :shape :rounded :radius 6
270 :background +gray80+ :highlight-background +gray90+)
271 (format stream "OK"))))
272 (formatting-cell (stream)
273 (with-output-as-presentation
e3a195f Fixed problem with Cancel button in accepting-values.
Robert Strandh authored
274 (stream nil 'abort-button)
5416a30 Add new keyword to accepting-values, select-first-query, to automatic…
Andy Hefner authored
275 (surrounding-output-with-border
e3a195f Fixed problem with Cancel button in accepting-values.
Robert Strandh authored
276 (stream :shape :rounded :radius 6
277 :background +gray80+ :highlight-background +gray90+)
278 (format stream "Cancel"))))))
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
279 (terpri stream)))
280
281 (defmethod stream-accept ((stream accepting-values-stream) type
282 &rest rest-args
283 &key
284 (view (stream-default-view stream))
285 (default nil default-supplied-p)
286 default-type
287 provide-default
288 insert-default
289 replace-input
290 history
291 active-p
292 prompt
293 prompt-mode
294 display-default
295 (query-identifier prompt)
296 activation-gestures
297 additional-activation-gestures
298 delimiter-gestures
299 additional-delimiter-gestures)
b6f5ae7 Added more IGNORE declarations.
Robert Strandh authored
300 (declare (ignore default-type provide-default insert-default replace-input
301 history active-p prompt-mode display-default
302 activation-gestures additional-activation-gestures
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
303 delimiter-gestures additional-delimiter-gestures))
304 (let ((query (find query-identifier (queries stream)
45da96f Implemented :ALIGN-PROMPTS in ACCEPTING-VALUES. This was harder than
Timothy Moore authored
305 :key #'query-identifier :test #'equal))
306 (align (align-prompts stream)))
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
307 (unless query
5a6514c Changed the handling of "empty input" for the purposes of returning a
Timothy Moore authored
308 ;; If there's no default but empty input could return a sensible value,
309 ;; use that as a default.
310 (unless default-supplied-p
311 (setq default
312 (ignore-errors (accept-from-string type
313 ""
314 :view +textual-view+ ))))
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
315 (setq query (make-instance 'query
316 :query-identifier query-identifier
317 :ptype type
318 :view view
319 :default default
7945407 Changed STREAM-DESIGNATOR-SYMBOL to take a default value
Timothy Moore authored
320 :default-supplied-p default-supplied-p
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
321 :value default))
849c306 Committed patch from Daniel Jensen changing name of ACCEPTING-VALUES
Troels Henriksen authored
322 (setf (queries stream) (nconc (queries stream) (list query)))
323 (when default
324 (setf (changedp query) t)))
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
325 (setf (accept-arguments query) rest-args)
326 ;; If the program changes the default, that becomes the value.
327 (unless (equal default (default query))
328 (setf (default query) default)
329 (setf (value query) default))
45da96f Implemented :ALIGN-PROMPTS in ACCEPTING-VALUES. This was harder than
Timothy Moore authored
330 (flet ((do-prompt ()
331 (apply #'prompt-for-accept stream type view rest-args))
332 (do-accept-present-default ()
333 (funcall-presentation-generic-function
334 accept-present-default
335 type (encapsulating-stream-stream stream) view
336 (value query)
337 default-supplied-p nil query-identifier)))
338 (let ((query-record nil))
339 (if align
340 (formatting-row (stream)
b621b37 Center the label with the text field, since s-o-w-b scrambles the notion
Andy Hefner authored
341 (formatting-cell (stream :align-x align :align-y :center)
45da96f Implemented :ALIGN-PROMPTS in ACCEPTING-VALUES. This was harder than
Timothy Moore authored
342 (do-prompt))
343 (formatting-cell (stream)
344 (setq query-record (do-accept-present-default))))
345 (progn
346 (do-prompt)
347 (setq query-record (do-accept-present-default))))
348 (setf (record query) query-record)
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
349 (when (and (last-pass stream) (accept-condition query))
45da96f Implemented :ALIGN-PROMPTS in ACCEPTING-VALUES. This was harder than
Timothy Moore authored
350 (signal (accept-condition query)))
351 (multiple-value-prog1
352 (values (value query) (ptype query) (changedp query))
353 (setf (default query) default)
354 (setf (ptype query) type)
355 (setf (changedp query) nil))))))
356
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
357
358 (defmethod prompt-for-accept ((stream accepting-values-stream)
359 type view
360 &rest args)
361 (declare (ignore view))
362 (apply #'prompt-for-accept-1 stream type :display-default nil args))
363
849c306 Committed patch from Daniel Jensen changing name of ACCEPTING-VALUES
Troels Henriksen authored
364 (define-command (com-query-exit :command-table accept-values
759e48e 2004-03-24 Timothy Moore <moore@bricoworks.com>
Timothy Moore authored
365 :name nil
366 :provide-output-destination-keyword nil)
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
367 ()
368 (signal 'av-exit))
369
849c306 Committed patch from Daniel Jensen changing name of ACCEPTING-VALUES
Troels Henriksen authored
370 (define-command (com-query-abort :command-table accept-values
759e48e 2004-03-24 Timothy Moore <moore@bricoworks.com>
Timothy Moore authored
371 :name nil
372 :provide-output-destination-keyword nil)
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
373 ()
374 (and (find-restart 'abort)
375 (invoke-restart 'abort)))
376
849c306 Committed patch from Daniel Jensen changing name of ACCEPTING-VALUES
Troels Henriksen authored
377 (define-command (com-change-query :command-table accept-values
759e48e 2004-03-24 Timothy Moore <moore@bricoworks.com>
Timothy Moore authored
378 :name nil
379 :provide-output-destination-keyword nil)
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
380 ((query-identifier t)
381 (value t))
382 (when *accepting-values-stream*
383 (let ((query (find query-identifier (queries *accepting-values-stream*)
384 :key #'query-identifier :test #'equal)))
385 (when query
386 (setf (value query) value)
387 (setf (changedp query) t)))))
388
389 (defgeneric select-query (stream query record)
390 (:documentation "Does whatever is needed for input (e.g., calls accept) when
53edf03 Implemented a pop-up-menu-view for displaying the completion
Timothy Moore authored
391 a query is selected for input. It is responsible for updating the
392 query object when a new value is entered in the query field." ))
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
393
394 (defgeneric deselect-query (stream query record)
395 (:documentation "Deselect a query field: turn the cursor off, turn off
396 highlighting, etc." ))
397
849c306 Committed patch from Daniel Jensen changing name of ACCEPTING-VALUES
Troels Henriksen authored
398 (define-command (com-select-query :command-table accept-values
759e48e 2004-03-24 Timothy Moore <moore@bricoworks.com>
Timothy Moore authored
399 :name nil
400 :provide-output-destination-keyword nil)
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
401 ((query-identifier t))
402 (when *accepting-values-stream*
403 (with-accessors ((selected-query selected-query))
404 *accepting-values-stream*
405 (let* ((query-list (member query-identifier
406 (queries *accepting-values-stream*)
407 :key #'query-identifier :test #'equal))
408 (query (car query-list)))
409 (when selected-query
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
410 (unless (equal query-identifier (query-identifier selected-query))
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
411 (deselect-query *accepting-values-stream*
412 selected-query
413 (record selected-query))))
414 (when query
415 (setf selected-query query)
416 (select-query *accepting-values-stream* query (record query))
849c306 Committed patch from Daniel Jensen changing name of ACCEPTING-VALUES
Troels Henriksen authored
417 (let ((command-ptype '(command :command-table accept-values)))
bb63cf8 Implement :SINGLE-BOX properly.:SINGLE-BOX NIL is the default, but
Timothy Moore authored
418 (if (cdr query-list)
419 (throw-object-ptype `(com-select-query ,(query-identifier
420 (cadr query-list)))
421 command-ptype)
422 (throw-object-ptype '(com-deselect-query) command-ptype))))))))
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
423
849c306 Committed patch from Daniel Jensen changing name of ACCEPTING-VALUES
Troels Henriksen authored
424 (define-command (com-deselect-query :command-table accept-values
759e48e 2004-03-24 Timothy Moore <moore@bricoworks.com>
Timothy Moore authored
425 :name nil
426 :provide-output-destination-keyword nil)
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
427 ()
428 (when *accepting-values-stream*
429 (with-accessors ((selected-query selected-query))
430 *accepting-values-stream*
431 (when selected-query
432 (deselect-query *accepting-values-stream*
433 selected-query
434 (record selected-query))
435 (setf selected-query nil)))))
436
437 (defclass av-text-record (standard-updating-output-record)
438 ((editing-stream :accessor editing-stream)
439 (snapshot :accessor snapshot :initarg :snapshot :initform nil
440 :documentation "A copy of the stream buffer before accept
441 is called. Used to determine if any editing has been done by user")))
442
870e24f Implement the :INITIALLY-SELECT-QUERY-IDENTIFIER option of
Timothy Moore authored
443 (defparameter *no-default-cache-value* (cons nil nil))
444
bb63cf8 Implement :SINGLE-BOX properly.:SINGLE-BOX NIL is the default, but
Timothy Moore authored
445 ;;; Hack until more views / dialog gadgets are defined.
446
447 (define-default-presentation-method accept-present-default
448 (type stream (view text-field-view) default default-supplied-p
449 present-p query-identifier)
450 (if (width view)
451 (multiple-value-bind (cx cy)
452 (stream-cursor-position stream)
453 (declare (ignore cy))
454 (letf (((stream-text-margin stream) (+ cx (width view))))
455 (funcall-presentation-generic-function accept-present-default
456 type
457 stream
458 +textual-dialog-view+
459 default default-supplied-p
460 present-p
461 query-identifier)))))
462
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
463 (define-default-presentation-method accept-present-default
464 (type stream (view textual-dialog-view) default default-supplied-p
465 present-p query-identifier)
7945407 Changed STREAM-DESIGNATOR-SYMBOL to take a default value
Timothy Moore authored
466 (declare (ignore present-p))
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
467 (let* ((editing-stream nil)
468 (record (updating-output (stream :unique-id query-identifier
0dd46af Committed changes necessary to support Drei (and non-Goatee input
Troels Henriksen authored
469 :cache-value (if default-supplied-p
470 default
471 *no-default-cache-value*)
472 :record-type 'av-text-record)
473 (with-output-as-presentation
474 (stream query-identifier 'selectable-query
475 :single-box t)
476 (surrounding-output-with-border
5416a30 Add new keyword to accepting-values, select-first-query, to automatic…
Andy Hefner authored
477 (stream :shape :rounded
478 :radius 3 :background +white+
479 :foreground +gray40+
480 :move-cursor t)
481 ;;; FIXME: In this instance we really want borders that
482 ;;; react to the growth of their children. This should
483 ;;; be straightforward unless there is some involvement
484 ;;; of incremental redisplay.
485 ;;; KLUDGE: Arbitrary min-width.
0dd46af Committed changes necessary to support Drei (and non-Goatee input
Troels Henriksen authored
486 (setq editing-stream
80047ed Now `*use-goatee*' also affects calls to `accept' within
Troels Henriksen authored
487 (make-instance (if *use-goatee*
488 'goatee-input-editing-stream
489 'standard-input-editing-stream)
0dd46af Committed changes necessary to support Drei (and non-Goatee input
Troels Henriksen authored
490 :stream stream
491 :cursor-visibility nil
492 :single-line t
5416a30 Add new keyword to accepting-values, select-first-query, to automatic…
Andy Hefner authored
493 :min-width (- (bounding-rectangle-max-x stream)
494 (stream-cursor-position stream)
495 100)))))
0dd46af Committed changes necessary to support Drei (and non-Goatee input
Troels Henriksen authored
496 (when default-supplied-p
497 (input-editing-rescan-loop ;XXX probably not needed
498 editing-stream
499 (lambda (s)
500 (presentation-replace-input s default type view
501 :rescan t)))))))
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
502 (when editing-stream
503 (setf (editing-stream record) editing-stream))
504 record))
505
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
506 (defun av-do-accept (query record interactive)
507 (let* ((estream (editing-stream record))
508 (ptype (ptype query))
509 (view (view query))
510 (default (default query))
511 (default-supplied-p (default-supplied-p query))
512 (accept-args (accept-arguments query))
513 (*activation-gestures* (apply #'make-activation-gestures
514 :existing-activation-gestures
515 (activation-gestures query)
516 accept-args))
517 (*delimiter-gestures* (apply #'make-delimiter-gestures
518 :existing-delimiter-args
519 (delimiter-gestures query)
520 accept-args)))
521 ;; If there was an error on a previous pass, set the insertion pointer to
522 ;; 0 so the user has a chance to edit the field without causing another
523 ;; error. Otherwise the insertion pointer should already be at the end of
524 ;; the input (because it was activated); perhaps we should set it anyway.
525 (when (accept-condition query)
526 (setf (stream-insertion-pointer estream) 0))
527 (reset-scan-pointer estream)
528 (setf (accept-condition query) nil)
529 ;; If a condition is thrown, then accept should return the old value and
530 ;; ptype.
531 (block accept-condition-handler
532 (setf (changedp query) nil)
533 (setf (values (value query) (ptype query))
534 (input-editing-rescan-loop
535 estream
536 #'(lambda (s)
537 (handler-bind
538 ((error
539 #'(lambda (c)
540 (format *trace-output*
0dd46af Committed changes necessary to support Drei (and non-Goatee input
Troels Henriksen authored
541 "accepting-values accept condition: ~A~%"
542 c)
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
543 (if interactive
0dd46af Committed changes necessary to support Drei (and non-Goatee input
Troels Henriksen authored
544 (progn
545 (beep)
546 (setf (stream-insertion-pointer estream)
547 (max 0 (1- (stream-scan-pointer estream))))
548 (immediate-rescan estream)
549 (format *trace-output* "Ack!~%"))
550 (progn
551 (setf (accept-condition query) c)
552 (return-from accept-condition-handler
553 c))))))
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
554 (if default-supplied-p
555 (accept ptype :stream s
556 :view view :prompt nil :default default)
557 (accept ptype :stream s :view view :prompt nil))))))
558 (setf (changedp query) t))))
559
7945407 Changed STREAM-DESIGNATOR-SYMBOL to take a default value
Timothy Moore authored
560
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
561
562
563 ;;; The desired
564 (defmethod select-query (stream query (record av-text-record))
565 (declare (ignore stream))
566 (let ((estream (editing-stream record))
567 (ptype (ptype query))
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
568 (view (view query)))
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
569 (declare (ignore ptype view)) ;for now
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
570 (with-accessors ((stream-input-buffer stream-input-buffer))
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
571 estream
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
572 (setf (cursor-visibility estream) t)
573 (setf (snapshot record) (copy-seq stream-input-buffer))
574 (av-do-accept query record t))))
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
575
576
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
577 ;;; If the query has not been changed (i.e., ACCEPT didn't return) and there is
578 ;;; no error, act as if the user activated the query.
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
579 (defmethod deselect-query (stream query (record av-text-record))
580 (let ((estream (editing-stream record)))
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
581 (setf (cursor-visibility estream) nil)
582 (when (not (or (changedp query) (accept-condition query)))
583 (finalize-query-record query record))))
584
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
585
586 (defgeneric finalize-query-record (query record)
587 (:documentation "Do any cleanup on a query before the accepting-values body
588 is run for the last time"))
589
590 (defmethod finalize-query-record (query record)
591 nil)
592
593 ;;; If the user edits a text field, selects another text field and
594 ;;; then exits from accepting-values without activating the first
595 ;;; field, the values returned would be some previous value or default
596 ;;; for the field, not what's on the screen. That would be completely
597 ;;; bogus. So, if a field has been edited but not activated, activate
598 ;;; it now. Unfortunately that's a bit hairy.
599
600 (defmethod finalize-query-record (query (record av-text-record))
601 (let ((estream (editing-stream record)))
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
602 (when (and (snapshot record)
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
603 (not (equal (snapshot record)
604 (stream-input-buffer estream))))
605 (let* ((activation-gestures (apply #'make-activation-gestures
606 :existing-activation-gestures
607 (activation-gestures query)
608 (accept-arguments query)))
609 (gesture (car activation-gestures)))
610 (when gesture
611 (let ((c (character-gesture-name gesture)))
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
612 (activate-stream estream c)
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
613 (reset-scan-pointer estream)
d015fe5 Fixed presentation highlighting to do the right thing in the
Timothy Moore authored
614 (av-do-accept query record nil)))))))
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
615
616 (defun finalize-query-records (av-stream)
617 (loop for query in (queries av-stream)
618 do (finalize-query-record query (record query))))
619
620
621 (define-presentation-to-command-translator com-select-field
849c306 Committed patch from Daniel Jensen changing name of ACCEPTING-VALUES
Troels Henriksen authored
622 (selectable-query com-select-query accept-values
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
623 :gesture :select
624 :documentation "Select field for input"
625 :pointer-documentation "Select field for input"
626 :echo nil
627 :tester ((object)
628 (let ((selected (selected-query *accepting-values-stream*)))
629 (or (null selected)
630 (not (eq (query-identifier selected) object))))))
631 (object)
632 `(,object))
633
634 (define-presentation-to-command-translator com-exit-button
849c306 Committed patch from Daniel Jensen changing name of ACCEPTING-VALUES
Troels Henriksen authored
635 (exit-button com-query-exit accept-values
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
636 :gesture :select
637 :documentation "Exit dialog"
638 :pointer-documentation "Exit dialog"
639 :echo nil)
640 ()
641 ())
642
643 (define-presentation-to-command-translator com-abort-button
849c306 Committed patch from Daniel Jensen changing name of ACCEPTING-VALUES
Troels Henriksen authored
644 (abort-button com-query-abort accept-values
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
645 :gesture :select
646 :documentation "Abort dialog"
647 :pointer-documentation "Abort dialog"
648 :echo nil)
649 ()
650 ())
56a3553 Added stub for ACCEPTING-VALUES.
Alexey Dejneka authored
651
6f5647d Accepting-values. It's ugly and has some cursor glitches but
Timothy Moore authored
652 (defun accepting-values-default-command ()
653 (loop
654 (read-gesture :stream *accepting-values-stream*)))
3ed1f42 Committing some old work: implementation of notify-user, with some
Andy Hefner authored
655
656
657 ;;;; notify-user
658
659 ;;; See http://openmap.bbn.com/hypermail/clim/0028.html for example usage.
660
661 ;;; TODO:
662 ;;; - associated-window argument?
663 ;;; - What is the correct return value from notify-user? We currently return
664 ;;; the name of the action given in the :exit-boxes argument.
665 ;;; - Invoke abort restart? Not necessary as it is with accepting-values,
666 ;;; but probably what "Classic CLIM" does.
667 ;;; - What are the default exit boxes? Just "Okay"? Okay and cancel?
668 ;;; - Reimplement using accepting-values, if accepting-values is ever
669 ;;; improved to produce comparable dialogs.
670 ;;; - Should the user really be able to close the window from the WM?
671
672 (defmethod notify-user (frame message &rest args)
673 (apply #'frame-manager-notify-user
674 (if frame (frame-manager frame) (find-frame-manager))
675 message
676 :frame frame
677 args))
678
679 (define-application-frame generic-notify-user-frame ()
680 ((message-string :initarg :message-string)
681 (exit-boxes :initarg :exit-boxes)
682 (title :initarg :title)
683 (style :initarg :style)
684 (text-style :initarg :text-style)
685 (return-value :initarg nil :initform :abort))
686 (:pane (generate-notify-user-dialog *application-frame*)))
687
688 (defun generate-notify-user-dialog (frame)
689 (with-slots (message-string exit-boxes text-style) frame
690 (vertically ()
691 (spacing (:thickness 6)
692 (make-pane 'label-pane :label (or message-string "I'm speechless.") :text-style text-style))
693 (spacing (:thickness 4)
694 (make-pane 'hbox-pane :contents (cons '+fill+ (generate-exit-box-buttons exit-boxes)))))))
695
696 (defun generate-exit-box-buttons (specs)
697 (mapcar
698 (lambda (spec)
699 (destructuring-bind (action string &rest args) spec
700 (spacing (:thickness 2)
701 (apply #'make-pane
702 'push-button
703 :label string
704 :text-style (make-text-style :sans-serif :roman :small) ; XXX
705 :activate-callback
706 (lambda (gadget)
707 (declare (ignore gadget))
708 ;; This is fboundp business is weird, and only implied by a
709 ;; random message on the old CLIM list. Does the user function
710 ;; take arguments?
711 (when (or (typep action 'function) (fboundp action))
712 (funcall action))
713 (setf (slot-value *application-frame* 'return-value) action)
714 ;; This doesn't work:
715 #+NIL
716 (when (eql action :abort)
717 (and (find-restart 'abort)
718 (invoke-restart 'abort)))
719 (frame-exit *application-frame*))
720 args))))
721 specs))
722
723
724 (defmethod frame-manager-notify-user
725 (frame-manager message-string &key frame associated-window
726 (title "")
727 documentation
728 (exit-boxes '((:exit "OK")))
729 ; The 'name' arg is in the spec but absent from the Lispworks
730 ; manual, and I can't imagine what it would do differently
731 ; than 'title'.
732 name
733 style
734 (text-style (make-text-style :sans-serif :roman :small)))
735 (declare (ignore associated-window documentation))
736 ;; Keywords from notify-user:
737 ;; associated-window title documentation exit-boxes name style text-style
738 (let ((frame (make-application-frame 'generic-notify-user-frame
5fb1d39 FRAME-MANAGER-NOTIFY-USER
Gilbert Baumann authored
739 :calling-frame frame
3ed1f42 Committing some old work: implementation of notify-user, with some
Andy Hefner authored
740 :pretty-name title
741 :message-string message-string
742 :frame-manager frame-manager
743 :exit-boxes exit-boxes
744 :title (or name title)
745 :style style
746 :text-style text-style)))
747 (run-frame-top-level frame)
748 (slot-value frame 'return-value)))
Something went wrong with that request. Please try again.