annotate lisp/dialog.el @ 390:c6012109f545 r21-2-10

Import from CVS: tag r21-2-10
author cvs
date Mon, 13 Aug 2007 11:10:03 +0200
parents cc15677e0335
children 2f8bb876ab1d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; dialog.el --- Dialog-box support for XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1991-4, 1997 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
5 ;; Maintainer: XEmacs Development Team
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
6 ;; Keywords: extensions, internal, dumped
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
7
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
9
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
22 ;; Free Software Foundation, 59 Temple Place - Suite 330,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25 ;;; Synched up with: Not in FSF.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
27 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29 ;; This file is dumped with XEmacs (when dialog boxes are compiled in).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32 (defun yes-or-no-p-dialog-box (prompt)
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
33 "Ask user a \"y or n\" question with a popup dialog box.
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
34 Returns t if answer is \"yes\".
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
35 Takes one argument, which is the string to display to ask the question."
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
36 (let ((echo-keystrokes 0)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
37 event)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
38 (popup-dialog-box
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
39 ;; "Non-violent language please!" says Robin.
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
40 (cons prompt '(["Yes" yes t] ["No" no t] nil ["Cancel" abort t])))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
41 ; (cons prompt '(["Yes" yes t] ["No" no t] nil ["Abort" abort t])))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
42 (catch 'ynp-done
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
43 (while t
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
44 (setq event (next-command-event event))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
45 (cond ((and (misc-user-event-p event) (eq (event-object event) 'yes))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
46 (throw 'ynp-done t))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
47 ((and (misc-user-event-p event) (eq (event-object event) 'no))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
48 (throw 'ynp-done nil))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
49 ((and (misc-user-event-p event)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
50 (or (eq (event-object event) 'abort)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
51 (eq (event-object event) 'menu-no-selection-hook)))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
52 (signal 'quit nil))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
53 ((button-release-event-p event) ;; don't beep twice
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
54 nil)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
55 (t
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
56 (beep)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 361
diff changeset
57 (message "please answer the dialog box")))))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 (defun yes-or-no-p-maybe-dialog-box (prompt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 "Ask user a yes-or-no question. Return t if answer is yes.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 The question is asked with a dialog box or the minibuffer, as appropriate.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62 Takes one argument, which is the string to display to ask the question.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 The user must confirm the answer with RET,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65 and can edit it until it as been confirmed."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 (if (should-use-dialog-box-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67 (yes-or-no-p-dialog-box prompt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 (yes-or-no-p-minibuf prompt)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 (defun y-or-n-p-maybe-dialog-box (prompt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 "Ask user a \"y or n\" question. Return t if answer is \"y\".
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 Takes one argument, which is the string to display to ask the question.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 The question is asked with a dialog box or the minibuffer, as appropriate.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74 It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 No confirmation of the answer is requested; a single character is enough.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 Also accepts Space to mean yes, or Delete to mean no."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 (if (should-use-dialog-box-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78 (yes-or-no-p-dialog-box prompt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79 (y-or-n-p-minibuf prompt)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 (if (fboundp 'popup-dialog-box)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83 (fset 'yes-or-no-p 'yes-or-no-p-maybe-dialog-box)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84 (fset 'y-or-n-p 'y-or-n-p-maybe-dialog-box)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 ;; this is call-compatible with the horribly-named FSF Emacs function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87 ;; `x-popup-dialog'. I refuse to use that name.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88 (defun get-dialog-box-response (position contents)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 ;; by Stig@hackvan.com
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90 ;; modified by pez@atlantic2.sbi.com
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91 "Pop up a dialog box and return user's selection.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 POSITION specifies which frame to use.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93 This is normally an event or a window or frame.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
94 If POSITION is t or nil, it means to use the frame the mouse is on.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 The dialog box appears in the middle of the specified frame.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97 CONTENTS specifies the alternatives to display in the dialog box.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
98 It is a list of the form (TITLE ITEM1 ITEM2...).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99 Each ITEM is a cons cell (STRING . VALUE).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100 The return value is VALUE from the chosen item.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 An ITEM may also be just a string--that makes a nonselectable item.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103 An ITEM may also be nil--that means to put all preceding items
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
104 on the left of the dialog box and all following items on the right."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
105 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 ((eventp position)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107 (select-frame (event-frame position)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 ((framep position)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 (select-frame position))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 ((windowp position)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 (select-window position)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 (let ((dbox (cons (car contents)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 (mapcar #'(lambda (x)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 ((null x)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 ((stringp x)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 `[,x 'ignore nil]) ;this will never get
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 ;selected
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
120 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121 `[,(car x) (throw 'result ',(cdr x)) t])))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
122 (cdr contents))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
123 )))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
124 (catch 'result
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
125 (popup-dialog-box dbox)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
126 (dispatch-event (next-command-event)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
127
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
128 (defun message-box (fmt &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
129 "Display a message, in a dialog box if possible.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
130 If the selected device has no dialog-box support, use the echo area.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
131 The arguments are the same as to `format'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
132
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
133 If the only argument is nil, clear any existing message; let the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
134 minibuffer contents show."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
135 (if (and (null fmt) (null args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
136 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
137 (clear-message nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
138 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
139 (let ((str (apply 'format fmt args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
140 (if (device-on-window-system-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
141 (get-dialog-box-response nil (list str (cons "OK" t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
142 (display-message 'message str))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
143 str)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
145 (defun message-or-box (fmt &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
146 "Display a message in a dialog box or in the echo area.\n\
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
147 If this command was invoked with the mouse, use a dialog box.\n\
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
148 Otherwise, use the echo area.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
149 The arguments are the same as to `format'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 If the only argument is nil, clear any existing message; let the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152 minibuffer contents show."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
153 (if (should-use-dialog-box-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 (apply 'message-box fmt args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
155 (apply 'message fmt args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
156
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
157 ;;; dialog.el ends here