|
|
@@ -0,0 +1,61 @@
|
|
|
+//
|
|
|
+// URLHintPreferencePane.swift
|
|
|
+// Todos
|
|
|
+//
|
|
|
+// Created by Sam Jaffe on 3/1/26.
|
|
|
+//
|
|
|
+
|
|
|
+import SwiftUI
|
|
|
+
|
|
|
+struct SettingsView: View {
|
|
|
+ @EnvironmentObject var allHints: URLHintArray
|
|
|
+ @State var active = URLHint()
|
|
|
+
|
|
|
+ var body: some View {
|
|
|
+ TabView {
|
|
|
+ Tab("URL Hints", systemImage: "link") {
|
|
|
+ Text("Custom rules to expand a tag into a URL")
|
|
|
+ Table(of: Binding<URLHint>.self) {
|
|
|
+ TableColumn("Tag Prefix") { hint in
|
|
|
+ TextField("", text: hint.prefix)
|
|
|
+ .onSubmit(addHint)
|
|
|
+ }
|
|
|
+ TableColumn("URL Expansion") { hint in
|
|
|
+ TextField("", text: hint.replacement)
|
|
|
+ .onSubmit(addHint)
|
|
|
+ }
|
|
|
+ TableColumn("") { hint in
|
|
|
+ if hint.id != active.id {
|
|
|
+ Button() {
|
|
|
+ allHints.array.removeAll(where: { $0.id == hint.id })
|
|
|
+ UserDefaults.standard.set(allHints.serial,
|
|
|
+ forKey: UserDefaultsKeys.UrlHints)
|
|
|
+ } label: {
|
|
|
+ Label("", systemImage: "trash")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.width(max: 20)
|
|
|
+ } rows: {
|
|
|
+ ForEach($allHints.array) { hint in
|
|
|
+ TableRow(hint)
|
|
|
+ }
|
|
|
+ TableRow($active)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private func addHint() {
|
|
|
+ if active.valid {
|
|
|
+ allHints.array.append(active)
|
|
|
+ UserDefaults.standard.set(allHints.serial,
|
|
|
+ forKey: UserDefaultsKeys.UrlHints)
|
|
|
+ active = URLHint()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#Preview {
|
|
|
+ SettingsView()
|
|
|
+ .environmentObject(URLHintArray())
|
|
|
+}
|