-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathFileIcon.swift
More file actions
119 lines (116 loc) · 3.71 KB
/
FileIcon.swift
File metadata and controls
119 lines (116 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import Foundation
import SwiftUI
@ViewBuilder
public func drawFileIcon(_ file: URL?) -> some View {
let fileExtension = file?.pathExtension.lowercased() ?? ""
switch fileExtension {
case "swift":
if let nsImage = NSImage(named: "SwiftIcon") {
Image(nsImage: nsImage)
.resizable()
} else {
Image(systemName: "doc.text")
.resizable()
}
case "md":
Text("M↓")
.scaledFont(size: 10, weight: .bold, design: .monospaced)
.foregroundColor(.indigo)
case "plist":
Image(systemName: "table")
.resizable()
case "xcconfig":
Image(systemName: "gearshape.2")
.resizable()
case "html":
Image(systemName: "chevron.left.slash.chevron.right")
.resizable()
.foregroundColor(.blue)
case "entitlements":
Image(systemName: "checkmark.seal.text.page")
.resizable()
.foregroundColor(.yellow)
case "sh":
Image(systemName: "terminal")
.resizable()
case "txt":
Image(systemName: "doc.plaintext")
.resizable()
case "c", "m", "mm":
Text("C")
.scaledFont(size: 12, weight: .bold, design: .monospaced)
.foregroundColor(.blue)
case "cpp":
Text("C++")
.scaledFont(size: 8, weight: .bold, design: .monospaced)
.foregroundColor(.blue)
case "h":
Text("h")
.scaledFont(size: 12, weight: .bold, design: .monospaced)
.foregroundColor(.blue)
case "xml":
Text("XML")
.scaledFont(size: 8, weight: .bold, design: .monospaced)
.foregroundColor(.orange)
case "yml", "yaml":
Text("YML")
.scaledFont(size: 8, weight: .bold, design: .monospaced)
.foregroundColor(.pink)
case "json":
Text("{}")
.scaledFont(size: 10, weight: .bold, design: .monospaced)
.foregroundColor(.red)
case "ts":
Text("TS")
.scaledFont(size: 10, weight: .bold, design: .monospaced)
.foregroundColor(.blue)
case "tsx":
Text("TSX")
.scaledFont(size: 8, weight: .bold, design: .monospaced)
.foregroundColor(.blue)
case "js":
Text("JS")
.scaledFont(size: 10, weight: .bold, design: .monospaced)
.foregroundColor(.yellow)
case "jsx":
Text("JSX")
.scaledFont(size: 8, weight: .bold, design: .monospaced)
.foregroundColor(.yellow)
case "css":
Text("CSS")
.scaledFont(size: 8, weight: .bold, design: .monospaced)
.foregroundColor(.purple)
case "py":
Text("PY")
.scaledFont(size: 10, weight: .bold, design: .monospaced)
.foregroundColor(.indigo)
case "xctestplan":
ZStack {
Text("P")
.scaledFont(size: 8, weight: .bold, design: .monospaced)
.foregroundColor(.blue)
RoundedRectangle(cornerRadius: 1.5)
.stroke(Color.blue, lineWidth: 1.5)
.scaledFrame(width: 10, height: 10)
.rotationEffect(.degrees(45))
}
default:
Image(systemName: "doc.text")
.resizable()
}
}
@ViewBuilder
public func drawFileIcon(_ file: URL?, isDirectory: Bool = false) -> some View {
if isDirectory {
if file?.lastPathComponent == "xcassets" {
Image(systemName: "photo.on.rectangle.angled")
.resizable()
.foregroundColor(.blue)
} else {
Image(systemName: "folder")
.resizable()
}
} else {
drawFileIcon(file)
}
}