Riece is a full featured IRC client.
[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 (defconst riece-toolbar-description
35   "Show toolbar icons.")
36
37 (defvar riece-toolbar-items
38   '(riece-command-quit
39     riece-command-join
40     riece-command-part
41     riece-command-previous-channel
42     riece-command-next-channel
43     riece-command-change-layout
44     riece-submit-bug-report))
45
46 (defun riece-toolbar-find-menu-item (command)
47   (let ((pointer riece-menu-items)
48         item)
49     (while pointer
50       (if (and (not (stringp (car pointer)))
51                (vectorp (car pointer))
52                (eq (aref (car pointer) 1) command))
53           (setq item (car pointer)
54                 pointer nil)
55         (setq pointer (cdr pointer))))
56     item))
57
58 (if (featurep 'xemacs)
59     (if (featurep 'toolbar)
60         (progn
61           (defun riece-make-toolbar-from-menu (items menu-items map)
62             (let ((pointer items)
63                   toolbar
64                   file
65                   menu-item)
66               (while pointer
67                 (setq file (locate-file (symbol-name (car pointer))
68                                         load-path
69                                         '(".xpm" ".pbm" ".xbm"))
70                       menu-item (riece-toolbar-find-menu-item (car pointer)))
71                 (if (and file (file-exists-p file))
72                     (setq toolbar
73                           (toolbar-add-item
74                            toolbar
75                            (toolbar-new-button
76                             file
77                             (car pointer)
78                             (if menu-item
79                                 (aref menu-item 0)
80                               (symbol-name (car pointer)))))))
81                 (setq pointer (cdr pointer)))
82               toolbar))
83           (defun riece-set-toolbar (toolbar)
84             (set-specifier default-toolbar toolbar (current-buffer))))
85       (defalias 'riece-make-toolbar-from-menu 'ignore)
86       (defalias 'riece-set-toolbar 'ignore))
87   (defun riece-make-toolbar-from-menu (items menu-items map)
88     (let ((pointer items)
89           (tool-bar-map (make-sparse-keymap)))
90       (while pointer
91         (tool-bar-add-item-from-menu (car pointer)
92                                      (symbol-name (car pointer))
93                                      map)
94         (setq pointer (cdr pointer)))
95       tool-bar-map))
96   (defun riece-set-toolbar (toolbar)
97     (make-local-variable 'tool-bar-map)
98     (setq tool-bar-map toolbar)))
99
100 (defvar riece-command-mode-map)
101 (defun riece-toolbar-insinuate-in-command-buffer ()
102   (riece-set-toolbar
103    (riece-make-toolbar-from-menu
104     riece-toolbar-items
105     riece-menu-items
106     riece-command-mode-map)))
107
108 (defun riece-toolbar-requires ()
109   '(riece-menu))
110
111 (defun riece-toolbar-insinuate ()
112   (add-hook 'riece-command-mode-hook
113             'riece-toolbar-insinuate-in-command-buffer
114             t))
115
116 (provide 'riece-toolbar)
117
118 ;;; riece-toolbar.el ends here