The intention of the edit-menu:between-.... methods is that you add
menu items to the argument menu and then supply that same method to
the super call (if you make the super call). Like the below, for
example (but this creates a submenu).

#lang racket/gui

(require framework)

(define ext-frame%
  (frame:standard-menus-mixin
   (frame:status-line-mixin frame:basic%)))

(define shc-frame%
  (class ext-frame%
    (super-new)
    (define/override (edit-menu:create-clear?) #f)
    (define/override (edit-menu:between-select-all-and-find edit-menu)
      (new menu%
           [parent edit-menu]
           [label "Patch"])
      (super edit-menu:between-select-all-and-find edit-menu))))

(define test-frame (new shc-frame%
                        [label "TEST!"]
                        [height 200]
                        [width 200]))

(send test-frame show #t)

On Fri, Apr 22, 2016 at 7:49 PM, Matthias Felleisen
<matth...@ccs.neu.edu> wrote:
> 2 small suggestions:
>
> #lang racket/gui
>
> (require framework)
>
> (define ext-frame%
>   (frame:standard-menus-mixin
>    (frame:status-line-mixin
>     frame:basic%)))
>
>
> (define (patch-menu parent-frame)
>   (define m
>     (new menu%
>          [parent (list-ref (send (send parent-frame get-menu-bar) get-items)
> 2)] ;; <<— position 2 not 1
>          [label "Patch"]))
>   ;; add a menu item 2
>   (new menu-item% [parent m] [label "Patch Item"] [callback void])
>   m)
>
> (define shc-frame%
>   (class ext-frame%
>     (super-new)
>     (define/override (edit-menu:create-clear?) #f)
>     (define/override (edit-menu:between-select-all-and-find _)
>       (super edit-menu:between-select-all-and-find (patch-menu this)))))
>
> (define test-frame
>   (new shc-frame% [label "TEST!"] [height 200] [width 200]))
>
> (send test-frame show #t)
>
>
>
> On Apr 22, 2016, at 4:02 PM, Bruce Steinberg <bruc...@gmail.com> wrote:
>
> expected: (or/c (is-a?/c menu%) (is-a?/c popup-menu%))
> given: 10
>
> The documentation actually states that the method should expect a
> menu-item%, not a menu%
>
> (send a-frame:standard-menus edit-menu:between-clear-and-select-all menu)
> → void?
> menu : (is-a?/c menu-item%)
>
> Also, I’m still having trouble getting it to work.
>
> When I run the follow code, the program executes, but no sub-menu is added
> to Edit Menu.
>
> #lang racket/gui
>
> (require framework)
>
> (define ext-frame%
>     (frame:standard-menus-mixin
>     (frame:status-line-mixin frame:basic%)))
>
>
> (define (patch-menu parent-frame)
>   (new menu%
>            [parent (list-ref (send (send parent-frame get-menu-bar)
> get-items) 1)]
>            [label "Patch”]))
>
> (define shc-frame%
>   (class ext-frame%
>     (super-new)
>       (define/override (edit-menu:create-clear?) #f)
>       (define/override (edit-menu:between-select-all-and-find _)
>           (super edit-menu:between-select-all-and-find (patch-menu this)))))
>
> (define test-frame (new shc-frame%
>                         [label "TEST!"]
>                         [height 200]
>                         [width 200]))
>
> (send test-frame show #t)
>
> Thanks so much for the quick replies and for bearing with me.
>
> -Bruce
>
> On 22 Apr 2016, at 8:52, Matthias Felleisen wrote:
>
> If you modify your sample code like this,
>
> lang racket/gui
>
> (require framework)
>
> (define ext-frame%
> (frame:standard-menus-mixin
> (frame:status-line-mixin frame:basic%)))
>
> (define shc-frame%
> (class ext-frame%
> (super-new)
> (define/override (edit-menu:create-clear?) #f)
> (define/override (edit-menu:between-select-all-and-find _)
> (super edit-menu:between-select-all-and-find 10)
> (new menu-item%
> [parent (list-ref (send (send this get-menu-bar) get-items) 1)]
> [label "Patch"]
> [callback (lambda (menu event)
> (send this show #t))])))) ; The callback is just a placeholder for now.
>
> (define test-frame (new shc-frame%
> [label "TEST!"]
> [height 200]
> [width 200]))
>
> you find out that (1) the method really takes one argument and (2) that it
> expects a menu:
>
> expected: (or/c (is-a?/c menu%) (is-a?/c popup-menu%))
> given: 10
>
> What this means is that someone added contracts to the method as it was
> implemented
> and that the docs are wrong.
>
> -- Matthias
>
> On Apr 22, 2016, at 8:46 AM, Bruce Steinberg bruc...@gmail.com wrote:
>
> I'm having trouble with overriding one of framework's methods to add a menu
> item. Here's what I'm currently doing:
>
> #lang racket/gui
>
> (require framework)
>
> (define ext-frame%
>     (frame:standard-menus-mixin
>     (frame:status-line-mixin frame:basic%)))
>
> (define shc-frame%
>   (class ext-frame%
>     (super-new)
>     (define/override (edit-menu:create-clear?) #f)
>     (define/override (edit-menu:between-select-all-and-find)
>       (new menu-item%
>            [parent (list-ref (send (send this get-menu-bar) get-items) 1)]
>            [label "Patch"]
>            [callback (lambda (menu event)
>                        (send this show #t))])))) ; The callback is just a
> placeholder for now.
>
> (define test-frame (new shc-frame%
>                         [label "TEST!"]
>                         [height 200]
>                         [width 200]))
>
> When I run the program I get the following error:
>
> edit-menu:between-select-all-and-find method in shc-frame%: arity mismatch;
>  the expected number of arguments does not match the given number
>   expected: 0
>   given: 1
>   arguments...:
>    (object:...ork/private/menu.rkt:33:4 ...)
>
> Sorry if I'm missing something basic. I'm fairly new to programming.
>
> Thanks so much.
>
> -Bruce
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to