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

import Cocoa
import PureLayout

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, WorkspaceDelegate {

  @IBOutlet weak var window: NSWindow!

  fileprivate var workspace: Workspace = Workspace(mainView: NSView())

  @IBAction func toggleBars(_ sender: AnyObject!) {
    workspace.toggleAllTools()
  }

  @IBAction func toggleButtons(_ sender: AnyObject!) {
    workspace.toggleToolButtons()
  }

  func applicationDidFinishLaunching(_ aNotification: Notification) {
    let contentView = self.window.contentView!
    let workspace = Workspace(mainView: DummyView(NSColor.white))
    self.workspace = workspace

    contentView.addSubview(workspace)
    workspace.autoPinEdgesToSuperviewEdges()

//    workspace.append(tool: dummyTool(title: "Top-1", color: .yellow), location: .top)

    workspace.append(tool: dummyTool(title: "Right-1", color: .magenta), location: .right)
    workspace.append(tool: dummyTool(title: "Right-2", color: .black), location: .right)

    let menuItems = [
      NSMenuItem(title: "First", action: nil, keyEquivalent: ""),
      NSMenuItem(title: "Second", action: nil, keyEquivalent: ""),
      NSMenuItem(title: "Third", action: nil, keyEquivalent: ""),
      NSMenuItem(title: "Fourth", action: nil, keyEquivalent: ""),
      NSMenuItem(title: "Fifth", action: nil, keyEquivalent: ""),
    ]

    let tool = dummyTool(title: "Left-1", color: .blue, customToolbar: DummyView(.orange), customMenu: menuItems)

    workspace.append(tool: tool, location: .left)
    workspace.append(tool: dummyTool(title: "Left-2", color: .red), location: .left)
    workspace.append(tool: dummyTool(title: "Left-3", color: .gray), location: .left)

    workspace.append(tool: dummyTool(title: "Bottom-1", color: .cyan), location: .bottom)
    workspace.append(tool: dummyTool(title: "Bottom-2", color: .blue), location: .bottom)

    tool.toggle()

    // FIXME: GH-422
    workspace.delegate = self
  }

  fileprivate func dummyTool(title: String,
                             color: NSColor,
                             customToolbar: NSView? = nil,
                             customMenu: [NSMenuItem] = []) -> WorkspaceTool
  {
    let config = WorkspaceTool.Config(title: title,
                                      view: DummyView(color),
                                      minimumDimension: 150,
                                      withInnerToolbar: true,
                                      customToolbar: customToolbar,
                                      customMenuItems: customMenu)

    return WorkspaceTool(config)
  }

  func resizeWillStart(workspace: Workspace, tool: WorkspaceTool?) {
    NSLog("\(#function)")
  }

  func resizeDidEnd(workspace: Workspace, tool: WorkspaceTool?) {
    NSLog("\(#function)")
  }

  func toggled(tool: WorkspaceTool) {
    NSLog("\(#function)")
  }

  func moved(tool: WorkspaceTool) {
    NSLog("\(#function)")
  }
}

class DummyView: NSView {

  required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }

  init(_ color: NSColor) {
    super.init(frame: .zero)
    self.configureForAutoLayout()<commit_msg>GH-436 Adapt workspace demo app<commit_after>/**
 * <NAME> - http://taewon.de - @hataewon
 * See LICENSE
 */

import Cocoa
import PureLayout

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, WorkspaceDelegate {

  @IBOutlet weak var window: NSWindow!

  fileprivate var workspace: Workspace = Workspace(mainView: NSView())

  @IBAction func toggleBars(_ sender: AnyObject!) {
    workspace.toggleAllTools()
  }

  @IBAction func toggleButtons(_ sender: AnyObject!) {
    workspace.toggleToolButtons()
  }

  func applicationDidFinishLaunching(_ aNotification: Notification) {
    let contentView = self.window.contentView!
    let workspace = Workspace(mainView: DummyView(NSColor.white))
    self.workspace = workspace

    contentView.addSubview(workspace)
    workspace.autoPinEdgesToSuperviewEdges()

//    workspace.append(tool: dummyTool(title: "Top-1", color: .yellow), location: .top)

    workspace.append(tool: dummyTool(title: "Right-1", color: .magenta), location: .right)
    workspace.append(tool: dummyTool(title: "Right-2", color: .black), location: .right)

    let menuItems = [
      NSMenuItem(title: "First", action: nil, keyEquivalent: ""),
      NSMenuItem(title: "Second", action: nil, keyEquivalent: ""),
      NSMenuItem(title: "Third", action: nil, keyEquivalent: ""),
      NSMenuItem(title: "Fourth", action: nil, keyEquivalent: ""),
      NSMenuItem(title: "Fifth", action: nil, keyEquivalent: ""),
    ]

    let tool = dummyTool(title: "Left-1", color: .blue, customToolbar: DummyView(.orange), customMenu: menuItems)

    workspace.append(tool: tool, location: .left)
    workspace.append(tool: dummyTool(title: "Left-2", color: .red), location: .left)
    workspace.append(tool: dummyTool(title: "Left-3", color: .gray), location: .left)

    workspace.append(tool: dummyTool(title: "Bottom-1", color: .cyan), location: .bottom)
    workspace.append(tool: dummyTool(title: "Bottom-2", color: .blue), location: .bottom)

    tool.toggle()

    // FIXME: GH-422
    workspace.delegate = self
  }

  fileprivate func dummyTool(title: String,
                             color: NSColor,
                             customToolbar: CustomToolBar? = nil,
                             customMenu: [NSMenuItem] = []) -> WorkspaceTool
  {
    let config = WorkspaceTool.Config(title: title,
                                      view: DummyView(color),
                                      minimumDimension: 150,
                                      withInnerToolbar: true,
                                      customToolbar: customToolbar,
                                      customMenuItems: customMenu)

    return WorkspaceTool(config)
  }

  func resizeWillStart(workspace: Workspace, tool: WorkspaceTool?) {
    NSLog("\(#function)")
  }

  func resizeDidEnd(workspace: Workspace, tool: WorkspaceTool?) {
    NSLog("\(#function)")
  }

  func toggled(tool: WorkspaceTool) {
    NSLog("\(#function)")
  }

  func moved(tool: WorkspaceTool) {
    NSLog("\(#function)")
  }
}

class DummyView: CustomToolBar {

  required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }

  init(_ color: NSColor) {
    super.init(frame: .zero)
    self.configureForAutoLayout()
{'fraction_non_alphanumeric': 0.12778121137206427, 'fraction_numerical': 0.004789864029666254, 'mean_word_length': 2.918280871670702, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '914253', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1922, 'n_words': 431}