changeset 111998:bc8dc4ac1e28

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.
author Chong Yidong <cyd@stupidchicken.com>
date Mon, 20 Dec 2010 08:17:26 +0800
parents a5a188ddc758
children 1c6bd016193a
files etc/ChangeLog etc/NEWS etc/images/separator.xpm lisp/ChangeLog lisp/info.el lisp/tool-bar.el src/ChangeLog src/keyboard.c src/xdisp.c
diffstat 9 files changed, 87 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/etc/ChangeLog	Sun Dec 19 00:43:42 2010 -0500
+++ b/etc/ChangeLog	Mon Dec 20 08:17:26 2010 +0800
@@ -1,3 +1,7 @@
+2010-12-18  Chong Yidong  <cyd@stupidchicken.com>
+
+	* images/separator.xpm: Tweak colors.
+
 2010-12-14  Michael Albinus  <michael.albinus@gmx.de>
 
 	* NEWS: Mention new Tramp method "ksu".
--- a/etc/NEWS	Sun Dec 19 00:43:42 2010 -0500
+++ b/etc/NEWS	Mon Dec 20 08:17:26 2010 +0800
@@ -692,9 +692,7 @@
 
 ** 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
 
--- a/etc/images/separator.xpm	Sun Dec 19 00:43:42 2010 -0500
+++ b/etc/images/separator.xpm	Mon Dec 20 08:17:26 2010 +0800
@@ -2,11 +2,12 @@
 static char * separator_xpm[] = {
 "2 24 3 1",
 " 	c None",
-".	c #DBD3CB",
-"+	c #FCFBFA",
+".	c #888888",
+"+	c #FFFFFF",
 "  ",
 "  ",
-"  ",
+".+ ",
+".+",
 ".+",
 ".+",
 ".+",
@@ -26,5 +27,4 @@
 ".+",
 ".+",
 "  ",
-"  ",
 "  "};
--- a/lisp/ChangeLog	Sun Dec 19 00:43:42 2010 -0500
+++ b/lisp/ChangeLog	Mon Dec 20 08:17:26 2010 +0800
@@ -1,3 +1,17 @@
+2010-12-20  Chong Yidong  <cyd@stupidchicken.com>
+
+	* 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  <kbrown@cornell.edu>
 
 	* loadup.el: Use version numbers in Cygwin build.
--- a/lisp/info.el	Sun Dec 19 00:43:42 2010 -0500
+++ b/lisp/info.el	Mon Dec 20 08:17:26 2010 +0800
@@ -3769,14 +3769,17 @@
 				   :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)
--- a/lisp/tool-bar.el	Sun Dec 19 00:43:42 2010 -0500
+++ b/lisp/tool-bar.el	Mon Dec 20 08:17:26 2010 +0800
@@ -139,6 +139,26 @@
 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 @@
 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 @@
     (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 @@
 ;;; 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"
--- a/src/ChangeLog	Sun Dec 19 00:43:42 2010 -0500
+++ b/src/ChangeLog	Mon Dec 20 08:17:26 2010 +0800
@@ -1,3 +1,12 @@
+2010-12-20  Chong Yidong  <cyd@stupidchicken.com>
+
+	* 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  <monnier@iro.umontreal.ca>
 
 	Minor clean up to silence some gcc warnings.
--- a/src/keyboard.c	Sun Dec 19 00:43:42 2010 -0500
+++ b/src/keyboard.c	Mon Dec 20 08:17:26 2010 +0800
@@ -212,6 +212,12 @@
 /* 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 @@
       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 @@
 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.
--- a/src/xdisp.c	Sun Dec 19 00:43:42 2010 -0500
+++ b/src/xdisp.c	Mon Dec 20 08:17:26 2010 +0800
@@ -10317,10 +10317,6 @@
       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 @@
 	      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 @@
   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