CLIM mail archive


help for editing text.

    Date: Fri, 24 Jul 1992 05:34 EDT

    If I try to accept a string that has some contents in it 
    like "default". It seems impossible to edit that. Instead I have always to retype the
    complete former input. I may use the default presentation, but if I like to make minor 
    changes, like corrections, I have to retype the input. Can somebody give me an example how 
    to re-edit strings?

Here's a quick-and-dirty example that Scott and I worked out a while
ago.  Things to understand:

 - Call REPLACE-INPUT to fill the input buffer of an input-editing stream.

 - Code inside with-input-editing will restart any time the user edits
   (e.g. types <rubout>).  Therefore you must make sure that replace-input
   only gets called the first time.  That's why it says
	  (when default-note
	    (replace-input ...)
	    (setq default-note nil))

 - The cursor-visibility stuff is to make the cursor visible during editing.
   Don't try to understand that stuff, it's just a kludge.

Disclaimer: only tested on Genera.

;;; -*- Mode: Lisp; Package: CLIM-USER; Syntax: Common-Lisp; Lowercase: Yes -*-

(defun read-note (&optional default-note)
  (with-menu (stream)
    ;; Set up the pop-up window the way we want to see it
    (setf (clim::cursor-visibility (clim::stream-text-cursor stream)) :off)
    (clim::window-set-inside-size  stream
      (* 60 (stream-character-width stream #\Space))
      (* 10 (stream-line-height stream)))
    (write-string "Enter a note:" stream)
    (fresh-line stream)
    (setf (stream-text-margin stream) (bounding-rectangle-width (window-viewport stream)))
    (window-expose stream)
	(with-input-editing (stream)
	  ;; Put the default note into the input buffer and ensure that
	  ;; we never do it again
	  (when default-note
	    (replace-input stream default-note :rescan t)
	    (setq default-note nil))
	  ;; Now get the input from the user
	  (with-activation-characters ('(#\Newline) :override t)
		(read-token stream)
	      ;; Eat the activation character
	      (read-gesture :stream stream :timeout 0))))
      (setf (clim::cursor-visibility (clim::stream-text-cursor stream)) :inactive))))


Main Index | Thread Index