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