<commit_before>$ = require 'jquery'
{View} = require 'space-pen'
Tab = require 'tabs/src/tab'

module.exports =
class Tabs extends View
  @activate: (rootView) ->
    rootView.eachEditor (editor) =>
      @prependToEditorPane(rootView, editor) if editor.attached

  @prependToEditorPane: (rootView, editor) ->
    if pane = editor.pane()
      pane.prepend(new Tabs(editor))

  @content: ->
    @ul class: 'tabs'

  initialize: (@editor) ->
    for editSession, index in @editor.editSessions
      @addTabForEditSession(editSession)

    @setActiveTab(@editor.getActiveEditSessionIndex())
    @editor.on 'editor:active-edit-session-changed', (e, editSession, index) => @setActiveTab(index)
    @editor.on 'editor:edit-session-added', (e, editSession) => @addTabForEditSession(editSession)
    @editor.on 'editor:edit-session-removed', (e, editSession, index) => @removeTabAtIndex(index)

    @on 'click', '.tab', (e) =>
      @editor.setActiveEditSessionIndex($(e.target).closest('.tab').index())
      @editor.focus()

    @on 'click', '.tab .close-icon', (e) =>
      index = $(e.target).closest('.tab').index()
      @editor.destroyEditSessionIndex(index)
      false

    @on 'dragstart', '.tab', (e) ->
      console.log 'TAB DRAGGED', e

  addTabForEditSession: (editSession) ->
    @append(new Tab(editSession, @editor))

  setActiveTab: (index) ->
    @find(".tab.active").removeClass('active')
    @find(".tab:eq(#{index})").addClass('active')

  removeTabAtIndex: (index) ->
    @find(".tab:eq(#{index})").remove()<commit_msg>basics of drag and drop support<commit_after>$ = require 'jquery'
{View} = require 'space-pen'
Tab = require 'tabs/src/tab'

module.exports =
class Tabs extends View
  dndType: 'text/x-atom-tab'

  @activate: (rootView) ->
    rootView.eachEditor (editor) =>
      @prependToEditorPane(rootView, editor) if editor.attached

  @prependToEditorPane: (rootView, editor) ->
    if pane = editor.pane()
      pane.prepend(new Tabs(editor))

  @content: ->
    @ul class: 'tabs'

  initialize: (@editor) ->
    for editSession, index in @editor.editSessions
      @addTabForEditSession(editSession)

    @setActiveTab(@editor.getActiveEditSessionIndex())
    @editor.on 'editor:active-edit-session-changed', (e, editSession, index) => @setActiveTab(index)
    @editor.on 'editor:edit-session-added', (e, editSession) => @addTabForEditSession(editSession)
    @editor.on 'editor:edit-session-removed', (e, editSession, index) => @removeTabAtIndex(index)

    @on 'click', '.tab', (e) =>
      @editor.setActiveEditSessionIndex($(e.target).closest('.tab').index())
      @editor.focus()

    @on 'click', '.tab .close-icon', (e) =>
      index = $(e.target).closest('.tab').index()
      @editor.destroyEditSessionIndex(index)
      false

    @on 'dragstart', '.tab', @onDragStart
    @on 'dragend',   '.tab', @onDragEnd
    @on 'dragenter', '.tab', @onDragEnter
    @on 'dragleave', '.tab', @onDragLeave

  onDragStart: (event) =>
    $(event.target).addClass 'is-dragging'

  onDragEnd: (event) =>
    $(event.target).removeClass 'is-dragging'

  onDragEnter: (event) =>
    el = $(event.target)
    el = el.closest('.tab') if !el.hasClass('tab')
    el.addClass 'is-drop-target'

  onDragLeave: (event) =>
    el = $(event.target)
    el.removeClass 'is-drop-target' if el.hasClass 'tab'

  addTabForEditSession: (editSession) ->
    @append(new Tab(editSession, @editor))

  setActiveTab: (index) ->
    @find(".tab.active").removeClass('active')
    @find(".tab:eq(#{index})").addClass('active')

  removeTabAtIndex: (index) ->
    @find(".tab:eq(#{index})").remove()
{'fraction_non_alphanumeric': 0.18106081643987781, 'fraction_numerical': 0.0, 'mean_word_length': 3.920765027322404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 34, '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': '4699138', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1199, 'n_words': 231}