X-Git-Url: https://cgit.sxemacs.org/?p=riece;a=blobdiff_plain;f=lisp%2Friece-button.el;h=f125dbfb49ef5da324811908f31bdc6f331fa448;hp=f9f2188cae396778f8f81a6c0614f3c0362915c7;hb=3052cb04a561ff5617e886c2b5454f7795946e54;hpb=0964de4aab84b7826e4e87ee11747424f101376e diff --git a/lisp/riece-button.el b/lisp/riece-button.el index f9f2188..f125dbf 100644 --- a/lisp/riece-button.el +++ b/lisp/riece-button.el @@ -49,6 +49,11 @@ ["Allow To Speak" riece-user-button-set-speakers]) "Menu for user buttons.") +(defvar riece-button-enabled nil) + +(defconst riece-button-description + "Display useful buttons in IRC buffers") + (defvar help-echo-owns-message) (define-widget 'riece-identity-button 'push-button "A channel button." @@ -78,9 +83,31 @@ This function is used as a callback for a channel button." (message "%s" (substitute-command-keys "Type \\[riece-command-join] to join the channel"))))) +(defun riece-identity-button-click (event) + "Call widget-button-click and select the last selected window." + (interactive "e") ;widget-button-click has + ;interactive spec "@e" + (let ((buffer (current-buffer)) + (point (point)) + window) + (unwind-protect + (save-excursion + (set-buffer (riece-event-buffer event)) + (goto-char (riece-event-point event)) + (widget-button-click event)) + ;; riece-button-switch-to-identity changes window-configuration + ;; so we must select the last selected window by _buffer_. + (if (setq window (get-buffer-window buffer)) + (progn + (select-window window) + (set-window-point window point)) + (if riece-debug + (riece-debug (format "buffer %s not visible" + (buffer-name buffer)))))))) + (defun riece-identity-button-popup-menu (event) "Popup the menu for identity buttons." - (interactive "@e") + (interactive "e") (save-excursion (set-buffer (riece-event-buffer event)) (goto-char (riece-event-point event)) @@ -174,22 +201,25 @@ This function is used as a callback for a channel button." (defun riece-make-identity-button-map () (let ((map (make-sparse-keymap))) (set-keymap-parent map (current-local-map)) + (define-key map [down-mouse-2] 'riece-identity-button-click) (define-key map [down-mouse-3] 'riece-identity-button-popup-menu) map)) (defvar riece-identity-button-map) (defun riece-button-add-identity-button (start end) - (riece-scan-property-region - 'riece-identity - start end - (lambda (start end) - (let ((inhibit-read-only t) - buffer-read-only) - (widget-convert-button 'riece-identity-button start end - (get-text-property start 'riece-identity)) - (add-text-properties start end - (list 'local-map riece-identity-button-map - 'keymap riece-identity-button-map)))))) + (if riece-button-enabled + (riece-scan-property-region + 'riece-identity + start end + (lambda (start end) + (let ((inhibit-read-only t) + buffer-read-only) + (widget-convert-button 'riece-identity-button start end + (get-text-property start 'riece-identity)) + (add-text-properties + start end + (list 'local-map riece-identity-button-map + 'keymap riece-identity-button-map))))))) (defun riece-button-update-buffer () (riece-button-add-identity-button (point-min) (point-max))) @@ -219,6 +249,31 @@ This function is used as a callback for a channel button." (riece-make-identity-button-map)))) (add-hook 'riece-after-insert-functions 'riece-button-add-identity-button)) +(defun riece-button-enable () + (setq riece-button-enabled t) + (let ((pointer riece-buffer-list)) + (while pointer + (with-current-buffer (car pointer) + (if (eq (derived-mode-class major-mode) + 'riece-dialogue-mode) + (riece-button-update-buffer))) + (setq pointer (cdr pointer))) + (if riece-current-channel + (riece-emit-signal 'user-list-changed riece-current-channel)) + (riece-emit-signal 'channel-list-changed))) + +(defun riece-button-disable () + (setq riece-button-enabled nil) + (save-excursion + (let ((pointer riece-buffer-list)) + (while pointer + ;; On XEmacs, BUFFER arg of widget-map-buttons is ignored. + (set-buffer (car pointer)) + (widget-map-buttons + (lambda (widget maparg) + (widget-leave-text widget))) + (setq pointer (cdr pointer)))))) + (provide 'riece-button) ;;; riece-button.el ends here