annotate lisp/dialog.el @ 361:7347b34c275b r21-1-10

Import from CVS: tag r21-1-10
author cvs
date Mon, 13 Aug 2007 10:58:40 +0200
parents 41ff10fd062f
children cc15677e0335
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)
361
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
33 "Ask user a yes-or-no question with a popup dialog box.
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
34 Return t if the 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."
361
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
36 (save-selected-frame
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
37 (let ((echo-keystrokes 0)
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
38 event)
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
39 (popup-dialog-box
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
40 (cons prompt '(["Yes" yes t] ["No" no t] nil ["Cancel" abort t])))
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
41 (catch 'ynp-done
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
42 (while t
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
43 (setq event (next-command-event event))
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
44 (cond ((and (misc-user-event-p event) (eq (event-object event) 'yes))
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
45 (throw 'ynp-done t))
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
46 ((and (misc-user-event-p event) (eq (event-object event) 'no))
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
47 (throw 'ynp-done nil))
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
48 ((and (misc-user-event-p event)
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
49 (or (eq (event-object event) 'abort)
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
50 (eq (event-object event) 'menu-no-selection-hook)))
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
51 (signal 'quit nil))
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
52 ((button-release-event-p event);; don't beep twice
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
53 nil)
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
54 (t
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
55 (beep)
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 209
diff changeset
56 (message "please answer the dialog box"))))))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 (defun yes-or-no-p-maybe-dialog-box (prompt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 "Ask user a yes-or-no question. Return t if answer is yes.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 The question is asked with a dialog box or the minibuffer, as appropriate.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 Takes one argument, which is the string to display to ask the question.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62 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
63 The user must confirm the answer with RET,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 and can edit it until it as been confirmed."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65 (if (should-use-dialog-box-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 (yes-or-no-p-dialog-box prompt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67 (yes-or-no-p-minibuf prompt)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 (defun y-or-n-p-maybe-dialog-box (prompt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 "Ask user a \"y or n\" question. Return t if answer is \"y\".
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 Takes one argument, which is the string to display to ask the question.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 The question is asked with a dialog box or the minibuffer, as appropriate.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 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
74 No confirmation of the answer is requested; a single character is enough.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 Also accepts Space to mean yes, or Delete to mean no."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 (if (should-use-dialog-box-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 (yes-or-no-p-dialog-box prompt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78 (y-or-n-p-minibuf prompt)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80 (if (fboundp 'popup-dialog-box)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 (fset 'yes-or-no-p 'yes-or-no-p-maybe-dialog-box)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83 (fset 'y-or-n-p 'y-or-n-p-maybe-dialog-box)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85 ;; this is call-compatible with the horribly-named FSF Emacs function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 ;; `x-popup-dialog'. I refuse to use that name.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87 (defun get-dialog-box-response (position contents)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88 ;; by Stig@hackvan.com
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 ;; modified by pez@atlantic2.sbi.com
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90 "Pop up a dialog box and return user's selection.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91 POSITION specifies which frame to use.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 This is normally an event or a window or frame.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93 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
94 The dialog box appears in the middle of the specified frame.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 CONTENTS specifies the alternatives to display in the dialog box.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97 It is a list of the form (TITLE ITEM1 ITEM2...).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
98 Each ITEM is a cons cell (STRING . VALUE).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99 The return value is VALUE from the chosen item.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101 An ITEM may also be just a string--that makes a nonselectable item.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 An ITEM may also be nil--that means to put all preceding items
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103 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
104 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
105 ((eventp position)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 (select-frame (event-frame position)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107 ((framep position)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 (select-frame position))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 ((windowp position)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 (select-window position)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 (let ((dbox (cons (car contents)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 (mapcar #'(lambda (x)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 ((null x)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116 ((stringp x)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 `[,x 'ignore nil]) ;this will never get
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 ;selected
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
120 `[,(car x) (throw 'result ',(cdr x)) t])))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121 (cdr contents))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
122 )))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
123 (catch 'result
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
124 (popup-dialog-box dbox)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
125 (dispatch-event (next-command-event)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
126
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
127 (defun message-box (fmt &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
128 "Display a message, in a dialog box if possible.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
129 If the selected device has no dialog-box support, use the echo area.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
130 The arguments are the same as to `format'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
131
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
132 If the only argument is nil, clear any existing message; let the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
133 minibuffer contents show."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
134 (if (and (null fmt) (null args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
135 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
136 (clear-message nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
137 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
138 (let ((str (apply 'format fmt args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
139 (if (device-on-window-system-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
140 (get-dialog-box-response nil (list str (cons "OK" t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
141 (display-message 'message str))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
142 str)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
143
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144 (defun message-or-box (fmt &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
145 "Display a message in a dialog box or in the echo area.\n\
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
146 If this command was invoked with the mouse, use a dialog box.\n\
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
147 Otherwise, use the echo area.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
148 The arguments are the same as to `format'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
149
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 If the only argument is nil, clear any existing message; let the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 minibuffer contents show."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152 (if (should-use-dialog-box-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
153 (apply 'message-box fmt args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 (apply 'message fmt args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
155
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
156 ;;; dialog.el ends here