feat(process): 增加搜索清空与右键复制菜单
This commit is contained in:
@@ -34,9 +34,9 @@ struct MemoryDetailsView: View {
|
||||
|
||||
@ViewBuilder private var pressure: some View {
|
||||
switch memory.pressure {
|
||||
case 1: Label("pressure.normal", systemImage: "circle.fill").foregroundStyle(Color("MetricCPU"))
|
||||
case 2: Label("pressure.warning", systemImage: "circle.fill").foregroundStyle(.orange)
|
||||
case 4: Label("pressure.critical", systemImage: "circle.fill").foregroundStyle(.red)
|
||||
case 1: Text("pressure.normal").foregroundStyle(Color("MetricCPU"))
|
||||
case 2: Text("pressure.warning").foregroundStyle(.orange)
|
||||
case 4: Text("pressure.critical").foregroundStyle(.red)
|
||||
default: Text(verbatim: "--").foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,17 +44,20 @@ struct ProcessTableView: View {
|
||||
HStack { Text(verbatim: row.threads.map(String.init) ?? "--"); if row.restricted { Image(systemName: "lock").accessibilityLabel(Text("panel.restricted")) } }
|
||||
}.width(65)
|
||||
}
|
||||
.contextMenu(forSelectionType: ProcessIdentity.self) { identities in
|
||||
if let id = identities.first, let row = rows.first(where: { $0.id == id }) {
|
||||
Button { copy(String(row.id.pid)) } label: { Text("copyPID", tableName: "Process") }
|
||||
Button { copy(row.name) } label: { Text("copyName", tableName: "Process") }
|
||||
Button { if let path = row.path { copy(path) } } label: { Text("copyPath", tableName: "Process") }
|
||||
.disabled(row.path == nil)
|
||||
}
|
||||
}
|
||||
.font(.system(size: 11)).monospacedDigit()
|
||||
.tableStyle(.inset(alternatesRowBackgrounds: true))
|
||||
.scrollContentBackground(.hidden)
|
||||
.transaction { $0.animation = nil }
|
||||
.overlay { if snapshot != nil && rows.isEmpty && snapshot?.failed != true { Text("panel.noResults").foregroundStyle(.secondary).allowsHitTesting(false) } }
|
||||
if let row = selectedRow {
|
||||
HStack(alignment: .top) {
|
||||
Text(verbatim: row.path ?? "--").textSelection(.enabled).lineLimit(2).frame(maxWidth: .infinity, alignment: .leading)
|
||||
if let path = row.path { Button("panel.copy") { NSPasteboard.general.clearContents(); NSPasteboard.general.setString(path, forType: .string) } }
|
||||
}.font(.system(size: 11))
|
||||
} else if exitedSelection != nil, let departed {
|
||||
if exitedSelection != nil, let departed {
|
||||
HStack { Text(verbatim: departed.name); Text("panel.exited"); Button("panel.dismiss") { selected = nil; self.departed = nil } }
|
||||
}
|
||||
}
|
||||
@@ -85,7 +88,24 @@ struct ProcessTableView: View {
|
||||
.help(Text("\(Text("panel.processScope"))\n\(Text("panel.coverage"))\n\(snapshot?.readable ?? 0) / \(snapshot?.enumerated ?? 0) · \(rows.count)"))
|
||||
}
|
||||
private var searchField: some View {
|
||||
TextField("panel.search", text: $search).textFieldStyle(.roundedBorder).focused($searchFocused)
|
||||
HStack(spacing: 4) {
|
||||
TextField("panel.search", text: $search).textFieldStyle(.plain).focused($searchFocused)
|
||||
if !search.isEmpty {
|
||||
Button { search = ""; searchFocused = true } label: {
|
||||
Image(systemName: "xmark.circle.fill").foregroundStyle(.secondary)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.accessibilityLabel(Text("clearSearch", tableName: "Process"))
|
||||
.help(Text("clearSearch", tableName: "Process"))
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 7).padding(.vertical, 4)
|
||||
.background(.background, in: RoundedRectangle(cornerRadius: 5))
|
||||
.overlay(RoundedRectangle(cornerRadius: 5).strokeBorder(.primary.opacity(0.15)))
|
||||
}
|
||||
private func copy(_ value: String) {
|
||||
NSPasteboard.general.clearContents()
|
||||
NSPasteboard.general.setString(value, forType: .string)
|
||||
}
|
||||
private func rebuild(retainOrder: Bool) {
|
||||
rows = ProcessTableProjection.rows(snapshot?.rows ?? [], query: search, sorting: sortOrder, order: retainOrder ? rows.map(\.id) : [])
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"sourceLanguage": "en",
|
||||
"strings": {
|
||||
"copyPID": {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Copy PID"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "复制 PID"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "複製 PID"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"copyName": {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Copy Name"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "复制名称"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "複製名稱"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"copyPath": {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Copy Path"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "复制路径"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "複製路徑"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"clearSearch": {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Clear Search"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "清空搜索"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "清除搜尋"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"version": "1.0"
|
||||
}
|
||||
Reference in New Issue
Block a user