-
-
Notifications
You must be signed in to change notification settings - Fork 381
Expand file tree
/
Copy pathInspectorColumnMenuBuilder.swift
More file actions
93 lines (87 loc) · 3.42 KB
/
Copy pathInspectorColumnMenuBuilder.swift
File metadata and controls
93 lines (87 loc) · 3.42 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
//
// InspectorColumnMenuBuilder.swift
// TablePro
//
import AppKit
import TableProPluginKit
@MainActor
enum InspectorColumnMenuBuilder {
static func structureItems(
forColumn index: Int,
currentType: InspectorColumnType,
deleteColumns: [Int]
) -> [NSMenuItem] {
let rename = actionItem(
title: String(localized: "Rename Column…"),
action: #selector(InspectorViewController.inspectorRenameColumn(_:)),
column: index
)
let insertLeft = actionItem(
title: String(localized: "Insert Column Left"),
action: #selector(InspectorViewController.inspectorInsertColumnLeft(_:)),
column: index
)
let insertRight = actionItem(
title: String(localized: "Insert Column Right"),
action: #selector(InspectorViewController.inspectorInsertColumnRight(_:)),
column: index
)
let changeType = NSMenuItem(title: String(localized: "Change Type"), action: nil, keyEquivalent: "")
changeType.submenu = typeSubmenu(forColumn: index, currentType: currentType)
let delete = actionItem(
title: deleteColumns.count > 1
? String(localized: "Delete Columns")
: String(localized: "Delete Column"),
action: #selector(InspectorViewController.inspectorDeleteColumn(_:)),
column: index
)
delete.representedObject = deleteColumns
return [rename, insertLeft, insertRight, changeType, .separator(), delete]
}
static func typeSubmenu(forColumn index: Int, currentType: InspectorColumnType) -> NSMenu {
let submenu = NSMenu()
for type in InspectorColumnType.allCases {
let item = actionItem(
title: typeLabel(type),
action: #selector(InspectorViewController.inspectorSetColumnType(_:)),
column: index
)
item.representedObject = ColumnTypeAssignment(column: index, type: type)
item.state = (type == currentType) ? .on : .off
submenu.addItem(item)
}
submenu.addItem(.separator())
let reset = actionItem(
title: String(localized: "Reset to Inferred"),
action: #selector(InspectorViewController.inspectorSetColumnType(_:)),
column: index
)
reset.representedObject = ColumnTypeAssignment(column: index, type: nil)
submenu.addItem(reset)
return submenu
}
static func typeSymbol(_ type: InspectorColumnType) -> String {
switch type {
case .text: return "textformat"
case .integer: return "number"
case .real: return "number.square"
case .boolean: return "checkmark.square"
case .date: return "calendar"
}
}
static func typeLabel(_ type: InspectorColumnType) -> String {
switch type {
case .text: return String(localized: "Text")
case .integer: return String(localized: "Integer")
case .real: return String(localized: "Real")
case .boolean: return String(localized: "Boolean")
case .date: return String(localized: "Date")
}
}
private static func actionItem(title: String, action: Selector, column: Int) -> NSMenuItem {
let item = NSMenuItem(title: title, action: action, keyEquivalent: "")
item.tag = column
item.target = nil
return item
}
}