Mercurial > emacs
annotate lisp/toolbar/toolbar.el @ 31691:9d8d65ca0bd4
(toolbar-like-menu-item): Like in
toolbar-add-item, if image doesn't have a mask add a `:mask
heuristic'.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Mon, 18 Sep 2000 12:25:36 +0000 |
parents | fe990a5df9d3 |
children |
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))) | |
31691
9d8d65ca0bd4
(toolbar-like-menu-item): Like in
Gerd Moellmann <gerd@gnu.org>
parents:
31649
diff
changeset
|
115 (unless (image-mask-p image) |
9d8d65ca0bd4
(toolbar-like-menu-item): Like in
Gerd Moellmann <gerd@gnu.org>
parents:
31649
diff
changeset
|
116 (setq image (append image '(:mask heuristic)))) |
31590 | 117 (define-key-after tb-map (vector key) |
118 (append (cdr (assq key (cdr submap))) (list :image image)))))) | |
119 | |
120 ;;; Set up some global items. Additions/deletions up for grabs. | |
121 | |
122 (toolbar-like-menu-item 'save-buffers-kill-emacs "exit") | |
123 (toolbar-like-menu-item 'find-file "new") | |
124 (toolbar-like-menu-item 'dired "fld_open") | |
125 (toolbar-like-menu-item 'kill-this-buffer "close") | |
126 (toolbar-like-menu-item 'save-buffer "save") | |
127 (toolbar-like-menu-item 'write-file "saveas") | |
128 (toolbar-like-menu-item 'undo "undo") | |
129 (toolbar-like-menu-item 'kill-region "cut") | |
130 (toolbar-like-menu-item 'menu-bar-kill-ring-save "copy") | |
131 (toolbar-like-menu-item 'yank "paste") | |
132 (toolbar-like-menu-item 'nonincremental-search-forward "search") | |
133 ;;(toolbar-like-menu-item 'ispell-buffer "spell") | |
134 | |
135 ;; There's no icon appropriate for News and we need a command rather | |
136 ;; than a lambda for Read Mail. | |
137 ;;(toolbar-like-menu-item 'compose-mail "mail_compose") | |
138 | |
139 (toolbar-like-menu-item 'print-buffer "print") | |
140 (toolbar-add-item "preferences" 'customize 'customize nil | |
141 :help "Edit preferences (customize)") | |
142 (toolbar-add-item "help" | |
143 (lambda () | |
144 (interactive) | |
145 (let ((p (mouse-position))) | |
146 (x-popup-menu (list (list (cadr p) (cddr p)) (car p)) | |
147 menu-bar-help-menu))) | |
148 'help nil :help "Pop up the Help menu") | |
149 | |
150 (provide 'toolbar) | |
151 | |
152 ;;; toolbar.el ends here |