From 9a5b7d44fd4ebdb0e2bbe5be42c0833aa2274fb8 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 13 Jan 2009 20:47:08 -0600 Subject: [PATCH] Add selection-required? slot to table gadget, which if set ensures that some item is always selected if the model is not empty --- basis/ui/gadgets/tables/tables.factor | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/basis/ui/gadgets/tables/tables.factor b/basis/ui/gadgets/tables/tables.factor index e54d219ba6..b54dd0b425 100644 --- a/basis/ui/gadgets/tables/tables.factor +++ b/basis/ui/gadgets/tables/tables.factor @@ -20,7 +20,7 @@ TUPLE: table < gadget renderer filled-column column-alignment action column-widths total-width font text-color selection-color focus-border-color -mouse-color column-line-color +mouse-color column-line-color selection-required? selected-index selected-value mouse-index focused? ; @@ -206,11 +206,12 @@ PRIVATE> : update-selected-value ( table -- ) [ selected-row drop ] [ selected-value>> ] bi set-model ; +: initial-selected-index ( model table -- n/f ) + [ value>> length 1 >= ] [ selection-required?>> ] bi* and 0 f ? ; + M: table model-changed - nip - [ f >>selected-index update-selected-value ] - [ relayout ] - bi ; + tuck initial-selected-index >>selected-index + [ update-selected-value ] [ relayout ] bi ; : thin-row-rect ( table row -- rect ) row-rect [ { 0 1 } v* ] change-dim ;