1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-28 11:35:35 +03:00

GH-296 Add uuid to tools to use it as pasteboard data

This commit is contained in:
Tae Won Ha 2016-11-13 22:35:05 +01:00
parent 54a0e4ec01
commit 22732e3fcc
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
3 changed files with 22 additions and 3 deletions

View File

@ -43,6 +43,7 @@ class Workspace: NSView, WorkspaceBarDelegate {
// MARK: - API // MARK: - API
let mainView: NSView let mainView: NSView
let bars: [WorkspaceBarLocation: WorkspaceBar] let bars: [WorkspaceBarLocation: WorkspaceBar]
var tools = [WorkspaceTool]()
let config: Config let config: Config
weak var delegate: WorkspaceDelegate? weak var delegate: WorkspaceDelegate?
@ -67,6 +68,11 @@ class Workspace: NSView, WorkspaceBarDelegate {
} }
func append(tool: WorkspaceTool, location: WorkspaceBarLocation) { func append(tool: WorkspaceTool, location: WorkspaceBarLocation) {
if self.tools.contains(tool) {
return
}
self.tools.append(tool)
self.bars[location]?.append(tool: tool) self.bars[location]?.append(tool: tool)
} }

View File

@ -10,9 +10,14 @@ protocol WorkspaceToolDelegate: class {
func toggle(_ tool: WorkspaceTool) func toggle(_ tool: WorkspaceTool)
} }
class WorkspaceTool { class WorkspaceTool: Equatable {
static func ==(left: WorkspaceTool, right: WorkspaceTool) -> Bool {
return left.uuid == right.uuid
}
// MARK: - API // MARK: - API
let uuid = UUID().uuidString
let title: String let title: String
let view: NSView let view: NSView
let button: WorkspaceToolButton let button: WorkspaceToolButton

View File

@ -145,7 +145,15 @@ extension WorkspaceToolButton {
// MARK: - NSPasteboardItemDataProvider // MARK: - NSPasteboardItemDataProvider
extension WorkspaceToolButton { extension WorkspaceToolButton {
func pasteboard(_ pasteboard: NSPasteboard?, item: NSPasteboardItem, provideDataForType type: String) { func pasteboard(_ pasteboardOptional: NSPasteboard?, item: NSPasteboardItem, provideDataForType type: String) {
// FIXME guard let pasteboard = pasteboardOptional else {
return
}
guard type == WorkspaceToolButton.toolUti else {
return
}
pasteboard.writeObjects([self.tool!.uuid as NSString])
} }
} }