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 To Channel" riece-channel-button-switch-to-channel]
40 ["Part Channel" riece-channel-button-part]
41 ["List Channel" riece-channel-button-list])
42 "Menu for channel buttons.")
44 (defconst riece-user-button-popup-menu
46 ["Start Private Conversation" riece-user-button-join-partner]
47 ["Give Channel Operator Privileges" riece-user-button-set-operators]
48 ["Allow To Speak" riece-user-button-set-speakers]
49 ["Finger (WHOIS)" riece-user-button-finger])
50 "Menu for user buttons.")
52 (defvar help-echo-owns-message)
53 (define-widget 'riece-identity-button 'push-button
55 :action 'riece-button-switch-to-identity
57 (lambda (widget/window &optional overlay pos)
58 ;; Needed to properly clear the message due to a bug in
59 ;; wid-edit (XEmacs only).
60 (if (boundp 'help-echo-owns-message)
61 (setq help-echo-owns-message t))
62 (format "%S: switch to %s; down-mouse-3: more options"
63 (aref riece-mouse-2 0)
64 ;; XEmacs will get a single widget arg; Emacs 21 will get
65 ;; window, overlay, position.
66 (riece-format-identity
68 (with-current-buffer (overlay-buffer overlay)
69 (widget-value (widget-at (overlay-start overlay))))
70 (widget-value widget/window))))))
72 (defun riece-button-switch-to-identity (widget &optional event)
73 "Switch to identity stored in WIDGET.
74 This function is used as a callback for a channel button."
75 (let ((channel (widget-value widget)))
76 (if (riece-identity-member channel riece-current-channels)
77 (riece-command-switch-to-channel channel)
78 (message "%s" (substitute-command-keys
79 "Type \\[riece-command-join] to join the channel")))))
81 (defun riece-identity-button-popup-menu (event)
82 "Popup the menu for identity buttons."
85 (set-buffer (riece-event-buffer event))
86 (goto-char (riece-event-point event))
87 (riece-popup-menu-popup
88 (if (riece-channel-p (riece-identity-prefix
89 (get-text-property (point) 'riece-identity)))
90 riece-channel-button-popup-menu
91 riece-user-button-popup-menu)
94 (defun riece-channel-button-switch-to-channel ()
96 (riece-command-switch-to-channel
97 (get-text-property (point) 'riece-identity)))
99 (defun riece-channel-button-part ()
102 (get-text-property (point) 'riece-identity)))
104 (defun riece-channel-button-list ()
107 (riece-identity-prefix (get-text-property (point) 'riece-identity))))
109 (defun riece-user-button-join-partner ()
111 (riece-command-join-partner
112 (get-text-property (point) 'riece-identity)))
114 (defun riece-user-button-set-operators ()
117 (if (riece-region-active-p)
119 (riece-button-map-identity-region
120 (region-beginning) (region-end)
122 (setq group (cons (get-text-property start 'riece-identity)
124 (setq group (list (get-text-property (point) 'riece-identity))))
129 (riece-with-server-buffer (riece-identity-server
130 riece-current-channel)
132 (riece-identity-prefix identity)
133 (riece-channel-get-users
134 (riece-identity-prefix
135 riece-current-channel)))
137 (riece-identity-prefix identity)
138 (riece-channel-get-operators
139 (riece-identity-prefix
140 riece-current-channel)))))
143 (riece-command-set-operators (mapcar #'riece-identity-prefix group)))))
145 (defun riece-user-button-set-speakers ()
148 (if (riece-region-active-p)
150 (riece-button-map-identity-region
151 (region-beginning) (region-end)
153 (setq group (cons (get-text-property start 'riece-identity)
155 (setq group (list (get-text-property (point) 'riece-identity))))
160 (riece-with-server-buffer (riece-identity-server
161 riece-current-channel)
163 (riece-identity-prefix identity)
164 (riece-channel-get-users
165 (riece-identity-prefix
166 riece-current-channel)))
168 (riece-identity-prefix identity)
169 (riece-channel-get-operators
170 (riece-identity-prefix
171 riece-current-channel))))
173 (riece-identity-prefix identity)
174 (riece-channel-get-speakers
175 (riece-identity-prefix
176 riece-current-channel)))))
179 (riece-command-set-speakers (mapcar #'riece-identity-prefix group)))))
181 (defun riece-user-button-finger ()
183 (riece-command-finger
184 (riece-identity-prefix (get-text-property (point) 'riece-identity))))
186 (defun riece-make-identity-button-map ()
187 (let ((map (make-sparse-keymap)))
188 (set-keymap-parent map (current-local-map))
189 (define-key map [down-mouse-3] 'riece-identity-button-popup-menu)
192 (defun riece-button-map-identity-region (start end function)
195 ;; Search for the beginning of the button region.
196 (unless (get-text-property start 'riece-identity)
197 (setq start (next-single-property-change start 'riece-identity
201 ;; Search for the end of the button region.
202 (let ((button-end (next-single-property-change start 'riece-identity
204 (if (= button-end end)
206 (funcall function start button-end)
207 (setq start button-end)))))
209 (defvar riece-identity-button-map)
210 (defun riece-button-add-identity-button (start end)
211 (riece-button-map-identity-region
214 (let ((inhibit-read-only t)
216 (widget-convert-button 'riece-identity-button start end
217 (get-text-property start 'riece-identity))
218 (add-text-properties start end
219 (list 'local-map riece-identity-button-map
220 'keymap riece-identity-button-map))))))
222 (defun riece-button-update-channel-list-buffer ()
224 (set-buffer riece-channel-list-buffer)
225 (riece-button-add-identity-button (point-min) (point-max))))
227 (defun riece-button-update-user-list-buffer ()
229 (set-buffer riece-user-list-buffer)
230 (riece-button-add-identity-button (point-min) (point-max))))
232 (defun riece-button-requires ()
235 (defvar riece-channel-list-mode-map)
236 (defvar riece-user-list-mode-map)
237 (defvar riece-dialogue-mode-map)
238 (defun riece-button-insinuate ()
239 (add-hook 'riece-update-buffer-functions
240 'riece-button-update-channel-list-buffer t)
241 (add-hook 'riece-update-buffer-functions
242 'riece-button-update-user-list-buffer t)
243 (add-hook 'riece-channel-list-mode-hook
245 (set-keymap-parent riece-channel-list-mode-map widget-keymap)
246 (set (make-local-variable 'riece-identity-button-map)
247 (riece-make-identity-button-map))))
248 (add-hook 'riece-user-list-mode-hook
250 (set-keymap-parent riece-user-list-mode-map widget-keymap)
251 (set (make-local-variable 'riece-identity-button-map)
252 (riece-make-identity-button-map))))
253 (add-hook 'riece-dialogue-mode-hook
255 (set-keymap-parent riece-dialogue-mode-map widget-keymap)
256 (set (make-local-variable 'riece-identity-button-map)
257 (riece-make-identity-button-map))))
258 (add-hook 'riece-after-insert-functions 'riece-button-add-identity-button))
260 (provide 'riece-button)
262 ;;; riece-button.el ends here