<commit_before>import React from "react"
import BaseComponent from "./base_component"
import ApplicationMenu from "../menus/application_menu"
import Tree from "./tree"
import Workspace from "./workspace"
import remote from "remote"
import path from "path"

export default class App extends BaseComponent {
  constructor(props, context) {
    super(props, context)
    this.state = this.getStoreState()
  }

  componentDidMount() {
    this.context.flux.getStore("TreeStore").listen(this.handleChange.bind(this))
    this.context.flux.getStore("BufferStore").listen(this.handleChange.bind(this))

    // TODO: is this the right place to set the app menu?
    new ApplicationMenu(this.context.flux)
    this.updateTitle()
  }

  getStoreState() {
    return {
      tree        : this.context.flux.getStore("TreeStore").getState(),
      bufferStore : this.context.flux.getStore("BufferStore").getState()
    }
  }

  handleChange() {
    this.setState(this.getStoreState())
    this.updateTitle()
  }

  updateTitle() {
    const win = remote.getCurrentWindow()
    const activeBuffer = this.context.flux.getStore("BufferStore").getBuffer()
    let title = remote.require("app").getName()

    if (activeBuffer) {
      if (activeBuffer.filePath) {
        win.setRepresentedFilename(activeBuffer.filePath)
        title = `${activeBuffer.name} - ${path.dirname(activeBuffer.filePath)} - ${title}`
      } else {
        title = `${activeBuffer.name} - ${title}`
      }
    }

    win.setTitle(title)
  }

  render() {
    return (
      <div className="u-container u-container--horizontal">
        <Tree className="u-panel" tree={this.state.tree}/>
        <Workspace className="u-panel u-panel--grow"
                   bufferStore={this.state.bufferStore}/>
      </div>
    )
  }
}<commit_msg>Only update window title if it needs to<commit_after>import React from "react"
import BaseComponent from "./base_component"
import ApplicationMenu from "../menus/application_menu"
import Tree from "./tree"
import Workspace from "./workspace"
import remote from "remote"

export default class App extends BaseComponent {
  constructor(props, context) {
    super(props, context)
    this.state = this.getStoreState()
  }

  componentDidMount() {
    this.context.flux.getStore("TreeStore").listen(this.handleChange.bind(this))
    this.context.flux.getStore("BufferStore").listen(this.handleChange.bind(this))

    // TODO: is this the right place to set the app menu?
    new ApplicationMenu(this.context.flux)
    this.updateTitle()
  }

  componentDidUpdate(prevProps, prevState) {
    // TODO: find a way to simplify this logic (move it to the store?)
    let activeBuffer, prevActiveBuffer
    if (this.state.bufferStore.activeBufferIndex > -1) {
      activeBuffer = this.state.bufferStore.buffers[this.state.bufferStore.activeBufferIndex]
      prevActiveBuffer = prevState.bufferStore.buffers[prevState.bufferStore.activeBufferIndex]
    }
    if (
      prevState.bufferStore.activeBufferIndex != this.state.bufferStore.activeBufferIndex ||
      activeBuffer && activeBuffer.name != prevActiveBuffer.name
    ) {
      this.updateTitle()
    }
  }

  getStoreState() {
    return {
      tree        : this.context.flux.getStore("TreeStore").getState(),
      bufferStore : this.context.flux.getStore("BufferStore").getState()
    }
  }

  handleChange() {
    this.setState(this.getStoreState())
  }

  updateTitle() {
    const win = remote.getCurrentWindow()
    const activeBuffer = this.context.flux.getStore("BufferStore").getBuffer()
    let title = remote.require("app").getName()

    if (activeBuffer) {
      if (activeBuffer.filePath) {
        win.setRepresentedFilename(activeBuffer.filePath)
      }
      title = `${activeBuffer.name} - ${title}`
    }

    win.setTitle(title)
  }

  render() {
    return (
      <div className="u-container u-container--horizontal">
        <Tree className="u-panel" tree={this.state.tree}/>
        <Workspace className="u-panel u-panel--grow"
                   bufferStore={this.state.bufferStore}/>
      </div>
    )
  }
}
{'fraction_non_alphanumeric': 0.1294664708761625, 'fraction_numerical': 0.0002447381302006853, 'mean_word_length': 3.2572916666666667, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, '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': '3357621', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1186, 'n_words': 235}