Skip to content

Commit

Permalink
Add ComplexModificationsEditView.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Sep 9, 2023
1 parent 47e351a commit 681732d
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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)
}
}
13 changes: 13 additions & 0 deletions src/apps/SettingsWindow/src/View/ComplexModificationsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -51,13 +53,21 @@ struct ComplexModificationsView: View {

Spacer()

Button(action: {
editingRule = complexModificationRule
showingEditSheet = true
}) {
Label("Edit", systemImage: "pencil.circle.fill")
}

Button(action: {
settings.removeComplexModificationsRule(complexModificationRule)
}) {
Image(systemName: "trash.fill")
.buttonLabelStyle()
}
.deleteButtonStyle()
.frame(width: 60)
}
.contextMenu {
Section(header: Text("Position")) {
Expand Down Expand Up @@ -98,6 +108,9 @@ struct ComplexModificationsView: View {
}
}
}
.sheet(isPresented: $showingEditSheet) {
ComplexModificationsEditView(rule: $editingRule, showing: $showingEditSheet)
}
}
}

Expand Down

0 comments on commit 681732d

Please sign in to comment.