<commit_before>class TeamworkTabView extends CollaborativePane

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

    super options, data

    @createElements()
    @keysRef  = @workspaceRef.child "keys"
    @indexRef = @workspaceRef.child "index"

    @tabView.on "PaneDidShow", (pane) =>
      @indexRef.set pane.getOptions().indexKey

    @indexRef.on "value", (snapshot) =>
      key = snapshot.val()
      return unless key

      for pane in @tabView.panes
        if pane.getOptions().indexKey is key
          @tabView.showPaneByIndex @tabView.getPaneIndex pane

    @keysRef.on "child_added", (snapshot) =>
      data    = snapshot.val()
      key     = data.indexKey
      {panes} = @tabView
      isExist = yes for pane in panes when pane.getOptions().indexKey is key

      @createTabFromFirebaseData data  unless isExist

    @keysRef.on "child_removed", (snapshot) =>
      data = snapshot.val()
      return unless data

      {indexKey} = data
      for pane in @tabView.panes
        if pane.getOptions().indexKey is indexKey
          @tabView.removePane pane

  createElements: ->
    @tabHandleHolder = new ApplicationTabHandleHolder delegate: this
    @tabView         = new ApplicationTabView
      delegate                  : this
      lastTabHandleMargin       : 200
      tabHandleContainer        : @tabHandleHolder
      closeAppWhenAllTabsClosed : no

  addNewTab: ->
    @createPlusHandleDropDown()

  createPlusHandleDropDown: ->
    offset        = @tabHandleHolder.plusHandle.$().offset()
    contextMenu   = new JContextMenu
      delegate    : this
      x           : offset.left - 125
      y           : offset.top  + 30
      arrow       :
        placement : "top"
        margin    : -20
    , @getDropdownItems()

    contextMenu.once "ContextMenuItemReceivedClick", ->
      contextMenu.destroy()

  getDropdownItems: ->
    return {
      "Dashboard" :
        separator : yes
        callback  : => @createDashboard()
      "Editor"    :
        callback  : => @createEditor()
      "Terminal"  :
        callback  : => @createTerminal()
      "Preview"   :
        callback  : => @createPreview()
      "Chat"      :
        callback  : => @createChat()
      "Drawing Board":
        callback  : => @createDrawingBoard()
    }


  createDashboard: ->
    return @tabView.showPane @dashboard  if @dashboard

    @dashboard = new KDTabPaneView title: "Dashboard"
    dashboard  = new TeamworkDashboard
      delegate : @workspace.getDelegate()

    @appendPane_ @dashboard, dashboard

    @dashboard.once "KDObjectWillBeDestroyed", =>
      @dashboard = null

    @keysRef.push type: "dashboard"  if @amIHost

  openFile: (file, content) -><commit_msg>Teamwork: Added createTabFormFirebaseData method to TeamworkTabView.<commit_after>class TeamworkTabView extends CollaborativePane

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

    super options, data

    @createElements()
    @keysRef  = @workspaceRef.child "keys"
    @indexRef = @workspaceRef.child "index"

    @tabView.on "PaneDidShow", (pane) =>
      @indexRef.set pane.getOptions().indexKey

    @indexRef.on "value", (snapshot) =>
      key = snapshot.val()
      return unless key

      for pane in @tabView.panes
        if pane.getOptions().indexKey is key
          @tabView.showPaneByIndex @tabView.getPaneIndex pane

    @keysRef.on "child_added", (snapshot) =>
      data    = snapshot.val()
      key     = data.indexKey
      {panes} = @tabView
      isExist = yes for pane in panes when pane.getOptions().indexKey is key

      @createTabFromFirebaseData data  unless isExist

    @keysRef.on "child_removed", (snapshot) =>
      data = snapshot.val()
      return unless data

      {indexKey} = data
      for pane in @tabView.panes
        if pane.getOptions().indexKey is indexKey
          @tabView.removePane pane

  createElements: ->
    @tabHandleHolder = new ApplicationTabHandleHolder delegate: this
    @tabView         = new ApplicationTabView
      delegate                  : this
      lastTabHandleMargin       : 200
      tabHandleContainer        : @tabHandleHolder
      closeAppWhenAllTabsClosed : no

  addNewTab: ->
    @createPlusHandleDropDown()

  createPlusHandleDropDown: ->
    offset        = @tabHandleHolder.plusHandle.$().offset()
    contextMenu   = new JContextMenu
      delegate    : this
      x           : offset.left - 125
      y           : offset.top  + 30
      arrow       :
        placement : "top"
        margin    : -20
    , @getDropdownItems()

    contextMenu.once "ContextMenuItemReceivedClick", ->
      contextMenu.destroy()

  getDropdownItems: ->
    return {
      "Dashboard" :
        separator : yes
        callback  : => @createDashboard()
      "Editor"    :
        callback  : => @createEditor()
      "Terminal"  :
        callback  : => @createTerminal()
      "Preview"   :
        callback  : => @createPreview()
      "Chat"      :
        callback  : => @createChat()
      "Drawing Board":
        callback  : => @createDrawingBoard()
    }

  createTabFromFirebaseData: (data) ->
    {sessionKey, indexKey} = data
    switch data.type
      when "dashboard" then @createDashboard()
      when "terminal"  then @createTerminal     sessionKey, indexKey
      when "preview"   then @createPreview      sessionKey, indexKey
      when "drawing"   then @createDrawingBoard sessionKey, indexKey
      when "editor"
        file = FSHelper.createFileFromPath data.filePath
        @createEditor file, "", sessionKey, indexKey

  createDashboard: ->
    return @tabView.showPane @dashboard  if @dashboard

    @dashboard = new KDTabPaneView title: "Dashboard"
    dashboard  = new TeamworkDashboard
      delegate : @workspace.getDelegate()

    @appendPane_ @dashboard, dashboard

    @dashboard.once "KDObjectWillBeDestroyed", =>
      @dashboard = null

    @keysRef.push type: "dashboard"  if @amIHost

  openFile: (file, content) ->
{'fraction_non_alphanumeric': 0.10022007787370917, 'fraction_numerical': 0.0033858134416793633, 'mean_word_length': 2.3740719588806396, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 42, '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': '3822898', 'n_tokens_mistral': 1764, 'n_tokens_neox': 1704, 'n_words': 403}