Mercurial > emacs
annotate lisp/toolbar/toolbar.el @ 31649:fe990a5df9d3
(toolbar-add-item): Use the same image
specification if or if not tool-bar item contains an `:enabled'
property.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Fri, 15 Sep 2000 21:00:32 +0000 |
parents | 77a8522f11d4 |
children | 9d8d65ca0bd4 |
rev | line source |
---|---|
31590 | 1 ;;; toolbar.el --- Setting up the toolbar |
2 ;; | |
3 ;; Copyright (C) 2000 Free Software Foundation, Inc. | |
4 ;; | |
5 ;; Author: Dave Love <fx@gnu.org> | |
6 ;; Keywords: mouse frames | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; Provides `toolbar-mode' to control display of the toolbar and | |
28 ;; bindings for the global toolbar with convenience functions | |
29 ;; `toolbar-add-item' and `toolbar-like-menu-item'. | |
30 | |
31 ;;; Code: | |
32 | |
33 ;;;###autoload | |
34 (define-minor-mode toolbar-mode | |
35 "Toggle use of the toolbar. | |
36 With ARG, display the toolbar if and only if ARG is positive. | |
37 | |
38 See `toolbar-add-item' and `toolbar-like-menu-item' for conveniently | |
39 adding toolbar items." nil nil nil | |
40 :global t | |
41 :group 'mouse | |
42 :group 'frames | |
43 (let ((lines (if toolbar-mode 1 0))) | |
44 ;; Alter existing frames... | |
45 (mapc (lambda (frame) | |
46 (modify-frame-parameters frame | |
47 (list (cons 'tool-bar-lines lines)))) | |
48 (frame-list)) | |
49 ;; ...and future ones. | |
50 (let ((elt (assq 'tool-bar-lines default-frame-alist))) | |
51 (if elt | |
52 (setcdr elt lines) | |
53 (add-to-list 'default-frame-alist (cons 'tool-bar-lines lines)))))) | |
54 | |
55 (defvar toolbar-global-map (let ((map (make-sparse-keymap "Toolbar"))) | |
56 (global-set-key [tool-bar] map)) | |
57 "Keymap for the toolbar in the global map.") | |
58 | |
59 ;;;###autoload | |
60 (defun toolbar-add-item (icon def key &optional map &rest props) | |
61 "Add an item to the toolbar. | |
62 ICON names the image, DEF is the key definition and KEY is a symbol | |
63 for the fake function key in the menu keymap. MAP is the toolbar | |
64 keymap in which to define the item; it defaults to | |
65 `toolbar-global-map'. Remaining arguments PROPS are additional items | |
66 to add to the menu item specification. See Info node `(elisp)Tool | |
67 Bar'. Items are added from left to right. | |
68 | |
69 ICON is the base name of a file cnntaining the image to use. The | |
70 function will try to use first ICON.xpm, then ICON.xbm using | |
71 `find-image'. If PROPS contains `:enable', a `disabled' version of | |
72 the icon is generated automatically using the Laplace algorithm (see | |
73 Info node `(elisp)Image Descriptors')." | |
74 (let ((image (find-image `((:type xbm :file ,(concat icon ".xbm")) | |
75 (:type xpm :file ,(concat icon ".xpm")))))) | |
76 (when image | |
31638
77a8522f11d4
(toolbar-add-item): Use image-mask-p.
Gerd Moellmann <gerd@gnu.org>
parents:
31634
diff
changeset
|
77 (unless (image-mask-p image) |
31649
fe990a5df9d3
(toolbar-add-item): Use the same image
Gerd Moellmann <gerd@gnu.org>
parents:
31638
diff
changeset
|
78 (setq image (append image '(:mask heuristic)))) |
31590 | 79 (define-key-after (or map toolbar-global-map) (vector key) |
80 `(menu-item ,(symbol-name key) ,def :image ,image ,@props))))) | |
81 | |
82 (defun toolbar-like-menu-item (command icon &optional map) | |
83 "Define toolbar binding for COMMAND using the given ICON in keymap MAP. | |
84 The binding of COMMAND is looked up in the menu bar in MAP (default | |
31598
f4f8a84783d0
(toolbar-like-menu-item): Doc fix.
Dave Love <fx@gnu.org>
parents:
31590
diff
changeset
|
85 `global-map') and modified to add an image specification for ICON, which |
f4f8a84783d0
(toolbar-like-menu-item): Doc fix.
Dave Love <fx@gnu.org>
parents:
31590
diff
changeset
|
86 is looked for as by `toolbar-add-item'. |
31590 | 87 MAP must contain appropriate keymaps bound to `[menu-bar]' and |
88 `[tool-bar]'." | |
89 (unless map | |
90 (setq map global-map)) | |
91 (let* ((menu-bar-map (lookup-key map [menu-bar])) | |
92 (keys (where-is-internal command menu-bar-map)) | |
93 (tb-map (key-binding [tool-bar] map)) | |
94 (image (find-image `((:type xpm :file ,(concat icon ".xpm")) | |
95 (:type xbm :file ,(concat icon ".xbm"))))) | |
96 submap key) | |
97 (when image | |
98 ;; We'll pick up the last valid entry in the list of keys if | |
99 ;; there's more than one. | |
100 (dolist (k keys) | |
101 ;; We're looking for a binding of the command in a submap of | |
102 ;; the menu bar map, so the key sequence must be two or more | |
103 ;; long. | |
104 (if (and (vectorp k) | |
105 (> (length k) 1)) | |
106 (let ((m (lookup-key menu-bar-map (substring k 0 -1))) | |
107 ;; Last element in the bound key sequence: | |
108 (kk (aref k (1- (length k))))) | |
109 (if (and (keymapp m) | |
110 (symbolp kk)) | |
111 (setq submap m | |
112 key kk))))) | |
113 (when (and (symbolp submap) (boundp submap)) | |
114 (setq submap (eval submap))) | |
115 (define-key-after tb-map (vector key) | |
116 (append (cdr (assq key (cdr submap))) (list :image image)))))) | |
117 | |
118 ;;; Set up some global items. Additions/deletions up for grabs. | |
119 | |
120 (toolbar-like-menu-item 'save-buffers-kill-emacs "exit") | |
121 (toolbar-like-menu-item 'find-file "new") | |
122 (toolbar-like-menu-item 'dired "fld_open") | |
123 (toolbar-like-menu-item 'kill-this-buffer "close") | |
124 (toolbar-like-menu-item 'save-buffer "save") | |
125 (toolbar-like-menu-item 'write-file "saveas") | |
126 (toolbar-like-menu-item 'undo "undo") | |
127 (toolbar-like-menu-item 'kill-region "cut") | |
128 (toolbar-like-menu-item 'menu-bar-kill-ring-save "copy") | |
129 (toolbar-like-menu-item 'yank "paste") | |
130 (toolbar-like-menu-item 'nonincremental-search-forward "search") | |
131 ;;(toolbar-like-menu-item 'ispell-buffer "spell") | |
132 | |
133 ;; There's no icon appropriate for News and we need a command rather | |
134 ;; than a lambda for Read Mail. | |
135 ;;(toolbar-like-menu-item 'compose-mail "mail_compose") | |
136 | |
137 (toolbar-like-menu-item 'print-buffer "print") | |
138 (toolbar-add-item "preferences" 'customize 'customize nil | |
139 :help "Edit preferences (customize)") | |
140 (toolbar-add-item "help" | |
141 (lambda () | |
142 (interactive) | |
143 (let ((p (mouse-position))) | |
144 (x-popup-menu (list (list (cadr p) (cddr p)) (car p)) | |
145 menu-bar-help-menu))) | |
146 'help nil :help "Pop up the Help menu") | |
147 | |
148 (provide 'toolbar) | |
149 | |
150 ;;; toolbar.el ends here |