(module tool mzscheme
  (define oi (current-inspector))
  (current-inspector (make-inspector))
  (require (lib "" "framework")
           (lib "" "mred")
           (lib "")
           (prefix language: "")
           (prefix preferences: "")
           (prefix marker: "")
           (planet "" ("dyoo" "version-case.plt" 1 0))
           (lib "" "drscheme"))
  (current-inspector oi)
  (print-struct #t)
  (provide tool@)
  ;; The following here is to provide backwards compatiblity between
  ;; the old unit system and the new one.  Ugly and VERY fragile.  I'll
  ;; be happy when we don't need this anymore.
  ;; Notes: the macro assumes there is only one import of the drscheme:tool^,
  ;; at the very beginning of the tool definition.  To make this cleaner,
  ;; I have to learn more about macros and lexical binding.
   [(version<= (version) "360.0")
    ;; Under the old unit system:
    (require (lib ""))
    (define-syntax (define-drscheme-tool stx)
      (syntax-case stx ()
        [(_ name tool-export import-body rest-body ...)
         (syntax/loc stx
           (define name
             (unit/sig tool-export
               rest-body ...)))]))]
    ;; Under the new unit system:
    (require (lib ""))
    (define-syntax (define-drscheme-tool stx)
      (syntax-case stx ()
        [(_ name tool-export import-body rest-body ...)
         (syntax/loc stx
           (define-unit name
             (export tool-export)
             rest-body ...))]))])
  (define-drscheme-tool tool@ drscheme:tool-exports^
    (import drscheme:tool^)
    ;; ~H~
    ;; The definitions and interactions windows have two classes : the text one and the canvas one.
    ;; The canvas is the containing object and the text is the contained object.
    ;; For one window of DrScheme, there is only one canvas for the definitions window and another one
    ;; for the interactions window, whatever the number of table is.
    ;; At the opposite, there is one text object for each tab, that is there are as many text objects as there are tabs.
    ;; Thus, when one switch from one tab to another one, only the content of the definitions window and the interactions window are changed:
    ;; the field of the canvas object of what it is currently displaying is changed, the previous text object is replaced by the next text object.
    ;; Currently, each class - mixin - is overloaded twice: a panel overloading and a mred overloading.
    ;; The Panel overloading deals with input stuffs, with giving a command to DivaScheme: hitting F4, the DivaBox, etc..
    ;; The MrEd overloading deals with output stuffs, with the actions to be performed on the text according to the given commmand.
    (define shared-diva-central (new diva-central%))
    (define (phase1)
      (let ([diva-central-mixin (make-diva-central-mixin shared-diva-central)])
        (define (diva-frame-mixin super%)
              (diva-central-mixin super%))))))
        (define (diva-definitions-canvas-mixin super%)
           (diva-central-mixin super%)))
        (define (diva-definitions-text-mixin super%)
             (diva-central-mixin super%)))))
        (define (diva-interactions-text-mixin super%)
              (diva-central-mixin super%))))))
        (drscheme:get/extend:extend-unit-frame diva-frame-mixin)
        (drscheme:get/extend:extend-definitions-canvas diva-definitions-canvas-mixin)
        (drscheme:get/extend:extend-definitions-text diva-definitions-text-mixin)
        (drscheme:get/extend:extend-interactions-text diva-interactions-text-mixin)
        (preferences:install-diva-central-handler shared-diva-central)
        (preferences:add-preference-panel shared-diva-central)))
    (define (phase2)
       (lambda ()
         (when (preferences:enable-on-startup?)
           (send shared-diva-central switch-on)))