Mercurial > emacs
comparison lisp/toolbar/tool-bar.el @ 31738:e8458588eb55
Renamed from toolbar.el. Change `toolbar'
to `tool-bar' generally in symbols. Make some items invisible in
`special' major modes.
(tool-bar-add-item-from-menu): Renamed from
toolbar-like-menu-item. Add arg PROPS.
author | Dave Love <fx@gnu.org> |
---|---|
date | Tue, 19 Sep 2000 17:36:49 +0000 |
parents | |
children | 3c4b8a33fed9 |
comparison
equal
deleted
inserted
replaced
31737:93eca5fb26ae | 31738:e8458588eb55 |
---|---|
1 ;;; tool-bar.el --- Setting up the tool bar | |
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 `tool-bar-mode' to control display of the tool -bar and | |
28 ;; bindings for the global tool bar with convenience functions | |
29 ;; `tool-bar-add-item' and `tool-bar-add-item-from-menu'. | |
30 | |
31 ;;; Code: | |
32 | |
33 ;;;###autoload | |
34 (define-minor-mode tool-bar-mode | |
35 "Toggle use of the tool bar. | |
36 With ARG, display the tool bar if and only if ARG is positive. | |
37 | |
38 See `tool-bar-add-item' and `tool-bar-add-item-from-menu' for | |
39 conveniently adding tool bar items." | |
40 nil nil nil | |
41 :global t | |
42 :group 'mouse | |
43 :group 'frames | |
44 (let ((lines (if tool-bar-mode 1 0))) | |
45 ;; Alter existing frames... | |
46 (mapc (lambda (frame) | |
47 (modify-frame-parameters frame | |
48 (list (cons 'tool-bar-lines lines)))) | |
49 (frame-list)) | |
50 ;; ...and future ones. | |
51 (let ((elt (assq 'tool-bar-lines default-frame-alist))) | |
52 (if elt | |
53 (setcdr elt lines) | |
54 (add-to-list 'default-frame-alist (cons 'tool-bar-lines lines)))))) | |
55 | |
56 (defvar tool-bar-global-map (let ((map (make-sparse-keymap))) | |
57 (global-set-key [tool-bar] map)) | |
58 "Keymap for the tool bar in the global map.") | |
59 | |
60 ;;;###autoload | |
61 (defun tool-bar-add-item (icon def key &optional map &rest props) | |
62 "Add an item to the tool bar. | |
63 ICON names the image, DEF is the key definition and KEY is a symbol | |
64 for the fake function key in the menu keymap. MAP is the tool bar | |
65 keymap in which to define the item; it defaults to | |
66 `tool-bar-global-map'. Remaining arguments PROPS are additional items | |
67 to add to the menu item specification. See Info node `(elisp)Tool | |
68 Bar'. Items are added from left to right. | |
69 | |
70 ICON is the base name of a file cnntaining the image to use. The | |
71 function will try to use first ICON.xpm, then ICON.xbm using | |
72 `find-image'. If PROPS contains `:enable', a `disabled' version of | |
73 the icon is generated automatically using the Laplace algorithm (see | |
74 Info node `(elisp)Image Descriptors')." | |
75 (let ((image (find-image `((:type xbm :file ,(concat icon ".xbm")) | |
76 (:type xpm :file ,(concat icon ".xpm")))))) | |
77 (when image | |
78 (unless (image-mask-p image) | |
79 (setq image (append image '(:mask heuristic)))) | |
80 (define-key-after (or map tool-bar-global-map) (vector key) | |
81 `(menu-item ,(symbol-name key) ,def :image ,image ,@props))))) | |
82 | |
83 (defun tool-bar-add-item-from-menu (command icon &optional map &rest props) | |
84 "Define tool bar binding for COMMAND using the given ICON in keymap MAP. | |
85 The binding of COMMAND is looked up in the menu bar in MAP (default | |
86 `global-map') and modified to add an image specification for ICON, which | |
87 is looked for as by `tool-bar-add-item'. | |
88 MAP must contain appropriate keymaps bound to `[menu-bar]' and | |
89 `[tool-bar]'. | |
90 PROPS is a list of additional properties to add to the binding." | |
91 (unless map | |
92 (setq map global-map)) | |
93 (let* ((menu-bar-map (lookup-key map [menu-bar])) | |
94 (keys (where-is-internal command menu-bar-map)) | |
95 (tb-map (key-binding [tool-bar] map)) | |
96 (image (find-image `((:type xpm :file ,(concat icon ".xpm")) | |
97 (:type xbm :file ,(concat icon ".xbm"))))) | |
98 submap key) | |
99 (when image | |
100 ;; We'll pick up the last valid entry in the list of keys if | |
101 ;; there's more than one. | |
102 (dolist (k keys) | |
103 ;; We're looking for a binding of the command in a submap of | |
104 ;; the menu bar map, so the key sequence must be two or more | |
105 ;; long. | |
106 (if (and (vectorp k) | |
107 (> (length k) 1)) | |
108 (let ((m (lookup-key menu-bar-map (substring k 0 -1))) | |
109 ;; Last element in the bound key sequence: | |
110 (kk (aref k (1- (length k))))) | |
111 (if (and (keymapp m) | |
112 (symbolp kk)) | |
113 (setq submap m | |
114 key kk))))) | |
115 (when (and (symbolp submap) (boundp submap)) | |
116 (setq submap (eval submap))) | |
117 (define-key-after tb-map (vector key) | |
118 (append (cdr (assq key (cdr submap))) (list :image image) props))))) | |
119 | |
120 ;;; Set up some global items. Additions/deletions up for grabs. | |
121 | |
122 (tool-bar-add-item-from-menu 'save-buffers-kill-emacs "exit") | |
123 (tool-bar-add-item-from-menu 'find-file "new") | |
124 (tool-bar-add-item-from-menu 'dired "open") | |
125 (tool-bar-add-item-from-menu 'kill-this-buffer "close") | |
126 (tool-bar-add-item-from-menu 'save-buffer "save" nil | |
127 :visible '(not (eq 'special (get major-mode | |
128 'mode-class)))) | |
129 (tool-bar-add-item-from-menu 'write-file "saveas" nil | |
130 :visible '(not (eq 'special (get major-mode | |
131 'mode-class)))) | |
132 (tool-bar-add-item-from-menu 'undo "undo" nil | |
133 :visible '(not (eq 'special (get major-mode | |
134 'mode-class)))) | |
135 (tool-bar-add-item-from-menu 'kill-region "cut" nil | |
136 :visible '(not (eq 'special (get major-mode | |
137 'mode-class)))) | |
138 (tool-bar-add-item-from-menu 'menu-bar-kill-ring-save "copy") | |
139 (tool-bar-add-item-from-menu 'yank "paste" nil | |
140 :visible '(not (eq 'special (get major-mode | |
141 'mode-class)))) | |
142 (tool-bar-add-item-from-menu 'nonincremental-search-forward "search") | |
143 ;;(tool-bar-add-item-from-menu 'ispell-buffer "spell") | |
144 | |
145 ;; There's no icon appropriate for News and we need a command rather | |
146 ;; than a lambda for Read Mail. | |
147 ;;(tool-bar-add-item-from-menu 'compose-mail "mail_compose") | |
148 | |
149 (tool-bar-add-item-from-menu 'print-buffer "print") | |
150 (tool-bar-add-item "preferences" 'customize 'customize nil | |
151 :help "Edit preferences (customize)") | |
152 (tool-bar-add-item "help" | |
153 (lambda () | |
154 (interactive) | |
155 (let ((p (mouse-position))) | |
156 (x-popup-menu (list (list (cadr p) (cddr p)) (car p)) | |
157 menu-bar-help-menu))) | |
158 'help nil :help "Pop up the Help menu") | |
159 | |
160 (provide 'tool-bar) | |
161 | |
162 ;;; tool-bar.el ends here |