<commit_before>/** @babel */

import path from 'path'

import {CompositeDisposable, File} from 'atom'

import React from 'react'
import ReactDom from 'react-dom'

import EtchWrapper from '../views/etch-wrapper'
import StatusBar from '../views/status-bar'
import Panel from '../views/panel'
import PaneItem from '../views/pane-item'
import FilePatchController from './file-patch-controller'
import GitPanelController from './git-panel-controller'
import StatusBarTileController from './status-bar-tile-controller'
import ModelObserver from '../models/model-observer'

const nullFilePatchState = {
  filePath: null,
  filePatch: null,
  stagingStatus: null,
  amending: null,
}

export default class GitController extends React.Component {
  static propTypes = {
    workspace: React.PropTypes.object.isRequired,
    commandRegistry: React.PropTypes.object.isRequired,
    notificationManager: React.PropTypes.object.isRequired,
    repository: React.PropTypes.object,
    statusBar: React.PropTypes.object,
    savedState: React.PropTypes.object,
  }

  static defaultProps = {
    savedState: {},
  }

  serialize () {
    return {
      gitPanelActive: this.state.gitPanelActive
    }
  }

  constructor (props, context) {
    super(props, context)
    this.state = {
      ...nullFilePatchState,
      gitPanelActive: !!props.savedState.gitPanelActive,
    }

    this.showFilePatchForPath = this.showFilePatchForPath.bind(this)
    this.showMergeConflictFileForPath = this.showMergeConflictFileForPath.bind(this)
    this.didChangeAmending = this.didChangeAmending.bind(this)
    this.onRepoRefresh = this.onRepoRefresh.bind(this)
    this.toggleGitPanel = this.toggleGitPanel.bind(this)
    this.openAndFocusGitPanel = this.openAndFocusGitPanel.bind(this)
    this.focusFilePatchView = this.focusFilePatchView.bind(this)
    this.focusGitPanel = this.focusGitPanel.bind(this)
    this.subscriptions = new CompositeDisposable()
    this.subscriptions.add(
      props.commandRegistry.add('atom-workspace', {
        'git:toggle-git-panel': this.toggleGitPanel.bind(this),
        'git:focus-git-panel': this.openAndFocusGitPanel.bind(this),
      })
    )

    this.repositoryObserver = new ModelObserver({
      didUpdate: () => this.onRepoRefresh()
    })
    this.repositoryObserver.setActiveModel(props.repository)
  }

  componentWillReceiveProps(newProps) {
    this.repositoryObserver.setActiveModel(newProps.repository)
  }

  render () {
    return (
      <div>
        {this.renderStatusBarTile()}
        {this.renderGitPanel()}
        {(this.state.filePath && this.state.filePatch) ? this.renderFilePatchController() : null}
      </div>
    )<commit_msg>Destroy ModelObserver when GitController unmounts<commit_after>/** @babel */

import path from 'path'

import {CompositeDisposable, Disposable, File} from 'atom'

import React from 'react'
import ReactDom from 'react-dom'

import EtchWrapper from '../views/etch-wrapper'
import StatusBar from '../views/status-bar'
import Panel from '../views/panel'
import PaneItem from '../views/pane-item'
import FilePatchController from './file-patch-controller'
import GitPanelController from './git-panel-controller'
import StatusBarTileController from './status-bar-tile-controller'
import ModelObserver from '../models/model-observer'

const nullFilePatchState = {
  filePath: null,
  filePatch: null,
  stagingStatus: null,
  amending: null,
}

export default class GitController extends React.Component {
  static propTypes = {
    workspace: React.PropTypes.object.isRequired,
    commandRegistry: React.PropTypes.object.isRequired,
    notificationManager: React.PropTypes.object.isRequired,
    repository: React.PropTypes.object,
    statusBar: React.PropTypes.object,
    savedState: React.PropTypes.object,
  }

  static defaultProps = {
    savedState: {},
  }

  serialize () {
    return {
      gitPanelActive: this.state.gitPanelActive
    }
  }

  constructor (props, context) {
    super(props, context)
    this.state = {
      ...nullFilePatchState,
      gitPanelActive: !!props.savedState.gitPanelActive,
    }

    this.showFilePatchForPath = this.showFilePatchForPath.bind(this)
    this.showMergeConflictFileForPath = this.showMergeConflictFileForPath.bind(this)
    this.didChangeAmending = this.didChangeAmending.bind(this)
    this.onRepoRefresh = this.onRepoRefresh.bind(this)
    this.toggleGitPanel = this.toggleGitPanel.bind(this)
    this.openAndFocusGitPanel = this.openAndFocusGitPanel.bind(this)
    this.focusFilePatchView = this.focusFilePatchView.bind(this)
    this.focusGitPanel = this.focusGitPanel.bind(this)
    this.subscriptions = new CompositeDisposable()
    this.subscriptions.add(
      props.commandRegistry.add('atom-workspace', {
        'git:toggle-git-panel': this.toggleGitPanel.bind(this),
        'git:focus-git-panel': this.openAndFocusGitPanel.bind(this),
      })
    )

    this.repositoryObserver = new ModelObserver({
      didUpdate: () => this.onRepoRefresh()
    })
    this.repositoryObserver.setActiveModel(props.repository)
    this.subscriptions.add(
      new Disposable(() => this.repositoryObserver.destroy())
    )
  }

  componentWillReceiveProps(newProps) {
    this.repositoryObserver.setActiveModel(newProps.repository)
  }

  render () {
    return (
      <div>
        {this.renderStatusBarTile()}
        {this.renderGitPanel()}
        {(this.state.filePath && this.state.filePatch) ? this.renderFilePatchController() : null}
      </div>
    )
{'fraction_non_alphanumeric': 0.11424927113702624, 'fraction_numerical': 0.0, 'mean_word_length': 3.8489399293286217, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, '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': '799041', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1618, 'n_words': 289}