Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "21529A54-CB6D-46F5-BCEA-8E54D54285C9"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "D86E7101-CC43-43A1-92CD-43FB1442E13B"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "PodfileLock/ChildView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "128"
endingLineNumber = "128"
landmarkName = "itemClicked(_:view:)"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "C1AE504D-68B8-4069-A747-67C8D8C4D578"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "PodfileLock/ChildView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "131"
endingLineNumber = "131"
landmarkName = "itemClicked(_:view:)"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "C613C760-44BC-4CD4-9894-BAF7E83F5B19"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "PodfileLock/ViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "127"
endingLineNumber = "127"
landmarkName = "buttonMenuCopyClicked(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>PodfileLock.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
9 changes: 7 additions & 2 deletions PodfileLock/PodfileLock/ChildView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [:]
Expand Down Expand Up @@ -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)
// 添加按钮到视图中
Expand All @@ -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 {
Expand Down
55 changes: 41 additions & 14 deletions PodfileLock/PodfileLock/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,44 @@ 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
view.frame = CGRect(x: 0, y: 0, width: 400, height: 400)

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()
Expand Down Expand Up @@ -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)
}

}