|
853 | 853 | (define tab-count (send frame get-tab-count)) |
854 | 854 | (unless (eq? (system-type) 'macosx) |
855 | 855 | (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)])) |
890 | 899 | (when (eq? (system-type) 'macosx) |
891 | 900 | (new separator-menu-item% [parent windows-menu]))))) |
892 | 901 |
|
|
0 commit comments