PS. Thanks for the postings re. command key input, it never crossed my mind
that the code handles would be catagorized as "window operation"s.
>(defmethod view-key-event-handler ((thing geo) char)
> (if (alpha-char-p char) (ed-beep) (call-next-method)))
>
>else you can't delete anything or do ctrl-f etc.
Alas, even that doesn't cut it, since (I think) there are a whole mess of
non-digit non-alpha characters that can get in there...
I did something like this once upon a time, and ended up checking for
specific characters (arrows, delete, backspace, etc), because Lisp didn't
have any built-in charset that matched what I wanted.
I dunno where I did this, or I'd send on the source. Sorry.
--
--
-- "TANSTAAFL" Rich ly...@lscorp.com
;-*- Mode: Lisp; Package: CCL -*-
;; ****************************************************************
;;
;; Author: Alan Ruttenberg, MIT Media Lab
;; email: al...@media.mit.edu
;;
;; Created: Thursday September 19,1991
;;
;; ****************************************************************
(in-package :ccl)
(defclass number-editable-text-dialog-item (editable-text-dialog-item)
((return/tab-action :initarg :return/tab-action :initform nil :accessor
return/tab-action)))
(defmethod view-key-event-handler ((v number-editable-text-dialog-item) char)
(let ((buffer-position (buffer-position (fred-buffer v))))
(cond ((or (char= char #\return) (char= char #\tab))
(funcall (or (return/tab-action v) 'not) v)
(change-key-handler (view-window v)))
;; allow digits, #\. #\-, but no other printable characters
((not (or (digit-char-p char) (char= char #\.) (char= char #\-)
(not (graphic-char-p char))
(any-modifier-keys-p)))
(ed-beep))
;; no more than one #\.
((and (char= char #\.) (find #\. (dialog-item-text v)))
(ed-beep))
;; no more than one #\-, and only at start
((and (char= char #\-)
(or (char= #\- (char (dialog-item-text v) 0))
(not (zerop buffer-position))))
(ed-beep))
;; insert 0 with 1 at lead of buffer
((and (char= char #\.) (zerop buffer-position))
(view-key-event-handler v #\0)
(call-next-method))
;; otherwise handle key as usual
(t (call-next-method)))))
(defmethod item-value ((v number-editable-text-dialog-item))
(read-from-string (dialog-item-text v)))
(defmethod set-item-value ((v number-editable-text-dialog-item) value)
(set-dialog-item-text v (prin1-to-string value)))
(defmethod paste ((v number-editable-text-dialog-item))
(let ((scrap (get-scrap :fred)))
(when scrap
(let ((string (car scrap)))
(loop for char across string do (view-key-event-handler v char))))))
You wrote:
Is there a custom editable-text-dialog-item to accept only number input (a
la CLIM (accept 'number))?
-Alan