emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tool-bar (Carbon port): labels under icons


From: David Reitter
Subject: Re: tool-bar (Carbon port): labels under icons
Date: Sat, 5 Apr 2008 12:48:20 +0100

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 via email to

[Prev in Thread] Current Thread [Next in Thread]