Skip to content

Commit 41067c3

Browse files
feat: polish file tools settings UI
1 parent 559fc8f commit 41067c3

13 files changed

Lines changed: 514 additions & 86 deletions

File tree

‎App/FileMint/ContentView.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private struct SettingsSidebarButton: View {
139139
.padding(.horizontal, 12).frame(height: 40)
140140
.background {
141141
RoundedRectangle(cornerRadius: 8, style: .continuous)
142-
.fill(isSelected ? mint.opacity(colorScheme == .dark ? 0.13 : 0.10)
142+
.fill(isSelected ? mint.opacity(colorScheme == .dark ? 0.17 : 0.13)
143143
: Color.primary.opacity(isHovered ? 0.045 : 0))
144144
}
145145
.overlay {
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import FileMintCore
2+
import SwiftUI
3+
4+
/// The settings surface also runs in an isolated native QA fixture, without a store.
5+
struct FileToolsSettingsView: View {
6+
@Binding var preferences: FileToolsPreferences
7+
let language: AppLanguage
8+
9+
private func text(_ key: FileMintTextKey) -> String {
10+
FileMintStrings.text(key, language: language)
11+
}
12+
13+
private var placementWidth: CGFloat { language.resolved() == .chinese ? 138 : 164 }
14+
15+
var body: some View {
16+
ScrollView {
17+
VStack(alignment: .leading, spacing: 26) {
18+
VStack(alignment: .leading, spacing: 12) {
19+
heading(.fileTools)
20+
VStack(alignment: .leading, spacing: 8) {
21+
Toggle(text(.enableFileTools), isOn: $preferences.isEnabled)
22+
.font(.system(size: 13, weight: .semibold))
23+
.accessibilityIdentifier("fileTools.enabled")
24+
Text(text(.fileToolsOffHint))
25+
.font(.caption).foregroundStyle(.secondary)
26+
.fixedSize(horizontal: false, vertical: true)
27+
.padding(.leading, 20)
28+
}.toolSettingsGroup()
29+
}
30+
31+
VStack(alignment: .leading, spacing: 12) {
32+
VStack(alignment: .leading, spacing: 5) {
33+
heading(.fileToolsActions)
34+
Text(text(.fileToolsActionsHint))
35+
.font(.caption).foregroundStyle(.secondary)
36+
}
37+
ForEach(FileTool.allCases, id: \.self) { tool in
38+
toolSection(tool)
39+
}
40+
}
41+
// Disable the whole subtree, not just the visible pointer targets.
42+
// This also disables keyboard and accessibility actions on its controls.
43+
.disabled(!preferences.isEnabled)
44+
.saturation(preferences.isEnabled ? 1 : 0)
45+
.opacity(preferences.isEnabled ? 1 : 0.6)
46+
}
47+
.toggleStyle(.checkbox)
48+
.tint(.mint)
49+
.padding(1)
50+
}
51+
}
52+
53+
private func heading(_ key: FileMintTextKey) -> some View {
54+
Text(text(key)).font(.headline).accessibilityAddTraits(.isHeader)
55+
}
56+
57+
private func toolSection(_ tool: FileTool) -> some View {
58+
let enabled = preferences.isToolEnabled(tool)
59+
return VStack(alignment: .leading, spacing: 14) {
60+
HStack(alignment: .top, spacing: 18) {
61+
VStack(alignment: .leading, spacing: 7) {
62+
Toggle(isOn: Binding(
63+
get: { preferences.isToolEnabled(tool) },
64+
set: { preferences.setEnabled($0, for: tool) }
65+
)) {
66+
HStack(spacing: 9) {
67+
if let image = FileToolAppearance.image(for: tool, size: 20) {
68+
Image(nsImage: image).resizable().scaledToFit()
69+
.frame(width: 20, height: 20)
70+
.saturation(enabled ? 1 : 0)
71+
.opacity(enabled ? 1 : 0.5)
72+
.accessibilityHidden(true)
73+
}
74+
Text(text(tool.title))
75+
.font(.system(size: 13, weight: .semibold))
76+
.fixedSize(horizontal: false, vertical: true)
77+
}
78+
}
79+
.accessibilityLabel(text(tool.title))
80+
.accessibilityIdentifier("fileTools.\(tool.rawValue)")
81+
Text(text(hint(for: tool)))
82+
.font(.caption).foregroundStyle(.secondary)
83+
.fixedSize(horizontal: false, vertical: true)
84+
.padding(.leading, 20)
85+
}.frame(maxWidth: .infinity, alignment: .leading)
86+
87+
VStack(alignment: .leading, spacing: 6) {
88+
Text(text(.toolMenuPosition)).font(.caption).foregroundStyle(.secondary)
89+
positionPicker(selection: Binding(
90+
get: { preferences.mainMenuTools.contains(tool) },
91+
set: { value in
92+
if value { preferences.mainMenuTools.insert(tool) }
93+
else { preferences.mainMenuTools.remove(tool) }
94+
}
95+
), label: "\(text(tool.title)) — \(text(.toolMenuPosition))")
96+
.accessibilityIdentifier("fileTools.\(tool.rawValue).mainMenu")
97+
}
98+
.frame(width: placementWidth)
99+
.disabled(!enabled)
100+
}
101+
102+
if tool == .move || tool == .permanentDelete {
103+
VStack(alignment: .leading, spacing: 12) {
104+
Divider()
105+
if tool == .move {
106+
HStack(spacing: 16) {
107+
Text(text(.moveHereMenuPosition))
108+
.fixedSize(horizontal: false, vertical: true)
109+
Spacer(minLength: 0)
110+
positionPicker(selection: $preferences.moveHereInMainMenu,
111+
label: text(.moveHereMenuPosition))
112+
.frame(width: placementWidth)
113+
.accessibilityIdentifier("fileTools.moveHere.mainMenu")
114+
}
115+
.help(text(.moveItemsHint))
116+
} else {
117+
HStack(spacing: 16) {
118+
Text(text(.deleteConfirmation))
119+
Spacer(minLength: 0)
120+
Picker(text(.deleteConfirmation), selection: $preferences.deleteConfirmation) {
121+
Text(text(.deleteRequireConfirmation)).tag(DeleteConfirmation.required)
122+
Text(text(.deleteSilently)).tag(DeleteConfirmation.silent)
123+
}
124+
.labelsHidden().pickerStyle(.segmented)
125+
.frame(width: language.resolved() == .chinese ? 250 : 290)
126+
.accessibilityIdentifier("fileTools.deleteConfirmation")
127+
}
128+
.help(text(.permanentDeleteHint))
129+
}
130+
}
131+
.font(.system(size: 12))
132+
.padding(.leading, 20)
133+
.disabled(!enabled)
134+
.opacity(enabled ? 1 : 0.6)
135+
}
136+
}.toolSettingsGroup()
137+
}
138+
139+
private func positionPicker(selection: Binding<Bool>, label: String) -> some View {
140+
Picker(label, selection: selection) {
141+
Text(text(.toolSubmenu)).tag(false)
142+
Text(text(.toolMainMenu)).tag(true)
143+
}
144+
.labelsHidden().pickerStyle(.menu)
145+
// Menu placement is a regular choice, so keep its value in the
146+
// system control text color instead of the page's mint accent.
147+
.tint(.primary)
148+
.foregroundStyle(.primary)
149+
.accessibilityLabel(label)
150+
}
151+
152+
private func hint(for tool: FileTool) -> FileMintTextKey {
153+
switch tool {
154+
case .copyNames: .copyNamesSettingsHint
155+
case .copyPaths: .copyPathsSettingsHint
156+
case .move: .moveSettingsHint
157+
case .permanentDelete: .deleteSettingsHint
158+
case .airDrop: .airDropHint
159+
}
160+
}
161+
}
162+
163+
private extension View {
164+
func toolSettingsGroup() -> some View {
165+
padding(16)
166+
.frame(maxWidth: .infinity, alignment: .leading)
167+
.background(Color(nsColor: .controlBackgroundColor),
168+
in: RoundedRectangle(cornerRadius: 10, style: .continuous))
169+
.overlay {
170+
RoundedRectangle(cornerRadius: 10, style: .continuous)
171+
.strokeBorder(Color(nsColor: .separatorColor).opacity(0.45), lineWidth: 0.5)
172+
}
173+
}
174+
}

‎App/FileMint/SettingsSections.swift‎

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -81,65 +81,9 @@ struct FileToolsPane: View {
8181
@EnvironmentObject private var model: PreferencesModel
8282

8383
var body: some View {
84-
ScrollView {
85-
VStack(alignment: .leading, spacing: 26) {
86-
SettingsSection(title: model.text(.fileTools)) {
87-
Toggle(model.text(.enableFileTools), isOn: $model.preferences.fileTools.isEnabled)
88-
.accessibilityIdentifier("fileTools.enabled")
89-
Text(model.text(.fileToolsOffHint)).font(.caption).foregroundStyle(.secondary)
90-
.fixedSize(horizontal: false, vertical: true)
91-
}
92-
if model.preferences.fileTools.isEnabled {
93-
SettingsSection(title: model.text(.fileToolsActions)) {
94-
ForEach(FileTool.allCases, id: \.self) { tool in
95-
if tool != FileTool.allCases.first { Divider() }
96-
VStack(alignment: .leading, spacing: 10) {
97-
Toggle(model.text(tool.title), isOn: Binding(
98-
get: { model.preferences.fileTools.isToolEnabled(tool) },
99-
set: { model.preferences.fileTools.setEnabled($0, for: tool) }
100-
)).accessibilityIdentifier("fileTools.\(tool.rawValue)")
101-
Toggle(model.text(.showInMainMenu), isOn: Binding(
102-
get: { model.preferences.fileTools.mainMenuTools.contains(tool) },
103-
set: { value in
104-
if value { model.preferences.fileTools.mainMenuTools.insert(tool) }
105-
else { model.preferences.fileTools.mainMenuTools.remove(tool) }
106-
}
107-
))
108-
.accessibilityLabel("\(model.text(tool.title)) — \(model.text(.showInMainMenu))")
109-
.accessibilityIdentifier("fileTools.\(tool.rawValue).mainMenu")
110-
.disabled(!model.preferences.fileTools.isToolEnabled(tool))
111-
.padding(.leading, 16)
112-
if tool == .move {
113-
Toggle(model.text(.moveHereInMainMenu), isOn: $model.preferences.fileTools.moveHereInMainMenu)
114-
.disabled(!model.preferences.fileTools.move)
115-
.accessibilityIdentifier("fileTools.moveHere.mainMenu")
116-
.padding(.leading, 16)
117-
}
118-
if tool == .permanentDelete {
119-
Picker(model.text(.deleteConfirmation), selection: $model.preferences.fileTools.deleteConfirmation) {
120-
Text(model.text(.deleteRequireConfirmation)).tag(DeleteConfirmation.required)
121-
Text(model.text(.deleteSilently)).tag(DeleteConfirmation.silent)
122-
}.pickerStyle(.menu)
123-
.disabled(!model.preferences.fileTools.permanentDelete)
124-
.accessibilityIdentifier("fileTools.deleteConfirmation")
125-
.padding(.leading, 16)
126-
Text(model.text(.permanentDeleteHint)).font(.caption).foregroundStyle(.secondary)
127-
.fixedSize(horizontal: false, vertical: true)
128-
}
129-
if tool == .airDrop {
130-
Text(model.text(.airDropHint)).font(.caption).foregroundStyle(.secondary)
131-
.fixedSize(horizontal: false, vertical: true)
132-
}
133-
}
134-
}
135-
Text(model.text(.moveItemsHint)).font(.caption).foregroundStyle(.secondary)
136-
.fixedSize(horizontal: false, vertical: true)
137-
Text(model.text(.copyItemsHint)).font(.caption).foregroundStyle(.secondary)
138-
.fixedSize(horizontal: false, vertical: true)
139-
}
140-
}
141-
}.toggleStyle(SmallSettingsSwitchStyle()).padding(1)
142-
}.onChange(of: model.preferences.fileTools) { _ in model.save() }
84+
FileToolsSettingsView(preferences: $model.preferences.fileTools,
85+
language: model.preferences.language)
86+
.onChange(of: model.preferences.fileTools) { _ in model.save() }
14387
}
14488
}
14589

‎CorePackage/Sources/FileMintCore/Localization.swift‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ public enum FileMintTextKey: String, CaseIterable, Sendable {
5959
case enableFileTools
6060
case fileToolsOffHint
6161
case fileToolsActions
62+
case fileToolsActionsHint
63+
case toolMenuPosition
64+
case toolSubmenu
65+
case toolMainMenu
66+
case moveHereMenuPosition
67+
case copyNamesSettingsHint
68+
case copyPathsSettingsHint
69+
case moveSettingsHint
70+
case deleteSettingsHint
6271
case showInMainMenu
6372
case moveHereInMainMenu
6473
case permanentDelete
@@ -233,9 +242,18 @@ public enum FileMintStrings {
233242
.basicSettings: ("Basics", "基础设置"),
234243
.extensions: ("Extensions", "扩展功能"),
235244
.fileTools: ("File & Folder Tools", "文件(夹)工具"),
236-
.fileToolsHint: ("Choose file and folder actions and where they appear in Finder.", "按需启用文件或文件夹操作,并选择显示在一级菜单或子菜单。"),
245+
.fileToolsHint: ("Choose the tools you need in Finder’s context menu.", "选择需要的工具,让 Finder 右键菜单更顺手。"),
237246
.enableFileTools: ("Enable File & Folder Tools", "启用文件(夹)工具"),
238-
.fileToolsOffHint: ("Off by default. Turning this off hides its Finder menu and preserves your choices.", "默认关闭。关闭后隐藏对应的右键菜单,并保留子功能设置。"),
247+
.fileToolsOffHint: ("Turning this off hides the Finder menu and preserves your choices.", "关闭后隐藏右键菜单,并保留各项设置。"),
248+
.fileToolsActionsHint: ("Check to enable; choose where each tool appears.", "勾选启用;菜单位置可单独设置。"),
249+
.toolMenuPosition: ("Menu location", "菜单位置"),
250+
.toolSubmenu: ("Tools submenu", "工具子菜单"),
251+
.toolMainMenu: ("Main menu", "一级菜单"),
252+
.moveHereMenuPosition: ("“Move Here” menu location", "「移到此处」菜单位置"),
253+
.copyNamesSettingsHint: ("Includes extensions, one item per line.", "包含文件后缀,多选时每项一行。"),
254+
.copyPathsSettingsHint: ("Copies full paths, one item per line.", "拷贝完整路径,多选时每项一行。"),
255+
.moveSettingsHint: ("Select items, then right-click their destination to move them.", "先选择项目,再到目标文件夹右键完成移动。"),
256+
.deleteSettingsHint: ("Bypasses Trash. Deletion cannot be undone.", "不经过废纸篓,删除后无法撤销。"),
239257
.showInMainMenu: ("Show in main menu", "显示在一级菜单"),
240258
.moveHereInMainMenu: ("Show “Move Selected Items Here” in main menu", "将「将所选项目移到此处」显示在一级菜单"),
241259
.permanentDelete: ("Delete Permanently", "彻底删除"),

‎FinderSyncExtension/FileMintFinderSync/FinderSync.swift‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ final class FinderSync: FIFinderSync {
8080
let title = pending.items.count == 1 ? text(.moveSelectedHere)
8181
: String(format: text(.moveSelectedHereCount), pending.items.count)
8282
let item = NSMenuItem(title: title, action: #selector(moveSelectedHere(_:)), keyEquivalent: "")
83-
item.image = Self.menuIcon("arrow.right.square", palette: [.systemMint, .systemTeal])
83+
item.image = FileToolAppearance.moveHereImage
8484
item.tag = actions.register([FileMenuAction(directory: destination, moveBatchID: pending.id)])[0]
8585
// Root-level entry; Finder owns placement relative to system rows.
8686
moveHereItem = item
@@ -93,7 +93,6 @@ final class FinderSync: FIFinderSync {
9393
if let moveHereItem {
9494
if layout.moveHereInMain { menu.insertItem(moveHereItem, at: 0) }
9595
else if layout.moveHereInSubmenu {
96-
moveHereItem.image = nil
9796
toolsMenu.addItem(moveHereItem)
9897
}
9998
}
@@ -102,31 +101,20 @@ final class FinderSync: FIFinderSync {
102101
})
103102
for (index, tool) in tools.enumerated() {
104103
let item = NSMenuItem(title: text(tool.title), action: #selector(performFileTool(_:)), keyEquivalent: "")
104+
item.image = FileToolAppearance.image(for: tool)
105105
item.tag = toolTags[index]
106106
if layout.main.contains(tool) { menu.addItem(item) }
107107
else { toolsMenu.addItem(item) }
108108
}
109109
if layout.showsSubmenu {
110110
let toolsRoot = NSMenuItem(title: text(.fileTools), action: nil, keyEquivalent: "")
111-
toolsRoot.image = Self.menuIcon("wrench.and.screwdriver", palette: [.systemMint, .systemBlue])
111+
toolsRoot.image = FileToolAppearance.toolsImage
112112
toolsRoot.submenu = toolsMenu
113113
menu.addItem(toolsRoot)
114114
}
115115
return menu
116116
}
117117

118-
private static func menuIcon(_ symbolName: String, palette: [NSColor]) -> NSImage? {
119-
guard let source = NSImage(systemSymbolName: symbolName, accessibilityDescription: nil),
120-
let image = source.withSymbolConfiguration(NSImage.SymbolConfiguration(paletteColors: palette))
121-
else { return nil }
122-
image.size = NSSize(width: 16, height: 16)
123-
// Preserve the FileMint palette instead of letting Finder remap this to
124-
// its monochrome template color. Finder still controls the surrounding
125-
// menu highlight and keeps the text contrast native.
126-
image.isTemplate = false
127-
return image
128-
}
129-
130118
@objc private func performFileTool(_ item: NSMenuItem) {
131119
guard let action = actions.take(item.tag), let tool = action.tool else { return }
132120
let selection = action.selection

0 commit comments

Comments
 (0)