Add more sort keys to SwiftUI.Tables

This commit is contained in:
1024jp 2024-05-25 15:40:42 +09:00
parent bb55e3c698
commit cf58574f11
6 changed files with 22 additions and 13 deletions

View File

@ -19,6 +19,7 @@
- Remove Solarized themes from the bundle.
- Update all the bundled themes to have a 70% opacity in the current line highlight.
- Improve the performance of counting values in the editor for the status bar and the document inspector to avoid flicking.
- Make more table columns sortable.
- [trivial] Organize the structure of the Edit menu.
- [trivial] Suppress display of “Extracting” message on the navigation bar in instantaneous parsing.
- [trivial] Make names of code contributors in the About window selectable.

View File

@ -94,7 +94,7 @@ struct IncompatibleCharactersView: View {
}
}
TableColumn(String(localized: "Converted", table: "Document", comment: "table column header for converted character")) {
TableColumn(String(localized: "Converted", table: "Document", comment: "table column header for converted character"), sortUsing: KeyPathComparator(\.value.converted)) {
if let converted = $0.value.converted {
Text(converted)
}

View File

@ -33,6 +33,7 @@ struct SyntaxCompletionEditView: View {
@Binding var items: [Item]
@State private var selection: Set<Item.ID> = []
@State private var sortOrder: [KeyPathComparator<Item>] = []
@FocusState private var focusedField: Item.ID?
@ -46,8 +47,8 @@ struct SyntaxCompletionEditView: View {
// create a table with wrapped values and then find the editable item again in each column
// to avoid taking time when leaving a pane with a large number of items. (2024-02-25 macOS 14)
Table(self.items, selection: $selection) {
TableColumn(String(localized: "Completion", table: "SyntaxEditor", comment: "table column header")) { wrappedItem in
Table(self.items, selection: $selection, sortOrder: $sortOrder) {
TableColumn(String(localized: "Completion", table: "SyntaxEditor", comment: "table column header"), value: \.string) { wrappedItem in
if let item = $items[id: wrappedItem.id] {
TextField(text: item.string, label: EmptyView.init)
.focused($focusedField, equals: item.id)
@ -55,6 +56,9 @@ struct SyntaxCompletionEditView: View {
}
}
}
.onChange(of: self.sortOrder) { (_, newValue) in
self.items.sort(using: newValue)
}
.tableStyle(.bordered)
.border(Color(nsColor: .gridColor))

View File

@ -34,6 +34,7 @@ struct SyntaxHighlightEditView: View {
var helpAnchor: String = "syntax_highlight_settings"
@State private var selection: Set<Item.ID> = []
@State private var sortOrder: [KeyPathComparator<Item>] = []
@FocusState private var focusedField: Item.ID?
@ -44,8 +45,8 @@ struct SyntaxHighlightEditView: View {
VStack(alignment: .leading) {
// create a table with wrapped values and then find the editable item again in each column
// to avoid taking time when leaving a pane with a large number of items. (2024-02-25 macOS 14)
Table(self.items, selection: $selection) {
TableColumn(String(localized: "RE", table: "SyntaxEditor", comment: "table column header (RE for Regular Expression)")) { wrappedItem in
Table(self.items, selection: $selection, sortOrder: $sortOrder) {
TableColumn(String(localized: "RE", table: "SyntaxEditor", comment: "table column header (RE for Regular Expression)"), value: \.isRegularExpression) { wrappedItem in
if let item = $items[id: wrappedItem.id] {
Toggle(isOn: item.isRegularExpression, label: EmptyView.init)
.help(String(localized: "Regular Expression", table: "SyntaxEditor", comment: "tooltip for RE checkbox"))
@ -58,10 +59,10 @@ struct SyntaxHighlightEditView: View {
}
}
}
.width(22)
.width(24)
.alignment(.center)
TableColumn(String(localized: "IC", table: "SyntaxEditor", comment: "table column header (IC for Ignore Case)")) { wrappedItem in
TableColumn(String(localized: "IC", table: "SyntaxEditor", comment: "table column header (IC for Ignore Case)"), value: \.ignoreCase) { wrappedItem in
if let item = $items[id: wrappedItem.id] {
Toggle(isOn: item.ignoreCase, label: EmptyView.init)
.help(String(localized: "Ignore Case", table: "SyntaxEditor", comment: "tooltip for IC checkbox"))
@ -74,10 +75,10 @@ struct SyntaxHighlightEditView: View {
}
}
}
.width(22)
.width(24)
.alignment(.center)
TableColumn(String(localized: "Begin String", table: "SyntaxEditor", comment: "table column header")) { wrappedItem in
TableColumn(String(localized: "Begin String", table: "SyntaxEditor", comment: "table column header"), value: \.begin) { wrappedItem in
if let item = $items[id: wrappedItem.id] {
RegexTextField(text: item.begin, showsError: true, showsInvisible: true)
.regexHighlighted(item.isRegularExpression.wrappedValue)
@ -86,7 +87,7 @@ struct SyntaxHighlightEditView: View {
}
}
TableColumn(String(localized: "End String", table: "SyntaxEditor", comment: "table column header")) { wrappedItem in
TableColumn(String(localized: "End String", table: "SyntaxEditor", comment: "table column header"), sortUsing: KeyPathComparator(\.end)) { wrappedItem in
if let item = $items[id: wrappedItem.id] {
RegexTextField(text: item.end ?? "", showsError: true, showsInvisible: true)
.regexHighlighted(item.isRegularExpression.wrappedValue)
@ -94,12 +95,15 @@ struct SyntaxHighlightEditView: View {
}
}
TableColumn(String(localized: "Description", table: "SyntaxEditor", comment: "table column header")) { wrappedItem in
TableColumn(String(localized: "Description", table: "SyntaxEditor", comment: "table column header"), sortUsing: KeyPathComparator(\.description)) { wrappedItem in
if let item = $items[id: wrappedItem.id] {
TextField(text: item.description ?? "", label: EmptyView.init)
}
}
}
.onChange(of: self.sortOrder) { (_, newValue) in
self.items.sort(using: newValue)
}
.tableStyle(.bordered)
.border(Color(nsColor: .gridColor))

View File

@ -124,7 +124,7 @@ private struct ConflictTable: View {
TableColumn(String(localized: "Used syntax", table: "SyntaxMappingConflict", comment: "table column header"), value: \.primarySyntax) {
Text($0.primarySyntax).fontWeight(.semibold)
}
TableColumn(String(localized: "Duplicated syntaxes", table: "SyntaxMappingConflict", comment: "table column header")) {
TableColumn(String(localized: "Duplicated syntaxes", table: "SyntaxMappingConflict", comment: "table column header"), sortUsing: KeyPathComparator(\.duplicatedSyntaxes.first)) {
Text($0.duplicatedSyntaxes, format: .list(type: .and, width: .narrow))
}
}

View File

@ -48,7 +48,7 @@ struct SyntaxOutlineEditView: View {
Toggle(isOn: item.ignoreCase, label: EmptyView.init)
.help(String(localized: "Ignore Case", table: "SyntaxEditor", comment: "tooltip for IC checkbox"))
}
.width(22)
.width(24)
.alignment(.center)
TableColumn(String(localized: "Regular Expression Pattern", table: "SyntaxEditor", comment: "table column header")) { item in