From e19243329cc15f2a4ba1a3e53934b7041187e30c Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Mon, 17 Dec 2012 09:09:56 -0600 Subject: [PATCH] adjust drracket to track an lru order on tabs and use it when closing one to pick the next one to show added the touched and get-last-touched methods to tab<%> --- collects/drracket/private/unit.rkt | 18 ++++++++++++++---- collects/scribblings/tools/unit.scrbl | 17 ++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/collects/drracket/private/unit.rkt b/collects/drracket/private/unit.rkt index 2378b14bd5..62b1974c44 100644 --- a/collects/drracket/private/unit.rkt +++ b/collects/drracket/private/unit.rkt @@ -1215,6 +1215,10 @@ module browser threading seems wrong. (send frame enable-evaluation-in-tab this)) (define/public (get-enabled) enabled?) + (define last-touched (current-inexact-milliseconds)) + (define/public-final (touched) (set! last-touched (current-inexact-milliseconds))) + (define/public-final (get-last-touched) last-touched) + ;; current-execute-warning is a snapshot of the needs-execution-message ;; that is taken each time repl submission happens, and it gets reset ;; when "Run" is clicked. @@ -2946,6 +2950,8 @@ module browser threading seems wrong. (send definitions-text update-frame-filename) (update-running (send current-tab is-running?)) + (when (eq? this (get-top-level-focus-window)) + (send current-tab touched)) (on-tab-change old-tab current-tab) (send tab update-log) (send tab update-planet-status) @@ -2991,10 +2997,9 @@ module browser threading seems wrong. (set! tabs (remq tab tabs)) (send tabs-panel delete (send tab get-i)) (update-menu-bindings) - (change-to-tab (cond - [(< (send tab get-i) (length tabs)) - (list-ref tabs (send tab get-i))] - [else (last tabs)]))) + (change-to-tab + (argmax (λ (tab) (send tab get-last-touched)) + tabs))) (loop (cdr l-tabs))))]))])) ;; a helper private method for close-current-tab -- doesn't close an arbitrary tab. @@ -3134,6 +3139,11 @@ module browser threading seems wrong. [else (super restore-keybinding)])) (super-new))) + (define/override (on-activate active?) + (when active? + (send (get-current-tab) touched)) + (super on-activate active?)) + (define/private (update-menu-bindings) (when close-tab-menu-item (update-close-tab-menu-item-shortcut close-tab-menu-item)) diff --git a/collects/scribblings/tools/unit.scrbl b/collects/scribblings/tools/unit.scrbl index c1b326ab01..7528afcf12 100644 --- a/collects/scribblings/tools/unit.scrbl +++ b/collects/scribblings/tools/unit.scrbl @@ -155,7 +155,22 @@ Calls the definitions text's See also @method[drracket:unit:tab<%> add-bkg-running-color]. } - +@defmethod[#:mode public-final (touched) void?]{ + Called by the system to indicate that the tab has + just been switched to from another tab in the + same frame (when the frame has the focus) + or the frame itself has come to the + front (via @method[top-level-window<%> on-activate]) + and the tab is the current tab in that frame. + + This method updates the private state that + @method[drracket:unit:tab<%> get-last-touched] + returns. + } +@defmethod[#:mode public-final (get-last-touched) flonum?]{ + Returns the time that this tab was last focused, as counted + by @racket[current-inexact-milliseconds]. + } }