[plt-scheme] Troubles with write-to-file and read-from-file in text%

From: Erich Rast (erich at snafu.de)
Date: Tue Mar 18 11:39:23 EST 2003

Like has been suggested to me, I may use write-to-file and  
read-from-file to get or set text including styles. Unfortunately, the  
code below (public methods inside a text% subclass) doesn't seem to  
work. According to my home-brewn debug calls, the string returned by  
get-rich-text looks good and includes a standard header plus the text  
data (sample far below), but insert-rich-text simply does nothing.

Strange enough, I've checked (send input-stream ok?) and it returns  

(DrScheme, version 203.6-cvs18mar2003)

What am I doing wrong?



;;;; code:

     ; Get a part of the editor, including all styles, etc.
       ; Returns a string containing private data, as returned from  
       (define (get-rich-text start end)
         (debug 'verbose 'gui-framework (format "(get-rich-text ~a ~a)"  
start end))
         (let* ((base (make-object editor-stream-out-string-base%))
                (output-stream  (make-object editor-stream-out% base)))
           (send this write-to-file output-stream
                 (get-absolute-position start)
                 (get-absolute-position end))
           (send base get-string)))

       ; Insert text from private string data, including all styles, etc.
       (define (insert-rich-text data start)
         (debug 'verbose 'gui-framework (format "(insert-rich-text ~s  
~a)" data start))
         (let* ((base (make-object editor-stream-in-string-base% data))
                (input-stream (make-object editor-stream-in% base)))
           (send this read-from-file input-stream (get-absolute-position  
start) #f)))

; Turn a standard position, i.e. a number or a symbol in '(start end  
first eof)
       ; into an absolute position, i.e. the number
       (define (get-absolute-position pos)
         (cond ((symbol? pos) (case pos
                                ((start) (get-start-position))
                                ((end) (get-end-position))
                                ((first) 0)
                                ((eof) (last-position))
                                (else (error 'basic-wordprocessor%
                                             "Cannot convert a symbolic  
to an absolute position, because the given position '~a' is unknown"
               (else pos)))

;;;;  sample string (from my debug calls)

GUI-FRAMEWORK 	(insert-rich-text  
0This is a Test: \0Áÿ\2\3\4bold\0Áÿ\1\3\1 \0Áÿ\3\3\6italic\0\0\0\0"  

Posted on the users mailing list.