Mercurial > emacs
annotate lisp/toolbar/tool-bar.el @ 32302:ef87e043f166
*** empty log message ***
author | Dave Love <fx@gnu.org> |
---|---|
date | Sun, 08 Oct 2000 17:53:13 +0000 |
parents | 4763231809cd |
children | d1c0cf83e365 |
rev | line source |
---|---|
31738
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
1 ;;; tool-bar.el --- Setting up the tool bar |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
2 ;; |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
3 ;; Copyright (C) 2000 Free Software Foundation, Inc. |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
4 ;; |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
5 ;; Author: Dave Love <fx@gnu.org> |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
6 ;; Keywords: mouse frames |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
7 |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
9 |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
13 ;; any later version. |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
14 |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
18 ;; GNU General Public License for more details. |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
19 |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
23 ;; Boston, MA 02111-1307, USA. |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
24 |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
25 ;;; Commentary: |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
26 |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
27 ;; Provides `tool-bar-mode' to control display of the tool -bar and |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
28 ;; bindings for the global tool bar with convenience functions |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
29 ;; `tool-bar-add-item' and `tool-bar-add-item-from-menu'. |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
30 |
32285 | 31 ;; The normal global binding for [tool-bar] (below) uses the value of |
32 ;; `tool-bar-map' as the actual keymap used to define the tool bar. | |
33 ;; Modes may either bind items under the [tool-bar] prefix key of the | |
34 ;; local map to add to the global bar or may set `tool-bar-map' | |
35 ;; buffer-locally to overirde it. (Some items are removed from the | |
36 ;; global bar in modes which have `special' as their `mode-class' | |
37 ;; properlty.) | |
38 | |
31738
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
39 ;;; Code: |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
40 |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
41 ;;;###autoload |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
42 (define-minor-mode tool-bar-mode |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
43 "Toggle use of the tool bar. |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
44 With ARG, display the tool bar if and only if ARG is positive. |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
45 |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
46 See `tool-bar-add-item' and `tool-bar-add-item-from-menu' for |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
47 conveniently adding tool bar items." |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
48 nil nil nil |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
49 :global t |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
50 :group 'mouse |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
51 :group 'frames |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
52 (let ((lines (if tool-bar-mode 1 0))) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
53 ;; Alter existing frames... |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
54 (mapc (lambda (frame) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
55 (modify-frame-parameters frame |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
56 (list (cons 'tool-bar-lines lines)))) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
57 (frame-list)) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
58 ;; ...and future ones. |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
59 (let ((elt (assq 'tool-bar-lines default-frame-alist))) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
60 (if elt |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
61 (setcdr elt lines) |
32124 | 62 (add-to-list 'default-frame-alist (cons 'tool-bar-lines lines))))) |
63 (if (and tool-bar-mode (display-graphic-p)) | |
64 (tool-bar-setup))) | |
31738
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
65 |
32285 | 66 (defvar tool-bar-map (make-sparse-keymap) |
67 "Keymap for the tool bar. | |
68 Define this locally to override the global tool bar.") | |
69 | |
70 (global-set-key [tool-bar] | |
71 '(menu-item "tool bar" ignore | |
72 :filter (lambda (ignore) tool-bar-map))) | |
31738
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
73 |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
74 ;;;###autoload |
32285 | 75 (defun tool-bar-add-item (icon def key &rest props) |
31738
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
76 "Add an item to the tool bar. |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
77 ICON names the image, DEF is the key definition and KEY is a symbol |
32285 | 78 for the fake function key in the menu keymap. Remaining arguments |
79 PROPS are additional items to add to the menu item specification. See | |
80 Info node `(elisp)Tool Bar'. Items are added from left to right. | |
31738
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
81 |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
82 ICON is the base name of a file cnntaining the image to use. The |
32285 | 83 function will try to use first ICON.xpm, ICON.pbm then ICON.xbm using |
84 `find-image'. | |
85 | |
86 Keybindings are made in the map `tool-bar-map'. To define items in | |
87 some local map, bind `tool-bar-map' with `let' around calls of this | |
88 function." | |
89 (let ((image (find-image `((:type xpm :file ,(concat icon ".xpm")) | |
90 (:type pbm :file ,(concat icon ".pbm")) | |
91 (:type xbm :file ,(concat icon ".xbm")))))) | |
31738
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
92 (when image |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
93 (unless (image-mask-p image) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
94 (setq image (append image '(:mask heuristic)))) |
32285 | 95 (define-key-after tool-bar-map (vector key) |
31738
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
96 `(menu-item ,(symbol-name key) ,def :image ,image ,@props))))) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
97 |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
98 (defun tool-bar-add-item-from-menu (command icon &optional map &rest props) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
99 "Define tool bar binding for COMMAND using the given ICON in keymap MAP. |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
100 The binding of COMMAND is looked up in the menu bar in MAP (default |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
101 `global-map') and modified to add an image specification for ICON, which |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
102 is looked for as by `tool-bar-add-item'. |
32285 | 103 MAP must contain an appropriate keymap bound to `[menu-bar]'. |
104 PROPS is a list of additional properties to add to the binding. | |
105 | |
106 Keybindings are made in the map `tool-bar-map'. To define items in | |
107 some local map, bind `tool-bar-map' with `let' around calls of this | |
108 function." | |
31738
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
109 (unless map |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
110 (setq map global-map)) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
111 (let* ((menu-bar-map (lookup-key map [menu-bar])) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
112 (keys (where-is-internal command menu-bar-map)) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
113 (image (find-image `((:type xpm :file ,(concat icon ".xpm")) |
32285 | 114 (:type pbm :file ,(concat icon ".pbm")) |
31738
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
115 (:type xbm :file ,(concat icon ".xbm"))))) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
116 submap key) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
117 (when image |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
118 ;; We'll pick up the last valid entry in the list of keys if |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
119 ;; there's more than one. |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
120 (dolist (k keys) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
121 ;; We're looking for a binding of the command in a submap of |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
122 ;; the menu bar map, so the key sequence must be two or more |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
123 ;; long. |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
124 (if (and (vectorp k) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
125 (> (length k) 1)) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
126 (let ((m (lookup-key menu-bar-map (substring k 0 -1))) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
127 ;; Last element in the bound key sequence: |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
128 (kk (aref k (1- (length k))))) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
129 (if (and (keymapp m) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
130 (symbolp kk)) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
131 (setq submap m |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
132 key kk))))) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
133 (when (and (symbolp submap) (boundp submap)) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
134 (setq submap (eval submap))) |
31751
3c4b8a33fed9
Reapply Gerd's change from 2000-09-18, which seems to have gotten lost:
Miles Bader <miles@gnu.org>
parents:
31738
diff
changeset
|
135 (unless (image-mask-p image) |
3c4b8a33fed9
Reapply Gerd's change from 2000-09-18, which seems to have gotten lost:
Miles Bader <miles@gnu.org>
parents:
31738
diff
changeset
|
136 (setq image (append image '(:mask heuristic)))) |
32285 | 137 (define-key-after tool-bar-map (vector key) |
31738
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
138 (append (cdr (assq key (cdr submap))) (list :image image) props))))) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
139 |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
140 ;;; Set up some global items. Additions/deletions up for grabs. |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
141 |
32124 | 142 (defun tool-bar-setup () |
143 (tool-bar-add-item-from-menu 'save-buffers-kill-emacs "exit") | |
144 (tool-bar-add-item-from-menu 'find-file "new") | |
145 (tool-bar-add-item-from-menu 'dired "open") | |
146 (tool-bar-add-item-from-menu 'kill-this-buffer "close") | |
147 (tool-bar-add-item-from-menu 'save-buffer "save" nil | |
148 :visible '(not (eq 'special (get major-mode | |
149 'mode-class)))) | |
150 (tool-bar-add-item-from-menu 'write-file "saveas" nil | |
151 :visible '(not (eq 'special (get major-mode | |
152 'mode-class)))) | |
153 (tool-bar-add-item-from-menu 'undo "undo" nil | |
154 :visible '(not (eq 'special (get major-mode | |
155 'mode-class)))) | |
156 (tool-bar-add-item-from-menu 'kill-region "cut" nil | |
157 :visible '(not (eq 'special (get major-mode | |
158 'mode-class)))) | |
159 (tool-bar-add-item-from-menu 'menu-bar-kill-ring-save "copy") | |
160 (tool-bar-add-item-from-menu 'yank "paste" nil | |
161 :visible '(not (eq 'special (get major-mode | |
162 'mode-class)))) | |
163 (tool-bar-add-item-from-menu 'nonincremental-search-forward "search") | |
164 ;;(tool-bar-add-item-from-menu 'ispell-buffer "spell") | |
31738
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
165 |
32124 | 166 ;; There's no icon appropriate for News and we need a command rather |
167 ;; than a lambda for Read Mail. | |
168 ;;(tool-bar-add-item-from-menu 'compose-mail "mail_compose") | |
31895
6d04db7a9256
(tool-bar-help): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
31751
diff
changeset
|
169 |
32124 | 170 (tool-bar-add-item-from-menu 'print-buffer "print") |
32285 | 171 (tool-bar-add-item "preferences" 'customize 'customize |
32124 | 172 :help "Edit preferences (customize)") |
31895
6d04db7a9256
(tool-bar-help): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
31751
diff
changeset
|
173 |
32285 | 174 (tool-bar-add-item "help" (lambda () |
175 (interactive) | |
176 (popup-menu menu-bar-help-menu)) | |
177 'help | |
178 :help "Pop up the Help menu") | |
32124 | 179 ) |
31738
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
180 |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
181 (provide 'tool-bar) |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
182 |
e8458588eb55
Renamed from toolbar.el. Change `toolbar'
Dave Love <fx@gnu.org>
parents:
diff
changeset
|
183 ;;; tool-bar.el ends here |