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 (dir)
82 (interactive "DDired directory: ")
83 (funcall toolbar-dired-function dir))
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 (defun toolbar-compile ()
301 "Run compile without having to touch the keyboard."
303 (declare (special compile-command toolbar-compile-already-run))
305 (if (boundp 'toolbar-compile-already-run)
306 (compile compile-command)
307 (setq toolbar-compile-already-run t)
308 (if (should-use-dialog-box-p)
309 (make-dialog-box 'question
310 :question (concat "Compile:\n " compile-command)
312 '(["Compile" (compile compile-command) t]
313 ["Edit command" compile t]
315 ["Cancel" (message "Quit") t]))
316 (compile compile-command))))
319 ;; toolbar news variables and defuns
322 (defcustom toolbar-news-commands-alist
323 `((not-configured . toolbar-not-configured)
324 (gnus . toolbar-gnus) ; M-x all-hail-gnus
325 (rn . (toolbar-external "xterm" "-e" "rn"))
326 (nn . (toolbar-external "xterm" "-e" "nn"))
327 (trn . (toolbar-external "xterm" "-e" "trn"))
328 (xrn . (toolbar-external "xrn"))
329 (slrn . (toolbar-external "xterm" "-e" "slrn"))
330 (pine . (toolbar-external "xterm" "-e" "pine")) ; *gag*
331 (tin . (toolbar-external "xterm" "-e" "tin")) ; *gag*
332 (netscape . (toolbar-external "netscape" "news:")))
333 "*Alist of news readers and their commands.
334 The car of each alist element the pair is the news reader, and the cdr
335 is the form used to start it."
336 :type '(repeat (cons :format "%v"
337 (symbol :tag "Reader") (sexp :tag "Start with")))
340 (defcustom toolbar-news-reader 'gnus
341 "*News reader toolbar will invoke.
342 The legal values are the keys from `toolbar-news-command-alist', which should
343 be used to add new news readers.
344 Newsreaders known by default are gnus, rn, nn, trn, xrn, slrn, pine
346 :type '(choice (const :tag "Not Configured" not-configured)
347 (const gnus) (const rn) (const nn) (const trn)
348 (const xrn) (const slrn) (const pine) (const tin)
351 :validate (lambda (wid)
352 (if (assq (widget-value wid)
353 toolbar-news-commands-alist)
355 (widget-put wid :error
356 "Unknown news reader")
360 (defcustom toolbar-news-use-separate-frame t
361 "*Whether Gnus is invoked in a separate frame."
365 (defvar toolbar-news-frame nil
366 "The frame in which news is displayed.")
368 (defcustom toolbar-news-frame-plist nil
369 "*The properties of the frame in which news is displayed."
373 (define-obsolete-variable-alias 'toolbar-news-frame-properties
374 'toolbar-news-frame-plist)
376 (defun toolbar-gnus ()
377 "Run Gnus in a separate frame."
379 (if (not toolbar-news-use-separate-frame)
381 (unless (frame-live-p toolbar-news-frame)
382 (setq toolbar-news-frame (make-frame toolbar-news-frame-plist))
383 (add-hook 'gnus-exit-gnus-hook
385 (when (frame-live-p toolbar-news-frame)
386 (if (cdr (frame-list))
387 (delete-frame toolbar-news-frame))
388 (setq toolbar-news-frame nil))))
389 (select-frame toolbar-news-frame)
391 (when (framep toolbar-news-frame)
392 (when (frame-iconified-p toolbar-news-frame)
393 (deiconify-frame toolbar-news-frame))
394 (select-frame toolbar-news-frame)
395 (raise-frame toolbar-news-frame))))
397 (defun toolbar-news ()
400 (let ((command (cdr-safe
401 (assq toolbar-news-reader toolbar-news-commands-alist))))
403 (error "Unknown news reader %s" toolbar-news-reader))
404 (if (symbolp command)
405 (call-interactively command)
408 (defvar toolbar-last-win-icon nil "A `last-win' icon set.")
409 (defvar toolbar-next-win-icon nil "A `next-win' icon set.")
410 (defvar toolbar-file-icon nil "A `file' icon set.")
411 (defvar toolbar-folder-icon nil "A `folder' icon set")
412 (defvar toolbar-disk-icon nil "A `disk' icon set.")
413 (defvar toolbar-printer-icon nil "A `printer' icon set.")
414 (defvar toolbar-cut-icon nil "A `cut' icon set.")
415 (defvar toolbar-copy-icon nil "A `copy' icon set.")
416 (defvar toolbar-paste-icon nil "A `paste' icon set.")
417 (defvar toolbar-undo-icon nil "An `undo' icon set.")
418 (defvar toolbar-spell-icon nil "A `spell' icon set.")
419 (defvar toolbar-replace-icon nil "A `replace' icon set.")
420 (defvar toolbar-mail-icon nil "A `mail' icon set.")
421 (defvar toolbar-info-icon nil "An `info' icon set.")
422 (defvar toolbar-compile-icon nil "A `compile' icon set.")
423 (defvar toolbar-debug-icon nil "A `debugger' icon set.")
424 (defvar toolbar-news-icon nil "A `news' icon set.")
426 ;;; each entry maps a variable to the prefix used.
428 (defvar init-x-toolbar-list
429 '((toolbar-last-win-icon . "last-win")
430 (toolbar-next-win-icon . "next-win")
431 (toolbar-file-icon . "file")
432 (toolbar-folder-icon . "folder")
433 (toolbar-disk-icon . "disk")
434 (toolbar-printer-icon . "printer")
435 (toolbar-cut-icon . "cut")
436 (toolbar-copy-icon . "copy")
437 (toolbar-paste-icon . "paste")
438 (toolbar-undo-icon . "undo")
439 (toolbar-spell-icon . "spell")
440 (toolbar-replace-icon . "replace")
441 (toolbar-mail-icon . "mail")
442 (toolbar-info-icon . "info-def")
443 (toolbar-compile-icon . "compile")
444 (toolbar-debug-icon . "debug")
445 (toolbar-news-icon . "news")))
447 (defun init-x-toolbar ()
448 (toolbar-add-item-data init-x-toolbar-list )
449 ;; do this now because errors will occur if the icon symbols
451 (set-specifier default-toolbar initial-toolbar-spec))
453 (defun toolbar-add-item-data ( icon-list &optional icon-dir )
454 (if (eq icon-dir nil)
455 (setq icon-dir toolbar-icon-directory))
458 (let ((prefix (expand-file-name (cdr cons) icon-dir)))
459 ;; #### This should use a better mechanism for finding the
460 ;; glyphs, allowing for formats other than x[pb]m. Look at
461 ;; `widget-glyph-find' for an example how it might be done.
464 (toolbar-make-button-list
465 (concat prefix "-up.xpm")
467 (concat prefix "-xx.xpm")
468 (concat prefix "-cap-up.xpm")
470 (concat prefix "-cap-xx.xpm"))
471 (toolbar-make-button-list
472 (concat prefix "-up.xbm")
473 (concat prefix "-dn.xbm")
474 (concat prefix "-xx.xbm"))))))
477 (defvar toolbar-vector-open
478 [toolbar-file-icon toolbar-open t "Open a file"]
479 "Define the vector for the \"Open\" toolbar button")
481 (defvar toolbar-vector-dired
482 [toolbar-folder-icon toolbar-dired t "Edit a directory"]
483 "Define the vector for the \"Dired\" toolbar button")
485 (defvar toolbar-vector-save
486 [toolbar-disk-icon toolbar-save t "Save buffer"]
487 "Define the vector for the \"Save\" toolbar button")
489 (defvar toolbar-vector-print
490 [toolbar-printer-icon toolbar-print t "Print buffer"]
491 "Define the vector for the \"Printer\" toolbar button")
493 (defvar toolbar-vector-cut
494 [toolbar-cut-icon toolbar-cut t "Kill region"]
495 "Define the vector for the \"Cut\" toolbar button")
497 (defvar toolbar-vector-copy
498 [toolbar-copy-icon toolbar-copy t "Copy region"]
499 "Define the vector for the \"Copy\" toolbar button")
501 (defvar toolbar-vector-paste
502 [toolbar-paste-icon toolbar-paste t "Paste from clipboard"]
503 "Define the vector for the \"Paste\" toolbar button")
505 (defvar toolbar-vector-undo
506 [toolbar-undo-icon toolbar-undo t "Undo edit"]
507 "Define the vector for the \"Undo\" toolbar button")
509 (defvar toolbar-vector-spell
510 [toolbar-spell-icon toolbar-ispell t "Check spelling"]
511 "Define the vector for the \"Spell\" toolbar button")
513 (defvar toolbar-vector-replace
514 [toolbar-replace-icon toolbar-replace t "Search & Replace"]
515 "Define the vector for the \"Replace\" toolbar button")
517 (defvar toolbar-vector-mail
518 [toolbar-mail-icon toolbar-mail t "Read mail"]
519 "Define the vector for the \"Mail\" toolbar button")
521 (defvar toolbar-vector-info
522 [toolbar-info-icon toolbar-info t "Info documentation"]
523 "Define the vector for the \"Info\" toolbar button")
525 (defvar toolbar-vector-compile
526 [toolbar-compile-icon toolbar-compile t "Start a compilation"]
527 "Define the vector for the \"Compile\" toolbar button")
529 (defvar toolbar-vector-debug
530 [toolbar-debug-icon toolbar-debug t "Start a debugger"]
531 "Define the vector for the \"Debug\" toolbar button")
533 (defvar toolbar-vector-news
534 [toolbar-news-icon toolbar-news t "Read news"]
535 "Define the vector for the \"News\" toolbar button")
537 (defvar initial-toolbar-spec
539 ;;[toolbar-last-win-icon pop-window-configuration
540 ;;(frame-property (selected-frame)
541 ;; 'window-config-stack) t "Most recent window config"]
542 ;; #### Illicit knowledge?
543 ;; #### These don't work right - not consistent!
544 ;; I don't know what's wrong; perhaps `selected-frame' is wrong
545 ;; sometimes when this is evaluated. Note that I even tried to
546 ;; kludge-fix this by calls to `set-specifier-dirty-flag' in
547 ;; pop-window-configuration and such.
549 ;;[toolbar-next-win-icon unpop-window-configuration
550 ;;(frame-property (selected-frame)
551 ;; 'window-config-unpop-stack) t "Undo \"Most recent window config\""]
552 ;; #### Illicit knowledge?
562 toolbar-vector-replace
565 toolbar-vector-compile
569 "The initial toolbar for a buffer.")
571 (defun x-init-toolbar-from-resources (locale)
572 (x-init-specifier-from-resources
573 top-toolbar-height 'natnum locale
574 '("topToolBarHeight" . "TopToolBarHeight"))
575 (x-init-specifier-from-resources
576 bottom-toolbar-height 'natnum locale
577 '("bottomToolBarHeight" . "BottomToolBarHeight"))
578 (x-init-specifier-from-resources
579 left-toolbar-width 'natnum locale
580 '("leftToolBarWidth" . "LeftToolBarWidth"))
581 (x-init-specifier-from-resources
582 right-toolbar-width 'natnum locale
583 '("rightToolBarWidth" . "RightToolBarWidth"))
584 (x-init-specifier-from-resources
585 top-toolbar-border-width 'natnum locale
586 '("topToolBarBorderWidth" . "TopToolBarBorderWidth"))
587 (x-init-specifier-from-resources
588 bottom-toolbar-border-width 'natnum locale
589 '("bottomToolBarBorderWidth" . "BottomToolBarBorderWidth"))
590 (x-init-specifier-from-resources
591 left-toolbar-border-width 'natnum locale
592 '("leftToolBarBorderWidth" . "LeftToolBarBorderWidth"))
593 (x-init-specifier-from-resources
594 right-toolbar-border-width 'natnum locale
595 '("rightToolBarBorderWidth" . "RightToolBarBorderWidth")))
597 ;;; toolbar-items.el ends here