@@ -15,11 +15,11 @@ public class JsonRPCPluginSettings
15
15
16
16
public required string SettingPath { get ; init ; }
17
17
public Dictionary < string , FrameworkElement > SettingControls { get ; } = new ( ) ;
18
-
18
+
19
19
public IReadOnlyDictionary < string , object > Inner => Settings ;
20
20
protected ConcurrentDictionary < string , object > Settings { get ; set ; }
21
21
public required IPublicAPI API { get ; init ; }
22
-
22
+
23
23
private JsonStorage < ConcurrentDictionary < string , object > > _storage ;
24
24
25
25
// maybe move to resource?
@@ -37,26 +37,26 @@ public async Task InitializeAsync()
37
37
_storage = new JsonStorage < ConcurrentDictionary < string , object > > ( SettingPath ) ;
38
38
Settings = await _storage . LoadAsync ( ) ;
39
39
40
- if ( Settings != null )
40
+ if ( Settings != null || Configuration == null )
41
41
{
42
42
return ;
43
43
}
44
44
45
- foreach ( var ( type , attributes ) in Configuration . Body )
45
+ foreach ( var ( type , attributes ) in Configuration . Body )
46
46
{
47
47
if ( attributes . Name == null )
48
48
{
49
49
continue ;
50
50
}
51
-
51
+
52
52
if ( ! Settings . ContainsKey ( attributes . Name ) )
53
53
{
54
54
Settings [ attributes . Name ] = attributes . DefaultValue ;
55
55
}
56
56
}
57
57
}
58
58
59
-
59
+
60
60
public void UpdateSettings ( IReadOnlyDictionary < string , object > settings )
61
61
{
62
62
if ( settings == null || settings . Count == 0 )
@@ -80,34 +80,35 @@ public void UpdateSettings(IReadOnlyDictionary<string, object> settings)
80
80
comboBox . Dispatcher . Invoke ( ( ) => comboBox . SelectedItem = value ) ;
81
81
break ;
82
82
case CheckBox checkBox :
83
- checkBox . Dispatcher . Invoke ( ( ) => checkBox . IsChecked = value is bool isChecked ? isChecked : bool . Parse ( value as string ?? string . Empty ) ) ;
83
+ checkBox . Dispatcher . Invoke ( ( ) =>
84
+ checkBox . IsChecked = value is bool isChecked
85
+ ? isChecked
86
+ : bool . Parse ( value as string ?? string . Empty ) ) ;
84
87
break ;
85
88
}
86
89
}
87
90
}
91
+
88
92
Save ( ) ;
89
93
}
90
-
94
+
91
95
public async Task SaveAsync ( )
92
96
{
93
97
await _storage . SaveAsync ( ) ;
94
98
}
95
-
99
+
96
100
public void Save ( )
97
101
{
98
102
_storage . Save ( ) ;
99
103
}
100
-
104
+
101
105
public Control CreateSettingPanel ( )
102
106
{
103
- if ( Settings == null )
107
+ if ( Settings == null || Settings . Count == 0 )
104
108
return new ( ) ;
105
109
106
110
var settingWindow = new UserControl ( ) ;
107
- var mainPanel = new Grid
108
- {
109
- Margin = settingPanelMargin , VerticalAlignment = VerticalAlignment . Center
110
- } ;
111
+ var mainPanel = new Grid { Margin = settingPanelMargin , VerticalAlignment = VerticalAlignment . Center } ;
111
112
112
113
ColumnDefinition gridCol1 = new ColumnDefinition ( ) ;
113
114
ColumnDefinition gridCol2 = new ColumnDefinition ( ) ;
@@ -242,10 +243,7 @@ public Control CreateSettingPanel()
242
243
Margin = new Thickness ( 10 , 0 , 0 , 0 ) , Content = "Browse"
243
244
} ;
244
245
245
- var dockPanel = new DockPanel ( )
246
- {
247
- Margin = settingControlMargin
248
- } ;
246
+ var dockPanel = new DockPanel ( ) { Margin = settingControlMargin } ;
249
247
250
248
DockPanel . SetDock ( Btn , Dock . Right ) ;
251
249
dockPanel . Children . Add ( Btn ) ;
@@ -352,7 +350,10 @@ public Control CreateSettingPanel()
352
350
case "checkbox" :
353
351
var checkBox = new CheckBox
354
352
{
355
- IsChecked = Settings [ attribute . Name ] is bool isChecked ? isChecked : bool . Parse ( attribute . DefaultValue ) ,
353
+ IsChecked =
354
+ Settings [ attribute . Name ] is bool isChecked
355
+ ? isChecked
356
+ : bool . Parse ( attribute . DefaultValue ) ,
356
357
Margin = settingCheckboxMargin ,
357
358
HorizontalAlignment = System . Windows . HorizontalAlignment . Right ,
358
359
ToolTip = attribute . Description
@@ -375,14 +376,12 @@ public Control CreateSettingPanel()
375
376
376
377
break ;
377
378
case "hyperlink" :
378
- var hyperlink = new Hyperlink
379
- {
380
- ToolTip = attribute . Description , NavigateUri = attribute . url
381
- } ;
379
+ var hyperlink = new Hyperlink { ToolTip = attribute . Description , NavigateUri = attribute . url } ;
382
380
383
381
var linkbtn = new System . Windows . Controls . Button
384
382
{
385
- HorizontalAlignment = System . Windows . HorizontalAlignment . Right , Margin = settingControlMargin
383
+ HorizontalAlignment = System . Windows . HorizontalAlignment . Right ,
384
+ Margin = settingControlMargin
386
385
} ;
387
386
388
387
linkbtn . Content = attribute . urlLabel ;
@@ -408,12 +407,9 @@ public Control CreateSettingPanel()
408
407
mainPanel . Children . Add ( panel ) ;
409
408
mainPanel . Children . Add ( contentControl ) ;
410
409
rowCount ++ ;
411
-
412
410
}
413
411
414
412
return settingWindow ;
415
413
}
416
-
417
-
418
414
}
419
415
}
0 commit comments