<commit_before>! Copyright (C) 2008 <NAME>
! See http://factorcode.org/license.txt for BSD license.

USING: accessors kernel fry math math.vectors sequences arrays vectors assocs
       hashtables models models.range models.compose combinators
       ui ui.gadgets ui.gadgets.buttons ui.gadgets.frames ui.gadgets.packs
       ui.gadgets.incremental ui.gadgets.viewports ui.gadgets.books ;

IN: ui.gadgets.tabs

TUPLE: tabbed names model toggler content ;

DEFER: (del-page)

: add-toggle ( model n name toggler -- )
    [ [ gadget-parent '[ , , , (del-page) ] "X" swap
       <bevel-button> @right frame, ] 3keep 
      [ swapd <toggle-button> @center frame, ] dip ] make-frame
    swap add-gadget ;

: redo-toggler ( tabbed -- )
     [ names>> ] [ model>> ] [ toggler>> ] tri
     [ clear-gadget ] keep
     [ [ length ] keep ] 2dip
    '[ , _ _ , add-toggle ] 2each ;

: refresh-book ( tabbed -- )
    model>> [ ] change-model ;

: (del-page) ( n name tabbed -- )
    { [ [ remove ] change-names redo-toggler ]
      [ dupd [ names>> length ] [ model>> ] bi
        [ [ = ] keep swap [ 1- ] when
          [ < ] keep swap [ 1- ] when ] change-model ]
      [ content>> nth-gadget unparent ]
      [ refresh-book ]
    } cleave ;

: add-page ( page name tabbed -- )
    [ names>> push ] 2keep
    [ [ model>> swap ]
      [ names>> length 1 - swap ]
      [ toggler>> ] tri add-toggle ]
    [ content>> add-gadget ]
    [ refresh-book ] tri ;

: del-page ( name tabbed -- )
    [ names>> index ] 2keep (del-page) ;

: <tabbed> ( assoc -- tabbed )
    tabbed new
    [ <pile> 1 >>fill g-> (>>toggler) @left frame,
      [ keys >vector g (>>names) ]
      [ values 0 <model> [ <book> g-> (>>content) @center frame, ] keep ] bi
      g swap >>model redo-toggler ] build-frame ;<commit_msg>ui.gadgets.tabs no longer uses delegation<commit_after>! Copyright (C) 2008 <NAME>
! See http://factorcode.org/license.txt for BSD license.

USING: accessors kernel fry math math.vectors sequences arrays vectors assocs
       hashtables models models.range models.compose combinators
       ui ui.gadgets ui.gadgets.buttons ui.gadgets.frames ui.gadgets.packs
       ui.gadgets.grids ui.gadgets.viewports ui.gadgets.books ;

IN: ui.gadgets.tabs

TUPLE: tabbed < frame names toggler content ;

DEFER: (del-page)

: add-toggle ( model n name toggler -- )
    [ [ gadget-parent '[ , , , (del-page) ] "X" swap
       <bevel-button> @right frame, ] 3keep 
      [ swapd <toggle-button> @center frame, ] dip ] make-frame
    swap add-gadget ;

: redo-toggler ( tabbed -- )
     [ names>> ] [ model>> ] [ toggler>> ] tri
     [ clear-gadget ] keep
     [ [ length ] keep ] 2dip
    '[ , _ _ , add-toggle ] 2each ;

: refresh-book ( tabbed -- )
    model>> [ ] change-model ;

: (del-page) ( n name tabbed -- )
    { [ [ remove ] change-names redo-toggler ]
      [ dupd [ names>> length ] [ model>> ] bi
        [ [ = ] keep swap [ 1- ] when
          [ < ] keep swap [ 1- ] when ] change-model ]
      [ content>> nth-gadget unparent ]
      [ refresh-book ]
    } cleave ;

: add-page ( page name tabbed -- )
    [ names>> push ] 2keep
    [ [ model>> swap ]
      [ names>> length 1 - swap ]
      [ toggler>> ] tri add-toggle ]
    [ content>> add-gadget ]
    [ refresh-book ] tri ;

: del-page ( name tabbed -- )
    [ names>> index ] 2keep (del-page) ;

: <tabbed> ( assoc -- tabbed )
    tabbed new-frame
    [ g 0 <model> >>model
      <pile> 1 >>fill [ >>toggler ] keep swap @left grid-add
      [ keys g swap >>names ]
      [ values g model>> <book> [ >>content ] keep swap @center grid-add ] bi
      g redo-toggler g ] with-gadget ;
{'fraction_non_alphanumeric': 0.14924137931034484, 'fraction_numerical': 0.007724137931034483, 'mean_word_length': 2.323556370302475, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 94, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2115976', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1271, 'n_words': 338}