<commit_before>import * as React from 'react'

import { FileStatus } from '../../models/status'
import { Octicon, OcticonSymbol } from '../octicons'
import { showContextualMenu } from '../main-process-proxy'
import { Checkbox, CheckboxValue } from './checkbox'
import { assertNever } from '../../lib/fatal-error'

interface IChangedFileProps {
  path: string
  status: FileStatus
  oldPath?: string
  include: boolean | null
  onIncludeChanged: (include: boolean) => void
  onDiscardChanges: () => void
}

/** a changed file in the working directory for a given repository */
export class ChangedFile extends React.Component<IChangedFileProps, void> {

  private static mapStatus(status: FileStatus): string {
    switch (status) {
      case FileStatus.New: return 'New'
      case FileStatus.Modified: return 'Modified'
      case FileStatus.Deleted: return 'Deleted'
      case FileStatus.Renamed: return 'Renamed'
      case FileStatus.Conflicted: return 'Conflicted'
      case FileStatus.Copied: return 'Copied'
    }

    return assertNever(status, `Unknown file status ${status}`)
  }

  private handleChange(event: React.FormEvent<HTMLInputElement>) {
    const include = event.currentTarget.checked
    this.props.onIncludeChanged(include)
  }

  private get checkboxValue(): CheckboxValue {
    if (this.props.include === true) {
      return CheckboxValue.On
    } else if (this.props.include === false) {
      return CheckboxValue.Off
    } else {
      return CheckboxValue.Mixed
    }
  }

  public renderPathLabel() {
    const props: React.HTMLProps<HTMLLabelElement> = {
      className: 'path',
      title: this.props.path,
    }

    if (this.props.status === FileStatus.Renamed && this.props.oldPath) {
      return (
        <label {...props}>
          {this.props.oldPath} <Octicon symbol={OcticonSymbol.arrowRight} /> {this.props.path}
        </label>
      )
    } else {
      return <label {...props}>{this.props.path}</label>
    }
  }

  public render() {
    const fileStatus = ChangedFile.mapStatus(this.props.status)

    return (
      <div className='changed-file' onContextMenu={e => this.onContextMenu(e)}>

        <Checkbox
          // The checkbox doesn't need to be tab reachable since we emulate
          // checkbox behavior on the list item itself, ie hitting space bar
          // while focused on a row will toggle selection.
          tabIndex={-1}
          value={this.checkboxValue}
          onChange={event => this.handleChange(event)}/>

        {this.renderPathLabel()}

        <div className={'status status-' + fileStatus.toLowerCase()} title={fileStatus}>
          <Octicon symbol={iconForStatus(this.props.status)} />
        </div>
      </div>
    )
  }

  private onContextMenu(event: React.MouseEvent<any>) {
    event.preventDefault()

    if (!__WIN32__) {
      const item = {
        label: 'Discard Changes',
        action: () => this.props.onDiscardChanges(),
      }
      showContextualMenu([ item ])
    }
  }
}

function iconForStatus(status: FileStatus): OcticonSymbol {

  switch (status) {
    case FileStatus.New: return OcticonSymbol.diffAdded
    case FileStatus.Modified: return OcticonSymbol.diffModified
    case FileStatus.Deleted: return OcticonSymbol.diffRemoved
    case FileStatus.Renamed: return OcticonSymbol.diffRenamed
    case FileStatus.Conflicted: return OcticonSymbol.alert
    // TODO: we don't have an Octicon for when the diff is copied
    case FileStatus.Copied: return OcticonSymbol.question
  }

  return assertNever(status, `Unknown file status ${status}`)
}<commit_msg>use added icon for copies<commit_after>import * as React from 'react'

import { FileStatus } from '../../models/status'
import { Octicon, OcticonSymbol } from '../octicons'
import { showContextualMenu } from '../main-process-proxy'
import { Checkbox, CheckboxValue } from './checkbox'
import { assertNever } from '../../lib/fatal-error'

interface IChangedFileProps {
  path: string
  status: FileStatus
  oldPath?: string
  include: boolean | null
  onIncludeChanged: (include: boolean) => void
  onDiscardChanges: () => void
}

/** a changed file in the working directory for a given repository */
export class ChangedFile extends React.Component<IChangedFileProps, void> {

  private static mapStatus(status: FileStatus): string {
    switch (status) {
      case FileStatus.New: return 'New'
      case FileStatus.Modified: return 'Modified'
      case FileStatus.Deleted: return 'Deleted'
      case FileStatus.Renamed: return 'Renamed'
      case FileStatus.Conflicted: return 'Conflicted'
      case FileStatus.Copied: return 'Copied'
    }

    return assertNever(status, `Unknown file status ${status}`)
  }

  private handleChange(event: React.FormEvent<HTMLInputElement>) {
    const include = event.currentTarget.checked
    this.props.onIncludeChanged(include)
  }

  private get checkboxValue(): CheckboxValue {
    if (this.props.include === true) {
      return CheckboxValue.On
    } else if (this.props.include === false) {
      return CheckboxValue.Off
    } else {
      return CheckboxValue.Mixed
    }
  }

  public renderPathLabel() {
    const props: React.HTMLProps<HTMLLabelElement> = {
      className: 'path',
      title: this.props.path,
    }

    if (this.props.status === FileStatus.Renamed && this.props.oldPath) {
      return (
        <label {...props}>
          {this.props.oldPath} <Octicon symbol={OcticonSymbol.arrowRight} /> {this.props.path}
        </label>
      )
    } else {
      return <label {...props}>{this.props.path}</label>
    }
  }

  public render() {
    const fileStatus = ChangedFile.mapStatus(this.props.status)

    return (
      <div className='changed-file' onContextMenu={e => this.onContextMenu(e)}>

        <Checkbox
          // The checkbox doesn't need to be tab reachable since we emulate
          // checkbox behavior on the list item itself, ie hitting space bar
          // while focused on a row will toggle selection.
          tabIndex={-1}
          value={this.checkboxValue}
          onChange={event => this.handleChange(event)}/>

        {this.renderPathLabel()}

        <div className={'status status-' + fileStatus.toLowerCase()} title={fileStatus}>
          <Octicon symbol={iconForStatus(this.props.status)} />
        </div>
      </div>
    )
  }

  private onContextMenu(event: React.MouseEvent<any>) {
    event.preventDefault()

    if (!__WIN32__) {
      const item = {
        label: 'Discard Changes',
        action: () => this.props.onDiscardChanges(),
      }
      showContextualMenu([ item ])
    }
  }
}

function iconForStatus(status: FileStatus): OcticonSymbol {

  switch (status) {
    case FileStatus.New: return OcticonSymbol.diffAdded
    case FileStatus.Modified: return OcticonSymbol.diffModified
    case FileStatus.Deleted: return OcticonSymbol.diffRemoved
    case FileStatus.Renamed: return OcticonSymbol.diffRenamed
    case FileStatus.Conflicted: return OcticonSymbol.alert
    case FileStatus.Copied: return OcticonSymbol.diffAdded
  }

  return assertNever(status, `Unknown file status ${status}`)
}
{'fraction_non_alphanumeric': 0.1150654100436067, 'fraction_numerical': 0.0008440005626670418, 'mean_word_length': 3.058219178082192, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 43, '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': '5197899', 'n_tokens_mistral': 2053, 'n_tokens_neox': 2018, 'n_words': 524}