1 ;;; toolbar-items.el -- Static initialization of SXEmacs 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: SXEmacs development team
9 ;; Keywords: frames, dumped
11 ;; This file is part of SXEmacs.
13 ;; SXEmacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; SXEmacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
26 ;;; Synched up: Not in FSF
30 ;; This file is dumped with SXEmacs (when window system and toolbar support
33 ;; Miscellaneous toolbar functions, useful for users to redefine, in
34 ;; order to get different behavior.
38 (globally-declare-fboundp
39 '(ispell-buffer ispell-message ispell-region compile gnus)))
42 "Configure SXEmacs Toolbar functions and properties"
45 ;; #### The following function is slightly obnoxious as it stands. I
46 ;; think it should print a message like "Toolbar not configured; press
47 ;; me again to configure it", and when the button is pressed again
48 ;; (within a reasonable period of time), `customize-variable' should
49 ;; be invoked for the appropriate variable.
51 (defun toolbar-not-configured ()
53 ;; Note: we don't use `susbtitute-command-keys' here, because
54 ;; Customize is bound to `C-h C' by default, and that binding is not
55 ;; familiar to people. This is more descriptive.
57 "Configure the item via `M-x customize RET toolbar RET'"))
59 (defcustom toolbar-open-function 'find-file
60 "*Function to call when the open icon is selected."
61 :type '(radio (function-item find-file)
62 (function :tag "Other"))
65 (defun toolbar-open ()
67 (call-interactively toolbar-open-function))
69 (defcustom toolbar-dired-function 'dired
70 "*Function to call when the dired icon is selected."
71 :type '(radio (function-item dired)
72 (function :tag "Other"))
75 (defun toolbar-dired (dir)
76 (interactive "DDired directory: ")
77 (funcall toolbar-dired-function dir))
79 (defcustom toolbar-save-function 'save-buffer
80 "*Function to call when the save icon is selected."
81 :type '(radio (function-item save-buffer)
82 (function :tag "Other"))
85 (defun toolbar-save ()
87 (call-interactively toolbar-save-function))
89 (defcustom toolbar-print-function 'lpr-buffer
90 "*Function to call when the print icon is selected."
91 :type '(radio (function-item lpr-buffer)
92 (function :tag "Other"))
95 (defun toolbar-print ()
97 (call-interactively toolbar-print-function))
99 (defcustom toolbar-cut-function 'kill-primary-selection
100 "*Function to call when the cut icon is selected."
101 :type '(radio (function-item kill-primary-selection)
102 (function :tag "Other"))
105 (defun toolbar-cut ()
107 (call-interactively toolbar-cut-function))
109 (defcustom toolbar-copy-function 'copy-primary-selection
110 "*Function to call when the copy icon is selected."
111 :type '(radio (function-item copy-primary-selection)
112 (function :tag "Other"))
115 (defun toolbar-copy ()
117 (call-interactively toolbar-copy-function))
119 (defcustom toolbar-paste-function 'yank-clipboard-selection
120 "*Function to call when the paste icon is selected."
121 :type '(radio (function-item yank-clipboard-selection)
122 (function :tag "Other"))
125 (defun toolbar-paste ()
127 ;; This horrible kludge is for pending-delete to work correctly.
128 (and-boundp 'pending-delete-mode
130 (let ((this-command toolbar-paste-function))
131 (declare-fboundp (pending-delete-pre-hook))))
132 (call-interactively toolbar-paste-function))
134 (defcustom toolbar-undo-function 'undo
135 "*Function to call when the undo icon is selected."
136 :type '(radio (function-item undo)
137 (function :tag "Other"))
140 (defun toolbar-undo ()
142 (call-interactively toolbar-undo-function))
144 (defcustom toolbar-replace-function 'query-replace
145 "*Function to call when the replace icon is selected."
146 :type '(radio (function-item query-replace)
147 (function :tag "Other"))
150 (defun toolbar-replace ()
152 (call-interactively toolbar-replace-function))
155 ;; toolbar ispell variables and defuns
158 (defun toolbar-ispell-internal ()
161 ((region-active-p) (ispell-region (region-beginning) (region-end)))
162 ((eq major-mode 'mail-mode) (ispell-message))
163 ((eq major-mode 'message-mode) (ispell-message))
164 (t (ispell-buffer))))
166 (defcustom toolbar-ispell-function 'toolbar-ispell-internal
167 "*Function to call when the ispell icon is selected."
168 :type '(radio (function-item toolbar-ispell-internal)
169 (function :tag "Other"))
172 (defun toolbar-ispell ()
173 "Intelligently spell the region or buffer."
175 (call-interactively toolbar-ispell-function))
178 ;; toolbar mail variables and defuns
181 ;; This used to be a macro that expanded its arguments to a form that
182 ;; called `call-process'. With the advent of customize, it's better
183 ;; to have it as a defun, to make customization easier.
184 (defun toolbar-external (process &rest args)
186 (apply 'call-process process nil 0 nil args))
188 (defcustom toolbar-mail-commands-alist
189 `((not-configured . toolbar-not-configured)
191 (gnus . gnus-no-server)
194 (pine . (toolbar-external "xterm" "-e" "pine")) ; *gag*
195 (elm . (toolbar-external "xterm" "-e" "elm"))
196 (mutt . (toolbar-external "xterm" "-e" "mutt"))
197 (exmh . (toolbar-external "exmh"))
198 (netscape . (toolbar-external "netscape" "mailbox:"))
200 "*Alist of mail readers and their commands.
201 The car of each alist element is the mail reader, and the cdr is the form
203 :type '(repeat (cons :format "%v"
204 (symbol :tag "Mailer") (function :tag "Start with")))
207 (defcustom toolbar-mail-reader 'not-configured
208 "*Mail reader toolbar will invoke.
209 The legal values are the keys from `toolbar-mail-command-alist', which
210 should be used to add new mail readers.
211 Mail readers known by default are vm, gnus, rmail, mh, pine, elm,
212 mutt, exmh, netscape and send."
213 :type '(choice (const :tag "Not Configured" not-configured)
214 (const vm) (const gnus) (const rmail) (const mh)
215 (const pine) (const elm) (const mutt) (const exmh)
219 :validate (lambda (wid)
220 (if (assq (widget-value wid)
221 toolbar-mail-commands-alist)
223 (widget-put wid :error
224 "Unknown mail reader")
229 (defun toolbar-mail ()
230 "Run mail in a separate frame."
232 (let ((command (cdr (assq toolbar-mail-reader toolbar-mail-commands-alist))))
234 (error "Uknown mail reader %s" toolbar-mail-reader))
235 (if (symbolp command)
236 (call-interactively command)
240 ;; toolbar info variables and defuns
243 (defcustom toolbar-info-use-separate-frame t
244 "*Whether Info is invoked in a separate frame."
248 (defcustom toolbar-info-frame-plist
249 ;; Info pages are 80 characters wide, so it makes a good default.
250 `(width 80 ,@(let ((h (plist-get default-frame-plist 'height)))
251 (and h `(height ,h))))
252 "*The properties of the frame in which news is displayed."
256 (define-obsolete-variable-alias 'Info-frame-plist
257 'toolbar-info-frame-plist)
259 (defvar toolbar-info-frame nil
260 "The frame in which info is displayed.")
262 (defun toolbar-info ()
263 "Run info in a separate frame."
265 (when toolbar-info-use-separate-frame
266 (cond ((or (not toolbar-info-frame)
267 (not (frame-live-p toolbar-info-frame)))
268 ;; We used to raise frame here, but it's a bad idea,
269 ;; because raising is a matter of WM policy. However, we
270 ;; *must* select it, to ensure that the info buffer goes to
272 (setq toolbar-info-frame (make-frame toolbar-info-frame-plist))
273 (select-frame toolbar-info-frame))
275 ;; However, if the frame already exists, and the user
276 ;; clicks on info, it's OK to raise it.
277 (select-frame toolbar-info-frame)
278 (raise-frame toolbar-info-frame)))
279 (when (frame-iconified-p toolbar-info-frame)
280 (deiconify-frame toolbar-info-frame)))
281 (declare-fboundp (info)))
284 ;; toolbar debug variables and defuns
287 (defun toolbar-debug ()
289 (if (featurep 'eos-debugger)
290 (call-interactively 'eos::start-debugger)
292 (call-interactively 'gdbsrc)))
294 (defun toolbar-compile ()
295 "Run compile without having to touch the keyboard."
297 (declare (special compile-command toolbar-compile-already-run))
299 (if (boundp 'toolbar-compile-already-run)
300 (compile compile-command)
301 (setq toolbar-compile-already-run t)
302 (if (should-use-dialog-box-p)
303 (make-dialog-box 'question
304 :question (concat "Compile:\n " compile-command)
306 '(["Compile" (compile compile-command) t]
307 ["Edit command" compile t]
309 ["Cancel" (message "Quit") t]))
310 (compile compile-command))))
313 ;; toolbar news variables and defuns
316 (defcustom toolbar-news-commands-alist
317 `((not-configured . toolbar-not-configured)
318 (gnus . toolbar-gnus) ; M-x all-hail-gnus
319 (rn . (toolbar-external "xterm" "-e" "rn"))
320 (nn . (toolbar-external "xterm" "-e" "nn"))
321 (trn . (toolbar-external "xterm" "-e" "trn"))
322 (xrn . (toolbar-external "xrn"))
323 (slrn . (toolbar-external "xterm" "-e" "slrn"))
324 (pine . (toolbar-external "xterm" "-e" "pine")) ; *gag*
325 (tin . (toolbar-external "xterm" "-e" "tin")) ; *gag*
326 (netscape . (toolbar-external "netscape" "news:")))
327 "*Alist of news readers and their commands.
328 The car of each alist element the pair is the news reader, and the cdr
329 is the form used to start it."
330 :type '(repeat (cons :format "%v"
331 (symbol :tag "Reader") (sexp :tag "Start with")))
334 (defcustom toolbar-news-reader 'gnus
335 "*News reader toolbar will invoke.
336 The legal values are the keys from `toolbar-news-command-alist', which should
337 be used to add new news readers.
338 Newsreaders known by default are gnus, rn, nn, trn, xrn, slrn, pine
340 :type '(choice (const :tag "Not Configured" not-configured)
341 (const gnus) (const rn) (const nn) (const trn)
342 (const xrn) (const slrn) (const pine) (const tin)
345 :validate (lambda (wid)
346 (if (assq (widget-value wid)
347 toolbar-news-commands-alist)
349 (widget-put wid :error
350 "Unknown news reader")
354 (defcustom toolbar-news-use-separate-frame t
355 "*Whether Gnus is invoked in a separate frame."
359 (defvar toolbar-news-frame nil
360 "The frame in which news is displayed.")
362 (defcustom toolbar-news-frame-plist nil
363 "*The properties of the frame in which news is displayed."
367 (define-obsolete-variable-alias 'toolbar-news-frame-properties
368 'toolbar-news-frame-plist)
370 (defun toolbar-gnus ()
371 "Run Gnus in a separate frame."
373 (if (not toolbar-news-use-separate-frame)
375 (unless (frame-live-p toolbar-news-frame)
376 (setq toolbar-news-frame (make-frame toolbar-news-frame-plist))
377 (add-hook 'gnus-exit-gnus-hook
379 (when (frame-live-p toolbar-news-frame)
380 (if (cdr (frame-list))
381 (delete-frame toolbar-news-frame))
382 (setq toolbar-news-frame nil))))
383 (select-frame toolbar-news-frame)
385 (when (framep toolbar-news-frame)
386 (when (frame-iconified-p toolbar-news-frame)
387 (deiconify-frame toolbar-news-frame))
388 (select-frame toolbar-news-frame)
389 (raise-frame toolbar-news-frame))))
391 (defun toolbar-news ()
394 (let ((command (cdr-safe
395 (assq toolbar-news-reader toolbar-news-commands-alist))))
397 (error "Unknown news reader %s" toolbar-news-reader))
398 (if (symbolp command)
399 (call-interactively command)
402 (defvar toolbar-last-win-icon nil "A `last-win' icon set.")
403 (defvar toolbar-next-win-icon nil "A `next-win' icon set.")
404 (defvar toolbar-file-icon nil "A `file' icon set.")
405 (defvar toolbar-folder-icon nil "A `folder' icon set")
406 (defvar toolbar-disk-icon nil "A `disk' icon set.")
407 (defvar toolbar-printer-icon nil "A `printer' icon set.")
408 (defvar toolbar-cut-icon nil "A `cut' icon set.")
409 (defvar toolbar-copy-icon nil "A `copy' icon set.")
410 (defvar toolbar-paste-icon nil "A `paste' icon set.")
411 (defvar toolbar-undo-icon nil "An `undo' icon set.")
412 (defvar toolbar-spell-icon nil "A `spell' icon set.")
413 (defvar toolbar-replace-icon nil "A `replace' icon set.")
414 (defvar toolbar-mail-icon nil "A `mail' icon set.")
415 (defvar toolbar-info-icon nil "An `info' icon set.")
416 (defvar toolbar-compile-icon nil "A `compile' icon set.")
417 (defvar toolbar-debug-icon nil "A `debugger' icon set.")
418 (defvar toolbar-news-icon nil "A `news' icon set.")
420 ;;; each entry maps a variable to the prefix used.
422 (defvar init-x-toolbar-list
423 '((toolbar-last-win-icon . "last-win")
424 (toolbar-next-win-icon . "next-win")
425 (toolbar-file-icon . "file")
426 (toolbar-folder-icon . "folder")
427 (toolbar-disk-icon . "disk")
428 (toolbar-printer-icon . "printer")
429 (toolbar-cut-icon . "cut")
430 (toolbar-copy-icon . "copy")
431 (toolbar-paste-icon . "paste")
432 (toolbar-undo-icon . "undo")
433 (toolbar-spell-icon . "spell")
434 (toolbar-replace-icon . "replace")
435 (toolbar-mail-icon . "mail")
436 (toolbar-info-icon . "info-def")
437 (toolbar-compile-icon . "compile")
438 (toolbar-debug-icon . "debug")
439 (toolbar-news-icon . "news")))
441 (defun init-x-toolbar ()
442 (toolbar-add-item-data init-x-toolbar-list )
443 ;; do this now because errors will occur if the icon symbols
445 (set-specifier default-toolbar initial-toolbar-spec))
447 (defun toolbar-add-item-data ( icon-list &optional icon-dir )
448 (if (eq icon-dir nil)
449 (setq icon-dir toolbar-icon-directory))
452 (let ((prefix (expand-file-name (cdr cons) icon-dir)))
453 ;; #### This should use a better mechanism for finding the
454 ;; glyphs, allowing for formats other than x[pb]m. Look at
455 ;; `widget-glyph-find' for an example how it might be done.
458 (toolbar-make-button-list
459 (concat prefix "-up.xpm")
461 (concat prefix "-xx.xpm")
462 (concat prefix "-cap-up.xpm")
464 (concat prefix "-cap-xx.xpm"))
465 (toolbar-make-button-list
466 (concat prefix "-up.xbm")
467 (concat prefix "-dn.xbm")
468 (concat prefix "-xx.xbm"))))))
471 (defvar toolbar-vector-open
472 [toolbar-file-icon toolbar-open t "Open a file"]
473 "Define the vector for the \"Open\" toolbar button")
475 (defvar toolbar-vector-dired
476 [toolbar-folder-icon toolbar-dired t "Edit a directory"]
477 "Define the vector for the \"Dired\" toolbar button")
479 (defvar toolbar-vector-save
480 [toolbar-disk-icon toolbar-save t "Save buffer"]
481 "Define the vector for the \"Save\" toolbar button")
483 (defvar toolbar-vector-print
484 [toolbar-printer-icon toolbar-print t "Print buffer"]
485 "Define the vector for the \"Printer\" toolbar button")
487 (defvar toolbar-vector-cut
488 [toolbar-cut-icon toolbar-cut t "Kill region"]
489 "Define the vector for the \"Cut\" toolbar button")
491 (defvar toolbar-vector-copy
492 [toolbar-copy-icon toolbar-copy t "Copy region"]
493 "Define the vector for the \"Copy\" toolbar button")
495 (defvar toolbar-vector-paste
496 [toolbar-paste-icon toolbar-paste t "Paste from clipboard"]
497 "Define the vector for the \"Paste\" toolbar button")
499 (defvar toolbar-vector-undo
500 [toolbar-undo-icon toolbar-undo t "Undo edit"]
501 "Define the vector for the \"Undo\" toolbar button")
503 (defvar toolbar-vector-spell
504 [toolbar-spell-icon toolbar-ispell t "Check spelling"]
505 "Define the vector for the \"Spell\" toolbar button")
507 (defvar toolbar-vector-replace
508 [toolbar-replace-icon toolbar-replace t "Search & Replace"]
509 "Define the vector for the \"Replace\" toolbar button")
511 (defvar toolbar-vector-mail
512 [toolbar-mail-icon toolbar-mail t "Read mail"]
513 "Define the vector for the \"Mail\" toolbar button")
515 (defvar toolbar-vector-info
516 [toolbar-info-icon toolbar-info t "Info documentation"]
517 "Define the vector for the \"Info\" toolbar button")
519 (defvar toolbar-vector-compile
520 [toolbar-compile-icon toolbar-compile t "Start a compilation"]
521 "Define the vector for the \"Compile\" toolbar button")
523 (defvar toolbar-vector-debug
524 [toolbar-debug-icon toolbar-debug t "Start a debugger"]
525 "Define the vector for the \"Debug\" toolbar button")
527 (defvar toolbar-vector-news
528 [toolbar-news-icon toolbar-news t "Read news"]
529 "Define the vector for the \"News\" toolbar button")
531 (defvar initial-toolbar-spec
533 ;;[toolbar-last-win-icon pop-window-configuration
534 ;;(frame-property (selected-frame)
535 ;; 'window-config-stack) t "Most recent window config"]
536 ;; #### Illicit knowledge?
537 ;; #### These don't work right - not consistent!
538 ;; I don't know what's wrong; perhaps `selected-frame' is wrong
539 ;; sometimes when this is evaluated. Note that I even tried to
540 ;; kludge-fix this by calls to `set-specifier-dirty-flag' in
541 ;; pop-window-configuration and such.
543 ;;[toolbar-next-win-icon unpop-window-configuration
544 ;;(frame-property (selected-frame)
545 ;; 'window-config-unpop-stack) t "Undo \"Most recent window config\""]
546 ;; #### Illicit knowledge?
556 toolbar-vector-replace
559 toolbar-vector-compile
563 "The initial toolbar for a buffer.")
565 (defun x-init-toolbar-from-resources (locale)
566 (x-init-specifier-from-resources
567 top-toolbar-height 'natnum locale
568 '("topToolBarHeight" . "TopToolBarHeight"))
569 (x-init-specifier-from-resources
570 bottom-toolbar-height 'natnum locale
571 '("bottomToolBarHeight" . "BottomToolBarHeight"))
572 (x-init-specifier-from-resources
573 left-toolbar-width 'natnum locale
574 '("leftToolBarWidth" . "LeftToolBarWidth"))
575 (x-init-specifier-from-resources
576 right-toolbar-width 'natnum locale
577 '("rightToolBarWidth" . "RightToolBarWidth"))
578 (x-init-specifier-from-resources
579 top-toolbar-border-width 'natnum locale
580 '("topToolBarBorderWidth" . "TopToolBarBorderWidth"))
581 (x-init-specifier-from-resources
582 bottom-toolbar-border-width 'natnum locale
583 '("bottomToolBarBorderWidth" . "BottomToolBarBorderWidth"))
584 (x-init-specifier-from-resources
585 left-toolbar-border-width 'natnum locale
586 '("leftToolBarBorderWidth" . "LeftToolBarBorderWidth"))
587 (x-init-specifier-from-resources
588 right-toolbar-border-width 'natnum locale
589 '("rightToolBarBorderWidth" . "RightToolBarBorderWidth")))
591 ;;; toolbar-items.el ends here