<commit_before>#require ST/Destructable
#require ST/List
#require ST/ViewHelper

ST.class 'View', 'Destructable', ->
  @ViewWithContent = (content) ->
    view = @create()
    view.load()
    view.element().append content
    view
    
  @initializer ->
    element = ST.ViewHelper.instance().tag('div')
    element.addClass @_class._name
    @initWithElement element
  
  @initializer 'withElement', (element) ->
    ST.Destructable.method('init').call this
    @_element = element
    @_loaded = false
    @_children = ST.List.create()
    @_children.bind 'itemAdded',   this, 'childAdded'
    @_children.bind 'itemRemoved', this, 'childRemoved'
  
  @property 'parent'
  @property 'children', 'read'
  @property 'element',  'read'
  @property 'loaded',   'read'
  
  @retainedProperty 'header'
  @retainedProperty 'footer'
  
  @delegate 'add', 'children', 'addChild'
  @delegate 'remove', 'children', 'removeChild'

  @destructor ->
    @unload() if @_loaded
    @_children.empty()
    @_children.unbind this
    @_element.remove()
    @super()
  
  @method 'helper', ->
    ST.ViewHelper.instance()
    
  # Sets a view as the header for this view. Headers always remain above
  # any content and all child views for a view.
  @method '_headerChanged', (oldHeader, newHeader) ->
    oldHeader.element().detach() if oldHeader
    if newHeader && @_loaded
      newHeader.load()
      @_element.prepend newHeader.element()
  
  # Sets a view as the footer for this view. Footers always remain below
  # any content and all child views for a view.
  @method '_footerChanged', (oldFooter, newFooter) ->
    oldFooter.element().detach() if oldFooter
    if newFooter && @_loaded
      newFooter.load()
      @_element.append newFooter.element()
  
  @method 'childAdded', (children, child) ->
    child.parent this
    if @_loaded
      child.load()
      if @_footer
        @_footer.element().before child.element()
      else
        @_element.append child.element()
  
  @method 'childRemoved', (children, child) ->
    child.element().detach() if @_loaded
  
  @method 'load', ->
    unless @_loaded
      @trigger 'loading'
    
      if @_header
        @element().append @_header.element()
        @_header.load()
        
      @render() if @render
      @loadChildren()
      
      if @_footer
        @_element.append @_footer.element()
        @_footer.load()
    
      @_loaded = true
      @trigger 'loaded'
    
  @method 'loadChildren', ->
    element = @_element
    @_children.each (child) ->
      element.append child.element()
      child.load()
  
  @method 'unload', ->
    if @_loaded
      @trigger 'unloading'
      @_header.element().detach() if @_header
      @_footer.element().detach() if @_footer
      @unloadChildren()
      @_element.empty()
      @_element.remove()
      @_loaded = false
      @trigger 'unloaded'
    
  @method 'unloadChildren', ->
    @_children.each (child) ->
      child.unload()
      child.element().detach()
    
  @method 'reload', ->
    @unload()
    @load()
  
  @method 'show', ->
    @load() unless @_loaded
    @element().show()
  
  @method 'hide', ->
    @element().hide()
        
  @method 'scrollTo', -> $.scrollTo @_element
  
  @method 'showDialog', (events) -> Dialog.showView this, events<commit_msg>Created View#visible property, which can be changed with #show and #hide<commit_after>#require ST/Destructable
#require ST/List
#require ST/ViewHelper

ST.class 'View', 'Destructable', ->
  @ViewWithContent = (content) ->
    view = @create()
    view.load()
    view.element().append content
    view
    
  @initializer ->
    element = ST.ViewHelper.instance().tag('div')
    element.addClass @_class._name
    @initWithElement element
  
  @initializer 'withElement', (element) ->
    ST.Destructable.method('init').call this
    @_element = element
    @_loaded = false
    @_visible = true
    @_children = ST.List.create()
    @_children.bind 'itemAdded',   this, 'childAdded'
    @_children.bind 'itemRemoved', this, 'childRemoved'
  
  @property 'parent'
  @property 'children', 'read'
  @property 'element',  'read'
  @property 'loaded',   'read'
  @property 'visible'
  
  @retainedProperty 'header'
  @retainedProperty 'footer'
  
  @delegate 'add', 'children', 'addChild'
  @delegate 'remove', 'children', 'removeChild'

  @destructor ->
    @unload() if @_loaded
    @_children.empty()
    @_children.unbind this
    @_element.remove()
    @super()
  
  @method 'helper', ->
    ST.ViewHelper.instance()
    
  # Sets a view as the header for this view. Headers always remain above
  # any content and all child views for a view.
  @method '_headerChanged', (oldHeader, newHeader) ->
    oldHeader.element().detach() if oldHeader
    if newHeader && @_loaded
      newHeader.load()
      @_element.prepend newHeader.element()
  
  # Sets a view as the footer for this view. Footers always remain below
  # any content and all child views for a view.
  @method '_footerChanged', (oldFooter, newFooter) ->
    oldFooter.element().detach() if oldFooter
    if newFooter && @_loaded
      newFooter.load()
      @_element.append newFooter.element()
  
  @method 'childAdded', (children, child) ->
    child.parent this
    if @_loaded
      child.load()
      if @_footer
        @_footer.element().before child.element()
      else
        @_element.append child.element()
  
  @method 'childRemoved', (children, child) ->
    child.element().detach() if @_loaded
  
  @method 'load', ->
    unless @_loaded
      @trigger 'loading'
    
      if @_header
        @element().append @_header.element()
        @_header.load()
        
      @render() if @render
      @loadChildren()
      
      if @_footer
        @_element.append @_footer.element()
        @_footer.load()
    
      @_loaded = true
      @trigger 'loaded'
    
  @method 'loadChildren', ->
    element = @_element
    @_children.each (child) ->
      element.append child.element()
      child.load()
  
  @method 'unload', ->
    if @_loaded
      @trigger 'unloading'
      @_header.element().detach() if @_header
      @_footer.element().detach() if @_footer
      @unloadChildren()
      @_element.empty()
      @_element.remove()
      @_loaded = false
      @trigger 'unloaded'
    
  @method 'unloadChildren', ->
    @_children.each (child) ->
      child.unload()
      child.element().detach()
    
  @method 'reload', ->
    @unload()
    @load()
  
  @method 'show', ->
    @visible true
  
  @method 'hide', ->
    @visible false
  
  @method '_visibleChanged', (oldValue, newValue) ->
    if newValue
      @load() unless @_loaded
      @element().show()
    else
      @element().hide()
        
  @method 'scrollTo', -> $.scrollTo @_element
  
  @method 'showDialog', (events) -> Dialog.showView this, events
{'fraction_non_alphanumeric': 0.1388561320754717, 'fraction_numerical': 0.0, 'mean_word_length': 2.6715367965367967, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 46, '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': '5066856', 'n_tokens_mistral': 2152, 'n_tokens_neox': 2145, 'n_words': 528}