(completion-ignored-extensions) [ms-dos, windows-nt]:
[bpt/emacs.git] / lisp / toolbar / tool-bar.el
index 64fcf09..c4e548e 100644 (file)
@@ -1,6 +1,6 @@
-;;; tool-bar.el --- Setting up the tool bar
+;;; tool-bar.el --- setting up the tool bar
 ;;
-;; Copyright (C) 2000 Free Software Foundation, Inc.
+;; Copyright (C) 2000, 2001 Free Software Foundation, Inc.
 ;;
 ;; Author: Dave Love <fx@gnu.org>
 ;; Keywords: mouse frames
@@ -50,21 +50,22 @@ conveniently adding tool bar items."
   :global t
   :group 'mouse
   :group 'frames
-  (let ((lines (if tool-bar-mode 1 0)))
-    ;; Alter existing frames...
-    (mapc (lambda (frame)
-           (modify-frame-parameters frame
-                                    (list (cons 'tool-bar-lines lines))))
-         (frame-list))
-    ;; ...and future ones.
-    (let ((elt (assq 'tool-bar-lines default-frame-alist)))
-      (if elt
-         (setcdr elt lines)
-       (add-to-list 'default-frame-alist (cons 'tool-bar-lines lines)))))
-  (if (and tool-bar-mode
-          (display-graphic-p)
-          (= 1 (length (default-value 'tool-bar-map)))) ; not yet setup
-      (tool-bar-setup)))
+  (and (display-images-p)
+       (let ((lines (if tool-bar-mode 1 0)))
+        ;; Alter existing frames...
+        (mapc (lambda (frame)
+                (modify-frame-parameters frame
+                                         (list (cons 'tool-bar-lines lines))))
+              (frame-list))
+        ;; ...and future ones.
+        (let ((elt (assq 'tool-bar-lines default-frame-alist)))
+          (if elt
+              (setcdr elt lines)
+            (add-to-list 'default-frame-alist (cons 'tool-bar-lines lines)))))
+       (if (and tool-bar-mode
+               (display-graphic-p)
+               (= 1 (length (default-value 'tool-bar-map)))) ; not yet setup
+          (tool-bar-setup))))
 
 (defvar tool-bar-map (make-sparse-keymap)
   "Keymap for the tool bar.
@@ -105,7 +106,7 @@ function."
                        (append (list :type 'xbm :file (concat icon ".xbm"))
                                colors)
                        (list :type 'xpm :file (concat icon ".xpm")))))))
-    (when image
+    (when (and (display-images-p) image)
       (unless (image-mask-p image)
        (setq image (append image '(:mask heuristic))))
       (define-key-after tool-bar-map (vector key)
@@ -144,7 +145,7 @@ function."
                       (list :type 'xpm :file (concat icon ".xpm")))))
         (image (find-image spec))
         submap key)
-    (when image
+    (when (and (display-images-p) image)
       ;; We'll pick up the last valid entry in the list of keys if
       ;; there's more than one.
       (dolist (k keys)
@@ -164,22 +165,34 @@ function."
        (setq submap (eval submap)))
       (unless (image-mask-p image)
        (setq image (append image '(:mask heuristic))))
-      (define-key-after tool-bar-map (vector key)
-       (append (cdr (assq key (cdr submap))) (list :image image) props)))))
+      (let ((defn (assq key (cdr submap))))
+       (if (eq (cadr defn) 'menu-item)
+           (define-key-after tool-bar-map (vector key)
+             (append (cdr defn) (list :image image) props))
+         (setq defn (cdr defn))
+         (define-key-after tool-bar-map (vector key)
+           (append `(menu-item ,(car defn) ,(cddr defn))
+                   (list :image image) props)))))))
 
 ;;; Set up some global items.  Additions/deletions up for grabs.
 
 (defun tool-bar-setup ()
-  (tool-bar-add-item-from-menu 'save-buffers-kill-emacs "exit")
+  ;; 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 'dired "open")
   (tool-bar-add-item-from-menu 'kill-this-buffer "close")
   (tool-bar-add-item-from-menu 'save-buffer "save" nil
-                              :visible '(not (eq 'special (get major-mode
-                                                               'mode-class))))
+                              :visible '(or buffer-file-name
+                                            (not (eq 'special
+                                                     (get major-mode
+                                                          'mode-class)))))
   (tool-bar-add-item-from-menu 'write-file "saveas" nil
-                              :visible '(not (eq 'special (get major-mode
-                                                               'mode-class))))
+                              :visible '(or buffer-file-name
+                                            (not (eq 'special
+                                                     (get major-mode
+                                                          'mode-class)))))
   (tool-bar-add-item-from-menu 'undo "undo" nil
                               :visible '(not (eq 'special (get major-mode
                                                                'mode-class))))