<commit_before>{CompositeDisposable} = require 'atom'
HistoryView = null
ChangesView = null

HISTORY_URI = 'atom://git/view-history'
CHANGES_URI = 'atom://git/view-changes'

module.exports = GitExperiment =
  subscriptions: null
  historyView: null
  changesView: null
  state: null

  activate: (@state) ->
    # Events subscribed to in atom's system can be easily
    # cleaned up with a CompositeDisposable
    @subscriptions = new CompositeDisposable
    process.nextTick =>
      @subscriptions.add atom.workspace.onWillDestroyPaneItem (pane) =>
        switch pane.item
          when @historyView
            @state.history = @historyView.serialize()
          when @changesView
            @state.changes = @changesView.serialize()

      @subscriptions.add atom.workspace.registerOpener (filePath) =>
        switch filePath
          when HISTORY_URI
            @historyView or= if @state.history?
              atom.deserializers.deserialize(@state.history)
            else
              createHistoryView(uri: HISTORY_URI)
          when CHANGES_URI
            @changesView or= if @state.changes?
              atom.deserializers.deserialize(@state.changes)
            else
              createChangesView(uri: CHANGES_URI)

  deactivate: ->
    @subscriptions?.dispose()

  serialize: ->
    @state

  openHistoryView: ->
    atom.workspace.open(HISTORY_URI)

  openChangesView: ->
    atom.workspace.open(CHANGES_URI)

atom.commands.add 'atom-workspace', 'git:view-history', =>
  GitExperiment.openHistoryView()

atom.commands.add 'atom-workspace', 'git:view-and-commit-changes', =>
  GitExperiment.openChangesView()

createHistoryView = (state) ->
 HistoryView ?= require './history/history-view'
 view = new HistoryView
 view.initialize(state)
 view

createChangesView = (state) ->
  ChangesView ?= require './changes/changes-view'
  view = new ChangesView
  view.initialize(state)
  view

atom.deserializers.add
  name: 'GitHistoryView'
  deserialize: (state) -> createHistoryView(state)

atom.deserializers.add
  name: 'GitChangesView'
  deserialize: (state) -> createChangesView(state)<commit_msg>Properly serialize panes<commit_after>{CompositeDisposable} = require 'atom'
HistoryView = null
ChangesView = null

HISTORY_URI = 'atom://git/view-history'
CHANGES_URI = 'atom://git/view-changes'

changesView = null
historyView = null
serializedState = {}

module.exports = GitExperiment =
  subscriptions: null
  state: null

  activate: (@state) ->
    # Events subscribed to in atom's system can be easily
    # cleaned up with a CompositeDisposable
    @subscriptions = new CompositeDisposable
    process.nextTick =>
      @subscriptions.add atom.workspace.onWillDestroyPaneItem (pane) =>
        switch pane.item
          when historyView
            serializedState.history = historyView.serialize()
          when changesView
            serializedState.changes = changesView.serialize()

      @subscriptions.add atom.workspace.registerOpener (filePath) =>
        switch filePath
          when HISTORY_URI
            historyView or= if @state.history?
              console.log 'deserialized'
              atom.deserializers.deserialize(@state.history)
            else
              console.log 'created'
              createHistoryView(uri: HISTORY_URI)
          when CHANGES_URI
            changesView or= if @state.changes?
              atom.deserializers.deserialize(@state.changes)
            else
              createChangesView(uri: CHANGES_URI)

  serialize: ->
    serializedState

  deactivate: ->
    @subscriptions?.dispose()

  openHistoryView: ->
    atom.workspace.open(HISTORY_URI)

  openChangesView: ->
    atom.workspace.open(CHANGES_URI)

atom.commands.add 'atom-workspace', 'git:view-history', =>
  GitExperiment.openHistoryView()

atom.commands.add 'atom-workspace', 'git:view-and-commit-changes', =>
  GitExperiment.openChangesView()

createHistoryView = (state) ->
 HistoryView ?= require './history/history-view'
 historyView = new HistoryView
 historyView.initialize(state)
 historyView

createChangesView = (state) ->
  ChangesView ?= require './changes/changes-view'
  changesView = new ChangesView
  changesView.initialize(state)
  changesView

atom.deserializers.add
  name: 'GitHistoryView'
  deserialize: (state) -> createHistoryView(state)

atom.deserializers.add
  name: 'GitChangesView'
  deserialize: (state) -> createChangesView(state)
{'fraction_non_alphanumeric': 0.10247109498979823, 'fraction_numerical': 0.0, 'mean_word_length': 3.1583411875589067, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '604146', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1275, 'n_words': 260}