[plt-scheme] Is there a direct way to get at an embedded snip's parent editor?

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Sun Jun 22 23:06:25 EDT 2008

Is there an easy way to get at an embedded snip's parent toplevel
editor?  I cooked up the following code, but I feel a little hesitant
and would like some confirmation on this.  Thank you for any
suggestions!


#lang scheme/base
(require scheme/gui/base
         scheme/class)

;; get-top-editor: snip -> (or/c editor #f)
;; Returns the topmost editor of a-snip, or #f if we can't do it.
(define (get-top-editor a-snip)
  (cond [(send a-snip get-admin)
         (let* ([editor (send (send a-snip get-admin) get-editor)]
                [editor-admin (send editor get-admin)])
           (cond [(is-a? editor-admin editor-snip-editor-admin<%>)
                  (get-top-editor (send editor-admin get-snip))]
                 [else
                  editor]))]
        [else
         #f]))


;; test: -> boolean
;; should return true.  FIXME: make this an automated test.
(define (test)
  (define e-parent (new text%))

  (define e1 (new editor-snip%))
  (define e2 (new editor-snip%))
  (define e3 (new editor-snip%))

  (send e-parent insert e1)
  (send (send e1 get-editor) insert e2)
  (send (send e2 get-editor) insert e3)
  (and
   (eq? (get-top-editor e3) e-parent)
   (eq? (get-top-editor e2) e-parent)


Posted on the users mailing list.