From ef52d1b94d6a18e0d9d62c18068d26d54eafa780 Mon Sep 17 00:00:00 2001 From: Sam Anklesaria Date: Wed, 27 May 2009 10:26:26 -0500 Subject: [PATCH] ui.gadgets.tables uses arrays, not vectors --- basis/inverse/inverse.factor | 16 ++++++++++++++-- basis/inverse/vectors/authors.txt | 1 - basis/inverse/vectors/summary.txt | 1 - basis/inverse/vectors/vectors.factor | 24 ------------------------ basis/ui/gadgets/tables/tables.factor | 25 +++++++++++++------------ 5 files changed, 27 insertions(+), 40 deletions(-) delete mode 100644 basis/inverse/vectors/authors.txt delete mode 100755 basis/inverse/vectors/summary.txt delete mode 100644 basis/inverse/vectors/vectors.factor diff --git a/basis/inverse/inverse.factor b/basis/inverse/inverse.factor index cf97a0b2c8..7a9e821b37 100755 --- a/basis/inverse/inverse.factor +++ b/basis/inverse/inverse.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2007, 2009 Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors kernel words summary slots quotations +USING: accessors kernel locals words summary slots quotations sequences assocs math arrays stack-checker effects continuations debugger classes.tuple namespaces make vectors bit-arrays byte-arrays strings sbufs math.functions macros @@ -231,6 +231,18 @@ DEFER: __ \ output>sequence 2 [ [undo] '[ dup _ assure-same-class _ inputsequence ] ] define-pop-inverse +! conditionals + +:: undo-if-empty ( result a b -- seq ) + a call( -- b ) result = [ { } ] [ result b [undo] call( a -- b ) ] if ; + +:: undo-if* ( result a b -- boolean ) + b call( -- b ) result = [ f ] [ result a [undo] call( a -- b ) ] if ; + +\ if-empty 2 [ swap [ undo-if-empty ] 2curry ] define-pop-inverse + +\ if* 2 [ swap [ undo-if* ] 2curry ] define-pop-inverse + ! Constructor inverse : deconstruct-pred ( class -- quot ) "predicate" word-prop [ dupd call assure ] curry ; @@ -283,4 +295,4 @@ M: no-match summary drop "Fall through in switch" ; reverse [ [ [undo] ] dip compose ] { } assoc>map recover-chain ; -MACRO: switch ( quot-alist -- ) [switch] ; +MACRO: switch ( quot-alist -- ) [switch] ; \ No newline at end of file diff --git a/basis/inverse/vectors/authors.txt b/basis/inverse/vectors/authors.txt deleted file mode 100644 index f990dd0ed2..0000000000 --- a/basis/inverse/vectors/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Daniel Ehrenberg diff --git a/basis/inverse/vectors/summary.txt b/basis/inverse/vectors/summary.txt deleted file mode 100755 index cb3c22991d..0000000000 --- a/basis/inverse/vectors/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Inverses of Common Words on Vectors diff --git a/basis/inverse/vectors/vectors.factor b/basis/inverse/vectors/vectors.factor deleted file mode 100644 index 4672aed3ec..0000000000 --- a/basis/inverse/vectors/vectors.factor +++ /dev/null @@ -1,24 +0,0 @@ -USING: generalizations inverse kernel locals sequences vectors ; -IN: inverse.vectors -: assure-vector ( vector -- vector ) - dup vector? assure ; inline - -: undo-nvector ( array n -- ... ) - [ assure-vector ] dip - firstn ; inline - -\ 1vector [ 1 undo-nvector ] define-inverse - -\ last [ 1vector ] define-inverse - -! if is too general to undo, but its derivatives aren't - -:: undo-if-empty ( result a b -- seq ) - a call( -- b ) result = [ V{ } clone ] [ result b [undo] call( a -- b ) ] if ; - -:: undo-if* ( result a b -- boolean ) - b call( -- b ) result = [ f ] [ result a [undo] call( a -- b ) ] if ; - -\ if-empty 2 [ swap [ undo-if-empty ] 2curry ] define-pop-inverse - -\ if* 2 [ swap [ undo-if* ] 2curry ] define-pop-inverse diff --git a/basis/ui/gadgets/tables/tables.factor b/basis/ui/gadgets/tables/tables.factor index fdeb7e05f9..e3ffa9237d 100644 --- a/basis/ui/gadgets/tables/tables.factor +++ b/basis/ui/gadgets/tables/tables.factor @@ -7,7 +7,7 @@ ui.gadgets.scrollers ui.gadgets.status-bar ui.gadgets.worlds ui.gestures ui.render ui.pens.solid ui.text ui.commands ui.images ui.gadgets.menus ui.gadgets.line-support models combinators combinators.short-circuit -fonts locals strings vectors ; +fonts locals strings sorting ; IN: ui.gadgets.tables ! Row rendererer protocol @@ -49,8 +49,8 @@ mouse-index focused? multiple-selection? ; -: in>out ( vector -- val/f ) [ f ] [ last ] if-empty ; -: out>in ( val/f -- vector ) [ 1vector ] [ V{ } clone ] if* ; +: in>out ( array -- val/f ) [ f ] [ first ] if-empty ; +: out>in ( val/f -- array ) [ 1array ] [ { } ] if* ; IN: accessors SLOT: selected-value SLOT: selected-index @@ -63,15 +63,16 @@ M: table selected-index*>> selected-indices*>> [ in>out ] ; M: table (>>selected-index*) [ [ out>in ] ] dip (>>selected-indices*) ; IN: ui.gadgets.tables -: push-selected-index ( table n -- table ) 2dup swap selected-indices>> index [ drop ] [ over selected-indices>> push ] if ; +: push-selected-index ( table n -- table ) 2dup swap selected-indices>> index + [ drop ] [ over selected-indices>> swap suffix natural-sort >>selected-indices ] if ; : new-table ( rows renderer class -- table ) new-line-gadget swap >>renderer swap >>model - V{ } clone >>selected-indices - V{ } clone >>selected-values - V{ } clone >>selected-indices* + { } >>selected-indices + { } >>selected-values + { } >>selected-indices* sans-serif-font >>font focus-border-color >>focus-border-color transparent >>column-line-color ; inline @@ -259,12 +260,12 @@ PRIVATE> : (selected-rows) ( table -- {row} ) [ selected-indices>> ] keep - [ nth-row [ 1array ] [ drop { } ] if ] curry map concat >vector ; + [ nth-row [ 1array ] [ drop { } ] if ] curry map concat ; : selected-rows ( table -- {value} ) [ (selected-rows) ] [ renderer>> ] bi [ row-value ] curry map ; -: multiple>single ( values -- value/f ? ) [ f f ] [ last t ] if-empty ; +: multiple>single ( values -- value/f ? ) [ f f ] [ first t ] if-empty ; : (selected-row) ( table -- value/f ? ) (selected-rows) multiple>single ; : selected-row ( table -- value/f ? ) selected-rows multiple>single ; @@ -290,7 +291,7 @@ PRIVATE> { [ model>> value>> empty? not ] [ selection-required?>> ] - [ drop V{ 0 } clone ] + [ drop { 0 } ] } 1&& ; : (update-selected-indices) ( table -- {n}/f ) @@ -304,9 +305,9 @@ PRIVATE> } 1|| ; M: table model-changed - nip dup update-selected-indices [ V{ } clone ] unless* { + nip dup update-selected-indices [ { } ] unless* { [ >>selected-indices f >>mouse-index drop ] - [ [ f ] [ last ] if-empty show-row-summary ] + [ [ f ] [ first ] if-empty show-row-summary ] [ drop update-selected-values ] [ drop relayout ] } 2cleave ;