Skip to content

Commit 8bd9ab0

Browse files
committed
fix bug in menu items in the window menu
before, if there were more than 9 tabs in a single window, not all of the tabs would have menu item entries in the windows menu
1 parent 7b2d1ab commit 8bd9ab0

File tree

1 file changed

+43
-34
lines changed
  • drracket-core-lib/drracket/private

1 file changed

+43
-34
lines changed

drracket-core-lib/drracket/private/main.rkt

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -853,40 +853,49 @@
853853
(define tab-count (send frame get-tab-count))
854854
(unless (eq? (system-type) 'macosx)
855855
(new separator-menu-item% [parent windows-menu]))
856-
(for ([i (in-range 1 10)])
857-
(define sc (integer->char (+ (char->integer #\0) i)))
858-
(cond
859-
[(and (= i 9) (not (= 1 tab-count)))
860-
(new menu-item%
861-
[parent windows-menu]
862-
[label
863-
(if (< tab-count i)
864-
(format (string-constant last-tab)
865-
(send frame get-tab-filename (- tab-count 1)))
866-
(format (string-constant tab-i)
867-
9
868-
(send frame get-tab-filename (- tab-count 1))))]
869-
[shortcut sc]
870-
[callback
871-
(λ (a b)
872-
(send frame change-to-nth-tab (- tab-count 1)))])]
873-
[(or (< tab-count i) (= 1 tab-count))
874-
(send (new menu-item%
875-
[parent windows-menu]
876-
[label (format (string-constant tab-i/no-name) i)]
877-
[shortcut sc]
878-
[callback void])
879-
enable #f)]
880-
[else
881-
(new menu-item%
882-
[parent windows-menu]
883-
[label (format (string-constant tab-i)
884-
i
885-
(send frame get-tab-filename (- i 1)))]
886-
[shortcut sc]
887-
[callback
888-
(λ (a b)
889-
(send frame change-to-nth-tab (- i 1)))])])))
856+
857+
;; all of the "i"s here are 1 based, so we need to subtract 1
858+
;; when calling the zero-based change-to-nth-tab or get-tab-filename,
859+
;; but otherwise we're using the indicies the user will see in the menus
860+
(define (make-menu-item last? tab-i shortcut-i)
861+
(new menu-item%
862+
[parent windows-menu]
863+
[label
864+
(if last?
865+
(format (string-constant last-tab)
866+
(send frame get-tab-filename (- tab-i 1)))
867+
(format (string-constant tab-i)
868+
tab-i
869+
(send frame get-tab-filename (- tab-i 1))))]
870+
[shortcut (and shortcut-i (integer->char (+ (char->integer #\0) shortcut-i)))]
871+
[callback (λ (a b) (send frame change-to-nth-tab (- tab-i 1)))]))
872+
(define (make-blank-menu-item i)
873+
(define mi
874+
(new menu-item%
875+
[parent windows-menu]
876+
[label (format (string-constant tab-i/no-name) i)]
877+
[shortcut (integer->char (+ (char->integer #\0) i))]
878+
[callback void]))
879+
(send mi enable #f))
880+
(cond
881+
[(= tab-count 1)
882+
(for ([i (in-inclusive-range 1 9)])
883+
(make-blank-menu-item i))]
884+
[(<= tab-count 8)
885+
(for ([i (in-inclusive-range 1 tab-count)])
886+
(make-menu-item #f i i))
887+
(for ([i (in-inclusive-range (+ tab-count 1) 8)])
888+
(make-blank-menu-item i))
889+
(make-menu-item #t tab-count 9)]
890+
[(= tab-count 9)
891+
(for ([i (in-inclusive-range 1 9)])
892+
(make-menu-item #f i i))]
893+
[else
894+
(for ([i (in-inclusive-range 1 8)])
895+
(make-menu-item #f i i))
896+
(for ([i (in-inclusive-range 9 (- tab-count 1))])
897+
(make-menu-item #f i #f))
898+
(make-menu-item #t tab-count 9)]))
890899
(when (eq? (system-type) 'macosx)
891900
(new separator-menu-item% [parent windows-menu])))))
892901

0 commit comments

Comments
 (0)