diff --git a/src/apps/SettingsWindow/src/View/ComplexModificationsEditView.swift b/src/apps/SettingsWindow/src/View/ComplexModificationsEditView.swift new file mode 100644 index 000000000..dd5a86fcd --- /dev/null +++ b/src/apps/SettingsWindow/src/View/ComplexModificationsEditView.swift @@ -0,0 +1,82 @@ +import SwiftUI + +struct ComplexModificationsEditView: View { + @Binding var rule: LibKrbn.ComplexModificationsRule? + @Binding var showing: Bool + @State private var description = "" + @State private var disabled = true + @State private var jsonString = "" + @ObservedObject private var settings = LibKrbn.Settings.shared + + var body: some View { + VStack(alignment: .leading, spacing: 12.0) { + if rule != nil { + VStack(alignment: .leading, spacing: 12.0) { + HStack(alignment: .center) { + Text("Description: \(description)") + + Spacer() + + Button(action: { + showing = false + }) { + Label(disabled ? "Close" : "Cancel", systemImage: "xmark") + } + + if !disabled { + Spacer() + .frame(width: 24.0) + + Button(action: { + showing = false + }) { + Label("Save", systemImage: "checkmark") + .buttonLabelStyle() + } + .prominentButtonStyle() + } + } + + if disabled { + VStack { + Text( + "Content is too large to edit. Please edit karabiner.json directly with your favorite editor." + ) + } + .padding() + .foregroundColor(Color.errorForeground) + .background(Color.errorBackground) + } else { + TextEditor(text: $jsonString) + } + + Spacer() + } + .padding(6.0) + } + } + .padding() + .frame(width: 1000, height: 600) + + .onAppear { + description = rule?.description ?? "" + + if let s = rule?.jsonString { + disabled = false + jsonString = s + } else { + disabled = true + jsonString = "" + } + } + } +} + +struct ComplexModificationsEditView_Previews: PreviewProvider { + @State static var rule: LibKrbn.ComplexModificationsRule? = LibKrbn.ComplexModificationsRule( + 0, "", "{}") + @State static var showing = true + static var previews: some View { + ComplexModificationsEditView(rule: $rule, showing: $showing) + } +} diff --git a/src/apps/SettingsWindow/src/View/ComplexModificationsView.swift b/src/apps/SettingsWindow/src/View/ComplexModificationsView.swift index e954281ce..3c9b741d7 100644 --- a/src/apps/SettingsWindow/src/View/ComplexModificationsView.swift +++ b/src/apps/SettingsWindow/src/View/ComplexModificationsView.swift @@ -9,6 +9,8 @@ struct ComplexModificationsView: View { @ObservedObject private var contentViewStates = ContentViewStates.shared @ObservedObject private var settings = LibKrbn.Settings.shared @State private var moveDisabled: Bool = true + @State private var showingEditSheet = false + @State private var editingRule: LibKrbn.ComplexModificationsRule? var body: some View { VStack(alignment: .leading, spacing: 12.0) { @@ -51,6 +53,13 @@ struct ComplexModificationsView: View { Spacer() + Button(action: { + editingRule = complexModificationRule + showingEditSheet = true + }) { + Label("Edit", systemImage: "pencil.circle.fill") + } + Button(action: { settings.removeComplexModificationsRule(complexModificationRule) }) { @@ -58,6 +67,7 @@ struct ComplexModificationsView: View { .buttonLabelStyle() } .deleteButtonStyle() + .frame(width: 60) } .contextMenu { Section(header: Text("Position")) { @@ -98,6 +108,9 @@ struct ComplexModificationsView: View { } } } + .sheet(isPresented: $showingEditSheet) { + ComplexModificationsEditView(rule: $editingRule, showing: $showingEditSheet) + } } }