<commit_before># This is the CoffeeScript API that wraps all of Cocoa.

# leak
canon = require 'pilot/canon'

# Handles the UI chrome
Chrome =
  init: ->
    console.log = OSX.NSLog

  # path - Optional. The String path to the file to base it on.
  createWindow: (path) ->
    c = OSX.AtomWindowController.alloc.initWithWindowNibName "AtomWindow"
    c.window

  # Set the active window's dirty status.
  setDirty: (bool) ->
    Chrome.activeWindow().setDocumentEdited bool

  # Returns a boolean
  dirty: ->
    Chrome.activeWindow().isDocumentEdited()

  # Returns the active NSWindow object
  activeWindow: ->
    OSX.NSApplication.sharedApplication.keyWindow

  # Returns null or a file path.
  openPanel: ->
    panel = OSX.NSOpenPanel.openPanel
    if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
      return null
    panel.filenames.lastObject

  # Returns null or a file path.
  savePanel: ->
    panel = OSX.NSSavePanel.savePanel
    if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
      return null
    panel.filenames.lastObject

  writeToPasteboard: (text) ->
    pb = OSX.NSPasteboard.generalPasteboard
    pb.declareTypes_owner [OSX.NSStringPboardType], null
    pb.setString_forType text, OSX.NSStringPboardType

  # name - Command name, like "Find in file"
  # shortcut - String command name, e.g.
  #            "Command-T"
  #            "Command-Shift-F"
  #            "Ctrl-I"
  # callback - (env, args, request)
  #
  # Returns nothing.
  bindKey: (name, shortcut, callback) ->
    canon.addCommand
      name: name
      exec: callback
      bindKey:
        win: null
        mac: shortcut
        sender: 'editor'

  title: (text) ->
#     App.title = text

  toggleFullscreen: ->
    if Chrome.fullscreen?
      Chrome.leaveFullscreen()
    else
      Chrome.enterFullscreen()

  leaveFullscreen: ->
    Chrome.fullscreen = false

    OSX.NSMenu.setMenuBarVisible not OSX.NSMenu.menuBarVisible
    window = App.window

  enterFullscreen: ->
    Chrome.fullscreen = true

    OSX.NSMenu.setMenuBarVisible not OSX.NSMenu.menuBarVisible
    window = App.window

    fullscreenWindow = OSX.NSWindow.alloc.
      initWithContentRect_styleMask_backing_defer_screen(
        window.contentRectForFrameRect(window.frame),
        OSX.NSBorderlessWindowMask,
        OSX.NSBackingStoreBuffered,
        true,
        window.screen)

    contentView = window.contentView<commit_msg>fix titles<commit_after># This is the CoffeeScript API that wraps all of Cocoa.

# leak
canon = require 'pilot/canon'

# Handles the UI chrome
Chrome =
  init: ->
    console.log = OSX.NSLog

  # path - Optional. The String path to the file to base it on.
  createWindow: (path) ->
    c = OSX.AtomWindowController.alloc.initWithWindowNibName "AtomWindow"
    c.window

  # Set the active window's dirty status.
  setDirty: (bool) ->
    Chrome.activeWindow().setDocumentEdited bool

  # Returns a boolean
  dirty: ->
    Chrome.activeWindow().isDocumentEdited()

  # Returns the active NSWindow object
  activeWindow: ->
    OSX.NSApplication.sharedApplication.keyWindow

  # Returns null or a file path.
  openPanel: ->
    panel = OSX.NSOpenPanel.openPanel
    if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
      return null
    panel.filenames.lastObject

  # Returns null or a file path.
  savePanel: ->
    panel = OSX.NSSavePanel.savePanel
    if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
      return null
    panel.filenames.lastObject

  writeToPasteboard: (text) ->
    pb = OSX.NSPasteboard.generalPasteboard
    pb.declareTypes_owner [OSX.NSStringPboardType], null
    pb.setString_forType text, OSX.NSStringPboardType

  # name - Command name, like "Find in file"
  # shortcut - String command name, e.g.
  #            "Command-T"
  #            "Command-Shift-F"
  #            "Ctrl-I"
  # callback - (env, args, request)
  #
  # Returns nothing.
  bindKey: (name, shortcut, callback) ->
    canon.addCommand
      name: name
      exec: callback
      bindKey:
        win: null
        mac: shortcut
        sender: 'editor'

  title: (text) ->
    Chrome.activeWindow().setTitle text

  toggleFullscreen: ->
    if Chrome.fullscreen?
      Chrome.leaveFullscreen()
    else
      Chrome.enterFullscreen()

  leaveFullscreen: ->
    Chrome.fullscreen = false

    OSX.NSMenu.setMenuBarVisible not OSX.NSMenu.menuBarVisible
    window = App.window

  enterFullscreen: ->
    Chrome.fullscreen = true

    OSX.NSMenu.setMenuBarVisible not OSX.NSMenu.menuBarVisible
    window = App.window

    fullscreenWindow = OSX.NSWindow.alloc.
      initWithContentRect_styleMask_backing_defer_screen(
        window.contentRectForFrameRect(window.frame),
        OSX.NSBorderlessWindowMask,
        OSX.NSBackingStoreBuffered,
        true,
        window.screen)

    contentView = window.contentView
{'fraction_non_alphanumeric': 0.08739669421487603, 'fraction_numerical': 0.0, 'mean_word_length': 2.7909162098668756, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '1302556', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1516, 'n_words': 356}