2001-07-16 12:23:00 +00:00
|
|
|
;;; tool-bar.el --- setting up the tool bar
|
2000-09-19 17:36:49 +00:00
|
|
|
;;
|
2001-08-06 10:41:52 +00:00
|
|
|
;; Copyright (C) 2000, 2001 Free Software Foundation, Inc.
|
2000-09-19 17:36:49 +00:00
|
|
|
;;
|
|
|
|
;; Author: Dave Love <fx@gnu.org>
|
|
|
|
;; Keywords: mouse frames
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
;; any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
|
|
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
;; Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; Provides `tool-bar-mode' to control display of the tool -bar and
|
|
|
|
;; bindings for the global tool bar with convenience functions
|
|
|
|
;; `tool-bar-add-item' and `tool-bar-add-item-from-menu'.
|
|
|
|
|
2000-10-08 15:29:52 +00:00
|
|
|
;; The normal global binding for [tool-bar] (below) uses the value of
|
2000-11-17 17:50:48 +00:00
|
|
|
;; `tool-bar-map' as the actual keymap to define the tool bar. Modes
|
|
|
|
;; may either bind items under the [tool-bar] prefix key of the local
|
|
|
|
;; map to add to the global bar or may set `tool-bar-map'
|
2000-10-11 14:11:47 +00:00
|
|
|
;; buffer-locally to override it. (Some items are removed from the
|
2000-10-08 15:29:52 +00:00
|
|
|
;; global bar in modes which have `special' as their `mode-class'
|
|
|
|
;; properlty.)
|
|
|
|
|
2000-10-09 11:12:06 +00:00
|
|
|
;; Todo: Somehow make tool bars easily customizable by the naive?
|
|
|
|
|
2000-09-19 17:36:49 +00:00
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(define-minor-mode tool-bar-mode
|
|
|
|
"Toggle use of the tool bar.
|
2000-11-29 15:29:45 +00:00
|
|
|
With numeric ARG, display the tool bar if and only if ARG is positive.
|
2000-09-19 17:36:49 +00:00
|
|
|
|
|
|
|
See `tool-bar-add-item' and `tool-bar-add-item-from-menu' for
|
|
|
|
conveniently adding tool bar items."
|
|
|
|
:global t
|
|
|
|
:group 'mouse
|
|
|
|
:group 'frames
|
2001-08-30 06:52:19 +00:00
|
|
|
(and (display-images-p)
|
|
|
|
(let ((lines (if tool-bar-mode 1 0)))
|
|
|
|
;; Alter existing frames...
|
|
|
|
(mapc (lambda (frame)
|
|
|
|
(modify-frame-parameters frame
|
|
|
|
(list (cons 'tool-bar-lines lines))))
|
|
|
|
(frame-list))
|
|
|
|
;; ...and future ones.
|
|
|
|
(let ((elt (assq 'tool-bar-lines default-frame-alist)))
|
|
|
|
(if elt
|
|
|
|
(setcdr elt lines)
|
|
|
|
(add-to-list 'default-frame-alist (cons 'tool-bar-lines lines)))))
|
|
|
|
(if (and tool-bar-mode
|
|
|
|
(display-graphic-p)
|
|
|
|
(= 1 (length (default-value 'tool-bar-map)))) ; not yet setup
|
|
|
|
(tool-bar-setup))))
|
2000-09-19 17:36:49 +00:00
|
|
|
|
2000-10-08 15:29:52 +00:00
|
|
|
(defvar tool-bar-map (make-sparse-keymap)
|
|
|
|
"Keymap for the tool bar.
|
|
|
|
Define this locally to override the global tool bar.")
|
|
|
|
|
|
|
|
(global-set-key [tool-bar]
|
|
|
|
'(menu-item "tool bar" ignore
|
|
|
|
:filter (lambda (ignore) tool-bar-map)))
|
2000-09-19 17:36:49 +00:00
|
|
|
|
|
|
|
;;;###autoload
|
2000-10-08 15:29:52 +00:00
|
|
|
(defun tool-bar-add-item (icon def key &rest props)
|
2000-09-19 17:36:49 +00:00
|
|
|
"Add an item to the tool bar.
|
|
|
|
ICON names the image, DEF is the key definition and KEY is a symbol
|
2000-10-08 15:29:52 +00:00
|
|
|
for the fake function key in the menu keymap. Remaining arguments
|
|
|
|
PROPS are additional items to add to the menu item specification. See
|
|
|
|
Info node `(elisp)Tool Bar'. Items are added from left to right.
|
2000-09-19 17:36:49 +00:00
|
|
|
|
2001-01-31 13:23:12 +00:00
|
|
|
ICON is the base name of a file containing the image to use. The
|
|
|
|
function will first try to use ICON.xpm, then ICON.pbm, and finally
|
|
|
|
ICON.xbm, using `find-image'.
|
2000-10-08 15:29:52 +00:00
|
|
|
|
|
|
|
Keybindings are made in the map `tool-bar-map'. To define items in
|
|
|
|
some local map, bind `tool-bar-map' with `let' around calls of this
|
|
|
|
function."
|
2000-11-29 19:21:47 +00:00
|
|
|
(let* ((fg (face-attribute 'tool-bar :foreground))
|
|
|
|
(bg (face-attribute 'tool-bar :background))
|
|
|
|
(colors (nconc (if (eq fg 'unspecified) nil (list :foreground fg))
|
|
|
|
(if (eq bg 'unspecified) nil (list :background bg))))
|
2000-10-23 18:00:51 +00:00
|
|
|
(image (find-image
|
2000-10-10 09:31:04 +00:00
|
|
|
(if (display-color-p)
|
2000-11-29 19:21:47 +00:00
|
|
|
(list (list :type 'xpm :file (concat icon ".xpm"))
|
|
|
|
(append (list :type 'pbm :file (concat icon ".pbm"))
|
|
|
|
colors)
|
|
|
|
(append (list :type 'xbm :file (concat icon ".xbm"))
|
|
|
|
colors))
|
|
|
|
(list (append (list :type 'pbm :file (concat icon ".pbm"))
|
|
|
|
colors)
|
|
|
|
(append (list :type 'xbm :file (concat icon ".xbm"))
|
|
|
|
colors)
|
|
|
|
(list :type 'xpm :file (concat icon ".xpm")))))))
|
2001-07-17 12:59:14 +00:00
|
|
|
(when (and (display-images-p) image)
|
2000-09-19 17:36:49 +00:00
|
|
|
(unless (image-mask-p image)
|
|
|
|
(setq image (append image '(:mask heuristic))))
|
2000-10-08 15:29:52 +00:00
|
|
|
(define-key-after tool-bar-map (vector key)
|
2000-09-19 17:36:49 +00:00
|
|
|
`(menu-item ,(symbol-name key) ,def :image ,image ,@props)))))
|
|
|
|
|
2000-10-09 17:56:11 +00:00
|
|
|
;;;###autoload
|
2000-09-19 17:36:49 +00:00
|
|
|
(defun tool-bar-add-item-from-menu (command icon &optional map &rest props)
|
|
|
|
"Define tool bar binding for COMMAND using the given ICON in keymap MAP.
|
|
|
|
The binding of COMMAND is looked up in the menu bar in MAP (default
|
|
|
|
`global-map') and modified to add an image specification for ICON, which
|
|
|
|
is looked for as by `tool-bar-add-item'.
|
2000-10-08 15:29:52 +00:00
|
|
|
MAP must contain an appropriate keymap bound to `[menu-bar]'.
|
|
|
|
PROPS is a list of additional properties to add to the binding.
|
|
|
|
|
|
|
|
Keybindings are made in the map `tool-bar-map'. To define items in
|
|
|
|
some local map, bind `tool-bar-map' with `let' around calls of this
|
|
|
|
function."
|
2000-09-19 17:36:49 +00:00
|
|
|
(unless map
|
|
|
|
(setq map global-map))
|
|
|
|
(let* ((menu-bar-map (lookup-key map [menu-bar]))
|
|
|
|
(keys (where-is-internal command menu-bar-map))
|
2000-11-29 19:21:47 +00:00
|
|
|
(fg (face-attribute 'tool-bar :foreground))
|
|
|
|
(bg (face-attribute 'tool-bar :background))
|
|
|
|
(colors (nconc (if (eq fg 'unspecified) nil (list :foreground fg))
|
|
|
|
(if (eq bg 'unspecified) nil (list :background bg))))
|
2000-11-27 11:28:24 +00:00
|
|
|
(spec (if (display-color-p)
|
|
|
|
(list (list :type 'xpm :file (concat icon ".xpm"))
|
|
|
|
(append (list :type 'pbm :file (concat icon ".pbm"))
|
|
|
|
colors)
|
|
|
|
(append (list :type 'xbm :file (concat icon ".xbm"))
|
|
|
|
colors))
|
|
|
|
(list (append (list :type 'pbm :file (concat icon ".pbm"))
|
|
|
|
colors)
|
|
|
|
(append (list :type 'xbm :file (concat icon ".xbm"))
|
|
|
|
colors)
|
|
|
|
(list :type 'xpm :file (concat icon ".xpm")))))
|
|
|
|
(image (find-image spec))
|
2000-09-19 17:36:49 +00:00
|
|
|
submap key)
|
2001-07-17 12:59:14 +00:00
|
|
|
(when (and (display-images-p) image)
|
2000-09-19 17:36:49 +00:00
|
|
|
;; We'll pick up the last valid entry in the list of keys if
|
|
|
|
;; there's more than one.
|
|
|
|
(dolist (k keys)
|
|
|
|
;; We're looking for a binding of the command in a submap of
|
|
|
|
;; the menu bar map, so the key sequence must be two or more
|
|
|
|
;; long.
|
|
|
|
(if (and (vectorp k)
|
|
|
|
(> (length k) 1))
|
|
|
|
(let ((m (lookup-key menu-bar-map (substring k 0 -1)))
|
|
|
|
;; Last element in the bound key sequence:
|
|
|
|
(kk (aref k (1- (length k)))))
|
|
|
|
(if (and (keymapp m)
|
|
|
|
(symbolp kk))
|
|
|
|
(setq submap m
|
|
|
|
key kk)))))
|
|
|
|
(when (and (symbolp submap) (boundp submap))
|
|
|
|
(setq submap (eval submap)))
|
2000-09-20 07:18:35 +00:00
|
|
|
(unless (image-mask-p image)
|
|
|
|
(setq image (append image '(:mask heuristic))))
|
2001-08-06 10:41:52 +00:00
|
|
|
(let ((defn (assq key (cdr submap))))
|
|
|
|
(if (eq (cadr defn) 'menu-item)
|
|
|
|
(define-key-after tool-bar-map (vector key)
|
|
|
|
(append (cdr defn) (list :image image) props))
|
|
|
|
(setq defn (cdr defn))
|
|
|
|
(define-key-after tool-bar-map (vector key)
|
|
|
|
(append `(menu-item ,(car defn) ,(cddr defn))
|
|
|
|
(list :image image) props)))))))
|
2000-09-19 17:36:49 +00:00
|
|
|
|
|
|
|
;;; Set up some global items. Additions/deletions up for grabs.
|
|
|
|
|
2000-10-04 09:36:30 +00:00
|
|
|
(defun tool-bar-setup ()
|
2001-06-21 12:48:03 +00:00
|
|
|
;; People say it's bad to have EXIT on the tool bar, since users
|
|
|
|
;; might inadvertently click that button.
|
|
|
|
;;(tool-bar-add-item-from-menu 'save-buffers-kill-emacs "exit")
|
2000-10-04 09:36:30 +00:00
|
|
|
(tool-bar-add-item-from-menu 'find-file "new")
|
|
|
|
(tool-bar-add-item-from-menu 'dired "open")
|
|
|
|
(tool-bar-add-item-from-menu 'kill-this-buffer "close")
|
|
|
|
(tool-bar-add-item-from-menu 'save-buffer "save" nil
|
2001-03-10 13:20:47 +00:00
|
|
|
:visible '(or buffer-file-name
|
|
|
|
(not (eq 'special
|
|
|
|
(get major-mode
|
|
|
|
'mode-class)))))
|
2000-10-04 09:36:30 +00:00
|
|
|
(tool-bar-add-item-from-menu 'write-file "saveas" nil
|
2001-03-10 13:20:47 +00:00
|
|
|
:visible '(or buffer-file-name
|
|
|
|
(not (eq 'special
|
|
|
|
(get major-mode
|
|
|
|
'mode-class)))))
|
2000-10-04 09:36:30 +00:00
|
|
|
(tool-bar-add-item-from-menu 'undo "undo" nil
|
|
|
|
:visible '(not (eq 'special (get major-mode
|
|
|
|
'mode-class))))
|
|
|
|
(tool-bar-add-item-from-menu 'kill-region "cut" nil
|
|
|
|
:visible '(not (eq 'special (get major-mode
|
|
|
|
'mode-class))))
|
|
|
|
(tool-bar-add-item-from-menu 'menu-bar-kill-ring-save "copy")
|
|
|
|
(tool-bar-add-item-from-menu 'yank "paste" nil
|
|
|
|
:visible '(not (eq 'special (get major-mode
|
|
|
|
'mode-class))))
|
|
|
|
(tool-bar-add-item-from-menu 'nonincremental-search-forward "search")
|
|
|
|
;;(tool-bar-add-item-from-menu 'ispell-buffer "spell")
|
|
|
|
|
|
|
|
;; There's no icon appropriate for News and we need a command rather
|
|
|
|
;; than a lambda for Read Mail.
|
|
|
|
;;(tool-bar-add-item-from-menu 'compose-mail "mail_compose")
|
|
|
|
|
|
|
|
(tool-bar-add-item-from-menu 'print-buffer "print")
|
2000-10-08 15:29:52 +00:00
|
|
|
(tool-bar-add-item "preferences" 'customize 'customize
|
2000-10-04 09:36:30 +00:00
|
|
|
:help "Edit preferences (customize)")
|
|
|
|
|
2000-10-08 15:29:52 +00:00
|
|
|
(tool-bar-add-item "help" (lambda ()
|
|
|
|
(interactive)
|
|
|
|
(popup-menu menu-bar-help-menu))
|
|
|
|
'help
|
|
|
|
:help "Pop up the Help menu")
|
2000-10-04 09:36:30 +00:00
|
|
|
)
|
2000-09-19 17:36:49 +00:00
|
|
|
|
|
|
|
(provide 'tool-bar)
|
|
|
|
|
|
|
|
;;; tool-bar.el ends here
|