unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: David Reitter <dreitter@inf.ed.ac.uk>
To: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
Cc: emacs-devel@gnu.org
Subject: Re: tool-bar (Carbon port): labels under icons
Date: Sat, 5 Apr 2008 12:48:20 +0100	[thread overview]
Message-ID: <488FE8E4-8EF1-4025-91BB-CDAD87B365B2@inf.ed.ac.uk> (raw)
In-Reply-To: <wlk5jcwv7y.wl%mituharu@math.s.chiba-u.ac.jp>

On 5 Apr 2008, at 09:40, YAMAMOTO Mitsuharu wrote:

> It sets a string as an event type.  But the "Classifying Events" node
> in the Emacs Lisp info says "the event type is always a symbol or a
> character".

True.  The new patch is below.  `tool-bar-add-item' and friends remain  
backwards-compatible.

>> 	* macterm.c [USE_MAC_TOOLBAR]: Add Vmac_tool_bar_display_mode.
>
> Shouldn't it be a frame parameter rather than a variable?


Either users need the labels, or they don't and want to save space.   
Can you think of a use case?

*** tool-bar.el	05 Apr 2008 01:23:45 +0100	1.7.2.2
--- tool-bar.el	05 Apr 2008 12:47:39 +0100	
***************
*** 110,156 ****
   ;;;###autoload
   (defun tool-bar-local-item (icon def key map &rest props)
     "Add an item to the tool bar in map MAP.
! ICON names the image, DEF is the key definition and KEY is a symbol
! for the fake function key in the menu keymap.  Remaining arguments
! PROPS are additional items to add to the menu item specification.  See
! Info node `(elisp)Tool Bar'.  Items are added from left to right.
!
! ICON is the base name of a file containing the image to use.  The
! function will first try to use low-color/ICON.xpm if display-color- 
cells
! is less or equal to 256, then ICON.xpm, then ICON.pbm, and finally
! ICON.xbm, using `find-image'."
!   (let* ((fg (face-attribute 'tool-bar :foreground))
   	 (bg (face-attribute 'tool-bar :background))
   	 (colors (nconc (if (eq fg 'unspecified) nil (list :foreground fg))
   			(if (eq bg 'unspecified) nil (list :background bg))))
! 	 (xpm-spec (list :type 'xpm :file (concat icon ".xpm")))
   	 (xpm-lo-spec (if (> (display-color-cells) 256)
   			  nil
   			(list :type 'xpm :file
!                               (concat "low-color/" icon ".xpm"))))
   	 (pbm-spec (append (list :type 'pbm :file
!                                  (concat icon ".pbm")) colors))
   	 (xbm-spec (append (list :type 'xbm :file
!                                  (concat icon ".xbm")) colors))
   	 (image (find-image
   		(if (display-color-p)
   		    (list xpm-lo-spec xpm-spec pbm-spec xbm-spec)
   		  (list pbm-spec xbm-spec xpm-lo-spec xpm-spec)))))
-
       (when (and (display-images-p) image)
         (unless (image-mask-p image)
   	(setq image (append image '(:mask heuristic))))
         (define-key-after map (vector key)
! 	`(menu-item ,(symbol-name key) ,def :image ,image ,@props)))))

   ;;;###autoload
   (defun tool-bar-add-item-from-menu (command icon &optional map  
&rest props)
     "Define tool bar binding for COMMAND in keymap MAP using the  
given ICON.
! This makes a binding for COMMAND in `tool-bar-map', copying its
! binding from the menu bar in MAP (which defaults to `global-map'), but
! modifies the binding by adding an image specification for ICON.  It
! finds ICON just like `tool-bar-add-item'.  PROPS are additional
! properties to add to the binding.

   MAP must contain appropriate binding for `[menu-bar]' which holds a  
keymap.

--- 110,165 ----
   ;;;###autoload
   (defun tool-bar-local-item (icon def key map &rest props)
     "Add an item to the tool bar in map MAP.
! ICON names the image, or is structure of the form (IMG . LABEL),
! with the image name IMG, and a string with the label of the icon
! displayed in the tool-bar as LABEL. LABEL defaults to the symbol
! name of KEY.  DEF is the key definition and KEY is a symbol for
! the fake function key in the menu keymap Remaining arguments
! PROPS are additional items to add to the menu item specification.
! See Info node `(elisp)Tool Bar'. Items are added from left to
! right.
!
! ICON or IMG is the base name of a file containing the image to
! use. The function will first try to use low-color/ICON.xpm if
! display-color-cells is less or equal to 256, then ICON.xpm, then
! ICON.pbm, and finally ICON.xbm, using `find-image'."
!   (let* ((icon-name (if (consp icon) (car icon) icon))
! 	 (label (if (consp icon) (cdr icon) (symbol-name key)))
! 	 (fg (face-attribute 'tool-bar :foreground))
   	 (bg (face-attribute 'tool-bar :background))
   	 (colors (nconc (if (eq fg 'unspecified) nil (list :foreground fg))
   			(if (eq bg 'unspecified) nil (list :background bg))))
! 	 (xpm-spec (list :type 'xpm :file (concat icon-name ".xpm")))
   	 (xpm-lo-spec (if (> (display-color-cells) 256)
   			  nil
   			(list :type 'xpm :file
!                               (concat "low-color/" icon-name  
".xpm"))))
   	 (pbm-spec (append (list :type 'pbm :file
!                                  (concat icon-name ".pbm")) colors))
   	 (xbm-spec (append (list :type 'xbm :file
!                                  (concat icon-name ".xbm")) colors))
   	 (image (find-image
   		(if (display-color-p)
   		    (list xpm-lo-spec xpm-spec pbm-spec xbm-spec)
   		  (list pbm-spec xbm-spec xpm-lo-spec xpm-spec)))))
       (when (and (display-images-p) image)
         (unless (image-mask-p image)
   	(setq image (append image '(:mask heuristic))))
         (define-key-after map (vector key)
! 	`(menu-item ,label ,def :image ,image ,@props)))))

   ;;;###autoload
   (defun tool-bar-add-item-from-menu (command icon &optional map  
&rest props)
     "Define tool bar binding for COMMAND in keymap MAP using the  
given ICON.
! ICON names the image, or is structure of the form (IMG . LABEL),
! with the image name IMG, and a string with the label of the icon
! displyed in the tool-bar as LABEL. LABEL defaults to the string
! defined for the menu item.  This function creates a binding for
! COMMAND in `tool-bar-map', copying its binding from the menu bar
! in MAP (which defaults to `global-map'), but modifies the binding
! by adding an image specification for ICON. It finds ICON just
! like `tool-bar-add-item'. PROPS are additional properties to add
! to the binding.

   MAP must contain appropriate binding for `[menu-bar]' which holds a  
keymap.

***************
*** 162,192 ****
   ;;;###autoload
   (defun tool-bar-local-item-from-menu (command icon in-map &optional  
from-map &rest props)
     "Define local tool bar binding for COMMAND using the given ICON.
! This makes a binding for COMMAND in IN-MAP, copying its binding from
! the menu bar in FROM-MAP (which defaults to `global-map'), but
! modifies the binding by adding an image specification for ICON.  It
! finds ICON just like `tool-bar-add-item'.  PROPS are additional
   properties to add to the binding.

   FROM-MAP must contain appropriate binding for `[menu-bar]' which
   holds a keymap."
     (unless from-map
       (setq from-map global-map))
!   (let* ((menu-bar-map (lookup-key from-map [menu-bar]))
   	 (keys (where-is-internal command menu-bar-map))
   	 (fg (face-attribute 'tool-bar :foreground))
   	 (bg (face-attribute 'tool-bar :background))
   	 (colors (nconc (if (eq fg 'unspecified) nil (list :foreground fg))
   			(if (eq bg 'unspecified) nil (list :background bg))))
! 	 (xpm-spec (list :type 'xpm :file (concat icon ".xpm")))
   	 (xpm-lo-spec (if (> (display-color-cells) 256)
   			  nil
   			(list :type 'xpm :file
!                               (concat "low-color/" icon ".xpm"))))
   	 (pbm-spec (append (list :type 'pbm :file
!                                  (concat icon ".pbm")) colors))
   	 (xbm-spec (append (list :type 'xbm :file
!                                  (concat icon ".xbm")) colors))
   	 (spec (if (display-color-p)
   		   (list xpm-lo-spec xpm-spec pbm-spec xbm-spec)
   		 (list pbm-spec xbm-spec xpm-lo-spec xpm-spec)))
--- 171,206 ----
   ;;;###autoload
   (defun tool-bar-local-item-from-menu (command icon in-map &optional  
from-map &rest props)
     "Define local tool bar binding for COMMAND using the given ICON.
! ICON names the image, or is structure of the form (IMG . LABEL),
! with the image name IMG, and a string with the label of the icon
! displyed in the tool-bar as LABEL. This function creates a
! binding for COMMAND in IN-MAP, copying its binding from the menu
! bar in FROM-MAP (which defaults to `global-map'), but modifies
! the binding by adding an image specification for ICON. It finds
! ICON just like `tool-bar-add-item'. PROPS are additional
   properties to add to the binding.

   FROM-MAP must contain appropriate binding for `[menu-bar]' which
   holds a keymap."
     (unless from-map
       (setq from-map global-map))
!   (let* ((icon-name (if (consp icon) (car icon) icon))
! 	 (label (if (consp icon) (cdr icon)))
! 	 (menu-bar-map (lookup-key from-map [menu-bar]))
   	 (keys (where-is-internal command menu-bar-map))
   	 (fg (face-attribute 'tool-bar :foreground))
   	 (bg (face-attribute 'tool-bar :background))
   	 (colors (nconc (if (eq fg 'unspecified) nil (list :foreground fg))
   			(if (eq bg 'unspecified) nil (list :background bg))))
! 	 (xpm-spec (list :type 'xpm :file (concat icon-name ".xpm")))
   	 (xpm-lo-spec (if (> (display-color-cells) 256)
   			  nil
   			(list :type 'xpm :file
!                               (concat "low-color/" icon-name  
".xpm"))))
   	 (pbm-spec (append (list :type 'pbm :file
!                                  (concat icon-name ".pbm")) colors))
   	 (xbm-spec (append (list :type 'xbm :file
!                                  (concat icon-name ".xbm")) colors))
   	 (spec (if (display-color-p)
   		   (list xpm-lo-spec xpm-spec pbm-spec xbm-spec)
   		 (list pbm-spec xbm-spec xpm-lo-spec xpm-spec)))
***************
*** 215,221 ****
         (let ((defn (assq key (cdr submap))))
   	(if (eq (cadr defn) 'menu-item)
   	    (define-key-after in-map (vector key)
! 	      (append (cdr defn) (list :image image) props))
   	  (setq defn (cdr defn))
   	  (define-key-after in-map (vector key)
   	    (let ((rest (cdr defn)))
--- 229,236 ----
         (let ((defn (assq key (cdr submap))))
   	(if (eq (cadr defn) 'menu-item)
   	    (define-key-after in-map (vector key)
! 	      (append `(menu-item ,(or label (car (cdr defn)))) (cdddr defn)
! 		      (list :image image) props))
   	  (setq defn (cdr defn))
   	  (define-key-after in-map (vector key)
   	    (let ((rest (cdr defn)))
***************
*** 223,229 ****
   	      ;; with a list of menu cache info, get rid of that.
   	      (if (and (consp rest) (consp (car rest)))
   		  (setq rest (cdr rest)))
! 	      (append `(menu-item ,(car defn) ,rest)
   		      (list :image image) props))))))))

   ;;; Set up some global items.  Additions/deletions up for grabs.
--- 238,244 ----
   	      ;; with a list of menu cache info, get rid of that.
   	      (if (and (consp rest) (consp (car rest)))
   		  (setq rest (cdr rest)))
! 	      (append `(menu-item ,(or label (car defn)) ,rest)
   		      (list :image image) props))))))))

   ;;; Set up some global items.  Additions/deletions up for grabs.
***************
*** 232,247 ****
     ;; People say it's bad to have EXIT on the tool bar, since users
     ;; might inadvertently click that button.
     ;;(tool-bar-add-item-from-menu 'save-buffers-kill-emacs "exit")
!   (tool-bar-add-item-from-menu 'find-file "new")
!   (tool-bar-add-item-from-menu 'menu-find-file-existing "open")
!   (tool-bar-add-item-from-menu 'dired "diropen")
     (tool-bar-add-item-from-menu 'kill-this-buffer "close")
!   (tool-bar-add-item-from-menu 'save-buffer "save" nil
   			       :visible '(or buffer-file-name
   					     (not (eq 'special
   						      (get major-mode
   							   'mode-class)))))
!   (tool-bar-add-item-from-menu 'write-file "saveas" nil
   			       :visible '(or buffer-file-name
   					     (not (eq 'special
   						      (get major-mode
--- 247,262 ----
     ;; People say it's bad to have EXIT on the tool bar, since users
     ;; might inadvertently click that button.
     ;;(tool-bar-add-item-from-menu 'save-buffers-kill-emacs "exit")
!   (tool-bar-add-item-from-menu 'find-file '("new" . "New"))
!   (tool-bar-add-item-from-menu 'menu-find-file-existing '("open" .  
"Open"))
!   (tool-bar-add-item-from-menu 'dired '("diropen" . "Directory"))
     (tool-bar-add-item-from-menu 'kill-this-buffer "close")
!   (tool-bar-add-item-from-menu 'save-buffer '("save" . "Save") nil
   			       :visible '(or buffer-file-name
   					     (not (eq 'special
   						      (get major-mode
   							   'mode-class)))))
!   (tool-bar-add-item-from-menu 'write-file '("saveas" . "Save As") nil
   			       :visible '(or buffer-file-name
   					     (not (eq 'special
   						      (get major-mode
***************
*** 273,282 ****
     ;; we must explicitly operate on the default value.

     (let ((tool-bar-map (default-value 'tool-bar-map)))
!     (tool-bar-add-item "preferences" 'customize 'customize
   		       :help "Edit preferences (customize)")

!     (tool-bar-add-item "help" (lambda ()
   				(interactive)
   				(popup-menu menu-bar-help-menu))
   		       'help
--- 288,297 ----
     ;; we must explicitly operate on the default value.

     (let ((tool-bar-map (default-value 'tool-bar-map)))
!     (tool-bar-add-item '("preferences" . "Customize") 'customize  
'customize
   		       :help "Edit preferences (customize)")

!     (tool-bar-add-item '("help" . "Help") (lambda ()
   				(interactive)
   				(popup-menu menu-bar-help-menu))
   		       'help





  reply	other threads:[~2008-04-05 11:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-05  7:50 tool-bar (Carbon port): labels under icons David Reitter
2008-04-05  8:10 ` Jan Djärv
2008-04-05  8:42   ` YAMAMOTO Mitsuharu
2008-04-05  8:40 ` YAMAMOTO Mitsuharu
2008-04-05 11:48   ` David Reitter [this message]
2008-04-05 12:33     ` YAMAMOTO Mitsuharu
2008-04-05 13:36       ` David Reitter
2008-04-05 15:40 ` Stefan Monnier
2008-04-05 22:27   ` David Reitter
2008-04-06  1:53     ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=488FE8E4-8EF1-4025-91BB-CDAD87B365B2@inf.ed.ac.uk \
    --to=dreitter@inf.ed.ac.uk \
    --cc=emacs-devel@gnu.org \
    --cc=mituharu@math.s.chiba-u.ac.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).