1 ;;; toolbar-items.el -- Static initialization of XEmacs toolbar
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1994 Andy Piper <andyp@parallax.demon.co.uk>
5 ;; Copyright (C) 1995 Board of Trustees, University of Illinois
6 ;; Copyright (C) 1996 Ben Wing <ben@xemacs.org>
8 ;; Maintainer: XEmacs development team
9 ;; Keywords: frames, dumped
11 ;; This file is part of XEmacs.
13 ;; XEmacs is free software; you can redistribute it and/or modify it
14 ;; under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; XEmacs is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with XEmacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
28 ;;; Synched up: Not in FSF
32 ;; This file is dumped with XEmacs (when window system and toolbar support
35 ;; Miscellaneous toolbar functions, useful for users to redefine, in
36 ;; order to get different behavior.
40 ;; Suppress warning message from bytecompiler
42 (defvar pending-delete-mode)
43 ;; #### The compiler still warns about missing
44 ;; `pending-delete-pre-hook'. Any way to get rid of the warning?
48 "Configure XEmacs Toolbar functions and properties"
51 ;; #### The following function is slightly obnoxious as it stands. I
52 ;; think it should print a message like "Toolbar not configured; press
53 ;; me again to configure it", and when the button is pressed again
54 ;; (within a reasonable period of time), `customize-variable' should
55 ;; be invoked for the appropriate variable.
57 (defun toolbar-not-configured ()
59 ;; Note: we don't use `susbtitute-command-keys' here, because
60 ;; Customize is bound to `C-h C' by default, and that binding is not
61 ;; familiar to people. This is more descriptive.
63 "Configure the item via `M-x customize RET toolbar RET'"))
65 (defcustom toolbar-open-function 'find-file
66 "*Function to call when the open icon is selected."
67 :type '(radio (function-item find-file)
68 (function :tag "Other"))
71 (defun toolbar-open ()
73 (call-interactively toolbar-open-function))
75 (defcustom toolbar-dired-function 'dired
76 "*Function to call when the dired icon is selected."
77 :type '(radio (function-item dired)
78 (function :tag "Other"))
81 (defun toolbar-dired ()
83 (call-interactively toolbar-dired-function))
85 (defcustom toolbar-save-function 'save-buffer
86 "*Function to call when the save icon is selected."
87 :type '(radio (function-item save-buffer)
88 (function :tag "Other"))
91 (defun toolbar-save ()
93 (call-interactively toolbar-save-function))
95 (defcustom toolbar-print-function 'lpr-buffer
96 "*Function to call when the print icon is selected."
97 :type '(radio (function-item lpr-buffer)
98 (function :tag "Other"))
101 (defun toolbar-print ()
103 (call-interactively toolbar-print-function))
105 (defcustom toolbar-cut-function 'kill-primary-selection
106 "*Function to call when the cut icon is selected."
107 :type '(radio (function-item kill-primary-selection)
108 (function :tag "Other"))
111 (defun toolbar-cut ()
113 (call-interactively toolbar-cut-function))
115 (defcustom toolbar-copy-function 'copy-primary-selection
116 "*Function to call when the copy icon is selected."
117 :type '(radio (function-item copy-primary-selection)
118 (function :tag "Other"))
121 (defun toolbar-copy ()
123 (call-interactively toolbar-copy-function))
125 (defcustom toolbar-paste-function 'yank-clipboard-selection
126 "*Function to call when the paste icon is selected."
127 :type '(radio (function-item yank-clipboard-selection)
128 (function :tag "Other"))
131 (defun toolbar-paste ()
133 ;; This horrible kludge is for pending-delete to work correctly.
134 (and (boundp 'pending-delete-mode)
136 (let ((this-command toolbar-paste-function))
137 (pending-delete-pre-hook)))
138 (call-interactively toolbar-paste-function))
140 (defcustom toolbar-undo-function 'undo
141 "*Function to call when the undo icon is selected."
142 :type '(radio (function-item undo)
143 (function :tag "Other"))
146 (defun toolbar-undo ()
148 (call-interactively toolbar-undo-function))
150 (defcustom toolbar-replace-function 'query-replace
151 "*Function to call when the replace icon is selected."
152 :type '(radio (function-item query-replace)
153 (function :tag "Other"))
156 (defun toolbar-replace ()
158 (call-interactively toolbar-replace-function))
161 ;; toolbar ispell variables and defuns
164 (defun toolbar-ispell-internal ()
167 ((region-active-p) (ispell-region (region-beginning) (region-end)))
168 ((eq major-mode 'mail-mode) (ispell-message))
169 ((eq major-mode 'message-mode) (ispell-message))
170 (t (ispell-buffer))))
172 (defcustom toolbar-ispell-function 'toolbar-ispell-internal
173 "*Function to call when the ispell icon is selected."
174 :type '(radio (function-item toolbar-ispell-internal)
175 (function :tag "Other"))
178 (defun toolbar-ispell ()
179 "Intelligently spell the region or buffer."
181 (call-interactively toolbar-ispell-function))
184 ;; toolbar mail variables and defuns
187 ;; This used to be a macro that expanded its arguments to a form that
188 ;; called `call-process'. With the advent of customize, it's better
189 ;; to have it as a defun, to make customization easier.
190 (defun toolbar-external (process &rest args)
192 (apply 'call-process process nil 0 nil args))
194 (defcustom toolbar-mail-commands-alist
195 `((not-configured . toolbar-not-configured)
197 (gnus . gnus-no-server)
200 (pine . (toolbar-external "xterm" "-e" "pine")) ; *gag*
201 (elm . (toolbar-external "xterm" "-e" "elm"))
202 (mutt . (toolbar-external "xterm" "-e" "mutt"))
203 (exmh . (toolbar-external "exmh"))
204 (netscape . (toolbar-external "netscape" "mailbox:"))
206 "*Alist of mail readers and their commands.
207 The car of each alist element is the mail reader, and the cdr is the form
209 :type '(repeat (cons :format "%v"
210 (symbol :tag "Mailer") (function :tag "Start with")))
213 (defcustom toolbar-mail-reader 'not-configured
214 "*Mail reader toolbar will invoke.
215 The legal values are the keys from `toolbar-mail-command-alist', which
216 should be used to add new mail readers.
217 Mail readers known by default are vm, gnus, rmail, mh, pine, elm,
218 mutt, exmh, netscape and send."
219 :type '(choice (const :tag "Not Configured" not-configured)
220 (const vm) (const gnus) (const rmail) (const mh)
221 (const pine) (const elm) (const mutt) (const exmh)
225 :validate (lambda (wid)
226 (if (assq (widget-value wid)
227 toolbar-mail-commands-alist)
229 (widget-put wid :error
230 "Unknown mail reader")
235 (defun toolbar-mail ()
236 "Run mail in a separate frame."
238 (let ((command (cdr (assq toolbar-mail-reader toolbar-mail-commands-alist))))
240 (error "Uknown mail reader %s" toolbar-mail-reader))
241 (if (symbolp command)
242 (call-interactively command)
246 ;; toolbar info variables and defuns
249 (defcustom toolbar-info-use-separate-frame t
250 "*Whether Info is invoked in a separate frame."
254 (defcustom toolbar-info-frame-plist
255 ;; Info pages are 80 characters wide, so it makes a good default.
256 `(width 80 ,@(let ((h (plist-get default-frame-plist 'height)))
257 (and h `(height ,h))))
258 "*The properties of the frame in which news is displayed."
262 (define-obsolete-variable-alias 'Info-frame-plist
263 'toolbar-info-frame-plist)
265 (defvar toolbar-info-frame nil
266 "The frame in which info is displayed.")
268 (defun toolbar-info ()
269 "Run info in a separate frame."
271 (when toolbar-info-use-separate-frame
272 (cond ((or (not toolbar-info-frame)
273 (not (frame-live-p toolbar-info-frame)))
274 ;; We used to raise frame here, but it's a bad idea,
275 ;; because raising is a matter of WM policy. However, we
276 ;; *must* select it, to ensure that the info buffer goes to
278 (setq toolbar-info-frame (make-frame toolbar-info-frame-plist))
279 (select-frame toolbar-info-frame))
281 ;; However, if the frame already exists, and the user
282 ;; clicks on info, it's OK to raise it.
283 (select-frame toolbar-info-frame)
284 (raise-frame toolbar-info-frame)))
285 (when (frame-iconified-p toolbar-info-frame)
286 (deiconify-frame toolbar-info-frame)))
290 ;; toolbar debug variables and defuns
293 (defun toolbar-debug ()
295 (if (featurep 'eos-debugger)
296 (call-interactively 'eos::start-debugger)
298 (call-interactively 'gdbsrc)))
300 (defvar compile-command)
301 (defvar toolbar-compile-already-run nil)
303 (defun toolbar-compile ()
304 "Run compile without having to touch the keyboard."
307 (if toolbar-compile-already-run
308 (compile compile-command)
309 (setq toolbar-compile-already-run t)
310 (if (should-use-dialog-box-p)
312 `(,(concat "Compile:\n " compile-command)
313 ["Compile" (compile compile-command) t]
314 ["Edit command" compile t]
316 ["Cancel" (message "Quit") t]))
317 (compile compile-command))))
320 ;; toolbar news variables and defuns
323 (defcustom toolbar-news-commands-alist
324 `((not-configured . toolbar-not-configured)
325 (gnus . toolbar-gnus) ; M-x all-hail-gnus
326 (rn . (toolbar-external "xterm" "-e" "rn"))
327 (nn . (toolbar-external "xterm" "-e" "nn"))
328 (trn . (toolbar-external "xterm" "-e" "trn"))
329 (xrn . (toolbar-external "xrn"))
330 (slrn . (toolbar-external "xterm" "-e" "slrn"))
331 (pine . (toolbar-external "xterm" "-e" "pine")) ; *gag*
332 (tin . (toolbar-external "xterm" "-e" "tin")) ; *gag*
333 (netscape . (toolbar-external "netscape" "news:")))
334 "*Alist of news readers and their commands.
335 The car of each alist element the pair is the news reader, and the cdr
336 is the form used to start it."
337 :type '(repeat (cons :format "%v"
338 (symbol :tag "Reader") (sexp :tag "Start with")))
341 (defcustom toolbar-news-reader 'gnus
342 "*News reader toolbar will invoke.
343 The legal values are the keys from `toolbar-news-command-alist', which should
344 be used to add new news readers.
345 Newsreaders known by default are gnus, rn, nn, trn, xrn, slrn, pine
347 :type '(choice (const :tag "Not Configured" not-configured)
348 (const gnus) (const rn) (const nn) (const trn)
349 (const xrn) (const slrn) (const pine) (const tin)
352 :validate (lambda (wid)
353 (if (assq (widget-value wid)
354 toolbar-news-commands-alist)
356 (widget-put wid :error
357 "Unknown news reader")
361 (defcustom toolbar-news-use-separate-frame t
362 "*Whether Gnus is invoked in a separate frame."
366 (defvar toolbar-news-frame nil
367 "The frame in which news is displayed.")
369 (defcustom toolbar-news-frame-plist nil
370 "*The properties of the frame in which news is displayed."
374 (define-obsolete-variable-alias 'toolbar-news-frame-properties
375 'toolbar-news-frame-plist)
377 (defun toolbar-gnus ()
378 "Run Gnus in a separate frame."
380 (if (not toolbar-news-use-separate-frame)
382 (unless (frame-live-p toolbar-news-frame)
383 (setq toolbar-news-frame (make-frame toolbar-news-frame-plist))
384 (add-hook 'gnus-exit-gnus-hook
386 (when (frame-live-p toolbar-news-frame)
387 (if (cdr (frame-list))
388 (delete-frame toolbar-news-frame))
389 (setq toolbar-news-frame nil))))
390 (select-frame toolbar-news-frame)
392 (when (framep toolbar-news-frame)
393 (when (frame-iconified-p toolbar-news-frame)
394 (deiconify-frame toolbar-news-frame))
395 (select-frame toolbar-news-frame)
396 (raise-frame toolbar-news-frame))))
398 (defun toolbar-news ()
401 (let ((command (cdr-safe
402 (assq toolbar-news-reader toolbar-news-commands-alist))))
404 (error "Unkown news reader %s" toolbar-news-reader))
405 (if (symbolp command)
406 (call-interactively command)
409 (defvar toolbar-last-win-icon nil "A `last-win' icon set.")
410 (defvar toolbar-next-win-icon nil "A `next-win' icon set.")
411 (defvar toolbar-file-icon nil "A `file' icon set.")
412 (defvar toolbar-folder-icon nil "A `folder' icon set")
413 (defvar toolbar-disk-icon nil "A `disk' icon set.")
414 (defvar toolbar-printer-icon nil "A `printer' icon set.")
415 (defvar toolbar-cut-icon nil "A `cut' icon set.")
416 (defvar toolbar-copy-icon nil "A `copy' icon set.")
417 (defvar toolbar-paste-icon nil "A `paste' icon set.")
418 (defvar toolbar-undo-icon nil "An `undo' icon set.")
419 (defvar toolbar-spell-icon nil "A `spell' icon set.")
420 (defvar toolbar-replace-icon nil "A `replace' icon set.")
421 (defvar toolbar-mail-icon nil "A `mail' icon set.")
422 (defvar toolbar-info-icon nil "An `info' icon set.")
423 (defvar toolbar-compile-icon nil "A `compile' icon set.")
424 (defvar toolbar-debug-icon nil "A `debugger' icon set.")
425 (defvar toolbar-news-icon nil "A `news' icon set.")
427 ;;; each entry maps a variable to the prefix used.
429 (defvar init-x-toolbar-list
430 '((toolbar-last-win-icon . "last-win")
431 (toolbar-next-win-icon . "next-win")
432 (toolbar-file-icon . "file")
433 (toolbar-folder-icon . "folder")
434 (toolbar-disk-icon . "disk")
435 (toolbar-printer-icon . "printer")
436 (toolbar-cut-icon . "cut")
437 (toolbar-copy-icon . "copy")
438 (toolbar-paste-icon . "paste")
439 (toolbar-undo-icon . "undo")
440 (toolbar-spell-icon . "spell")
441 (toolbar-replace-icon . "replace")
442 (toolbar-mail-icon . "mail")
443 (toolbar-info-icon . "info-def")
444 (toolbar-compile-icon . "compile")
445 (toolbar-debug-icon . "debug")
446 (toolbar-news-icon . "news")))
448 (defun init-x-toolbar ()
449 (toolbar-add-item-data init-x-toolbar-list )
450 ;; do this now because errors will occur if the icon symbols
452 (set-specifier default-toolbar initial-toolbar-spec))
454 (defun toolbar-add-item-data ( icon-list &optional icon-dir )
455 (if (eq icon-dir nil)
456 (setq icon-dir toolbar-icon-directory))
459 (let ((prefix (expand-file-name (cdr cons) icon-dir)))
460 ;; #### This should use a better mechanism for finding the
461 ;; glyphs, allowing for formats other than x[pb]m. Look at
462 ;; `widget-glyph-find' for an example how it might be done.
465 (toolbar-make-button-list
466 (concat prefix "-up.xpm")
468 (concat prefix "-xx.xpm")
469 (concat prefix "-cap-up.xpm")
471 (concat prefix "-cap-xx.xpm"))
472 (toolbar-make-button-list
473 (concat prefix "-up.xbm")
474 (concat prefix "-dn.xbm")
475 (concat prefix "-xx.xbm"))))))
478 (defvar toolbar-vector-open
479 [toolbar-file-icon toolbar-open t "Open a file"]
480 "Define the vector for the \"Open\" toolbar button")
482 (defvar toolbar-vector-dired
483 [toolbar-folder-icon toolbar-dired t "Edit a directory"]
484 "Define the vector for the \"Dired\" toolbar button")
486 (defvar toolbar-vector-save
487 [toolbar-disk-icon toolbar-save t "Save buffer"]
488 "Define the vector for the \"Save\" toolbar button")
490 (defvar toolbar-vector-print
491 [toolbar-printer-icon toolbar-print t "Print buffer"]
492 "Define the vector for the \"Printer\" toolbar button")
494 (defvar toolbar-vector-cut
495 [toolbar-cut-icon toolbar-cut t "Kill region"]
496 "Define the vector for the \"Cut\" toolbar button")
498 (defvar toolbar-vector-copy
499 [toolbar-copy-icon toolbar-copy t "Copy region"]
500 "Define the vector for the \"Copy\" toolbar button")
502 (defvar toolbar-vector-paste
503 [toolbar-paste-icon toolbar-paste t "Paste from clipboard"]
504 "Define the vector for the \"Paste\" toolbar button")
506 (defvar toolbar-vector-undo
507 [toolbar-undo-icon toolbar-undo t "Undo edit"]
508 "Define the vector for the \"Undo\" toolbar button")
510 (defvar toolbar-vector-spell
511 [toolbar-spell-icon toolbar-ispell t "Check spelling"]
512 "Define the vector for the \"Spell\" toolbar button")
514 (defvar toolbar-vector-replace
515 [toolbar-replace-icon toolbar-replace t "Search & Replace"]
516 "Define the vector for the \"Replace\" toolbar button")
518 (defvar toolbar-vector-mail
519 [toolbar-mail-icon toolbar-mail t "Read mail"]
520 "Define the vector for the \"Mail\" toolbar button")
522 (defvar toolbar-vector-info
523 [toolbar-info-icon toolbar-info t "Info documentation"]
524 "Define the vector for the \"Info\" toolbar button")
526 (defvar toolbar-vector-compile
527 [toolbar-compile-icon toolbar-compile t "Start a compilation"]
528 "Define the vector for the \"Compile\" toolbar button")
530 (defvar toolbar-vector-debug
531 [toolbar-debug-icon toolbar-debug t "Start a debugger"]
532 "Define the vector for the \"Debug\" toolbar button")
534 (defvar toolbar-vector-news
535 [toolbar-news-icon toolbar-news t "Read news"]
536 "Define the vector for the \"News\" toolbar button")
538 (defvar initial-toolbar-spec
540 ;;[toolbar-last-win-icon pop-window-configuration
541 ;;(frame-property (selected-frame)
542 ;; 'window-config-stack) t "Most recent window config"]
543 ;; #### Illicit knowledge?
544 ;; #### These don't work right - not consistent!
545 ;; I don't know what's wrong; perhaps `selected-frame' is wrong
546 ;; sometimes when this is evaluated. Note that I even tried to
547 ;; kludge-fix this by calls to `set-specifier-dirty-flag' in
548 ;; pop-window-configuration and such.
550 ;;[toolbar-next-win-icon unpop-window-configuration
551 ;;(frame-property (selected-frame)
552 ;; 'window-config-unpop-stack) t "Undo \"Most recent window config\""]
553 ;; #### Illicit knowledge?
563 toolbar-vector-replace
566 toolbar-vector-compile
570 "The initial toolbar for a buffer.")
572 (defun x-init-toolbar-from-resources (locale)
573 (x-init-specifier-from-resources
574 top-toolbar-height 'natnum locale
575 '("topToolBarHeight" . "TopToolBarHeight"))
576 (x-init-specifier-from-resources
577 bottom-toolbar-height 'natnum locale
578 '("bottomToolBarHeight" . "BottomToolBarHeight"))
579 (x-init-specifier-from-resources
580 left-toolbar-width 'natnum locale
581 '("leftToolBarWidth" . "LeftToolBarWidth"))
582 (x-init-specifier-from-resources
583 right-toolbar-width 'natnum locale
584 '("rightToolBarWidth" . "RightToolBarWidth"))
585 (x-init-specifier-from-resources
586 top-toolbar-border-width 'natnum locale
587 '("topToolBarBorderWidth" . "TopToolBarBorderWidth"))
588 (x-init-specifier-from-resources
589 bottom-toolbar-border-width 'natnum locale
590 '("bottomToolBarBorderWidth" . "BottomToolBarBorderWidth"))
591 (x-init-specifier-from-resources
592 left-toolbar-border-width 'natnum locale
593 '("leftToolBarBorderWidth" . "LeftToolBarBorderWidth"))
594 (x-init-specifier-from-resources
595 right-toolbar-border-width 'natnum locale
596 '("rightToolBarBorderWidth" . "RightToolBarBorderWidth")))
598 ;;; toolbar-items.el ends here