|
2877 | 2877 | (send (send tab get-defs) on-close) |
2878 | 2878 | (send (send tab get-ints) on-close))) |
2879 | 2879 | tabs) |
| 2880 | + (update-recently-closed-tabs tabs) |
2880 | 2881 | (when (eq? this newest-frame) |
2881 | 2882 | (set! newest-frame #f)) |
2882 | 2883 | (when transcript |
|
3075 | 3076 | ;; create-new-tab : -> void |
3076 | 3077 | ;; creates a new tab and updates the GUI for that new tab |
3077 | 3078 | (define/public create-new-tab |
3078 | | - (lambda ([filename #f]) |
| 3079 | + (lambda ([filename #f] #:start-pos [start-pos 0] #:end-pos [end-pos 'same]) |
3079 | 3080 | (let* ([defs (new (drracket:get/extend:get-definitions-text))] |
3080 | 3081 | [tab-count (length tabs)] |
3081 | 3082 | [new-tab (new (drracket:get/extend:get-tab) |
|
3086 | 3087 | (ints-shown? (not filename)))] |
3087 | 3088 | [ints (make-object (drracket:get/extend:get-interactions-text) new-tab)]) |
3088 | 3089 | (send new-tab set-ints ints) |
| 3090 | + (send (send new-tab get-defs) set-position start-pos end-pos) |
3089 | 3091 | (set! tabs (append tabs (list new-tab))) |
3090 | 3092 | (send tabs-panel append |
3091 | 3093 | (gui-utils:trim-string |
|
3248 | 3250 | (send tab set-i (- (send tab get-i) 1))) |
3249 | 3251 | (set! tabs (remq tab-to-close tabs)) |
3250 | 3252 | (send tabs-panel delete (send tab-to-close get-i)) |
| 3253 | + (update-recently-closed-tabs (list tab-to-close)) |
3251 | 3254 | (update-menu-bindings) |
3252 | 3255 | (cond |
3253 | 3256 | [(eq? tab-to-close current-tab) |
|
3265 | 3268 | #t] |
3266 | 3269 | [else #f])) |
3267 | 3270 |
|
3268 | | - (define/public (open-in-new-tab filename) |
3269 | | - (create-new-tab filename)) |
| 3271 | + (define/public (open-in-new-tab filename #:start-pos [start-pos 0] #:end-pos [end-pos 'same]) |
| 3272 | + (create-new-tab filename #:start-pos start-pos #:end-pos end-pos)) |
3270 | 3273 |
|
| 3274 | + ;; reopen-closed-tab : -> void |
| 3275 | + ;; Opens previously closed tabs. If no tabs were closed in current session, files from |
| 3276 | + ;; previous sessions are opened. |
| 3277 | + (define/public (reopen-closed-tab) |
| 3278 | + (define closed-tabs (preferences:get 'drracket:recently-closed-tabs)) |
| 3279 | + (define-values (file-to-open new-closed-tabs) |
| 3280 | + (let loop ([closed-tabs closed-tabs]) |
| 3281 | + (cond |
| 3282 | + [(null? closed-tabs) (values #f '())] |
| 3283 | + [else |
| 3284 | + (define closed-tab (car closed-tabs)) |
| 3285 | + (cond |
| 3286 | + [(file-exists? (car closed-tab)) |
| 3287 | + (values closed-tab (cdr closed-tabs))] |
| 3288 | + [else (loop (cdr closed-tabs))])]))) |
| 3289 | + (when file-to-open |
| 3290 | + (define tab (find-matching-tab (car file-to-open))) |
| 3291 | + (define start-pos (cadr file-to-open)) |
| 3292 | + (define end-pos (caddr file-to-open)) |
| 3293 | + (if tab |
| 3294 | + (change-to-tab tab) |
| 3295 | + (open-in-new-tab (car file-to-open) #:start-pos start-pos #:end-pos end-pos))) |
| 3296 | + (preferences:set 'drracket:recently-closed-tabs new-closed-tabs) |
| 3297 | + #f) |
| 3298 | + |
3271 | 3299 | (define/public (get-tab-count) (length tabs)) |
3272 | 3300 | (define/public (change-to-nth-tab n) |
3273 | 3301 | (unless (< n (length tabs)) |
|
3350 | 3378 | (with-handlers ([exn:fail? (λ (x) #f)]) |
3351 | 3379 | (string=? (path->string (normal-case-path (normalize-path p1))) |
3352 | 3380 | (path->string (normal-case-path (normalize-path p2)))))) |
3353 | | - |
| 3381 | + |
3354 | 3382 | (define/override (make-visible filename) |
3355 | 3383 | (let ([tab (find-matching-tab filename)]) |
3356 | 3384 | (when tab |
|
3396 | 3424 | (when close-tab-menu-item |
3397 | 3425 | (update-close-tab-menu-item-shortcut close-tab-menu-item)) |
3398 | 3426 | (update-close-menu-item-shortcut (file-menu:get-close-item))) |
3399 | | - |
| 3427 | + |
| 3428 | + (define/private (update-recently-closed-tabs tabs) |
| 3429 | + (define closed-tabs (preferences:get 'drracket:recently-closed-tabs)) |
| 3430 | + (define recently-closed-tabs-max-count (preferences:get 'drracket:recently-closed-tabs-max-count)) |
| 3431 | + (for ([tab (in-list tabs)]) |
| 3432 | + (define defs (send tab get-defs)) |
| 3433 | + (define tab-filename (send defs get-filename)) |
| 3434 | + (when tab-filename |
| 3435 | + (define start-pos (send defs get-start-position)) |
| 3436 | + (define end-pos (send defs get-end-position)) |
| 3437 | + (define new-ent (list tab-filename start-pos end-pos)) |
| 3438 | + (set! closed-tabs |
| 3439 | + (cons new-ent |
| 3440 | + (remove* (list new-ent) |
| 3441 | + closed-tabs |
| 3442 | + (λ (l1 l2) |
| 3443 | + (pathname-equal? (car l1) (car l2)))))))) |
| 3444 | + (unless (<= (length closed-tabs) recently-closed-tabs-max-count) |
| 3445 | + (set! closed-tabs (take closed-tabs recently-closed-tabs-max-count))) |
| 3446 | + (preferences:set 'drracket:recently-closed-tabs closed-tabs)) |
| 3447 | + |
3400 | 3448 | (define/private (update-close-tab-menu-item-shortcut item) |
3401 | 3449 | (define just-one? (and (pair? tabs) (null? (cdr tabs)))) |
3402 | 3450 | (send item set-label (if just-one? |
|
3932 | 3980 | (let-values ([(base name dir?) (split-path editing-path)]) |
3933 | 3981 | base)))) |
3934 | 3982 | (when pth (handler:edit-file pth)))]) |
| 3983 | + (new menu:can-restore-menu-item% |
| 3984 | + (label (string-constant reopen-closed-tab)) |
| 3985 | + (shortcut #\t) |
| 3986 | + (shortcut-prefix (cons 'shift (get-default-shortcut-prefix))) |
| 3987 | + (parent file-menu) |
| 3988 | + [demand-callback (λ (item) (send item enable (pair? (preferences:get 'drracket:recently-closed-tabs))))] |
| 3989 | + (callback |
| 3990 | + (λ (x y) |
| 3991 | + (reopen-closed-tab)))) |
3935 | 3992 | (super file-menu:between-open-and-revert file-menu) |
3936 | 3993 | (make-object separator-menu-item% file-menu))] |
3937 | 3994 | (define close-tab-menu-item #f) |
|
4055 | 4112 | (mk-menu-item (λ (ed) (send ed get-spell-check-text)) |
4056 | 4113 | (λ (ed new-val) (send ed set-spell-check-text new-val)) |
4057 | 4114 | 'framework:spell-check-text? |
4058 | | - #\t |
| 4115 | + #f |
4059 | 4116 | (string-constant spell-check-scribble-text)) |
4060 | 4117 |
|
4061 | 4118 | (new menu:can-restore-menu-item% |
|
0 commit comments