CLIM mail archive

[Prev][Next][Index][Thread]

input editing, CLIM 1.1



Scott McKay writes:
 >     Date: Tue, 5 Oct 1993 14:34 EDT
 >     From: Carolyn Banda <banda@marlin.arc.nasa.gov>
 > 
 >     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?  
 > 
 > WITH-INPUT-EDITING is intended for editing strings.  So, yes.
 > 
 > 							 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?  
 > 					    
 > Since, ACCEPT uses WITH-INPUT-EDITING, there is no need to use
 > WITH-INPUT-EDITING inside of a call to ACCEPT.  In fact, the inner
 > use of WITH-INPUT-EDITING is effectively a no-op.
 > 
 > 					    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.
 > 
 > I don't think this is a meaningful question.  WITH-INPUT-EDITING
 > interacts only with input primitives such as READ-GESTURE and the
 > things that use READ-GESTURE, such as ACCEPT.
 > 
 >     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?
 > 
 > Hmm, I dunno.  It works for me.
 > 
 >     ;;; ----------------------------------------------------------------------------
 >     ;;; EDIT A LISP-LIKE EXPRESSION, CALLED "CLAUSE" BELOW.
 >     ;;; E.G., (ASSIGN <X> 34); (ASSIGN <Y> (CALL (GET-AIRSPEED))); 
 >     ;;; (WRITE-MESSAGE NIL "The value of <Y> is " <Y>)
 > 
 > I don't understand why you haven't just written a CLAUSE presentation
 > type, with a PRESENT method that is basically PRINC and an ACCEPT method
 > that is what you have below (with all of the default handling, replace
 > input, and input editing stuff gone).  You seem to have done way too
 > much work here.
 > 

Actually, I had written a CLAUSE presentation type with PRESENT and ACCEPT
methods, but I was using them for cases where the user is entering the
entire clause from scratch.  I would also like to have an "edit an existing clause"
option, where the user is presented with a clause to modify, and can use the typical
editor commands, like CONTROL-A, CONTROL-B, etc. for cursor movement.  (I
anticipate having some long clauses and don't want to require the user to
re-enter the entire clause to make a change.)  I was
under the impression that the only way to do this is to use
WITH-INPUT-EDITING.  Am I wrong?  Is there a better way?

Many thanks for the help!

 >     (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)))
 > 	    new-value
 > 	    new-clause)
 > 	;;kludge to activate cursor up arrow...
 > 	(setf (clim::cursor-visibility (clim::stream-text-cursor stream)) :off) ;kludge 
 > 	(unwind-protect
 >     ;;        (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)
 > 				   (unwind-protect
 > 				       (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
 > 	  )))
 > 
 > 
 >     ;;; CONVERT-TO-STRING
 >     ;;; Utility function to convert an expression to a string for use
 >     ;;; in EDIT-CLAUSE.
 >     ;;; 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 
 > 					  collect 
 > 					    (if (equal item (car (last a-list)))
 > 						(format nil "~a" item)
 > 						(format nil "~a " item)))))
 > 	    new-list)
 > 	(loop for item in list-of-strings do
 > 	      (setq new-list
 > 		(concatenate 'string item new-list)))
 > 	(concatenate 'string "(" new-list ")")))


Follow-Ups: References:

Main Index | Thread Index