From: Chong Yidong Date: Mon, 20 Dec 2010 00:17:26 +0000 (+0800) Subject: Implement tool-bar separators for non-GTK tool-bars. X-Git-Tag: emacs-pretest-24.0.90~104^2~618^2~1322^2~278^2~83 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=949752705efd6a4b7478623d41b3552f93e9596c;p=emacs.git Implement tool-bar separators for non-GTK tool-bars. * lisp/tool-bar.el (tool-bar--image-expression): New function. (tool-bar-local-item, tool-bar--image-exp): Use it. (tool-bar-setup): Initialize tool-bar-separator-image-expression. Use :enable instead of :visible to avoid changing the tool-bar configuration unnecessarily. * src/keyboard.c (Vtool_bar_separator_image_expression): New variable. (parse_tool_bar_item): Use it to obtain image separators for displays not using native tool-bar separators. * src/xdisp.c (build_desired_tool_bar_string): Don't handle separators specially, since this is now done in parse_tool_bar_item. * lisp/info.el (info-tool-bar-map): Add separators. --- diff --git a/etc/ChangeLog b/etc/ChangeLog index 87236dc4eb2..ebd613ddfe8 100644 --- a/etc/ChangeLog +++ b/etc/ChangeLog @@ -1,3 +1,7 @@ +2010-12-18 Chong Yidong + + * images/separator.xpm: Tweak colors. + 2010-12-14 Michael Albinus * NEWS: Mention new Tramp method "ksu". diff --git a/etc/NEWS b/etc/NEWS index 1ec8325c2a3..89d6139dc0e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -692,9 +692,7 @@ input. ** Tool-bars can display separators. Tool-bar separators are handled like menu separators in menu-bar maps, -i.e. with entries of the form `(menu-item "--")'. - -Currently, tool-bar separators are only displayed on GTK. +i.e. via menu entries of the form `(menu-item "--")'. ** Image API diff --git a/etc/images/separator.xpm b/etc/images/separator.xpm index 0c518fa7599..b728316a8f8 100644 --- a/etc/images/separator.xpm +++ b/etc/images/separator.xpm @@ -2,11 +2,12 @@ static char * separator_xpm[] = { "2 24 3 1", " c None", -". c #DBD3CB", -"+ c #FCFBFA", -" ", +". c #888888", +"+ c #FFFFFF", " ", " ", +".+ ", +".+", ".+", ".+", ".+", @@ -25,6 +26,5 @@ static char * separator_xpm[] = { ".+", ".+", ".+", -" ", " ", " "}; diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 4ed1a75cda2..0c363ab7a03 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,17 @@ +2010-12-20 Chong Yidong + + * vc/diff.el (diff-better-file-name): Function deleted; + abbreviating file name creates problems with shell-quote-argument. + (diff-no-select): Just use expand-file-name. + + * tool-bar.el (tool-bar--image-expression): New function. + (tool-bar-local-item, tool-bar--image-exp): Use it. + (tool-bar-setup): Initialize tool-bar-separator-image-expression. + Use :enable instead of :visible to avoid changing the tool-bar + configuration unnecessarily. + + * info.el (info-tool-bar-map): Add separators. + 2010-12-17 Ken Brown * loadup.el: Use version numbers in Cygwin build. diff --git a/lisp/info.el b/lisp/info.el index 7c0333f6b8e..ad92914a54d 100644 --- a/lisp/info.el +++ b/lisp/info.el @@ -3769,14 +3769,17 @@ If FORK is non-nil, it is passed to `Info-goto-node'." :rtl "left-arrow" :label "Forward" :vert-only t) + (define-key-after map [separator-1] menu-bar-separator) (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map :rtl "next-node") (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map :rtl "prev-node") (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map :vert-only t) + (define-key-after map [separator-2] menu-bar-separator) (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map) (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map) + (define-key-after map [separator-3] menu-bar-separator) (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map :label "Index Search") (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map) diff --git a/lisp/tool-bar.el b/lisp/tool-bar.el index 7c7216ed7d3..e819cbe99a8 100644 --- a/lisp/tool-bar.el +++ b/lisp/tool-bar.el @@ -139,6 +139,26 @@ Use this function only to make bindings in the global value of `tool-bar-map'. To define items in any other map, use `tool-bar-local-item'." (apply 'tool-bar-local-item icon def key tool-bar-map props)) +(defun tool-bar--image-expression (icon) + "Return an expression that evaluates to an image spec for ICON." + (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 (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))) + `(find-image (cond ((not (display-color-p)) + ',(list pbm-spec xbm-spec xpm-lo-spec xpm-spec)) + ((< (display-color-cells) 256) + ',(list xpm-lo-spec xpm-spec pbm-spec xbm-spec)) + (t + ',(list xpm-spec pbm-spec xbm-spec)))))) + ;;;###autoload (defun tool-bar-local-item (icon def key map &rest props) "Add an item to the tool bar in map MAP. @@ -151,24 +171,7 @@ 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 (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-exp `(find-image - (cond ((not (display-color-p)) - ',(list pbm-spec xbm-spec xpm-lo-spec xpm-spec)) - ((< (display-color-cells) 256) - ',(list xpm-lo-spec xpm-spec pbm-spec xbm-spec)) - (t - ',(list xpm-spec pbm-spec xbm-spec)))))) + (let* ((image-exp (tool-bar--image-expression icon))) (define-key-after map (vector key) `(menu-item ,(symbol-name key) ,def :image ,image-exp ,@props)))) @@ -203,24 +206,7 @@ holds a keymap." (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 (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-exp `(find-image - (cond ((not (display-color-p)) - ',(list pbm-spec xbm-spec xpm-lo-spec xpm-spec)) - ((< (display-color-cells) 256) - ',(list xpm-lo-spec xpm-spec pbm-spec xbm-spec)) - (t - ',(list xpm-spec pbm-spec xbm-spec))))) + (image-exp (tool-bar--image-expression icon)) submap key) ;; We'll pick up the last valid entry in the list of keys if ;; there's more than one. @@ -257,32 +243,34 @@ holds a keymap." ;;; Set up some global items. Additions/deletions up for grabs. (defun tool-bar-setup () + (setq tool-bar-separator-image-expression + (tool-bar--image-expression "separator")) (tool-bar-add-item-from-menu 'find-file "new" nil :label "New File" :vert-only t) (tool-bar-add-item-from-menu 'menu-find-file-existing "open" nil :label "Open" :vert-only t) (tool-bar-add-item-from-menu 'dired "diropen" nil :vert-only t) (tool-bar-add-item-from-menu 'kill-this-buffer "close" nil :vert-only t) - (tool-bar-add-item-from-menu 'save-buffer "save" nil :vert-only t + (tool-bar-add-item-from-menu 'save-buffer "save" nil :label "Save" - :visible '(or buffer-file-name + :enable '(or buffer-file-name (not (eq 'special (get major-mode 'mode-class))))) (define-key-after (default-value 'tool-bar-map) [separator-1] menu-bar-separator) (tool-bar-add-item-from-menu 'undo "undo" nil :vert-only t - :visible '(not (eq 'special (get major-mode + :enable '(not (eq 'special (get major-mode 'mode-class)))) (define-key-after (default-value 'tool-bar-map) [separator-2] menu-bar-separator) (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [cut]) "cut" nil :vert-only t - :visible '(not (eq 'special (get major-mode + :enable '(not (eq 'special (get major-mode 'mode-class)))) (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [copy]) "copy" nil :vert-only t) (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [paste]) "paste" nil :vert-only t - :visible '(not (eq 'special (get major-mode + :enable '(not (eq 'special (get major-mode 'mode-class)))) (define-key-after (default-value 'tool-bar-map) [separator-3] menu-bar-separator) (tool-bar-add-item-from-menu 'nonincremental-search-forward "search" diff --git a/src/ChangeLog b/src/ChangeLog index 4313c68f593..a6ee107422c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2010-12-20 Chong Yidong + + * keyboard.c (Vtool_bar_separator_image_expression): New variable. + (parse_tool_bar_item): Use it to obtain image separators for + displays not using native tool-bar separators. + + * xdisp.c (build_desired_tool_bar_string): Don't handle separators + specially, since this is now done in parse_tool_bar_item. + 2010-12-19 Stefan Monnier Minor clean up to silence some gcc warnings. diff --git a/src/keyboard.c b/src/keyboard.c index 959c57a81e3..27c311d72e2 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -212,6 +212,12 @@ Lisp_Object Vprefix_help_command; /* List of items that should move to the end of the menu bar. */ Lisp_Object Vmenu_bar_final_items; +/* Expression to evaluate for the tool bar separator image. + This is used for build_desired_tool_bar_string only. For GTK, we + use GTK tool bar seperators. */ + +Lisp_Object Vtool_bar_separator_image_expression; + /* Non-nil means show the equivalent key-binding for any M-x command that has one. The value can be a length of time to show the message for. @@ -8294,6 +8300,15 @@ parse_tool_bar_item (Lisp_Object key, Lisp_Object item) if (menu_separator_name_p (SDATA (caption))) { PROP (TOOL_BAR_ITEM_TYPE) = Qt; +#if !defined (USE_GTK) && !defined (HAVE_NS) + /* If we use build_desired_tool_bar_string to render the + tool bar, the separator is rendered as an image. */ + PROP (TOOL_BAR_ITEM_IMAGES) + = menu_item_eval_property (Vtool_bar_separator_image_expression); + PROP (TOOL_BAR_ITEM_ENABLED_P) = Qnil; + PROP (TOOL_BAR_ITEM_SELECTED_P) = Qnil; + PROP (TOOL_BAR_ITEM_CAPTION) = Qnil; +#endif return 1; } return 0; @@ -12151,6 +12166,12 @@ might happen repeatedly and make Emacs nonfunctional. */); The elements of the list are event types that may have menu bar bindings. */); Vmenu_bar_final_items = Qnil; + DEFVAR_LISP ("tool-bar-separator-image-expression", &Vtool_bar_separator_image_expression, + doc: /* Expression evaluating to the image spec for a tool-bar separator. +This is used internally by graphical displays that do not render +tool-bar separators natively. Otherwise it is unused (e.g. on GTK). */); + Vtool_bar_separator_image_expression = Qnil; + DEFVAR_KBOARD ("overriding-terminal-local-map", Voverriding_terminal_local_map, doc: /* Per-terminal keymap that overrides all other local keymaps. diff --git a/src/xdisp.c b/src/xdisp.c index 41204e0a5b4..7a299055185 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -10317,10 +10317,6 @@ build_desired_tool_bar_string (struct frame *f) int selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P)); int hmargin, vmargin, relief, idx, end; - /* Ignore separator items. */ - if (EQ (PROP (TOOL_BAR_ITEM_TYPE), Qt)) - continue; - /* If image is a vector, choose the image according to the button state. */ image = PROP (TOOL_BAR_ITEM_IMAGES); @@ -10495,7 +10491,7 @@ display_tool_bar_line (struct it *it, int height) row->used[TEXT_AREA] = n_glyphs_before; *it = it_before; /* If this is the only glyph on this line, it will never fit on the - toolbar, so skip it. But ensure there is at least one glyph, + tool-bar, so skip it. But ensure there is at least one glyph, so we don't accidentally disable the tool-bar. */ if (n_glyphs_before == 0 && (it->vpos > 0 || IT_STRING_CHARPOS (*it) < it->end_charpos-1)) @@ -26885,7 +26881,7 @@ vertical margin. */); tool_bar_button_relief = DEFAULT_TOOL_BAR_BUTTON_RELIEF; DEFVAR_LISP ("tool-bar-style", &Vtool_bar_style, - doc: /* *Tool bar style to use. + doc: /* Tool bar style to use. It can be one of image - show images only text - show text only