-
-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ComplexModificationsEditView.swift
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/apps/SettingsWindow/src/View/ComplexModificationsEditView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters