]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorSam Anklesaria <sam@Tintin.local>
Wed, 22 Jul 2009 15:02:09 +0000 (10:02 -0500)
committerSam Anklesaria <sam@Tintin.local>
Wed, 22 Jul 2009 15:02:09 +0000 (10:02 -0500)
Conflicts:
basis/functors/functors.factor
basis/io/launcher/launcher.factor
basis/ui/gadgets/tables/tables.factor

1  2 
basis/functors/functors.factor
basis/ui/gadgets/tables/tables.factor
core/vocabs/parser/parser.factor

index ccd1e9618ed7bed74f27db197db62cd9bbf7b21b,51295159807cd5441e72b737ed06612fea5e106a..5f519aeecefe41ad70e489bafe35c84d9f963859
@@@ -1,11 -1,11 +1,11 @@@
  ! Copyright (C) 2008, 2009 Slava Pestov.
  ! See http://factorcode.org/license.txt for BSD license.
 -USING: accessors arrays classes.mixin classes.parser classes.singleton
 -classes.tuple classes.tuple.parser combinators effects effects.parser
 -fry generic generic.parser generic.standard interpolate
 -io.streams.string kernel lexer locals.parser locals.rewrite.closures
 -locals.types make namespaces parser quotations sequences vocabs.parser
 -words words.symbol ;
 +USING: accessors arrays classes.mixin classes.parser
- classes.tuple classes.tuple.parser combinators effects
- effects.parser fry generic generic.parser generic.standard
- interpolate io.streams.string kernel lexer locals.parser
- locals.rewrite.closures locals.types make macros namespaces
- parser quotations sequences vocabs.parser words words.symbol ;
++classes.singleton classes.tuple classes.tuple.parser
++combinators effects.parser fry generic generic.parser
++generic.standard interpolate io.streams.string kernel lexer
++locals.parser locals.types macros make namespaces parser
++quotations sequences vocabs.parser words words.symbol ;
  IN: functors
  
  ! This is a hack
@@@ -71,6 -71,14 +71,14 @@@ SYNTAX: `TUPLE
      } case
      \ define-tuple-class parsed ;
  
+ SYNTAX: `SINGLETON:
+     scan-param parsed
+     \ define-singleton-class parsed ;
+ SYNTAX: `MIXIN:
+     scan-param parsed
+     \ define-mixin-class parsed ;
  SYNTAX: `M:
      scan-param parsed
      scan-param parsed
@@@ -109,11 -117,6 +117,11 @@@ SYNTAX: `GENERIC
      complete-effect parsed
      \ define-simple-generic* parsed ;
  
 +SYNTAX: `MACRO:
 +    scan-param parsed
 +    parse-declared*
 +    \ define-macro parsed ;
 +
  SYNTAX: `inline [ word make-inline ] over push-all ;
  
  SYNTAX: `call-next-method T{ fake-call-next-method } parsed ;
@@@ -126,6 -129,8 +134,8 @@@ PRIVATE
  
  SYNTAX: IS [ dup search [ ] [ no-word ] ?if ] (INTERPOLATE) ;
  
+ SYNTAX: DEFERS [ current-vocab create ] (INTERPOLATE) ;
  SYNTAX: DEFINES [ create-in ] (INTERPOLATE) ;
  
  SYNTAX: DEFINES-CLASS [ create-class-in ] (INTERPOLATE) ;
@@@ -137,6 -142,8 +147,8 @@@ DEFER: ;FUNCTOR delimite
  : functor-words ( -- assoc )
      H{
          { "TUPLE:" POSTPONE: `TUPLE: }
+         { "SINGLETON:" POSTPONE: `SINGLETON: }
+         { "MIXIN:" POSTPONE: `MIXIN: }
          { "M:" POSTPONE: `M: }
          { "C:" POSTPONE: `C: }
          { ":" POSTPONE: `: }
          { "SYNTAX:" POSTPONE: `SYNTAX: }
          { "SYMBOL:" POSTPONE: `SYMBOL: }
          { "inline" POSTPONE: `inline }
 +        { "MACRO:" POSTPONE: `MACRO: }
          { "call-next-method" POSTPONE: `call-next-method }
      } ;
  
index c0b792785dc75f729ab7e4b5a96e741701b7f52e,3beb0af79f946a75cbe630b046a982005c725a2a..353dd912701ee825e2d2a282bb61e2814b533e13
@@@ -1,13 -1,12 +1,13 @@@
  ! Copyright (C) 2008, 2009 Slava Pestov.
  ! See http://factorcode.org/license.txt for BSD license.
  USING: accessors arrays colors colors.constants fry kernel math
 -math.functions math.rectangles math.order math.vectors namespaces
 -opengl sequences ui.gadgets 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 math.ranges combinators
 -combinators.short-circuit fonts locals strings ;
 +math.functions math.ranges math.rectangles math.order math.vectors
 +models.illusion namespaces opengl sequences ui.gadgets
 +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 sorting ;
  IN: ui.gadgets.tables
  
  ! Row rendererer protocol
@@@ -42,37 -41,16 +42,37 @@@ focus-border-colo
  { mouse-color initial: COLOR: black }
  column-line-color
  selection-required?
 -selected-index selected-value
 +selected-indices selected-values
 +selected-indices*
  mouse-index
  { takes-focus? initial: t }
 -focused? ;
 +focused?
 +multiple-selection? ;
 +
 +: in>out ( array -- val/f ) [ f ] [ first ] if-empty ;
 +: out>in ( val/f -- array ) [ 1array ] [ { } ] if* ;
 +IN: accessors
 +SLOT: selected-value
 +SLOT: selected-index
 +SLOT: selected-index*
 +M: table selected-value>> selected-values>> [ in>out ] <illusion> ;
 +M: table (>>selected-value) [ [ out>in ] <activated-illusion> ] dip (>>selected-values) ;
 +M: table selected-index>> selected-indices>> in>out ;
 +M: table (>>selected-index) [ out>in ] dip (>>selected-indices) ;
 +M: table selected-index*>> selected-indices*>> [ in>out ] <illusion> ;
 +M: table (>>selected-index*) [ [ out>in ] <activated-illusion> ] dip (>>selected-indices*) ;
 +
 +IN: ui.gadgets.tables
 +: 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
 -        f <model> >>selected-value
 +        { } >>selected-indices
 +        { } <model> >>selected-values
 +        { } <model> >>selected-indices*
          sans-serif-font >>font
          focus-border-color >>focus-border-color
          transparent >>column-line-color ; inline
@@@ -153,12 -131,12 +153,12 @@@ M: table layout
  : row-bounds ( table row -- loc dim )
      row-rect rect-bounds ; inline
  
 -: draw-selected-row ( table -- )
 +: draw-selected-rows ( table -- )
      {
 -        { [ dup selected-index>> not ] [ drop ] }
 +        { [ dup selected-indices>> empty? ] [ drop ] }
          [
 -            [ ] [ selected-index>> ] [ selection-color>> gl-color ] tri
 -            row-bounds gl-fill-rect
 +            [ selected-indices>> ] [ selection-color>> gl-color ] [ ] tri
 +            [ swap row-bounds gl-fill-rect ] curry each
          ]
      } cond ;
  
      dup renderer>> column-alignment
      [ ] [ column-widths>> length 0 <repetition> ] ?if ;
  
 -:: row-font ( row index table -- font )
 +:: row-font ( row ind table -- font )
      table font>> clone
      row table renderer>> row-color [ >>foreground ] when*
 -    index table selected-index>> = [ table selection-color>> >>background ] when ;
 +    ind table selected-indices>> index [ table selection-color>> >>background ] when ;
  
  : draw-columns ( columns widths alignment font gap -- )
      '[ [ _ ] 3dip _ draw-column ] 3each ;
@@@ -235,7 -213,7 +235,7 @@@ M: table draw-gadget
      dup control-value empty? [ drop ] [
          dup line-height \ line-height [
              {
 -                [ draw-selected-row ]
 +                [ draw-selected-rows ]
                  [ draw-lines ]
                  [ draw-column-lines ]
                  [ draw-focused-row ]
@@@ -258,22 -236,17 +258,22 @@@ M: table pref-dim
  
  PRIVATE>
  
 -: (selected-row) ( table -- value/f ? )
 -    [ selected-index>> ] keep nth-row ;
 +: (selected-rows) ( table -- {row} )
 +    [ selected-indices>> ] keep
 +    [ nth-row [ 1array ] [ drop { } ] if ] curry map concat ;
  
 -: selected-row ( table -- value/f ? )
 -    [ (selected-row) ] keep
 -    swap [ renderer>> row-value t ] [ 2drop f f ] if ;
 +: selected-rows ( table -- {value} )
 +    [ (selected-rows) ] [ renderer>> ] bi [ row-value ] curry map ;
 +
 +: 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 ;
  
  <PRIVATE
  
 -: update-selected-value ( table -- )
 -    [ selected-row drop ] [ selected-value>> ] bi set-model ;
 +: update-selected-values ( table -- )
 +    [ [ selected-rows ] [ selected-values>> ] bi set-model ]
 +    [ [ selected-indices>> ] [ selected-indices*>> ] bi set-model ] bi ;
  
  : show-row-summary ( table n -- )
      over nth-row
  : find-row-index ( value table -- n/f )
      [ model>> value>> ] [ renderer>> '[ _ row-value ] map index ] bi ;
  
 -: initial-selected-index ( table -- n/f )
 +: initial-selected-indices ( table -- {n}/f )
      {
          [ model>> value>> empty? not ]
          [ selection-required?>> ]
 -        [ drop 0 ]
 +        [ drop { 0 } ]
      } 1&& ;
  
 -: (update-selected-index) ( table -- n/f )
 -    [ selected-value>> value>> ] keep over
 -    [ find-row-index ] [ 2drop f ] if ;
 +: (update-selected-indices) ( table -- {n}/f )
 +    [ selected-values>> value>> ] keep
 +    [ find-row-index ] curry map [ ] filter [ f ] when-empty ;
  
 -: update-selected-index ( table -- n/f )
 +: update-selected-indices ( table -- {n}/f )
      {
 -        [ (update-selected-index) ]
 -        [ initial-selected-index ]
 +        [ (update-selected-indices) ]
 +        [ initial-selected-indices ]
      } 1|| ;
  
  M: table model-changed
 -    nip dup update-selected-index {
 -        [ >>selected-index f >>mouse-index drop ]
 -        [ show-row-summary ]
 -        [ drop update-selected-value ]
 +    nip dup update-selected-indices [ { } ] unless* {
 +        [ >>selected-indices f >>mouse-index drop ]
 +        [ [ f ] [ first ] if-empty show-row-summary ]
 +        [ drop update-selected-values ]
          [ drop relayout ]
      } 2cleave ;
  
  : thin-row-rect ( table row -- rect )
      row-rect [ { 0 1 } v* ] change-dim ;
  
 +: scroll-to-row ( table n -- )
 +    dup [ [ thin-row-rect ] [ drop ] 2bi scroll>rect ] [ 2drop ] if ;
 +
 +: add-selected-row ( table n -- )
 +    [ scroll-to-row ]
 +    [ push-selected-index relayout-1 ] 2bi ;
 +
  : (select-row) ( table n -- )
 -    [ dup [ [ thin-row-rect ] [ drop ] 2bi scroll>rect ] [ 2drop ] if ]
 +    [ scroll-to-row ]
      [ >>selected-index relayout-1 ]
      2bi ;
  
  : mouse-row ( table -- n )
      [ hand-rel second ] keep y>line ;
  
 -: if-mouse-row ( table true: ( table mouse-index -- ) false: ( table -- ) -- )
 +: if-mouse-row ( table true: ( mouse-index table -- ) false: ( table -- ) -- )
      [ [ mouse-row ] keep 2dup valid-line? ]
      [ ] [ '[ nip @ ] ] tri* if ; inline
  
 -: table-button-down ( table -- )
 -    dup takes-focus?>> [ dup request-focus ] when
 -    [ swap [ >>mouse-index ] [ (select-row) ] bi ] [ drop ] if-mouse-row ;
 +: (table-button-down) ( quot table -- )
 +    dup takes-focus?>> [ dup request-focus ] when swap
 +   '[ swap [ >>mouse-index ] _ bi ] [ drop ] if-mouse-row ; inline
 +
 +: table-button-down ( table -- ) [ (select-row) ] swap (table-button-down) ;
 +: continued-button-down ( table -- ) dup multiple-selection?>> [ [ add-selected-row ] swap (table-button-down) ] [ table-button-down ] if ;
 +: thru-button-down ( table -- ) dup multiple-selection?>> [
 +    [ 2dup over selected-index>> (a,b) swap
 +      [ swap push-selected-index drop ] curry each add-selected-row ]
 +    swap (table-button-down) ] [ table-button-down ] if ;
  
  PRIVATE>
  
      if ;
  
  : row-action? ( table -- ? )
-     [ [ mouse-row ] keep valid-line? ]
-     [ single-click?>> hand-click# get 2 = or ] bi and ;
+     single-click?>> hand-click# get 2 = or ;
  
  <PRIVATE
  
  : table-button-up ( table -- )
-     dup row-action? [ row-action ] [ update-selected-values ] if ;
+     dup [ mouse-row ] keep valid-line? [
 -        dup row-action? [ row-action ] [ update-selected-value ] if
++        dup row-action? [ row-action ] [ update-selected-values ] if
+     ] [ drop ] if ;
  
  PRIVATE>
  
  : select-row ( table n -- )
      over validate-line
      [ (select-row) ]
 -    [ drop update-selected-value ]
 +    [ drop update-selected-values ]
      [ show-row-summary ]
      2tri ;
  
@@@ -426,11 -386,8 +427,11 @@@ table "sundry" f 
      { mouse-enter show-mouse-help }
      { mouse-leave hide-mouse-help }
      { motion show-mouse-help }
 -    { T{ button-down } table-button-down }
 +    { T{ button-down f { S+ } 1 } thru-button-down }
 +    { T{ button-down f { A+ } 1 } continued-button-down }
      { T{ button-up } table-button-up }
 +    { T{ button-up f { S+ } } table-button-up }
 +    { T{ button-down } table-button-down }
      { gain-focus focus-table }
      { lose-focus unfocus-table }
      { T{ drag } table-button-down }
index 0bfb607a52f67c33a95374405b96851684e35ac3,7ac0bd2e58fd6b1298da969a847f5d9a8c9d7269..7ac0bd2e58fd6b1298da969a847f5d9a8c9d7269
mode 100755,100644..100755
@@@ -59,16 -59,19 +59,19 @@@ C: <extra-words> extra-word
      [ qualified-vocabs>> delete-all ]
      tri ;
  
+ ERROR: no-word-in-vocab word vocab ;
  <PRIVATE
  
  : (add-qualified) ( qualified -- )
      manifest get qualified-vocabs>> push ;
  
- : (from) ( vocab words -- vocab words words' assoc )
-     2dup swap load-vocab words>> ;
+ : (from) ( vocab words -- vocab words words' vocab )
+     2dup swap load-vocab ;
  
- : extract-words ( seq assoc -- assoc' )
-     extract-keys dup [ [ drop ] [ no-word-error ] if ] assoc-each ;
+ : extract-words ( seq vocab -- assoc' )
+     [ words>> extract-keys dup ] [ name>> ] bi
+     [ swap [ 2drop ] [ no-word-in-vocab ] if ] curry assoc-each ;
  
  : (lookup) ( name assoc -- word/f )
      at dup forward-reference? [ drop f ] when ;
@@@ -148,7 -151,7 +151,7 @@@ TUPLE: from vocab names words 
  TUPLE: exclude vocab names words ;
  
  : <exclude> ( vocab words -- from )
-     (from) [ nip ] [ extract-words ] 2bi assoc-diff exclude boa ;
+     (from) [ nip words>> ] [ extract-words ] 2bi assoc-diff exclude boa ;
  
  : add-words-excluding ( vocab words -- )
      <exclude> (add-qualified) ;
  TUPLE: rename word vocab words ;
  
  : <rename> ( word vocab new-name -- rename )
-     [ 2dup load-vocab words>> dupd at [ ] [ no-word-error ] ?if ] dip
+     [ 2dup load-vocab words>> dupd at [ ] [ swap no-word-in-vocab ] ?if ] dip
      associate rename boa ;
  
  : add-renamed-word ( word vocab new-name -- )