0
|
1 ;;; Toolbar related functions and commands
|
|
2 ;;; Copyright (C) 1995 Kyle E. Jones
|
|
3 ;;;
|
|
4 ;;; This program is free software; you can redistribute it and/or modify
|
|
5 ;;; it under the terms of the GNU General Public License as published by
|
|
6 ;;; the Free Software Foundation; either version 1, or (at your option)
|
|
7 ;;; any later version.
|
|
8 ;;;
|
|
9 ;;; This program 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
|
|
12 ;;; GNU General Public License for more details.
|
|
13 ;;;
|
|
14 ;;; You should have received a copy of the GNU General Public License
|
|
15 ;;; along with this program; if not, write to the Free Software
|
|
16 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17
|
|
18 (provide 'vm-toolbar)
|
|
19
|
|
20 (defvar vm-toolbar-specifier nil)
|
|
21
|
|
22 (defvar vm-toolbar-next-button
|
|
23 [vm-toolbar-next-icon
|
|
24 vm-toolbar-next-command
|
|
25 (vm-toolbar-any-messages-p)
|
|
26 "Go to the next message.\n
|
|
27 The command `vm-toolbar-next-command' is run, which is normally
|
|
28 bound to `vm-next-message'.
|
|
29 You can make this button run some other command by using a Lisp
|
|
30 s-expression like this one in your .vm file:
|
|
31 (fset 'vm-toolbar-next-command 'some-other-command)"])
|
|
32 (defvar vm-toolbar-next-icon nil)
|
|
33 (or (fboundp 'vm-toolbar-next-command)
|
|
34 (fset 'vm-toolbar-next-command 'vm-next-message))
|
|
35
|
|
36 (defvar vm-toolbar-previous-button
|
|
37 [vm-toolbar-previous-icon
|
|
38 vm-toolbar-previous-command
|
|
39 (vm-toolbar-any-messages-p)
|
|
40 "Go to the previous message.\n
|
|
41 The command `vm-toolbar-previous-command' is run, which is normally
|
|
42 bound to `vm-previous-message'.
|
|
43 You can make this button run some other command by using a Lisp
|
|
44 s-expression like this one in your .vm file:
|
|
45 (fset 'vm-toolbar-previous-command 'some-other-command)"])
|
|
46 (defvar vm-toolbar-previous-icon nil)
|
|
47 (or (fboundp 'vm-toolbar-previous-command)
|
|
48 (fset 'vm-toolbar-previous-command 'vm-previous-message))
|
|
49
|
|
50 (defvar vm-toolbar-autofile-button
|
|
51 [vm-toolbar-autofile-icon
|
|
52 vm-toolbar-autofile-message
|
|
53 (vm-toolbar-can-autofile-p)
|
|
54 "Save the current message to a folder selected using vm-auto-folder-alist."])
|
|
55 (defvar vm-toolbar-autofile-icon nil)
|
|
56
|
|
57 (defvar vm-toolbar-file-button
|
|
58 [vm-toolbar-file-icon vm-toolbar-file-command (vm-toolbar-any-messages-p)
|
|
59 "Save the current message to a folder.\n
|
|
60 The command `vm-toolbar-file-command' is run, which is normally
|
|
61 bound to `vm-save-message'.
|
|
62 You can make this button run some other command by using a Lisp
|
|
63 s-expression like this one in your .vm file:
|
|
64 (fset 'vm-toolbar-file-command 'some-other-command)"])
|
|
65 (defvar vm-toolbar-file-icon nil)
|
|
66 (or (fboundp 'vm-toolbar-file-command)
|
|
67 (fset 'vm-toolbar-file-command 'vm-save-message))
|
|
68
|
|
69 (defvar vm-toolbar-print-button
|
|
70 [vm-toolbar-print-icon
|
|
71 vm-toolbar-print-command
|
|
72 (vm-toolbar-any-messages-p)
|
|
73 "Print the current message.\n
|
|
74 The command `vm-toolbar-print-command' is run, which is normally
|
|
75 bound to `vm-print-message'.
|
|
76 You can make this button run some other command by using a Lisp
|
|
77 s-expression like this one in your .vm file:
|
|
78 (fset 'vm-toolbar-print-command 'some-other-command)"])
|
|
79 (defvar vm-toolbar-print-icon nil)
|
|
80 (or (fboundp 'vm-toolbar-print-command)
|
|
81 (fset 'vm-toolbar-print-command 'vm-print-message))
|
|
82
|
|
83 (defvar vm-toolbar-visit-button
|
|
84 [vm-toolbar-visit-icon vm-toolbar-visit-command t
|
|
85 "Visit a different folder.\n
|
|
86 The command `vm-toolbar-visit-command' is run, which is normally
|
|
87 bound to `vm-visit-folder'.
|
|
88 You can make this button run some other command by using a Lisp
|
|
89 s-expression like this one in your .vm file:
|
|
90 (fset 'vm-toolbar-visit-command 'some-other-command)"])
|
|
91 (defvar vm-toolbar-visit-icon nil)
|
|
92 (or (fboundp 'vm-toolbar-visit-command)
|
|
93 (fset 'vm-toolbar-visit-command 'vm-visit-folder))
|
|
94
|
|
95 (defvar vm-toolbar-reply-button
|
|
96 [vm-toolbar-reply-icon
|
|
97 vm-toolbar-reply-command
|
|
98 (vm-toolbar-any-messages-p)
|
|
99 "Reply to the current message.\n
|
|
100 The command `vm-toolbar-reply-command' is run, which is normally
|
|
101 bound to `vm-followup-include-text'.
|
|
102 You can make this button run some other command by using a Lisp
|
|
103 s-expression like this one in your .vm file:
|
|
104 (fset 'vm-toolbar-reply-command 'some-other-command)"])
|
|
105 (defvar vm-toolbar-reply-icon nil)
|
|
106 (or (fboundp 'vm-toolbar-reply-command)
|
|
107 (fset 'vm-toolbar-reply-command 'vm-followup-include-text))
|
|
108
|
|
109 (defvar vm-toolbar-compose-button
|
|
110 [vm-toolbar-compose-icon vm-toolbar-compose-command t
|
|
111 "Compose a new message.\n
|
|
112 The command `vm-toolbar-compose-command' is run, which is normally
|
|
113 bound to `vm-mail'.
|
|
114 You can make this button run some other command by using a Lisp
|
|
115 s-expression like this one in your .vm file:
|
|
116 (fset 'vm-toolbar-compose-command 'some-other-command)"])
|
|
117 (defvar vm-toolbar-compose-icon nil)
|
|
118 (or (fboundp 'vm-toolbar-compose-command)
|
|
119 (fset 'vm-toolbar-compose-command 'vm-mail))
|
|
120
|
|
121 (defvar vm-toolbar-delete-icon nil)
|
|
122
|
|
123 (defvar vm-toolbar-undelete-icon nil)
|
|
124
|
|
125 (defvar vm-toolbar-delete/undelete-button
|
|
126 [vm-toolbar-delete/undelete-icon
|
|
127 vm-toolbar-delete/undelete-message
|
|
128 (vm-toolbar-any-messages-p)
|
|
129 "Delete the current message, or undelete it if it is already deleted."])
|
|
130 (defvar vm-toolbar-delete/undelete-icon nil)
|
|
131 (make-variable-buffer-local 'vm-toolbar-delete/undelete-icon)
|
|
132
|
|
133 (defvar vm-toolbar-help-icon nil)
|
|
134
|
|
135 (defvar vm-toolbar-recover-icon nil)
|
|
136
|
|
137 (defvar vm-toolbar-helper-icon nil)
|
|
138 (make-variable-buffer-local 'vm-toolbar-helper-icon)
|
|
139
|
|
140 (defvar vm-toolbar-help-button
|
|
141 [vm-toolbar-helper-icon vm-toolbar-helper-command t
|
|
142 "Don't Panic.\n
|
|
143 VM uses this button to offer help if you're in trouble.
|
|
144 Under normal circumstances, this button runs `vm-help'.\n
|
|
145 If the current folder looks out-of-date relative to its auto-save
|
|
146 file then this button will run `recover-file'."])
|
|
147
|
|
148 (defvar vm-toolbar-helper-command nil)
|
|
149 (make-variable-buffer-local 'vm-toolbar-helper-command)
|
|
150
|
|
151 (defun vm-toolbar-helper-command ()
|
|
152 (interactive)
|
|
153 (setq this-command vm-toolbar-helper-command)
|
|
154 (call-interactively vm-toolbar-helper-command))
|
|
155
|
|
156 (defvar vm-toolbar-quit-button
|
|
157 [vm-toolbar-quit-icon vm-toolbar-quit-command t
|
10
|
158 "Quit visiting this folder.\n
|
0
|
159 The command `vm-toolbar-quit-command' is run, which is normally
|
|
160 bound to `vm-quit'.
|
|
161 You can make this button run some other command by using a Lisp
|
|
162 s-expression like this one in your .vm file:
|
|
163 (fset 'vm-toolbar-quit-command 'some-other-command)"])
|
|
164 (defvar vm-toolbar-quit-icon nil)
|
|
165 (or (fboundp 'vm-toolbar-quit-command)
|
|
166 (fset 'vm-toolbar-quit-command 'vm-quit))
|
|
167
|
|
168 (defun vm-toolbar-any-messages-p ()
|
|
169 (save-excursion
|
|
170 (vm-check-for-killed-folder)
|
|
171 (vm-select-folder-buffer)
|
|
172 vm-message-list))
|
|
173
|
|
174 (defun vm-toolbar-delete/undelete-message (&optional prefix-arg)
|
|
175 (interactive "P")
|
|
176 (vm-follow-summary-cursor)
|
|
177 (vm-select-folder-buffer)
|
|
178 (vm-check-for-killed-summary)
|
|
179 (vm-error-if-folder-read-only)
|
|
180 (vm-error-if-folder-empty)
|
|
181 (let ((current-prefix-arg prefix-arg))
|
|
182 (if (vm-deleted-flag (car vm-message-pointer))
|
|
183 (call-interactively 'vm-undelete-message)
|
|
184 (call-interactively 'vm-delete-message))))
|
|
185
|
|
186 (defun vm-toolbar-can-autofile-p ()
|
|
187 (interactive)
|
|
188 (save-excursion
|
|
189 (vm-check-for-killed-folder)
|
|
190 (vm-select-folder-buffer)
|
|
191 (and vm-message-pointer
|
|
192 (vm-auto-select-folder vm-message-pointer vm-auto-folder-alist))))
|
|
193
|
|
194 (defun vm-toolbar-autofile-message ()
|
|
195 (interactive)
|
|
196 (vm-follow-summary-cursor)
|
|
197 (vm-select-folder-buffer)
|
|
198 (vm-check-for-killed-summary)
|
|
199 (vm-error-if-folder-read-only)
|
|
200 (vm-error-if-folder-empty)
|
|
201 (let ((file (vm-auto-select-folder vm-message-pointer vm-auto-folder-alist)))
|
|
202 (if file
|
|
203 (progn
|
|
204 (vm-save-message file 1)
|
|
205 (message "Message saved to %s" file))
|
|
206 (error "No match for message in vm-auto-folder-alist."))))
|
|
207
|
|
208 (defun vm-toolbar-can-recover-p ()
|
|
209 (save-excursion
|
|
210 (vm-check-for-killed-folder)
|
|
211 (vm-select-folder-buffer)
|
|
212 (and vm-folder-read-only
|
|
213 buffer-file-name
|
|
214 buffer-auto-save-file-name
|
|
215 (null (buffer-modified-p))
|
|
216 (file-newer-than-file-p
|
|
217 buffer-auto-save-file-name
|
|
218 buffer-file-name))))
|
|
219
|
|
220 (defun vm-toolbar-update-toolbar ()
|
|
221 (if (and vm-message-pointer (vm-deleted-flag (car vm-message-pointer)))
|
|
222 (setq vm-toolbar-delete/undelete-icon vm-toolbar-undelete-icon)
|
|
223 (setq vm-toolbar-delete/undelete-icon vm-toolbar-delete-icon))
|
|
224 (cond ((vm-toolbar-can-recover-p)
|
|
225 (setq vm-toolbar-helper-command 'recover-file
|
|
226 vm-toolbar-helper-icon vm-toolbar-recover-icon))
|
|
227 (t
|
|
228 (setq vm-toolbar-helper-command 'vm-help
|
|
229 vm-toolbar-helper-icon vm-toolbar-help-icon)))
|
|
230 (if vm-summary-buffer
|
|
231 (vm-copy-local-variables vm-summary-buffer
|
|
232 'vm-toolbar-delete/undelete-icon
|
|
233 'vm-toolbar-helper-command
|
|
234 'vm-toolbar-helper-icon))
|
|
235 (and vm-toolbar-specifier
|
|
236 (progn
|
10
|
237 (set-specifier vm-toolbar-specifier (cons (current-buffer) nil))
|
|
238 (set-specifier vm-toolbar-specifier (cons (current-buffer)
|
|
239 vm-toolbar)))))
|
0
|
240
|
|
241 (defun vm-toolbar-install-toolbar ()
|
|
242 (vm-toolbar-initialize)
|
10
|
243 (let ((height (+ 4 (glyph-height (car vm-toolbar-help-icon))))
|
0
|
244 (width (+ 4 (glyph-width (car vm-toolbar-help-icon))))
|
10
|
245 toolbar )
|
|
246 ;; honor user setting of vm-toolbar if they are daring enough
|
|
247 ;; to set it.
|
|
248 (if vm-toolbar
|
|
249 (setq toolbar vm-toolbar)
|
|
250 (setq toolbar (vm-toolbar-make-toolbar-spec)
|
|
251 vm-toolbar toolbar))
|
0
|
252 (cond ((eq vm-toolbar-orientation 'right)
|
|
253 (setq vm-toolbar-specifier right-toolbar)
|
10
|
254 (set-specifier right-toolbar (cons (current-buffer) toolbar))
|
|
255 (set-specifier right-toolbar-width
|
|
256 (cons (selected-frame) width)))
|
0
|
257 ((eq vm-toolbar-orientation 'left)
|
|
258 (setq vm-toolbar-specifier left-toolbar)
|
10
|
259 (set-specifier left-toolbar (cons (current-buffer) toolbar))
|
|
260 (set-specifier left-toolbar-width
|
|
261 (cons (selected-frame) width)))
|
0
|
262 ((eq vm-toolbar-orientation 'bottom)
|
|
263 (setq vm-toolbar-specifier bottom-toolbar)
|
10
|
264 (set-specifier bottom-toolbar (cons (current-buffer) toolbar))
|
|
265 (set-specifier bottom-toolbar-height
|
|
266 (cons (selected-frame) height)))
|
0
|
267 (t
|
|
268 (setq vm-toolbar-specifier top-toolbar)
|
10
|
269 (set-specifier top-toolbar (cons (current-buffer) toolbar))
|
|
270 (set-specifier top-toolbar-height
|
|
271 (cons (selected-frame) height))))))
|
0
|
272
|
|
273 (defun vm-toolbar-make-toolbar-spec ()
|
|
274 (let ((button-alist '(
|
|
275 (autofile . vm-toolbar-autofile-button)
|
|
276 (compose . vm-toolbar-compose-button)
|
|
277 (delete/undelete . vm-toolbar-delete/undelete-button)
|
|
278 (file . vm-toolbar-file-button)
|
|
279 (help . vm-toolbar-help-button)
|
|
280 (next . vm-toolbar-next-button)
|
|
281 (previous . vm-toolbar-previous-button)
|
|
282 (print . vm-toolbar-print-button)
|
|
283 (quit . vm-toolbar-quit-button)
|
|
284 (reply . vm-toolbar-reply-button)
|
|
285 (visit . vm-toolbar-visit-button)
|
|
286 ))
|
|
287 (button-list vm-use-toolbar)
|
|
288 cons
|
|
289 (toolbar nil))
|
|
290 (while button-list
|
|
291 (if (null (car button-list))
|
|
292 (setq toolbar (cons nil toolbar))
|
|
293 (setq cons (assq (car button-list) button-alist))
|
|
294 (if cons
|
|
295 (setq toolbar (cons (symbol-value (cdr cons)) toolbar))))
|
|
296 (setq button-list (cdr button-list)))
|
|
297 (nreverse toolbar) ))
|
|
298
|
|
299 (defun vm-toolbar-initialize ()
|
|
300 ;; drag these in now instead of waiting for them to be
|
|
301 ;; autoloaded. the "loading..." messages could come at a bad
|
|
302 ;; moment and wipe an important echo area message, like "Auto
|
|
303 ;; save file is newer..."
|
|
304 (require 'vm-save)
|
|
305 (require 'vm-summary)
|
|
306 (cond
|
|
307 ((null vm-toolbar-help-icon)
|
|
308 (let ((tuples
|
|
309 (if (featurep 'xpm)
|
|
310 '(
|
|
311 (vm-toolbar-next-icon "next-up.xpm" "next-dn.xpm" "next-dn.xpm")
|
|
312 (vm-toolbar-previous-icon "previous-up.xpm" "previous-dn.xpm"
|
|
313 "previous-dn.xpm")
|
|
314 (vm-toolbar-delete-icon "delete-up.xpm" "delete-dn.xpm" "delete-dn.xpm")
|
|
315 (vm-toolbar-undelete-icon "undelete-up.xpm" "undelete-dn.xpm"
|
|
316 "undelete-dn.xpm")
|
|
317 (vm-toolbar-autofile-icon "autofile-up.xpm" "autofile-dn.xpm"
|
|
318 "autofile-dn.xpm")
|
|
319 (vm-toolbar-file-icon "file-up.xpm" "file-dn.xpm" "file-dn.xpm")
|
|
320 (vm-toolbar-reply-icon "reply-up.xpm" "reply-dn.xpm" "reply-dn.xpm")
|
|
321 (vm-toolbar-compose-icon "compose-up.xpm" "compose-dn.xpm" "compose-dn.xpm")
|
|
322 (vm-toolbar-print-icon "print-up.xpm" "print-dn.xpm" "print-dn.xpm")
|
|
323 (vm-toolbar-visit-icon "visit-up.xpm" "visit-dn.xpm" "visit-dn.xpm")
|
|
324 (vm-toolbar-quit-icon "quit-up.xpm" "quit-dn.xpm" "quit-dn.xpm")
|
|
325 (vm-toolbar-help-icon "help-up.xpm" "help-dn.xpm" "help-dn.xpm")
|
|
326 (vm-toolbar-recover-icon "recover-up.xpm" "recover-dn.xpm" "recover-dn.xpm")
|
|
327 )
|
|
328 '(
|
|
329 (vm-toolbar-next-icon "next-up.xbm" "next-dn.xbm" "next-xx.xbm")
|
|
330 (vm-toolbar-previous-icon "previous-up.xbm" "previous-dn.xbm"
|
|
331 "previous-xx.xbm")
|
|
332 (vm-toolbar-delete-icon "delete-up.xbm" "delete-dn.xbm" "delete-xx.xbm")
|
|
333 (vm-toolbar-undelete-icon "undelete-up.xbm" "undelete-dn.xbm"
|
|
334 "undelete-xx.xbm")
|
|
335 (vm-toolbar-autofile-icon "autofile-up.xbm" "autofile-dn.xbm"
|
|
336 "autofile-xx.xbm")
|
|
337 (vm-toolbar-file-icon "file-up.xbm" "file-dn.xbm" "file-xx.xbm")
|
|
338 (vm-toolbar-reply-icon "reply-up.xbm" "reply-dn.xbm" "reply-xx.xbm")
|
|
339 (vm-toolbar-compose-icon "compose-up.xbm" "compose-dn.xbm" "compose-xx.xbm")
|
|
340 (vm-toolbar-print-icon "print-up.xbm" "print-dn.xbm" "print-xx.xbm")
|
|
341 (vm-toolbar-visit-icon "visit-up.xbm" "visit-dn.xbm" "visit-xx.xbm")
|
|
342 (vm-toolbar-quit-icon "quit-up.xbm" "quit-dn.xbm" "quit-xx.xbm")
|
|
343 (vm-toolbar-help-icon "help-up.xbm" "help-dn.xbm" "help-xx.xpm")
|
|
344 (vm-toolbar-recover-icon "recover-up.xbm" "recover-dn.xbm" "recover-xx.xpm")
|
|
345 )))
|
|
346 tuple files var)
|
|
347 (if (not (file-directory-p vm-toolbar-pixmap-directory))
|
|
348 (error "Bad toolbar pixmap directory: %s"
|
|
349 vm-toolbar-pixmap-directory)
|
|
350 (while tuples
|
|
351 (setq tuple (car tuples)
|
|
352 var (car tuple)
|
|
353 files (cdr tuple))
|
|
354 (set var (mapcar
|
|
355 (function
|
|
356 (lambda (f)
|
|
357 (make-glyph
|
|
358 (expand-file-name f vm-toolbar-pixmap-directory))))
|
|
359 files))
|
|
360 (setq tuples (cdr tuples)))))))
|
|
361 (setq vm-toolbar-delete/undelete-icon vm-toolbar-delete-icon)
|
|
362 (setq vm-toolbar-helper-command 'vm-help)
|
|
363 (setq vm-toolbar-helper-icon vm-toolbar-help-icon))
|