<commit_before>fsUtils = require './fs-utils'
path = require 'path'
telepath = require 'telepath'
$ = require './jquery-extensions'
_ = require './underscore-extensions'
remote = require 'remote'
ipc = require 'ipc'
WindowEventHandler = require './window-event-handler'

deserializers = {}
deferredDeserializers = {}
defaultWindowDimensions = {width: 800, height: 600}

### Internal ###

windowEventHandler = null

# Schedule the window to be shown and focused on the next tick
#
# This is done in a next tick to prevent a white flicker from occurring
# if called synchronously.
displayWindow = ->
  _.nextTick ->
    atom.show()
    atom.focus()

# This method is called in any window needing a general environment, including specs
window.setUpEnvironment = (windowMode) ->
  atom.windowMode = windowMode
  window.resourcePath = atom.getLoadSettings().resourcePath

  Syntax = require './syntax'

  window.rootViewParentSelector = 'body'
  window.config = atom.config
  window.syntax = deserialize(atom.getWindowState('syntax')) ? new Syntax
  window.pasteboard = atom.pasteboard
  window.keymap = atom.keymap


# Set up the default event handlers and menus for a non-editor windows.
#
# This can be used by packages to have a minimum level of keybindings and
# menus available when not using the standard editor window.
#
# This should only be called after setUpEnvironment() has been called.
window.setUpDefaultEvents = ->
  windowEventHandler = new WindowEventHandler
  keymap.loadBundledKeymaps()
  ipc.sendChannel 'update-application-menu', keymap.keystrokesByCommandForSelector('body')

# This method is only called when opening a real application window
window.startEditorWindow = ->
  installAtomCommand()
  installApmCommand()

  windowEventHandler = new WindowEventHandler
  restoreDimensions()
  config.load()
  keymap.loadBundledKeymaps()
  atom.themes.loadBaseStylesheets()
  atom.loadPackages()
  atom.loadThemes()
  deserializeEditorWindow()
  atom.activatePackages()
  keymap.loadUserKeymaps()
  atom.requireUserInitScript()
  ipc.sendChannel 'update-application-menu', keymap.keystrokesByCommandForSelector('body')
  $(window).on 'unload', ->
    $(document.body).hide()
    unloadEditorWindow()
    false

  displayWindow()

window.unloadEditorWindow = ->
  return if not project and not rootView
  windowState = atom.getWindowState()
  windowState.set('project', project.serialize())
  windowState.set('syntax', syntax.serialize())
  windowState.set('rootView', rootView.serialize())
  atom.deactivatePackages()
  windowState.set('packageStates', atom.packageStates)
  atom.saveWindowState()
  rootView.remove()
  project.destroy()
  windowEventHandler?.unsubscribe()
  lessCache?.destroy()
  window.rootView = null
  window.project = null

window.installAtomCommand = (callback) ->
  commandPath = path.join(window.resourcePath, 'atom.sh')
  require('./command-installer').install(commandPath, callback)

window.installApmCommand = (callback) ->
  commandPath = path.join(window.resourcePath, 'node_modules', '.bin', 'apm')
  require('./command-installer').install(commandPath, callback)

window.onDrop = (e) ->
  e.preventDefault()
  e.stopPropagation()
  pathsToOpen = _.pluck(e.originalEvent.dataTransfer.files, 'path')
  atom.open({pathsToOpen}) if pathsToOpen.length > 0

window.deserializeEditorWindow = ->
  RootView = require './root-view'
  Project = require './project'

  windowState = atom.getWindowState()

  atom.packageStates = windowState.getObject('packageStates') ? {}
  windowState.remove('packageStates')

  window.project = deserialize(windowState.get('project'))
  unless window.project?
    window.project = new Project(atom.getLoadSettings().initialPath)
    windowState.set('project', window.project.getState())

  window.rootView = deserialize(windowState.get('rootView'))
  unless window.rootView?
    window.rootView = new RootView()
    windowState.set('rootView', window.rootView.getState())

  $(rootViewParentSelector).append(rootView)
<commit_msg>Keep command install functions local<commit_after>fsUtils = require './fs-utils'
path = require 'path'
telepath = require 'telepath'
$ = require './jquery-extensions'
_ = require './underscore-extensions'
remote = require 'remote'
ipc = require 'ipc'
WindowEventHandler = require './window-event-handler'

deserializers = {}
deferredDeserializers = {}
defaultWindowDimensions = {width: 800, height: 600}

### Internal ###

windowEventHandler = null

# Schedule the window to be shown and focused on the next tick
#
# This is done in a next tick to prevent a white flicker from occurring
# if called synchronously.
displayWindow = ->
  _.nextTick ->
    atom.show()
    atom.focus()

# This method is called in any window needing a general environment, including specs
window.setUpEnvironment = (windowMode) ->
  atom.windowMode = windowMode
  window.resourcePath = atom.getLoadSettings().resourcePath

  Syntax = require './syntax'

  window.rootViewParentSelector = 'body'
  window.config = atom.config
  window.syntax = deserialize(atom.getWindowState('syntax')) ? new Syntax
  window.pasteboard = atom.pasteboard
  window.keymap = atom.keymap


# Set up the default event handlers and menus for a non-editor windows.
#
# This can be used by packages to have a minimum level of keybindings and
# menus available when not using the standard editor window.
#
# This should only be called after setUpEnvironment() has been called.
window.setUpDefaultEvents = ->
  windowEventHandler = new WindowEventHandler
  keymap.loadBundledKeymaps()
  ipc.sendChannel 'update-application-menu', keymap.keystrokesByCommandForSelector('body')

# This method is only called when opening a real application window
window.startEditorWindow = ->
  installAtomCommand()
  installApmCommand()

  windowEventHandler = new WindowEventHandler
  restoreDimensions()
  config.load()
  keymap.loadBundledKeymaps()
  atom.themes.loadBaseStylesheets()
  atom.loadPackages()
  atom.loadThemes()
  deserializeEditorWindow()
  atom.activatePackages()
  keymap.loadUserKeymaps()
  atom.requireUserInitScript()
  ipc.sendChannel 'update-application-menu', keymap.keystrokesByCommandForSelector('body')
  $(window).on 'unload', ->
    $(document.body).hide()
    unloadEditorWindow()
    false

  displayWindow()

window.unloadEditorWindow = ->
  return if not project and not rootView
  windowState = atom.getWindowState()
  windowState.set('project', project.serialize())
  windowState.set('syntax', syntax.serialize())
  windowState.set('rootView', rootView.serialize())
  atom.deactivatePackages()
  windowState.set('packageStates', atom.packageStates)
  atom.saveWindowState()
  rootView.remove()
  project.destroy()
  windowEventHandler?.unsubscribe()
  lessCache?.destroy()
  window.rootView = null
  window.project = null

installAtomCommand = (callback) ->
  commandPath = path.join(window.resourcePath, 'atom.sh')
  require('./command-installer').install(commandPath, callback)

installApmCommand = (callback) ->
  commandPath = path.join(window.resourcePath, 'node_modules', '.bin', 'apm')
  require('./command-installer').install(commandPath, callback)

window.onDrop = (e) ->
  e.preventDefault()
  e.stopPropagation()
  pathsToOpen = _.pluck(e.originalEvent.dataTransfer.files, 'path')
  atom.open({pathsToOpen}) if pathsToOpen.length > 0

window.deserializeEditorWindow = ->
  RootView = require './root-view'
  Project = require './project'

  windowState = atom.getWindowState()

  atom.packageStates = windowState.getObject('packageStates') ? {}
  windowState.remove('packageStates')

  window.project = deserialize(windowState.get('project'))
  unless window.project?
    window.project = new Project(atom.getLoadSettings().initialPath)
    windowState.set('project', window.project.getState())

  window.rootView = deserialize(windowState.get('rootView'))
  unless window.rootView?
    window.rootView = new RootView()
    windowState.set('rootView', window.rootView.getState())

  $(rootViewParentSelector).append(rootView)

{'fraction_non_alphanumeric': 0.11683934589938834, 'fraction_numerical': 0.0017475970540506804, 'mean_word_length': 4.956877323420074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '6155039', 'n_tokens_mistral': 2355, 'n_tokens_neox': 2312, 'n_words': 552}