[gnus git] branch master updated: m0-7-54-g7869a1c =1= (eww-click-radio): Implement radio and checkboxes.

Lars Magne Ingebrigtsen <[email protected]>
Newsgroups gmane.emacs.gnus.cvs
Message-ID <[email protected]>
       via  7869a1c0ab015c5d7ba42c64c0396c877e24e9fd (commit)
      from  12e45ad1adef95972f6e2a1a33d745b757268f65 (commit)


- Log -----------------------------------------------------------------
commit 7869a1c0ab015c5d7ba42c64c0396c877e24e9fd
Author: Lars Magne Ingebrigtsen <[email protected]>
Date:   Mon Jun 10 22:44:50 2013 +0200

    (eww-click-radio): Implement radio and checkboxes.

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index cfab73f..e6f4180 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -2,6 +2,7 @@
 
 	* eww.el (eww-submit): Make form submission work.
 	(eww-tag-input): Implement submit buttons.
+	(eww-click-radio): Implement radio and checkboxes.
 
 	* shr.el (shr-descend): Allow other packages to override (or provide)
 	rendering of elements.
diff --git a/lisp/eww.el b/lisp/eww.el
index d8aa052..5e893be 100644
--- a/lisp/eww.el
+++ b/lisp/eww.el
@@ -118,6 +118,7 @@
   (let ((map (make-sparse-keymap)))
     (suppress-keymap map)
     (define-key map "q" 'eww-quit)
+    (define-key map "g" 'eww-reload)
     (define-key map [tab] 'widget-forward)
     (define-key map [backtab] 'widget-backward)
     (define-key map [delete] 'scroll-down-command)
@@ -158,6 +159,12 @@
   (let ((prev (pop eww-history)))
     (url-retrieve (car prev) 'eww-render (list (car prev) (cadr prev)))))
 
+(defun eww-reload ()
+  "Reload the current page."
+  (interactive)
+  (url-retrieve eww-current-url 'eww-render
+		(list eww-current-url (point))))
+
 ;; Form support.
 
 (defvar eww-form nil)
@@ -183,8 +190,17 @@
 	    (list
 	     'push-button
 	     :notify 'eww-submit
+	     :name (cdr (assq :name cont))
 	     :eww-form eww-form
 	     (or (cdr (assq :value cont)) "Submit")))
+	   ((or (equal type "radio")
+		(equal type "checkbox"))
+	    (list 'checkbox
+		  :notify 'eww-click-radio
+		  :name (cdr (assq :name cont))
+		  :checkbox-value (cdr (assq :value cont))
+		  :eww-form eww-form
+		  (cdr (assq :checked cont))))
 	   (t
 	    (list
 	     'editable-field
@@ -196,19 +212,40 @@
 	     :name (cdr (assq :name cont))
 	     :eww-form eww-form)))))
     (apply 'widget-create widget)
-    (shr-generic cont)
     (put-text-property start (point) 'eww-widget widget)))
 
-(defun eww-submit (widget &optional dummy dummy)
+(defun eww-click-radio (widget &rest ignore)
+  (let ((form (getf (cdr widget) :eww-form))
+	(name (getf (cdr widget) :name)))
+    (if (widget-value widget)
+	;; Switch all the other radio buttons off.
+	(dolist (overlay (overlays-in (point-min) (point-max)))
+	  (let ((field (getf (overlay-properties overlay) 'button)))
+	    (when (and (eq (getf (cdr field) :eww-form) form)
+		       (equal name (getf (cdr field) :name)))
+	      (unless (eq field widget)
+		(widget-value-set field nil)))))
+      (widget-value-set widget t))
+    (eww-fix-widget-keymap)))
+
+(defun eww-submit (widget &rest ignore)
   (let ((form (getf (cdr widget) :eww-form))
 	values)
     (dolist (overlay (overlays-in (point-min) (point-max)))
-      (let ((field (getf (overlay-properties overlay) 'field)))
+      (let ((field (or (getf (overlay-properties overlay) 'field)
+		       (getf (overlay-properties overlay) 'button))))
 	(when (eq (getf (cdr field) :eww-form) form)
 	  (let ((name (getf (cdr field) :name)))
 	    (when name
+	      (cond
+	       ((eq (car field) 'checkbox)
+		(when (widget-value field)
+		  (push (cons name (getf (cdr field) :checkbox-value))
+			values)))
+	       (t
 	      (push (cons name (widget-value field))
-		    values))))))
+		      values))))))))
+    (debug values)
     (let ((shr-base eww-current-url))
       (if (and (stringp (getf form :method))
 	       (equal (downcase (getf form :method)) "post"))
@@ -229,10 +266,15 @@
       (setq widget (get-text-property start 'eww-widget))
       (goto-char start)
       (delete-region start (next-single-property-change start 'eww-widget))
-      (apply 'widget-create widget)
-      (when (equal (car widget) 'push-button)
-	(put-text-property start (point) 'local-map widget-keymap)))
-    (widget-setup)))
+      (apply 'widget-create widget))
+    (widget-setup)
+    (eww-fix-widget-keymap)))
+
+(defun eww-fix-widget-keymap ()
+  (dolist (overlay (overlays-in (point-min) (point-max)))
+    (when (or (getf (overlay-properties overlay) 'field)
+	      (getf (overlay-properties overlay) 'button))
+      (overlay-put overlay 'local-map widget-keymap))))
 
 (provide 'eww)
 

-----------------------------------------------------------------------
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we listed those
revisions in full, above.

Summary of changes:
 lisp/ChangeLog |    1 +
 lisp/eww.el    |   60 +++++++++++++++++++++++++++++++++++++++++++++++--------
 2 files changed, 52 insertions(+), 9 deletions(-)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnus Project".

The branch, master has been updated


hooks/post-receive
-- 
Gnus Project
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.