diff --git a/PodfileLock/PodfileLock.xcodeproj/project.xcworkspace/xcuserdata/huzhilin.xcuserdatad/UserInterfaceState.xcuserstate b/PodfileLock/PodfileLock.xcodeproj/project.xcworkspace/xcuserdata/huzhilin.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..60683ad Binary files /dev/null and b/PodfileLock/PodfileLock.xcodeproj/project.xcworkspace/xcuserdata/huzhilin.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/PodfileLock/PodfileLock.xcodeproj/xcuserdata/huzhilin.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/PodfileLock/PodfileLock.xcodeproj/xcuserdata/huzhilin.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..8f3e43f --- /dev/null +++ b/PodfileLock/PodfileLock.xcodeproj/xcuserdata/huzhilin.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + diff --git a/PodfileLock/PodfileLock.xcodeproj/xcuserdata/huzhilin.xcuserdatad/xcschemes/xcschememanagement.plist b/PodfileLock/PodfileLock.xcodeproj/xcuserdata/huzhilin.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..ad144b6 --- /dev/null +++ b/PodfileLock/PodfileLock.xcodeproj/xcuserdata/huzhilin.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + PodfileLock.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/PodfileLock/PodfileLock/ChildView.swift b/PodfileLock/PodfileLock/ChildView.swift index 5de7385..5daf44a 100644 --- a/PodfileLock/PodfileLock/ChildView.swift +++ b/PodfileLock/PodfileLock/ChildView.swift @@ -12,7 +12,7 @@ var layerContentView = FlippedView() var itemContentView = FlippedView() -var allLines: [CAShapeLayer] = [] +//var allLines: [CAShapeLayer] = [] var selectedBtn: NSButton? var node_dic:[Int: DependencyNode] = [:] var btns_dic:[Int: NSButton] = [:] @@ -151,6 +151,11 @@ func drawItem(_ item: DependencyNode, vc: ViewController) { button.tag = item.index button.bezelStyle = .regularSquare button.isBordered = false + let menu = NSMenu() + let copyItem = NSMenuItem(title: "复制", action: #selector(ViewController.buttonMenuCopyClicked(_:)), keyEquivalent: "") + copyItem.representedObject = button + menu.addItem(copyItem) + button.menu = menu vc.addAction(button) // 添加按钮到视图中 @@ -173,7 +178,7 @@ func drawline(first: NSButton, sec: NSButton, up: Bool) { lineLayer.strokeColor = sec.layer?.backgroundColor ?? (NSColor.black).cgColor lineLayer.lineWidth = 1.0 layerContentView.layer?.addSublayer(lineLayer) - allLines.append(lineLayer) +// allLines.append(lineLayer) } func pointLine(btn: NSButton) -> CGPoint { diff --git a/PodfileLock/PodfileLock/ViewController.swift b/PodfileLock/PodfileLock/ViewController.swift index 643be46..91e879f 100644 --- a/PodfileLock/PodfileLock/ViewController.swift +++ b/PodfileLock/PodfileLock/ViewController.swift @@ -5,10 +5,28 @@ import Foundation var podfilePath: URL? +extension NSView { + func edge(equalTo aSuperview: NSView) { + translatesAutoresizingMaskIntoConstraints = false + leftAnchor.constraint(equalTo: aSuperview.leftAnchor).isActive = true + rightAnchor.constraint(equalTo: aSuperview.rightAnchor).isActive = true + topAnchor.constraint(equalTo: aSuperview.topAnchor).isActive = true + bottomAnchor.constraint(equalTo: aSuperview.bottomAnchor).isActive = true + } +} class ViewController: NSViewController { - + lazy var scrollView: NSScrollView = { + let sView = NSScrollView() + sView.hasVerticalScroller = true + sView.hasHorizontalScroller = true + sView.autohidesScrollers = true + return sView + }() + let cView = NSView() override func viewDidLoad() { super.viewDidLoad() + view.addSubview(scrollView) + scrollView.edge(equalTo: view) view.wantsLayer = true view.layer?.backgroundColor = NSColor.white.cgColor @@ -16,11 +34,15 @@ class ViewController: NSViewController { layerContentView.frame = view.bounds itemContentView.frame = view.bounds + cView.frame = view.bounds itemContentView.layer?.backgroundColor = NSColor.clear.cgColor - view.addSubview(layerContentView) - view.addSubview(itemContentView) + scrollView.documentView = cView + cView.addSubview(layerContentView) + cView.addSubview(itemContentView) + layerContentView.edge(equalTo: cView) + itemContentView.edge(equalTo: cView) } override func viewDidAppear() { super.viewDidAppear() @@ -76,30 +98,35 @@ class ViewController: NSViewController { // 更新窗口大小 let newSize = NSSize(width: max_w + 100, height: max_h + 100) - resizeWindow(to: newSize) - layerContentView.frame = view.bounds - itemContentView.frame = view.bounds +// resizeWindow(to: newSize) + cView.frame = NSRect(origin: .zero, size: newSize) } // 调整窗口大小的方法 var window: NSWindow? { return view.window } - func resizeWindow(to newSize: NSSize) { - guard let window = window else { return } - - var frame = window.frame - frame.size = newSize - window.setFrame(frame, display: true) - } +// func resizeWindow(to newSize: NSSize) { +// guard let window = window else { return } +// +// var frame = window.frame +// frame.size = newSize +// window.setFrame(frame, display: true) +// } // 按钮点击事件处理方法 func addAction(_ sender: NSButton) { sender.action = #selector(buttonClicked(_:)) } - @objc func buttonClicked(_ sender: NSButton) { itemClicked(sender, view: view) } + @objc func buttonMenuCopyClicked(_ sender: NSMenuItem) { + guard let button = sender.representedObject as? NSButton else { return } + let title = button.attributedTitle.string + let pasteboard = NSPasteboard.general + pasteboard.clearContents() + pasteboard.setString(title, forType: .string) + } }