1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-29 00:34:26 +03:00
vimr/VimR-Workspace-Demo/AppDelegate.swift

109 lines
3.3 KiB
Swift
Raw Normal View History

2016-09-18 21:49:42 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Cocoa
import PureLayout
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, WorkspaceDelegate {
2016-09-18 21:49:42 +03:00
@IBOutlet weak var window: NSWindow!
2016-09-25 18:50:33 +03:00
fileprivate var workspace: Workspace = Workspace(mainView: NSView())
2016-09-18 21:49:42 +03:00
2016-09-25 18:50:33 +03:00
@IBAction func toggleBars(_ sender: AnyObject!) {
2016-09-18 21:49:42 +03:00
workspace.toggleAllTools()
}
2016-09-25 18:50:33 +03:00
@IBAction func toggleButtons(_ sender: AnyObject!) {
2016-09-18 21:49:42 +03:00
workspace.toggleToolButtons()
}
2016-09-25 18:50:33 +03:00
func applicationDidFinishLaunching(_ aNotification: Notification) {
2016-09-18 21:49:42 +03:00
let contentView = self.window.contentView!
2016-11-27 18:41:52 +03:00
let workspace = Workspace(mainView: DummyView(NSColor.white))
2016-09-18 21:49:42 +03:00
self.workspace = workspace
contentView.addSubview(workspace)
workspace.autoPinEdgesToSuperviewEdges()
// workspace.append(tool: dummyTool(title: "Top-1", color: .yellow), location: .top)
2016-11-27 23:37:30 +03:00
workspace.append(tool: dummyTool(title: "Right-1", color: .magenta), location: .right)
workspace.append(tool: dummyTool(title: "Right-2", color: .black), location: .right)
2016-11-27 23:37:30 +03:00
2016-12-04 19:04:55 +03:00
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)
2016-12-04 19:04:55 +03:00
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)
2016-11-27 18:41:52 +03:00
workspace.append(tool: dummyTool(title: "Bottom-1", color: .cyan), location: .bottom)
workspace.append(tool: dummyTool(title: "Bottom-2", color: .blue), location: .bottom)
2016-11-27 18:41:52 +03:00
tool.toggle()
// FIXME: GH-422
workspace.delegate = self
}
2016-11-27 18:41:52 +03:00
fileprivate func dummyTool(title: String,
color: NSColor,
2017-06-29 09:02:15 +03:00
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)")
}
2016-11-27 18:41:52 +03:00
}
2017-06-29 09:02:15 +03:00
class DummyView: CustomToolBar {
2016-11-27 18:41:52 +03:00
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
2016-09-18 21:49:42 +03:00
}
2016-11-27 18:41:52 +03:00
init(_ color: NSColor) {
super.init(frame: .zero)
self.configureForAutoLayout()
self.wantsLayer = true
self.layer?.backgroundColor = color.cgColor
}
override func mouseDown(with event: NSEvent) {
NSLog("mouse down")
2016-09-18 21:49:42 +03:00
}
}