<commit_before>/**
 * <NAME> - http://taewon.de - @hataewon
 * See LICENSE
 */

import Cocoa
import RxSwift
import SwiftNeoVim
import PureLayout

class MainWindow: NSObject,
                  UiComponent,
                  NeoVimViewDelegate,
                  NSWindowDelegate,
                  NSUserInterfaceValidations,
                  WorkspaceDelegate {

  typealias StateType = State

  enum Action {

    case open(Set<Token>)

    case cd(to: URL)
    case setBufferList([NeoVimBuffer])

    case setCurrentBuffer(NeoVimBuffer)
    case setDirtyStatus(Bool)

    case becomeKey

    case scroll(to: Marked<Position>)
    case setCursor(to: Marked<Position>)

    case focus(FocusableView)

    case openQuickly

    case toggleAllTools(Bool)
    case toggleToolButtons(Bool)
    case setState(for: Tools, with: WorkspaceTool)

    case close
  }

  enum FocusableView {

    case neoVimView
    case fileBrowser
    case preview
  }

  enum Tools: String {

    static let all = Set([Tools.fileBrowser, Tools.openedFilesList, Tools.preview])

    case fileBrowser = "com.qvacua.vimr.tools.file-browser"
    case openedFilesList = "com.qvacua.vimr.tools.opened-files-list"
    case preview = "com.qvacua.vimr.tools.preview"
  }

  enum OpenMode {

    case `default`
    case currentTab
    case newTab
    case horizontalSplit
    case verticalSplit
  }

  required init(source: Observable<StateType>, emitter: ActionEmitter, state: StateType) {
    self.uuid = state.uuid
    self.emitter = emitter

    self.defaultFont = state.appearance.font
    self.linespacing = state.appearance.linespacing
    self.usesLigatures = state.appearance.usesLigatures

    self.editorPosition = state.preview.editorPosition
    self.previewPosition = state.preview.previewPosition

    self.neoVimView = NeoVimView(frame: CGRect.zero,
                                 config: NeoVimView.Config(useInteractiveZsh: state.useInteractiveZsh))
    self.neoVimView.configureForAutoLayout()

    self.workspace = Workspace(mainView: self.neoVimView)
    self.preview = PreviewTool(source: source, emitter: emitter, state: state)
    self.fileBrowser = FileBrowser(source: source, emitter: emitter, state: state)
    self.openedFileList = OpenedFileList(source: source, emitter: emitter, state: state)

    self.windowController = NSWindowController(windowNibName: "MainWindow")

    let previewConfig = WorkspaceTool.Config(title: "Preview",
                                             view: self.preview,
                                             customMenuItems: self.preview.menuItems)
    self.previewContainer = WorkspaceTool(previewConfig)
    previewContainer.dimension = state.tools[.preview]?.dimension ?? 250

    let fileBrowserConfig = WorkspaceTool.Config(title: "Files",
                                                 view: self.fileBrowser,
                                                 customToolbar: self.fileBrowser.innerCustomToolbar,
                                                 customMenuItems: self.fileBrowser.menuItems)
    self.fileBrowserContainer = WorkspaceTool(fileBrowserConfig)
    fileBrowserContainer.dimension = state.tools[.fileBrowser]?.dimension ?? 200

    let openedFileListConfig = WorkspaceTool.Config(title: "Opened", view: self.openedFileList)
    self.openedFileListContainer = WorkspaceTool(openedFileListConfig)
    self.openedFileListContainer.dimension = state.tools[.openedFilesList]?.dimension ?? 200

    self.workspace.append(tool: previewContainer, location: state.tools[.preview]?.location ?? .right)
    self.workspace.append(tool: fileBrowserContainer, location: state.tools[.fileBrowser]?.location ?? .left)
    self.workspace.append(tool: openedFileListContainer, location: state.tools[.openedFilesList]?.location ?? .left)

    self.tools = [
      .fileBrowser: self.fileBrowserContainer,
      .openedFilesList: self.openedFileListContainer,
      .preview: self.previewContainer,
    ]

    super.init()

    self.tools.forEach {
      if state.tools[$0]?.open == true {
        $1.toggle()<commit_msg>GH-405 Stick with "Buffers" for now...<commit_after>/**
 * <NAME> - http://taewon.de - @hataewon
 * See LICENSE
 */

import Cocoa
import RxSwift
import SwiftNeoVim
import PureLayout

class MainWindow: NSObject,
                  UiComponent,
                  NeoVimViewDelegate,
                  NSWindowDelegate,
                  NSUserInterfaceValidations,
                  WorkspaceDelegate {

  typealias StateType = State

  enum Action {

    case open(Set<Token>)

    case cd(to: URL)
    case setBufferList([NeoVimBuffer])

    case setCurrentBuffer(NeoVimBuffer)
    case setDirtyStatus(Bool)

    case becomeKey

    case scroll(to: Marked<Position>)
    case setCursor(to: Marked<Position>)

    case focus(FocusableView)

    case openQuickly

    case toggleAllTools(Bool)
    case toggleToolButtons(Bool)
    case setState(for: Tools, with: WorkspaceTool)

    case close
  }

  enum FocusableView {

    case neoVimView
    case fileBrowser
    case preview
  }

  enum Tools: String {

    static let all = Set([Tools.fileBrowser, Tools.openedFilesList, Tools.preview])

    case fileBrowser = "com.qvacua.vimr.tools.file-browser"
    case openedFilesList = "com.qvacua.vimr.tools.opened-files-list"
    case preview = "com.qvacua.vimr.tools.preview"
  }

  enum OpenMode {

    case `default`
    case currentTab
    case newTab
    case horizontalSplit
    case verticalSplit
  }

  required init(source: Observable<StateType>, emitter: ActionEmitter, state: StateType) {
    self.uuid = state.uuid
    self.emitter = emitter

    self.defaultFont = state.appearance.font
    self.linespacing = state.appearance.linespacing
    self.usesLigatures = state.appearance.usesLigatures

    self.editorPosition = state.preview.editorPosition
    self.previewPosition = state.preview.previewPosition

    self.neoVimView = NeoVimView(frame: CGRect.zero,
                                 config: NeoVimView.Config(useInteractiveZsh: state.useInteractiveZsh))
    self.neoVimView.configureForAutoLayout()

    self.workspace = Workspace(mainView: self.neoVimView)
    self.preview = PreviewTool(source: source, emitter: emitter, state: state)
    self.fileBrowser = FileBrowser(source: source, emitter: emitter, state: state)
    self.openedFileList = OpenedFileList(source: source, emitter: emitter, state: state)

    self.windowController = NSWindowController(windowNibName: "MainWindow")

    let previewConfig = WorkspaceTool.Config(title: "Preview",
                                             view: self.preview,
                                             customMenuItems: self.preview.menuItems)
    self.previewContainer = WorkspaceTool(previewConfig)
    previewContainer.dimension = state.tools[.preview]?.dimension ?? 250

    let fileBrowserConfig = WorkspaceTool.Config(title: "Files",
                                                 view: self.fileBrowser,
                                                 customToolbar: self.fileBrowser.innerCustomToolbar,
                                                 customMenuItems: self.fileBrowser.menuItems)
    self.fileBrowserContainer = WorkspaceTool(fileBrowserConfig)
    fileBrowserContainer.dimension = state.tools[.fileBrowser]?.dimension ?? 200

    let openedFileListConfig = WorkspaceTool.Config(title: "Buffers", view: self.openedFileList)
    self.openedFileListContainer = WorkspaceTool(openedFileListConfig)
    self.openedFileListContainer.dimension = state.tools[.openedFilesList]?.dimension ?? 200

    self.workspace.append(tool: previewContainer, location: state.tools[.preview]?.location ?? .right)
    self.workspace.append(tool: fileBrowserContainer, location: state.tools[.fileBrowser]?.location ?? .left)
    self.workspace.append(tool: openedFileListContainer, location: state.tools[.openedFilesList]?.location ?? .left)

    self.tools = [
      .fileBrowser: self.fileBrowserContainer,
      .openedFilesList: self.openedFileListContainer,
      .preview: self.previewContainer,
    ]

    super.init()

    self.tools.forEach {
      if state.tools[$0]?.open == true {
        $1.toggle()
{'fraction_non_alphanumeric': 0.09090909090909091, 'fraction_numerical': 0.0030629747610879687, 'mean_word_length': 2.832394366197183, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '75142', 'n_tokens_mistral': 2374, 'n_tokens_neox': 2199, 'n_words': 446}