* riece-menu.el (riece-menu-items): Add "Next Channel" and
[riece] / lisp / riece-toolbar.el
1 ;;; riece-toolbar.el --- show toolbar icons
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 ;; To use, add the following line to your ~/.riece/init.el:
28 ;; (add-to-list 'riece-addons 'riece-toolbar)
29
30 ;;; Code:
31
32 (require 'riece-menu)
33
34 (defvar riece-toolbar-items
35   '(riece-command-quit
36     riece-command-join
37     riece-command-part))
38
39 (defun riece-toolbar-find-menu-item (command)
40   (let ((pointer riece-menu-items)
41         item)
42     (while pointer
43       (if (and (not (stringp (car pointer)))
44                (vectorp (car pointer))
45                (eq (aref (car pointer) 1) command))
46           (setq item (car pointer)
47                 pointer nil)
48         (setq pointer (cdr pointer))))
49     item))
50
51 (if (featurep 'xemacs)
52     (progn
53       (defun riece-make-toolbar-from-menu (items menu-items map)
54         (let ((pointer items)
55               toolbar
56               file
57               menu-item)
58           (while pointer
59             (setq file (locate-file (symbol-name (car pointer))
60                                     load-path
61                                     '(".xpm" ".pbm" ".xbm"))
62                   menu-item (riece-toolbar-find-menu-item (car pointer)))
63             (if (and file (file-exists-p file))
64                 (setq toolbar
65                       (toolbar-add-item
66                        toolbar
67                        (toolbar-new-button
68                         file
69                         (car pointer)
70                         (if menu-item
71                             (aref menu-item 0)
72                           (symbol-name (car pointer)))))))
73             (setq pointer (cdr pointer)))
74           toolbar))
75       (defun riece-set-toolbar (toolbar)
76         (set-specifier default-toolbar toolbar (current-buffer))))
77   (defun riece-make-toolbar-from-menu (items menu-items map)
78     (let ((pointer items)
79           (tool-bar-map (make-sparse-keymap)))
80       (while pointer
81         (tool-bar-add-item-from-menu (car pointer)
82                                      (symbol-name (car pointer))
83                                      map)
84         (setq pointer (cdr pointer)))
85       tool-bar-map))
86   (defun riece-set-toolbar (toolbar)
87     (make-local-variable 'tool-bar-map)
88     (setq tool-bar-map toolbar)))
89
90 (defvar riece-command-mode-map)
91 (defun riece-toolbar-insinuate-in-command-buffer ()
92   (riece-set-toolbar
93    (riece-make-toolbar-from-menu
94     riece-toolbar-items
95     riece-menu-items
96     riece-command-mode-map)))
97
98 (defun riece-toolbar-requires ()
99   '(riece-menu))
100
101 (defun riece-toolbar-insinuate ()
102   (add-hook 'riece-command-mode-hook
103             'riece-toolbar-insinuate-in-command-buffer
104             t))
105
106 (provide 'riece-toolbar)
107
108 ;;; riece-toolbar.el ends here