<commit_before>KDScrollView         = require './../scrollview/scrollview.coffee'
KDTabHandleContainer = require './tabhandlecontainer.coffee'
KDTabHandleMoveNav   = require './tabhandlemovenav.coffee'

module.exports = class KDTabView extends KDScrollView

  constructor:(options = {}, data)->

    options.resizeTabHandles     ?= no
    options.maxHandleWidth       ?= 128
    options.minHandleWidth       ?= 30
    options.lastTabHandleMargin  ?= 0
    options.sortable             ?= no
    options.hideHandleContainer  ?= no
    options.hideHandleCloseIcons ?= no
    options.enableMoveTabHandle  ?= no
    options.detachPanes          ?= yes
    options.tabHandleContainer   ?= null
    options.tabHandleClass      or= KDTabHandleView
    options.paneData            or= []
    options.cssClass              = KD.utils.curry "kdtabview", options.cssClass

    # Is there a reason why are we setting those before super? ~ GG

    @handles                      = []
    @panes                        = []
    @selectedIndex                = []
    @tabConstructor               = options.tabClass ? KDTabPaneView
    @lastOpenPaneIndex            = 0

    # ---

    super options, data

    @activePane           = null
    @handlesHidden        = no
    @blockTabHandleResize = no

    @setTabHandleContainer options.tabHandleContainer
    @setTabHandleMoveNav()  if options.enableMoveTabHandle

    @hideHandleCloseIcons() if options.hideHandleCloseIcons
    @hideHandleContainer()  if options.hideHandleContainer

    @on "PaneRemoved", => @resizeTabHandles()
    @on "PaneAdded", =>
      @blockTabHandleResize = no
      @resizeTabHandles()
    @on "PaneDidShow", @bound "setActivePane"

    if options.paneData.length > 0
      @on "viewAppended", => @createPanes options.paneData

    @tabHandleContainer.on "mouseleave", =>
      if @blockTabHandleResize
        @blockTabHandleResize = no
        @resizeTabHandles()

  # ADD/REMOVE PANES
  createPanes:(paneData = @getOptions().paneData)->
    for paneOptions in paneData
      @addPane new @tabConstructor paneOptions, null

  addPane:(paneInstance, shouldShow = yes)->

    if paneInstance instanceof KDTabPaneView

      { tabHandleClass, sortable, detachPanes } = @getOptions()

      paneInstance.setOption "detachable", detachPanes
      @panes.push paneInstance

      { name, title, hiddenHandle, tabHandleView, closable, lazy } = paneInstance.getOptions()

      @addHandle newTabHandle = new tabHandleClass
        pane      : paneInstance
        title     : name or title
        hidden    : hiddenHandle
        cssClass  : KD.utils.slugify name.toLowerCase()
        view      : tabHandleView
        closable  : closable
        sortable  : sortable
        click     : (event)=> @handleMouseDownDefaultAction newTabHandle, event

      paneInstance.tabHandle = newTabHandle
      @appendPane paneInstance
      @showPane paneInstance  if shouldShow and not lazy

      @emit "PaneAdded", paneInstance

      {minHandleWidth, maxHandleWidth} = @getOptions()

      newTabHandle.getDomElement().css
        maxWidth : maxHandleWidth<commit_msg>TabView: Use tabpane's handle if exists.<commit_after>KDScrollView         = require './../scrollview/scrollview.coffee'
KDTabHandleContainer = require './tabhandlecontainer.coffee'
KDTabHandleMoveNav   = require './tabhandlemovenav.coffee'

module.exports = class KDTabView extends KDScrollView

  constructor:(options = {}, data)->

    options.resizeTabHandles     ?= no
    options.maxHandleWidth       ?= 128
    options.minHandleWidth       ?= 30
    options.lastTabHandleMargin  ?= 0
    options.sortable             ?= no
    options.hideHandleContainer  ?= no
    options.hideHandleCloseIcons ?= no
    options.enableMoveTabHandle  ?= no
    options.detachPanes          ?= yes
    options.tabHandleContainer   ?= null
    options.tabHandleClass      or= KDTabHandleView
    options.paneData            or= []
    options.cssClass              = KD.utils.curry "kdtabview", options.cssClass

    # Is there a reason why are we setting those before super? ~ GG

    @handles                      = []
    @panes                        = []
    @selectedIndex                = []
    @tabConstructor               = options.tabClass ? KDTabPaneView
    @lastOpenPaneIndex            = 0

    # ---

    super options, data

    @activePane           = null
    @handlesHidden        = no
    @blockTabHandleResize = no

    @setTabHandleContainer options.tabHandleContainer
    @setTabHandleMoveNav()  if options.enableMoveTabHandle

    @hideHandleCloseIcons() if options.hideHandleCloseIcons
    @hideHandleContainer()  if options.hideHandleContainer

    @on "PaneRemoved", => @resizeTabHandles()
    @on "PaneAdded", =>
      @blockTabHandleResize = no
      @resizeTabHandles()
    @on "PaneDidShow", @bound "setActivePane"

    if options.paneData.length > 0
      @on "viewAppended", => @createPanes options.paneData

    @tabHandleContainer.on "mouseleave", =>
      if @blockTabHandleResize
        @blockTabHandleResize = no
        @resizeTabHandles()

  # ADD/REMOVE PANES
  createPanes:(paneData = @getOptions().paneData)->
    for paneOptions in paneData
      @addPane new @tabConstructor paneOptions, null

  addPane:(paneInstance, shouldShow = yes)->

    if paneInstance instanceof KDTabPaneView

      { tabHandleClass, sortable, detachPanes } = @getOptions()

      paneInstance.setOption "detachable", detachPanes
      @panes.push paneInstance

      { name, title, hiddenHandle, tabHandleView, closable, lazy } = paneInstance.getOptions()

      newTabHandle = paneInstance.tabHandle or new tabHandleClass
        pane       : paneInstance
        title      : name or title
        hidden     : hiddenHandle
        cssClass   : KD.utils.slugify name.toLowerCase()
        view       : tabHandleView
        closable   : closable
        sortable   : sortable
        click      : (event)=> @handleMouseDownDefaultAction newTabHandle, event

      @addHandle newTabHandle

      paneInstance.tabHandle = newTabHandle
      @appendPane paneInstance

      @showPane paneInstance  if shouldShow and not lazy

      @emit "PaneAdded", paneInstance

      {minHandleWidth, maxHandleWidth} = @getOptions()

      newTabHandle.getDomElement().css
        maxWidth : maxHandleWidth
{'fraction_non_alphanumeric': 0.08438685208596713, 'fraction_numerical': 0.0025284450063211127, 'mean_word_length': 2.5616207090602137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '5267385', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1739, 'n_words': 393}