adjust the windows menu so that it doesn't rely on

various callbacks to keep its menu items straight, but
instead uses the on-demand callback to just get them
all right.
This commit is contained in:
Robby Findler 2012-08-16 08:42:42 -05:00
parent 1e375bab48
commit 49eb4ab11c
4 changed files with 65 additions and 60 deletions

View File

@ -770,6 +770,14 @@
@{Procedures passed to this function are called when the @onscreen{Windows} @{Procedures passed to this function are called when the @onscreen{Windows}
menu is created. Use it to add additional menu items.}) menu is created. Use it to add additional menu items.})
(proc-doc/names
group:create-windows-menu
(-> (is-a?/c menu-item-container<%>) (is-a?/c menu%))
(mb)
@{Creates a windows menu, registers it (internally) with
the frame group (see @racket[(get-the-frame-group)]), and
returns it.})
(proc-doc/names (proc-doc/names
handler:handler? handler:handler?
(any/c . -> . boolean?) (any/c . -> . boolean?)

View File

@ -242,12 +242,7 @@
(set-icon large (send large get-loaded-mask) 'large)) (set-icon large (send large get-loaded-mask) 'large))
(set-icon icon (send icon get-loaded-mask) 'both)))) (set-icon icon (send icon get-loaded-mask) 'both))))
(let ([mb (make-object (get-menu-bar%) this)]) (group:create-windows-menu (make-object (get-menu-bar%) this))
(make-object menu:can-restore-underscore-menu%
(case (system-type)
[(macosx) (string-constant windows-menu-label)]
[else (string-constant tabs-menu-label)])
mb))
(reorder-menus this) (reorder-menus this)

View File

@ -34,6 +34,8 @@
[(macosx) (string-constant windows-menu-label)] [(macosx) (string-constant windows-menu-label)]
[else (string-constant tabs-menu-label)])) [else (string-constant tabs-menu-label)]))
(define-local-member-name update-windows-menu)
(define % (define %
(class object% (class object%
@ -68,7 +70,7 @@
(let ([menu (get-windows-menu frame)]) (let ([menu (get-windows-menu frame)])
(when menu (when menu
;; to help the (conservative) gc. ;; to help the gc.
(for-each (λ (i) (send i delete)) (send menu get-items)) (for-each (λ (i) (send i delete)) (send menu get-items))
(set! windows-menus (set! windows-menus
@ -77,7 +79,7 @@
windows-menus windows-menus
eq?))))) eq?)))))
(define/private (update-windows-menus) (define/public (update-windows-menu menu)
(let* ([windows (length windows-menus)] (let* ([windows (length windows-menus)]
[default-name (string-constant untitled)] [default-name (string-constant untitled)]
[get-name [get-name
@ -97,8 +99,6 @@
(λ (f1 f2) (λ (f1 f2)
(string-ci<=? (get-name (frame-frame f1)) (string-ci<=? (get-name (frame-frame f1))
(get-name (frame-frame f2)))))]) (get-name (frame-frame f2)))))])
(for-each
(λ (menu)
(for-each (λ (item) (send item delete)) (send menu get-items)) (for-each (λ (item) (send item delete)) (send menu get-items))
(when (eq? (system-type) 'macosx) (when (eq? (system-type) 'macosx)
(new menu:can-restore-menu-item% (new menu:can-restore-menu-item%
@ -138,8 +138,7 @@
menu menu
(λ (_1 _2) (λ (_1 _2)
(send frame show #t))))) (send frame show #t)))))
sorted/visible-frames))) sorted/visible-frames))))
windows-menus)))
;; most-recent-window-to-front : -> void? ;; most-recent-window-to-front : -> void?
;; brings the most recent window to the front ;; brings the most recent window to the front
@ -174,12 +173,10 @@
(define/public (get-frames) (map frame-frame frames)) (define/public (get-frames) (map frame-frame frames))
(define/public (frame-label-changed frame) (define/public (frame-label-changed frame)
(when (memq frame (map frame-frame frames)) (void))
(update-windows-menus)))
(define/public (frame-shown/hidden frame) (define/public (frame-shown/hidden frame)
(when (memq frame (map frame-frame frames)) (void))
(update-windows-menus)))
(define/public (for-each-frame f) (define/public (for-each-frame f)
(for-each (λ (x) (f (frame-frame x))) frames) (for-each (λ (x) (f (frame-frame x))) frames)
@ -207,8 +204,7 @@
frames)]) frames)])
(set! frames new-frames) (set! frames new-frames)
(update-close-menu-item-state) (update-close-menu-item-state)
(insert-windows-menu new-frame) (insert-windows-menu new-frame))
(update-windows-menus))
(todo-to-new-frames new-frame))) (todo-to-new-frames new-frame)))
(define/public (remove-frame f) (define/public (remove-frame f)
@ -220,8 +216,7 @@
(λ (f fr) (eq? f (frame-frame fr))))]) (λ (f fr) (eq? f (frame-frame fr))))])
(set! frames new-frames) (set! frames new-frames)
(update-close-menu-item-state) (update-close-menu-item-state)
(remove-windows-menu f) (remove-windows-menu f)))
(update-windows-menus)))
(define/public (clear) (define/public (clear)
(set! frames null) (set! frames null)
@ -262,6 +257,12 @@
(super-new))) (super-new)))
(define (create-windows-menu mb)
(new menu:can-restore-underscore-menu%
[label windows-menu-label]
[demand-callback (λ (menu) (send (get-the-frame-group) update-windows-menu menu))]
[parent mb]))
(define (can-close-check) (define (can-close-check)
(let ([number-of-frames (length (send (get-the-frame-group) get-frames))]) (let ([number-of-frames (length (send (get-the-frame-group) get-frames))])
(or (not (preferences:get 'framework:exit-when-no-frames)) (or (not (preferences:get 'framework:exit-when-no-frames))

View File

@ -318,7 +318,8 @@
(get-the-frame-group (get-the-frame-group
on-close-action on-close-action
can-close-check can-close-check
add-to-windows-menu)) add-to-windows-menu
create-windows-menu))
(define-signature handler-class^ (define-signature handler-class^
()) ())