aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/toolbar
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/toolbar')
-rw-r--r--lisp/toolbar/tool-bar.el61
1 files changed, 43 insertions, 18 deletions
diff --git a/lisp/toolbar/tool-bar.el b/lisp/toolbar/tool-bar.el
index 7a201ff4020..195f57e0a90 100644
--- a/lisp/toolbar/tool-bar.el
+++ b/lisp/toolbar/tool-bar.el
@@ -99,9 +99,21 @@ ICON is the base name of a file containing the image to use. The
99function will first try to use ICON.xpm, then ICON.pbm, and finally 99function will first try to use ICON.xpm, then ICON.pbm, and finally
100ICON.xbm, using `find-image'. 100ICON.xbm, using `find-image'.
101 101
102Keybindings are made in the map `tool-bar-map'. To define items in 102Use this function only to make bindings in the global value of `tool-bar-map'.
103some local map, bind `tool-bar-map' with `let' around calls of this 103To define items in any other map, use `tool-bar-local-item'."
104function." 104 (apply 'tool-bar-local-item icon def key tool-bar-map props))
105
106;;;###autoload
107(defun tool-bar-local-item (icon def key map &rest props)
108 "Add an item to the tool bar in map MAP.
109ICON names the image, DEF is the key definition and KEY is a symbol
110for the fake function key in the menu keymap. Remaining arguments
111PROPS are additional items to add to the menu item specification. See
112Info node `(elisp)Tool Bar'. Items are added from left to right.
113
114ICON is the base name of a file containing the image to use. The
115function will first try to use ICON.xpm, then ICON.pbm, and finally
116ICON.xbm, using `find-image'."
105 (let* ((fg (face-attribute 'tool-bar :foreground)) 117 (let* ((fg (face-attribute 'tool-bar :foreground))
106 (bg (face-attribute 'tool-bar :background)) 118 (bg (face-attribute 'tool-bar :background))
107 (colors (nconc (if (eq fg 'unspecified) nil (list :foreground fg)) 119 (colors (nconc (if (eq fg 'unspecified) nil (list :foreground fg))
@@ -121,24 +133,37 @@ function."
121 (when (and (display-images-p) image) 133 (when (and (display-images-p) image)
122 (unless (image-mask-p image) 134 (unless (image-mask-p image)
123 (setq image (append image '(:mask heuristic)))) 135 (setq image (append image '(:mask heuristic))))
124 (define-key-after tool-bar-map (vector key) 136 (define-key-after map (vector key)
125 `(menu-item ,(symbol-name key) ,def :image ,image ,@props))))) 137 `(menu-item ,(symbol-name key) ,def :image ,image ,@props)))))
126 138
127;;;###autoload 139;;;###autoload
128(defun tool-bar-add-item-from-menu (command icon &optional map &rest props) 140(defun tool-bar-add-item-from-menu (command icon &optional map &rest props)
129 "Define tool bar binding for COMMAND using the given ICON in keymap MAP. 141 "Define tool bar binding for COMMAND using the given ICON in keymap MAP.
130The binding of COMMAND is looked up in the menu bar in MAP (default 142This makes a binding for COMMAND in `tool-bar-map', copying its
131`global-map') and modified to add an image specification for ICON, which 143binding from the menu bar in MAP (which defaults to `global-map'), but
132is looked for as by `tool-bar-add-item'. 144modifies the binding by adding an image specification for ICON. It
133MAP must contain an appropriate keymap bound to `[menu-bar]'. 145finds ICON just like `tool-bar-add-item'. PROPS are additional
134PROPS is a list of additional properties to add to the binding. 146properties to add to the binding.
135 147
136Keybindings are made in the map `tool-bar-map'. To define items in 148MAP must contain appropriate binding for `[menu-bar]' which holds a keymap.
137some local map, bind `tool-bar-map' with `let' around calls of this 149
138function." 150Use this function only to make bindings in the global value of `tool-bar-map'.
139 (unless map 151To define items in any other map, use `tool-bar-local-item'."
140 (setq map global-map)) 152 (apply 'tool-bar-local-item-from-menu command icon tool-bar-map map props))
141 (let* ((menu-bar-map (lookup-key map [menu-bar])) 153
154;;;###autoload
155(defun tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
156 "Define tool bar binding for COMMAND using the given ICON in keymap MAP.
157This makes a binding for COMMAND in IN-MAP, copying its binding from
158the menu bar in FROM-MAP (which defaults to `global-map'), but
159modifies the binding by adding an image specification for ICON. It
160finds ICON just like `tool-bar-add-item'. PROPS are additional
161properties to add to the binding.
162
163MAP must contain appropriate binding for `[menu-bar]' which holds a keymap."
164 (unless from-map
165 (setq from-map global-map))
166 (let* ((menu-bar-map (lookup-key from-map [menu-bar]))
142 (keys (where-is-internal command menu-bar-map)) 167 (keys (where-is-internal command menu-bar-map))
143 (fg (face-attribute 'tool-bar :foreground)) 168 (fg (face-attribute 'tool-bar :foreground))
144 (bg (face-attribute 'tool-bar :background)) 169 (bg (face-attribute 'tool-bar :background))
@@ -179,10 +204,10 @@ function."
179 (setq image (append image '(:mask heuristic)))) 204 (setq image (append image '(:mask heuristic))))
180 (let ((defn (assq key (cdr submap)))) 205 (let ((defn (assq key (cdr submap))))
181 (if (eq (cadr defn) 'menu-item) 206 (if (eq (cadr defn) 'menu-item)
182 (define-key-after tool-bar-map (vector key) 207 (define-key-after in-map (vector key)
183 (append (cdr defn) (list :image image) props)) 208 (append (cdr defn) (list :image image) props))
184 (setq defn (cdr defn)) 209 (setq defn (cdr defn))
185 (define-key-after tool-bar-map (vector key) 210 (define-key-after in-map (vector key)
186 (append `(menu-item ,(car defn) ,(cddr defn)) 211 (append `(menu-item ,(car defn) ,(cddr defn))
187 (list :image image) props))))))) 212 (list :image image) props)))))))
188 213