14
14
using TextBox = System . Windows . Controls . TextBox ;
15
15
using UserControl = System . Windows . Controls . UserControl ;
16
16
17
+ #nullable enable
18
+
17
19
namespace Flow . Launcher . Core . Plugin
18
20
{
19
21
public class JsonRPCPluginSettings
@@ -24,12 +26,12 @@ public class JsonRPCPluginSettings
24
26
public Dictionary < string , FrameworkElement > SettingControls { get ; } = new ( ) ;
25
27
26
28
public IReadOnlyDictionary < string , object > Inner => Settings ;
27
- protected ConcurrentDictionary < string , object > Settings { get ; set ; }
29
+ protected ConcurrentDictionary < string , object > Settings { get ; set ; } = null ! ;
28
30
public required IPublicAPI API { get ; init ; }
29
31
30
- private JsonStorage < ConcurrentDictionary < string , object > > _storage ;
32
+ private JsonStorage < ConcurrentDictionary < string , object > > _storage = null ! ;
31
33
32
- // maybe move to resource?
34
+ // TODO: Move to resource
33
35
private static readonly Thickness settingControlMargin = new ( 0 , 9 , 18 , 9 ) ;
34
36
private static readonly Thickness settingCheckboxMargin = new ( 0 , 9 , 9 , 9 ) ;
35
37
private static readonly Thickness settingPanelMargin = ( Thickness ) System . Windows . Application . Current . FindResource ( "SettingPanelMargin" ) ;
@@ -104,10 +106,10 @@ public void Save()
104
106
_storage . Save ( ) ;
105
107
}
106
108
107
- public Control CreateSettingPanel ( )
109
+ public Control ? CreateSettingPanel ( )
108
110
{
109
111
// If there are no settings or the settings are empty, return null
110
- if ( Settings == null || Settings . IsEmpty )
112
+ if ( Configuration == null || Settings == null || Settings . IsEmpty )
111
113
{
112
114
return null ;
113
115
}
@@ -124,7 +126,7 @@ public Control CreateSettingPanel()
124
126
} ) ;
125
127
126
128
// Iterate over each setting and create one row for it
127
- int rowCount = 0 ;
129
+ var rowCount = 0 ;
128
130
foreach ( var ( type , attributes ) in Configuration . Body )
129
131
{
130
132
// Skip if the setting does not have attributes or name
@@ -137,7 +139,7 @@ public Control CreateSettingPanel()
137
139
mainPanel . RowDefinitions . Add ( new RowDefinition ( ) ) ;
138
140
139
141
// State controls for column 0 and 1
140
- StackPanel panel = null ;
142
+ StackPanel ? panel = null ;
141
143
FrameworkElement contentControl ;
142
144
143
145
// If the type is textBlock or seperator, we do not need to create a panel
@@ -151,6 +153,7 @@ public Control CreateSettingPanel()
151
153
} ;
152
154
153
155
// Create a text block for name
156
+ // TODO: Move to resource
154
157
var name = new TextBlock ( )
155
158
{
156
159
Text = attributes . Label ,
@@ -159,9 +162,10 @@ public Control CreateSettingPanel()
159
162
} ;
160
163
161
164
// Create a text block for description
162
- TextBlock desc = null ;
165
+ TextBlock ? desc = null ;
163
166
if ( attributes . Description != null )
164
167
{
168
+ // TODO: Move to resource
165
169
desc = new TextBlock ( )
166
170
{
167
171
Text = attributes . Description ,
@@ -170,7 +174,6 @@ public Control CreateSettingPanel()
170
174
Margin = new ( 0 , 2 , 0 , 0 ) , // TODO: Use resource
171
175
TextWrapping = TextWrapping . WrapWithOverflow
172
176
} ;
173
-
174
177
desc . SetResourceReference ( TextBlock . ForegroundProperty , "Color04B" ) ; // for theme change
175
178
}
176
179
@@ -188,7 +191,7 @@ public Control CreateSettingPanel()
188
191
{
189
192
contentControl = new TextBlock
190
193
{
191
- Text = attributes . Description . Replace ( "\\ r\\ n" , "\r \n " ) ,
194
+ Text = attributes . Description ? . Replace ( "\\ r\\ n" , "\r \n " ) ?? string . Empty ,
192
195
Padding = new Thickness ( 0 , 0 , 0 , 0 ) ,
193
196
HorizontalAlignment = System . Windows . HorizontalAlignment . Left ,
194
197
TextAlignment = TextAlignment . Left ,
@@ -250,6 +253,7 @@ public Control CreateSettingPanel()
250
253
{
251
254
FolderBrowserDialog folderDialog => folderDialog . SelectedPath ,
252
255
OpenFileDialog fileDialog => fileDialog . FileName ,
256
+ _ => string . Empty
253
257
} ;
254
258
textBox . Text = path ;
255
259
Settings [ attributes . Name ] = path ;
@@ -341,7 +345,7 @@ Settings[attributes.Name] is bool isChecked
341
345
342
346
checkBox . Click += ( sender , _ ) =>
343
347
{
344
- Settings [ attributes . Name ] = ( ( CheckBox ) sender ) . IsChecked ;
348
+ Settings [ attributes . Name ] = ( ( CheckBox ) sender ) . IsChecked ! ;
345
349
} ;
346
350
347
351
contentControl = checkBox ;
0 commit comments