@@ -5,14 +5,10 @@ import SwiftyJSON
55
66protocol OptionView : View {
77 var label : String { get }
8- var overrideLabel : String ? { get }
98}
109
1110struct BooleanOptionView : OptionView {
1211 let label : String
13- var overrideLabel : String ? {
14- return label
15- }
1612 @ObservedObject var model : BooleanOption
1713 var body : some View {
1814 Toggle ( " " , isOn: $model. value)
@@ -32,7 +28,6 @@ func recordedKeyView(_ pair: (String, String?)) -> some View {
3228
3329struct KeyOptionView : OptionView {
3430 let label : String
35- let overrideLabel : String ? = nil
3631 @ObservedObject var model : KeyOption
3732 @State private var showRecorder = false
3833 @State private var recordedShortcut : ( String , String ? ) = ( " " , nil )
@@ -76,7 +71,6 @@ struct KeyOptionView: OptionView {
7671
7772struct StringOptionView : OptionView {
7873 let label : String
79- let overrideLabel : String ? = nil
8074 @ObservedObject var model : StringOption
8175 var body : some View {
8276 TextField ( label, text: $model. value)
@@ -93,7 +87,6 @@ let numberFormatter: NumberFormatter = {
9387
9488struct IntegerOptionView : OptionView {
9589 let label : String
96- let overrideLabel : String ? = nil
9790 @ObservedObject var model : IntegerOption
9891 @FocusState private var isFocused : Bool
9992
@@ -140,7 +133,6 @@ struct IntegerOptionView: OptionView {
140133
141134struct ColorOptionView : OptionView {
142135 let label : String
143- let overrideLabel : String ? = nil
144136 @ObservedObject var model : ColorOption
145137 var body : some View {
146138 HStack {
@@ -195,7 +187,6 @@ class ExternalConfigViewModel: ObservableObject {
195187struct ExternalOptionView : OptionView {
196188 let label : String
197189 let model : ExternalOption
198- let overrideLabel : String ? = " "
199190
200191 @StateObject private var viewModel = ExternalConfigViewModel ( )
201192 @State private var showExportCurrentTheme = false
@@ -284,7 +275,6 @@ struct ExternalOptionView: OptionView {
284275
285276struct EnumOptionView : OptionView {
286277 let label : String
287- let overrideLabel : String ? = nil
288278 @ObservedObject var model : EnumOption
289279 var body : some View {
290280 Picker ( " " , selection: $model. value) {
@@ -297,7 +287,6 @@ struct EnumOptionView: OptionView {
297287
298288struct ListOptionView < T: Option & EmptyConstructible > : OptionView {
299289 let label : String
300- let overrideLabel : String ? = nil
301290 @ObservedObject var model : ListOption < T >
302291
303292 var body : some View {
@@ -371,7 +360,6 @@ struct ListOptionView<T: Option & EmptyConstructible>: OptionView {
371360
372361struct FontOptionView : OptionView {
373362 let label : String
374- let overrideLabel : String ? = nil
375363 @ObservedObject var model : FontOption
376364 @State private var selectorIsOpen = false
377365 @State var searchInput = " "
@@ -457,7 +445,6 @@ struct FontOptionView: OptionView {
457445
458446struct PunctuationMapOptionView : OptionView {
459447 let label : String
460- let overrideLabel : String ? = nil
461448 @ObservedObject var model : PunctuationMapOption
462449
463450 var body : some View {
@@ -486,14 +473,13 @@ struct PunctuationMapOptionView: OptionView {
486473
487474struct GroupOptionView : OptionView {
488475 let label : String
489- let overrideLabel : String ? = nil
490476 let children : [ Config ]
491477
492478 var body : some View {
493479 Grid ( alignment: . topLeading) {
494480 ForEach ( children) { child in
495481 let subView = buildViewImpl ( config: child)
496- let subLabel = Text ( subView. overrideLabel ?? subView . label)
482+ let subLabel = Text ( subView. label)
497483 if subView is GroupOptionView {
498484 // If this is a nested group, put it inside a box, and let
499485 // it span two columns.
@@ -519,16 +505,20 @@ struct GroupOptionView: OptionView {
519505 // Otherwise, put the label in the left column and the
520506 // content in the right column.
521507 GridRow {
522- subLabel
523- . frame ( minWidth: 100 , maxWidth: 250 , alignment: . trailing)
524- . help ( NSLocalizedString ( " Right click to reset this item " , comment: " " ) )
525- . contextMenu {
526- Button {
527- child. resetToDefault ( )
528- } label: {
529- Text ( " Reset to default " )
508+ if subView is ExternalOptionView {
509+ HStack { } // Label is baked in button.
510+ } else {
511+ subLabel
512+ . frame ( minWidth: 100 , maxWidth: 250 , alignment: . trailing)
513+ . help ( NSLocalizedString ( " Right click to reset this item " , comment: " " ) )
514+ . contextMenu {
515+ Button {
516+ child. resetToDefault ( )
517+ } label: {
518+ Text ( " Reset to default " )
519+ }
530520 }
531- }
521+ }
532522 AnyView ( subView)
533523 }
534524 }
@@ -539,7 +529,6 @@ struct GroupOptionView: OptionView {
539529
540530struct UnsupportedOptionView : OptionView {
541531 let label = " "
542- let overrideLabel : String ? = nil
543532 let model : any Option
544533
545534 var body : some View {
@@ -611,42 +600,3 @@ func buildViewImpl(config: Config) -> any OptionView {
611600func buildView( config: Config ) -> AnyView {
612601 AnyView ( buildViewImpl ( config: config) )
613602}
614-
615- let testConfig = Config (
616- path: " Fuzzy " ,
617- description: " Fuzzy " ,
618- kind: . group( [
619- Config (
620- path: " AN_ANG " , description: " Fuzzy an ang " ,
621- kind: . option( BooleanOption ( defaultValue: false , value: true ) ) ) ,
622- Config (
623- path: " foo " , description: " FOOOO! " ,
624- kind: . option( StringOption ( defaultValue: " " , value: " semicolon " ) ) ) ,
625- Config (
626- path: " external " , description: " External test " ,
627- kind: . option( ExternalOption ( option: " Punctuation " , external: " fcitx://addon/punctuation " ) ) ) ,
628- Config (
629- path: " Shuangpin Profile " , description: " 双拼方案 " ,
630- kind: . option(
631- EnumOption (
632- defaultValue: " Ziranma " , value: " MS " , enumStrings: [ " Ziranma " , " MS " ] ,
633- enumStringsI18n: [ " 自然码 " , " 微软 " ] ) ) ) ,
634- Config (
635- path: " interval " , description: " int test " ,
636- kind: . option( IntegerOption ( defaultValue: 0 , value: 10 , min: 0 , max: 1000 ) ) ) ,
637- // Config(
638- // path: "list", description: "List test",
639- // kind: .option(
640- // ListOption(
641- // defaultValue: ["a", "b", "c"], value: ["c", "d"], elementType: "String"))
642- // ),
643- ] ) )
644-
645- #Preview {
646- VStack {
647- buildView ( config: testConfig)
648- Button ( " Print " ) {
649- print ( testConfig. encodeValue ( ) )
650- }
651- }
652- }
0 commit comments