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<%>
This commit is contained in:
Robby Findler 2012-12-17 09:09:56 -06:00
parent 4fc71951ee
commit e19243329c
2 changed files with 30 additions and 5 deletions

View File

@ -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))

View File

@ -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].
}
}