1 ;;; riece-button.el --- adding buttons in channel buffers
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
6 ;; Keywords: IRC, riece
8 ;; This file is part of Riece.
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)
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.
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.
27 ;; To use, add the following line to your ~/.riece/init.el:
28 ;; (add-to-list 'riece-addons 'riece-button)
32 (require 'riece-commands)
33 (require 'riece-identity)
37 (defconst riece-channel-button-popup-menu
39 ["Switch" riece-channel-button-switch-to-channel]
40 ["Part" riece-channel-button-part]
41 ["List" riece-channel-button-list])
42 "Menu for channel buttons")
44 (defvar help-echo-owns-message)
45 (define-widget 'riece-channel-button 'push-button
47 :action 'riece-channel-button-action
49 (lambda (widget/window &optional overlay pos)
50 ;; Needed to properly clear the message due to a bug in
51 ;; wid-edit (XEmacs only).
52 (if (boundp 'help-echo-owns-message)
53 (setq help-echo-owns-message t))
54 (format "%S: switch to %s; down-mouse-3: more options"
55 (aref riece-mouse-2 0)
56 ;; XEmacs will get a single widget arg; Emacs 21 will get
57 ;; window, overlay, position.
58 (riece-format-identity
60 (with-current-buffer (overlay-buffer overlay)
61 (widget-value (widget-at (overlay-start overlay))))
62 (widget-value widget/window))))))
64 (defun riece-channel-button-action (widget &optional event)
65 "Callback for channel buttons."
66 (let ((channel (widget-value widget)))
67 (if (riece-identity-member channel riece-current-channels)
68 (riece-command-switch-to-channel channel)
69 (message "%s" (substitute-command-keys
70 "Type \\[riece-command-join] to join the channel")))))
72 (defun riece-channel-button-popup-menu (event)
73 "Popup the menu for channel buttons."
75 (riece-popup-menu-popup riece-channel-button-popup-menu event))
77 (defun riece-channel-button-switch-to-channel ()
79 (riece-command-switch-to-channel
80 (get-text-property (point) 'riece-identity)))
82 (defun riece-channel-button-part ()
85 (get-text-property (point) 'riece-identity)))
87 (defun riece-channel-button-list ()
90 (riece-identity-prefix (get-text-property (point) 'riece-identity))))
92 (defvar riece-channel-button-map
93 (let ((map (make-sparse-keymap)))
94 (set-keymap-parent map riece-channel-list-mode-map)
95 (define-key map [down-mouse-3] 'riece-channel-button-popup-menu)
98 (defun riece-button-add-channel-buttons (start end)
102 ;; Search for the beginning of the button region.
103 (unless (get-text-property start 'riece-identity)
104 (setq start (next-single-property-change start 'riece-identity
106 ;; Search for the end of the button region.
107 (let* ((identity (get-text-property start 'riece-identity))
108 (button-end (next-single-property-change start 'riece-identity
110 (if (= button-end end)
112 (if (riece-channel-p (riece-identity-prefix identity))
114 (widget-convert-button 'riece-channel-button start
118 (list 'local-map riece-channel-button-map
119 'keymap riece-channel-button-map))))
120 (setq start button-end)))))))
122 (defun riece-button-update-channel-list-buffer ()
123 (if riece-channel-list-buffer-mode
125 (set-buffer riece-channel-list-buffer)
126 (let ((inhibit-read-only t)
128 (riece-button-add-channel-buttons (point-min) (point-max))))))
130 (defun riece-button-requires ()
133 (defun riece-button-insinuate ()
134 (add-hook 'riece-channel-list-mode-hook
136 (set-keymap-parent riece-channel-list-mode-map widget-keymap)
137 (add-hook 'riece-update-buffer-functions
138 'riece-button-update-channel-list-buffer t)))
139 (add-hook 'riece-dialogue-mode-hook
141 (set-keymap-parent riece-dialogue-mode-map widget-keymap)))
142 (add-hook 'riece-after-insert-functions 'riece-button-add-channel-buttons))
144 (provide 'riece-button)
146 ;;; riece-button.el ends here