* riece-toolbar.el: New add-on.
[riece] / lisp / riece-toolbar.el
1 ;;; riece-toolbar.el --- show icons on toolbar
2 ;; Copyright (C) 1998-2004 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece
7
8 ;; This file is part of Riece.
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; NOTE: This add-on doesn't support XEmacs yet.
28
29 ;; To use, add the following line to your ~/.riece/init.el:
30 ;; (add-to-list 'riece-addons 'riece-toolbar)
31
32 ;;; Code:
33
34 (require 'riece-menu)
35
36 (defvar riece-toolbar-item-list
37   '((riece-command-quit "riece-command-quit")
38     (riece-command-join "riece-command-join")
39     (riece-command-part "riece-command-part")
40     (riece-command-next-channel "riece-command-next-channel")
41     (riece-command-previous-channel "riece-command-previous-channel")
42     (riece-command-change-window-layout "riece-command-change-window-layout")))
43
44 (if (fboundp 'tool-bar-local-item-from-menu)
45     (defalias 'riece-tool-bar-local-item-from-menu
46       'tool-bar-local-item-from-menu)
47   (if (fboundp 'tool-bar-add-item-from-menu)
48       (defun riece-tool-bar-local-item-from-menu (command icon in-map
49                                                           &optional from-map
50                                                           &rest props)
51         "Define tool bar binding for COMMAND using the given ICON in \
52 keymap IN-MAP."
53         (let ((tool-bar-map in-map))
54           (apply #'tool-bar-add-item-from-menu command icon from-map props)))
55     (defalias 'riece-tool-bar-local-item-from-menu 'ignore)))
56
57 (defvar riece-command-mode-map)
58 (defun riece-toolbar-insinuate-in-command-buffer ()
59   (when (boundp 'tool-bar-map)
60     (make-local-variable 'tool-bar-map)
61     (setq tool-bar-map
62           (let ((map (make-sparse-keymap))
63                 (pointer riece-toolbar-item-list))
64             (while pointer
65               (riece-tool-bar-local-item-from-menu (car (car pointer))
66                                                    (nth 1 (car pointer))
67                                                    map riece-command-mode-map)
68               (setq pointer (cdr pointer)))
69             map))))
70
71 (defun riece-toolbar-requires ()
72   '(riece-menu))
73
74 (defun riece-toolbar-insinuate ()
75   (add-hook 'riece-command-mode-hook
76             (lambda ()
77               (riece-toolbar-insinuate-in-command-buffer))
78             t))
79
80 (provide 'riece-toolbar)
81
82 ;;; riece-toolbar.el ends here