feat(process): 增加搜索清空与右键复制菜单
This commit is contained in:
@@ -233,3 +233,5 @@ MenuPanelView 主文件保留生命周期、布局和顶栏控制,资源卡片
|
|||||||
`ProcessTableView` 使用原生 Table 的 sortOrder 绑定,`ProcessSort`/`ProcessTableProjection` 在排序、筛选或快照事件时计算行序,不在单元格渲染时排序;初始 CPU 降序,数值缺失在任意方向均置后。交互期间保序,主动切换表头立即重新投影。标题覆盖率移入悬停说明,右侧只保留搜索;CPU 仅显示百分比数值,不按逻辑核心数归一化为条形图。没有逐进程 GPU 列或数据接入。
|
`ProcessTableView` 使用原生 Table 的 sortOrder 绑定,`ProcessSort`/`ProcessTableProjection` 在排序、筛选或快照事件时计算行序,不在单元格渲染时排序;初始 CPU 降序,数值缺失在任意方向均置后。交互期间保序,主动切换表头立即重新投影。标题覆盖率移入悬停说明,右侧只保留搜索;CPU 仅显示百分比数值,不按逻辑核心数归一化为条形图。没有逐进程 GPU 列或数据接入。
|
||||||
|
|
||||||
`ProcessIcon` 属于 MenuBar 特性层,由进程列表与电池进程行复用,通过采样路径解析应用包或可执行文件图标;无路径使用占位。图标任务以进程身份和路径为键,UI 渲染时不查询 PID 对应应用,Core 数据模型保持不依赖 AppKit。
|
`ProcessIcon` 属于 MenuBar 特性层,由进程列表与电池进程行复用,通过采样路径解析应用包或可执行文件图标;无路径使用占位。图标任务以进程身份和路径为键,UI 渲染时不查询 PID 对应应用,Core 数据模型保持不依赖 AppKit。
|
||||||
|
|
||||||
|
进程选中状态仅用于保序及退出提示,不追加路径详情区。复制操作通过 Table 的 `contextMenu(forSelectionType:)` 按上下文行身份查询当前投影,提供 PID、名称、路径三项;路径不可用时禁用对应菜单。剪贴板操作仅由用户点击菜单触发。搜索框清空按钮仅清除筛选并保持输入焦点,不影响排序。
|
||||||
|
|||||||
@@ -203,3 +203,9 @@
|
|||||||
CPU 列移除进度条,保留一位小数数值。进程名称增加 15pt 图标,按采样可执行文件路径寻找最近的 `.app` 图标,无应用包时使用文件图标,路径不可读时使用占位图标。共用 `ProcessIcon`,同步替换电池进程行的重复实现,避免依赖可能复用的 PID 获取应用图标。按用户后续要求取消 GPU 列,不增加 GPU 采样或占位列。
|
CPU 列移除进度条,保留一位小数数值。进程名称增加 15pt 图标,按采样可执行文件路径寻找最近的 `.app` 图标,无应用包时使用文件图标,路径不可读时使用占位图标。共用 `ProcessIcon`,同步替换电池进程行的重复实现,避免依赖可能复用的 PID 获取应用图标。按用户后续要求取消 GPU 列,不增加 GPU 采样或占位列。
|
||||||
|
|
||||||
验证:Debug 构建及独立布局/进程投影检查通过;新增升降序、PID 排序和缺失指标置后边界检查。独立原生窗口加载实际 ProcessTableView,固定三行数据验证初始 CPU 降序、点击内存默认降序、CPU 表头再次点击切换升序、缺失数据末尾、搜索和 Escape 恢复;截图确认应用图标和纯数值 CPU。该窗口不加载正式菜单面板生命周期;正式菜单形态、窄窗口横向滚动及长期图标加载成本本轮未验证。原生交互测试时有临时 GPU 占位列,随后按用户要求移除;最终无 GPU 版本通过构建和投影检查,并重新启动隔离窗口确认列已移除、默认 CPU 降序正常。
|
验证:Debug 构建及独立布局/进程投影检查通过;新增升降序、PID 排序和缺失指标置后边界检查。独立原生窗口加载实际 ProcessTableView,固定三行数据验证初始 CPU 降序、点击内存默认降序、CPU 表头再次点击切换升序、缺失数据末尾、搜索和 Escape 恢复;截图确认应用图标和纯数值 CPU。该窗口不加载正式菜单面板生命周期;正式菜单形态、窄窗口横向滚动及长期图标加载成本本轮未验证。原生交互测试时有临时 GPU 占位列,随后按用户要求移除;最终无 GPU 版本通过构建和投影检查,并重新启动隔离窗口确认列已移除、默认 CPU 降序正常。
|
||||||
|
|
||||||
|
### 进程操作与内存压力后续调整
|
||||||
|
|
||||||
|
进程搜索框在有输入时于内部末尾显示清空按钮,清空后保留输入焦点;空输入不显示按钮。选中进程不再追加路径及复制区域,复制 PID、名称和路径统一由原生行上下文菜单提供,缺失路径时禁用复制路径。菜单使用 Table 的上下文行身份而非既有选中行,避免右键另一行复制错对象。内存压力保留状态文字和语义颜色,去掉前置圆点。新增菜单文案使用独立 Process 字符串目录,提供简体、繁体及英语,保留已有 Localizable.xcstrings 工作区修改。
|
||||||
|
|
||||||
|
验证:Debug 构建通过;隔离原生窗口加载实际进程表,验证输入后显示清空按钮、点击清空恢复全部行且保持焦点、选中不展开路径区、右键菜单三项,以及已选中可读行时右键不可读行会禁用复制路径。未执行菜单复制以避免改动用户剪贴板,剪贴板写入沿用 NSPasteboard 字符串操作。内存压力三个状态均已从 Label 改为 Text 并通过构建,正式面板运行观感本轮未验证。
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ struct MemoryDetailsView: View {
|
|||||||
|
|
||||||
@ViewBuilder private var pressure: some View {
|
@ViewBuilder private var pressure: some View {
|
||||||
switch memory.pressure {
|
switch memory.pressure {
|
||||||
case 1: Label("pressure.normal", systemImage: "circle.fill").foregroundStyle(Color("MetricCPU"))
|
case 1: Text("pressure.normal").foregroundStyle(Color("MetricCPU"))
|
||||||
case 2: Label("pressure.warning", systemImage: "circle.fill").foregroundStyle(.orange)
|
case 2: Text("pressure.warning").foregroundStyle(.orange)
|
||||||
case 4: Label("pressure.critical", systemImage: "circle.fill").foregroundStyle(.red)
|
case 4: Text("pressure.critical").foregroundStyle(.red)
|
||||||
default: Text(verbatim: "--").foregroundStyle(.secondary)
|
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")) } }
|
HStack { Text(verbatim: row.threads.map(String.init) ?? "--"); if row.restricted { Image(systemName: "lock").accessibilityLabel(Text("panel.restricted")) } }
|
||||||
}.width(65)
|
}.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()
|
.font(.system(size: 11)).monospacedDigit()
|
||||||
.tableStyle(.inset(alternatesRowBackgrounds: true))
|
.tableStyle(.inset(alternatesRowBackgrounds: true))
|
||||||
.scrollContentBackground(.hidden)
|
.scrollContentBackground(.hidden)
|
||||||
.transaction { $0.animation = nil }
|
.transaction { $0.animation = nil }
|
||||||
.overlay { if snapshot != nil && rows.isEmpty && snapshot?.failed != true { Text("panel.noResults").foregroundStyle(.secondary).allowsHitTesting(false) } }
|
.overlay { if snapshot != nil && rows.isEmpty && snapshot?.failed != true { Text("panel.noResults").foregroundStyle(.secondary).allowsHitTesting(false) } }
|
||||||
if let row = selectedRow {
|
if exitedSelection != nil, let departed {
|
||||||
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 {
|
|
||||||
HStack { Text(verbatim: departed.name); Text("panel.exited"); Button("panel.dismiss") { selected = nil; self.departed = nil } }
|
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)"))
|
.help(Text("\(Text("panel.processScope"))\n\(Text("panel.coverage"))\n\(snapshot?.readable ?? 0) / \(snapshot?.enumerated ?? 0) · \(rows.count)"))
|
||||||
}
|
}
|
||||||
private var searchField: some View {
|
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) {
|
private func rebuild(retainOrder: Bool) {
|
||||||
rows = ProcessTableProjection.rows(snapshot?.rows ?? [], query: search, sorting: sortOrder, order: retainOrder ? rows.map(\.id) : [])
|
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