[plt-scheme] editor snips and replacing the editor with set-editor
> I'm trying to create an editor snip that doesn't allow further edits to it.
> I tried the following, but the resulting snips that show up on the
> interaction window continue to allow internal editing. I'm missing something
> obvious but I don't quite see the problem yet.
... and, of course, five minutes later, I see the problem. Doh. Sorry
for bothering people.
Summary: I didn't realize that a call to the 'copy' method fires off when
the snip shows up on the interaction window. So for any of the custom
snips I write, I must make sure to define a copy method for them.
The following code does sorta what I want, although I suspect I need to be
much more careful. I guess I really do need to look closely at the
snipclass stuff to preserve my snips under other situations like saving to
disk.
;;;;;;
#lang scheme/base
(require scheme/gui/base
scheme/list
scheme/class
scheme/sandbox)
(define immutable-text%
(class text%
(inherit insert)
(init content)
(define after-initialize? #f)
(define (initialize)
(super-new)
(insert content)
(set! after-initialize? #t))
(define/augment (can-insert? pos len)
(not after-initialize?))
(define/augment (can-delete? pos len)
(not after-initialize?))
(initialize)))
(define immutable-editor-snip%
(class editor-snip%
(inherit set-editor)
(init-field content)
(define (initialize)
(super-new [editor (new immutable-text% [content content])]))
(define/override (copy)
(new immutable-editor-snip% [content content]))
(initialize)))