]> code.delx.au - gnu-emacs/blobdiff - lisp/tool-bar.el
Merge from emacs--devo--0
[gnu-emacs] / lisp / tool-bar.el
index 984dac92b12441635e0cb4888fcc018eed44892b..e3635f47fe70241ad237bea8e52e74cd24cc5591 100644 (file)
@@ -1,7 +1,7 @@
 ;;; tool-bar.el --- setting up the tool bar
 ;;
 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
-;;   2005 Free Software Foundation, Inc.
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 ;;
 ;; Author: Dave Love <fx@gnu.org>
 ;; Keywords: mouse frames
@@ -10,7 +10,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -41,7 +41,9 @@
 
 ;;; Code:
 
-;;;###autoload
+;; The autoload cookie doesn't work when preloading.
+;; Deleting it means invoking this command won't work
+;; when you are on a tty.  I hope that won't cause too much trouble -- rms.
 (define-minor-mode tool-bar-mode
   "Toggle use of the tool bar.
 With numeric ARG, display the tool bar if and only if ARG is positive.
@@ -53,22 +55,22 @@ conveniently adding tool bar items."
   :group 'mouse
   :group 'frames
   (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)))))
+       (modify-all-frames-parameters (list (cons 'tool-bar-lines
+                                                (if tool-bar-mode 1 0))))
        (if (and tool-bar-mode
-               (display-graphic-p)
-               (= 1 (length (default-value 'tool-bar-map)))) ; not yet setup
+               (display-graphic-p))
           (tool-bar-setup))))
 
+;;;###autoload
+;; Used in the Show/Hide menu, to have the toggle reflect the current frame.
+(defun toggle-tool-bar-mode-from-frame (&optional arg)
+  "Toggle tool bar on or off, based on the status of the current frame.
+See `tool-bar-mode' for more information."
+  (interactive (list (or current-prefix-arg 'toggle)))
+  (if (eq arg 'toggle)
+      (tool-bar-mode (if (> (frame-parameter nil 'tool-bar-lines) 0) 0 1))
+    (tool-bar-mode arg)))
+
 ;;;###autoload
 ;; We want to pretend the toolbar by standard is on, as this will make
 ;; customize consider disabling the toolbar a customization, and save
@@ -143,7 +145,7 @@ ICON.xbm, using `find-image'."
 
 ;;;###autoload
 (defun tool-bar-add-item-from-menu (command icon &optional map &rest props)
-  "Define tool bar binding for COMMAND using the given ICON in keymap MAP.
+  "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
@@ -153,20 +155,21 @@ properties to add to the binding.
 MAP must contain appropriate binding for `[menu-bar]' which holds a keymap.
 
 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'."
+To define items in any other map, use `tool-bar-local-item-from-menu'."
   (apply 'tool-bar-local-item-from-menu command icon
         (default-value 'tool-bar-map) map props))
 
 ;;;###autoload
 (defun tool-bar-local-item-from-menu (command icon in-map &optional from-map &rest props)
-  "Define tool bar binding for COMMAND using the given ICON in keymap MAP.
+  "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.
 
-MAP must contain appropriate binding for `[menu-bar]' which holds a keymap."
+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]))
@@ -225,56 +228,67 @@ MAP must contain appropriate binding for `[menu-bar]' which holds a keymap."
 
 ;;; Set up some global items.  Additions/deletions up for grabs.
 
-(defun tool-bar-setup ()
-  ;; 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 '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
-                                                          'mode-class)))))
-  (tool-bar-add-item-from-menu 'undo "undo" nil
-                              :visible '(not (eq 'special (get major-mode
-                                                               'mode-class))))
-  (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [cut])
-                              "cut" nil
-                              :visible '(not (eq 'special (get major-mode
-                                                               'mode-class))))
-  (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [copy])
-                              "copy")
-  (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [paste])
-                              "paste" nil
-                              :visible '(not (eq 'special (get major-mode
-                                                               'mode-class))))
-  (tool-bar-add-item-from-menu 'nonincremental-search-forward "search")
-  ;;(tool-bar-add-item-from-menu 'ispell-buffer "spell")
-
-  ;; There's no icon appropriate for News and we need a command rather
-  ;; than a lambda for Read Mail.
+(defvar tool-bar-setup nil
+  "t if the tool-bar has been set up by `tool-bar-setup'.")
+
+(defun tool-bar-setup (&optional frame)
+  (unless tool-bar-setup
+    (with-selected-frame (or frame (selected-frame))
+      ;; 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
+                                                              'mode-class)))))
+      (tool-bar-add-item-from-menu 'undo "undo" nil
+                                  :visible '(not (eq 'special (get major-mode
+                                                                   'mode-class))))
+      (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [cut])
+                                  "cut" nil
+                                  :visible '(not (eq 'special (get major-mode
+                                                                   'mode-class))))
+      (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [copy])
+                                  "copy")
+      (tool-bar-add-item-from-menu (lookup-key menu-bar-edit-menu [paste])
+                                  "paste" nil
+                                  :visible '(not (eq 'special (get major-mode
+                                                                   'mode-class))))
+      (tool-bar-add-item-from-menu 'nonincremental-search-forward "search")
+      ;;(tool-bar-add-item-from-menu 'ispell-buffer "spell")
+
+      ;; There's no icon appropriate for News and we need a command rather
+      ;; than a lambda for Read Mail.
   ;;(tool-bar-add-item-from-menu 'compose-mail "mail/compose")
 
   (tool-bar-add-item-from-menu 'print-buffer "print")
-  (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
-                    :help "Pop up the Help menu")
-  )
+  ;; tool-bar-add-item-from-menu itself operates on
+  ;; (default-value 'tool-bar-map), but when we don't use that function,
+  ;; we must explicitly operate on the default value.
 
-(provide 'tool-bar)
+  (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
+                      :help "Pop up the Help menu"))
+  (setq tool-bar-setup t))))
 
+
+(provide 'tool-bar)
 ;;; arch-tag: 15f30f0a-d0d7-4d50-bbb7-f48fd0c8582f
 ;;; tool-bar.el ends here