<commit_before>fsUtils = require './fs-utils'
$ = require './jquery-extensions'
_ = require './underscore-extensions'
Package = require './package'
ipc = require 'ipc'
remote = require 'remote'
shell = require 'shell'
crypto = require 'crypto'
path = require 'path'
dialog = remote.require 'dialog'
app = remote.require 'app'
{Document} = require 'telepath'
PackageManager = require './package-manager'
ThemeManager = require './theme-manager'
ContextMenuManager = require './context-menu-manager'

module.exports =
class Atom
  constructor: ->
    @packages = new PackageManager()
    @themes = new ThemeManager()
    @contextMenu = new ContextMenuManager(@getLoadSettings().devMode)

  getLoadSettings: ->
    @getCurrentWindow().loadSettings

  getCurrentWindow: ->
    remote.getCurrentWindow()

  #TODO Remove theses once packages have been migrated
  getPackageState: (args...) -> @packages.getPackageState(args...)
  setPackageState: (args...) -> @packages.setPackageState(args...)
  activatePackages: (args...) -> @packages.activatePackages(args...)
  activatePackage: (args...) -> @packages.activatePackage(args...)
  deactivatePackages: (args...) -> @packages.deactivatePackage(args...)
  deactivatePackage: (args...) -> @packages.deactivatePackage(args...)
  getActivePackage: (args...) -> @packages.getActivePackage(args...)
  isPackageActive: (args...) -> @packages.isPackageActive(args...)
  getActivePackages: (args...) -> @packages.getActivePackages(args...)
  loadPackages: (args...) -> @packages.loadPackages(args...)
  loadPackage: (args...) -> @packages.loadPackage(args...)
  unloadPackage: (args...) -> @packages.unloadPackage(args...)
  resolvePackagePath: (args...) -> @packages.resolvePackagePath(args...)
  isInternalPackage: (args...) -> @packages.isInternalPackage(args...)
  getLoadedPackage: (args...) -> @packages.getLoadedPackage(args...)
  isPackageLoaded: (args...) -> @packages.isPackageLoaded(args...)
  getLoadedPackages: (args...) -> @packages.getLoadedPackages(args...)
  isPackageDisabled: (args...) -> @packages.isPackageDisabled(args...)
  getAvailablePackagePaths: (args...) -> @packages.getAvailablePackagePaths(args...)
  getAvailablePackageNames: (args...) -> @packages.getAvailablePackageNames(args...)
  getAvailablePackageMetadata: (args...)-> @packages.getAvailablePackageMetadata(args...)

  loadThemes: ->
    @themes.load()

  watchThemes: ->
    @themes.on 'reloaded', =>
      pack.reloadStylesheets?() for name, pack of @getLoadedPackages()
      null

  open: (options) ->
    ipc.sendChannel('open', options)

  confirm: (message, detailedMessage, buttonLabelsAndCallbacks...) ->
    buttons = []
    callbacks = []
    while buttonLabelsAndCallbacks.length
      do =>
        buttons.push buttonLabelsAndCallbacks.shift()
        callbacks.push buttonLabelsAndCallbacks.shift()

    chosen = @confirmSync(message, detailedMessage, buttons)
    callbacks[chosen]?()

  confirmSync: (message, detailedMessage, buttons, browserWindow=@getCurrentWindow()) ->
    dialog.showMessageBox browserWindow,
      type: 'info'
      message: message
      detail: detailedMessage
      buttons: buttons

  showSaveDialog: (callback) ->
    callback(showSaveDialogSync())

  showSaveDialogSync: (defaultPath) ->
    defaultPath ?= project?.getPath()
    currentWindow = @getCurrentWindow()
    dialog.showSaveDialog currentWindow, {title: 'Save File', defaultPath}

  openDevTools: ->
    @getCurrentWindow().openDevTools()

  toggleDevTools: ->
    @getCurrentWindow().toggleDevTools()

  reload: ->
    @getCurrentWindow().restart()

  focus: ->
    @getCurrentWindow().focus()
    $(window).focus()

  show: ->
    @getCurrentWindow().show()

  hide: ->
    @getCurrentWindow().hide()

  close: ->
    @getCurrentWindow().close()

  exit: (status) ->
    app.exit(status)

  toggleFullScreen: ->
    @setFullScreen(!@isFullScreen())

  setFullScreen: (fullScreen=false) ->
    @getCurrentWindow().setFullScreen(fullScreen)

  isFullScreen: ->
    @getCurrentWindow().isFullScreen()

  getHomeDirPath: ->
    app.getHomeDir()

  getWindowStatePath: ->
    switch @windowMode<commit_msg>:lipstick: Add getCurrentWindow() helper<commit_after>fsUtils = require './fs-utils'
$ = require './jquery-extensions'
_ = require './underscore-extensions'
Package = require './package'
ipc = require 'ipc'
remote = require 'remote'
shell = require 'shell'
crypto = require 'crypto'
path = require 'path'
dialog = remote.require 'dialog'
app = remote.require 'app'
{Document} = require 'telepath'
PackageManager = require './package-manager'
ThemeManager = require './theme-manager'
ContextMenuManager = require './context-menu-manager'

module.exports =
class Atom
  constructor: ->
    @packages = new PackageManager()
    @themes = new ThemeManager()
    @contextMenu = new ContextMenuManager(@getLoadSettings().devMode)

  getCurrentWindow: ->
    remote.getCurrentWindow()

  getLoadSettings: ->
    @getCurrentWindow().loadSettings

  #TODO Remove theses once packages have been migrated
  getPackageState: (args...) -> @packages.getPackageState(args...)
  setPackageState: (args...) -> @packages.setPackageState(args...)
  activatePackages: (args...) -> @packages.activatePackages(args...)
  activatePackage: (args...) -> @packages.activatePackage(args...)
  deactivatePackages: (args...) -> @packages.deactivatePackage(args...)
  deactivatePackage: (args...) -> @packages.deactivatePackage(args...)
  getActivePackage: (args...) -> @packages.getActivePackage(args...)
  isPackageActive: (args...) -> @packages.isPackageActive(args...)
  getActivePackages: (args...) -> @packages.getActivePackages(args...)
  loadPackages: (args...) -> @packages.loadPackages(args...)
  loadPackage: (args...) -> @packages.loadPackage(args...)
  unloadPackage: (args...) -> @packages.unloadPackage(args...)
  resolvePackagePath: (args...) -> @packages.resolvePackagePath(args...)
  isInternalPackage: (args...) -> @packages.isInternalPackage(args...)
  getLoadedPackage: (args...) -> @packages.getLoadedPackage(args...)
  isPackageLoaded: (args...) -> @packages.isPackageLoaded(args...)
  getLoadedPackages: (args...) -> @packages.getLoadedPackages(args...)
  isPackageDisabled: (args...) -> @packages.isPackageDisabled(args...)
  getAvailablePackagePaths: (args...) -> @packages.getAvailablePackagePaths(args...)
  getAvailablePackageNames: (args...) -> @packages.getAvailablePackageNames(args...)
  getAvailablePackageMetadata: (args...)-> @packages.getAvailablePackageMetadata(args...)

  loadThemes: ->
    @themes.load()

  watchThemes: ->
    @themes.on 'reloaded', =>
      pack.reloadStylesheets?() for name, pack of @getLoadedPackages()
      null

  open: (options) ->
    ipc.sendChannel('open', options)

  confirm: (message, detailedMessage, buttonLabelsAndCallbacks...) ->
    buttons = []
    callbacks = []
    while buttonLabelsAndCallbacks.length
      do =>
        buttons.push buttonLabelsAndCallbacks.shift()
        callbacks.push buttonLabelsAndCallbacks.shift()

    chosen = @confirmSync(message, detailedMessage, buttons)
    callbacks[chosen]?()

  confirmSync: (message, detailedMessage, buttons, browserWindow=@getCurrentWindow()) ->
    dialog.showMessageBox browserWindow,
      type: 'info'
      message: message
      detail: detailedMessage
      buttons: buttons

  showSaveDialog: (callback) ->
    callback(showSaveDialogSync())

  showSaveDialogSync: (defaultPath) ->
    defaultPath ?= project?.getPath()
    currentWindow = @getCurrentWindow()
    dialog.showSaveDialog currentWindow, {title: 'Save File', defaultPath}

  openDevTools: ->
    @getCurrentWindow().openDevTools()

  toggleDevTools: ->
    @getCurrentWindow().toggleDevTools()

  reload: ->
    @getCurrentWindow().restart()

  focus: ->
    @getCurrentWindow().focus()
    $(window).focus()

  show: ->
    @getCurrentWindow().show()

  hide: ->
    @getCurrentWindow().hide()

  close: ->
    @getCurrentWindow().close()

  exit: (status) -> app.exit(status)

  toggleFullScreen: ->
    @setFullScreen(!@isFullScreen())

  setFullScreen: (fullScreen=false) ->
    @getCurrentWindow().setFullScreen(fullScreen)

  isFullScreen: ->
    @getCurrentWindow().isFullScreen()

  getHomeDirPath: ->
    app.getHomeDir()

  getWindowStatePath: ->
    switch @windowMode
{'fraction_non_alphanumeric': 0.16158205715663812, 'fraction_numerical': 0.0, 'mean_word_length': 3.919335705812574, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 95, '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': '2526104', 'n_tokens_mistral': 2368, 'n_tokens_neox': 2334, 'n_words': 452}