CLIM mail archive


input editing, CLIM 1.1

CLIM 1.1 with ACL on SGI

Some general questions on WITH-INPUT-EDITING:

I'm trying to use the WITH-INPUT-EDITING macro to present the user with a
default clause for editing.  The clauses look like Lisp expressions and may
contain strings.  So far the only way I've found that works is to convert
the default clause to a string.  Is this necessary?  Or can I edit Lisp-like
expressions using WITH-INPUT-EDITING?  Can I use ACCEPT on type 'EXPRESSION
or 'FORM in a WITH-INPUT-EDITING form?  Enclosed below is code that works OK
(except that strings within the expression are lost).  The code was adapted
from examples gleaned from the net.

Also, how does WITH-INPUT-EDITING interact with ACCEPTING-VALUES panes?  I
haven't used them yet, but will if they help.

Another question is: WITH-INPUT-FOCUS as I'm using it doesn't seem to focus
attention to the edit pane.  Am I using it improperly?

I appreciate any help, especially working code examples!

Carolyn Banda

NASA Ames Research Center
M.S. 269-6
Moffett Field, CA 94035

;;; ----------------------------------------------------------------------------
;;; E.G., (ASSIGN <X> 34); (ASSIGN <Y> (CALL (GET-AIRSPEED))); 
;;; (WRITE-MESSAGE NIL "The value of <Y> is " <Y>)

(define-edit-rule-form-command (edit-clause)
    ((clause 'clause) (editor 'standard-object))
  (let ((stream (clim:get-frame-pane editor 'edit-pane))
        (default (convert-to-string (value clause)))
    ;;kludge to activate cursor up arrow...
    (setf (clim::cursor-visibility (clim::stream-text-cursor stream)) :off) ;kludge 
;;        (clim:with-input-focus (stream))    ;; doesn't work (why not?)
          (clim:with-input-editing (stream)
            ;; Put the default into the input buffer and ensure that we never
            ;; do it again
            (when default
              (clim:replace-input stream default :rescan t)
              (setq default nil))
            ;; Now get the input from the user
            (setq new-value (read-from-string
                             (clim:with-activation-characters ('(#\Control-r #\Control-\r #\Newline)
                                                               :override nil)
                                   (clim:read-token stream)
                                 ;; Eat the activation character
                                 (clim:read-gesture :stream stream :timeout 0)) )))
            (setq new-clause (make-instance 'clause :value new-value))
            (setf (rule-lhs editor) (subst new-clause clause (rule-lhs editor)))
      (setf (clim::cursor-visibility (clim::stream-text-cursor stream)) :inactive)  ;kludge

;;; Utility function to convert an expression to a string for use
;;; Input:
;;;   a-list   - an expression, in the form of a GEST rule clause
;;; Output:
;;;   - returns a string whose elements are the elements of the expression.
;;;     Parentheses are added at beginning and end.
(defun convert-to-string (a-list)
  (let ((list-of-strings (reverse (loop for item in a-list 
                                        (if (equal item (car (last a-list)))
                                            (format nil "~a" item)
                                            (format nil "~a " item)))))
    (loop for item in list-of-strings do
          (setq new-list
            (concatenate 'string item new-list)))
    (concatenate 'string "(" new-list ")")))


Main Index | Thread Index