@@ -24,10 +24,14 @@ public class JsonRPCPluginSettings
24
24
25
25
private JsonStorage < ConcurrentDictionary < string , object > > _storage = null ! ;
26
26
27
- // TODO: Move to resource
28
- private static readonly Thickness settingControlMargin = new ( 0 , 9 , 18 , 9 ) ;
29
- private static readonly Thickness settingCheckboxMargin = new ( 0 , 9 , 9 , 9 ) ;
30
- private static readonly Thickness settingPanelMargin = ( Thickness ) Application . Current . FindResource ( "SettingPanelMargin" ) ;
27
+ private static readonly Thickness SettingPanelMargin = ( Thickness ) Application . Current . FindResource ( "SettingPanelMargin" ) ;
28
+
29
+ private static readonly Thickness SettingPanelItemLeftMargin = ( Thickness ) Application . Current . FindResource ( "SettingPanelItemLeftMargin" ) ;
30
+ private static readonly Thickness SettingPanelItemRightMargin = ( Thickness ) Application . Current . FindResource ( "SettingPanelItemRightMargin" ) ;
31
+ private static readonly Thickness SettingPanelItemTopBottomMargin = ( Thickness ) Application . Current . FindResource ( "SettingPanelItemTopBottomMargin" ) ;
32
+
33
+ private static readonly Thickness SettingPanelItemLeftTopBottomMargin = ( Thickness ) Application . Current . FindResource ( "SettingPanelItemLeftTopBottomMargin" ) ;
34
+ private static readonly Thickness SettingPanelItemRightTopBottomMargin = ( Thickness ) Application . Current . FindResource ( "SettingPanelItemRightTopBottomMargin" ) ;
31
35
32
36
public async Task InitializeAsync ( )
33
37
{
@@ -109,15 +113,15 @@ public void Save()
109
113
return null ;
110
114
}
111
115
112
- // Create main grid with two columns
113
- var mainPanel = new Grid { Margin = settingPanelMargin , VerticalAlignment = VerticalAlignment . Center } ;
116
+ // Create main grid with two columns (Column 1: Auto, Column 2: *)
117
+ var mainPanel = new Grid { Margin = SettingPanelMargin , VerticalAlignment = VerticalAlignment . Center } ;
114
118
mainPanel . ColumnDefinitions . Add ( new ColumnDefinition ( )
115
119
{
116
120
Width = new GridLength ( 0 , GridUnitType . Auto )
117
121
} ) ;
118
122
mainPanel . ColumnDefinitions . Add ( new ColumnDefinition ( )
119
123
{
120
- Width = new GridLength ( 0 , GridUnitType . Auto )
124
+ Width = new GridLength ( 1 , GridUnitType . Star )
121
125
} ) ;
122
126
123
127
// Iterate over each setting and create one row for it
@@ -140,12 +144,13 @@ public void Save()
140
144
StackPanel ? panel = null ;
141
145
FrameworkElement contentControl ;
142
146
143
- // If the type is textBlock or seperator , we do not need to create a panel
144
- if ( type != "textBlock" && type != "seperator" )
147
+ // If the type is textBlock, seperator or check box , we do not need to create a panel
148
+ if ( type != "textBlock" && type != "seperator" && type != "checkbox" )
145
149
{
146
150
// Create a panel to hold the label and description
147
151
panel = new StackPanel
148
152
{
153
+ Margin = SettingPanelItemTopBottomMargin ,
149
154
Orientation = Orientation . Vertical ,
150
155
VerticalAlignment = VerticalAlignment . Center
151
156
} ;
@@ -190,7 +195,7 @@ public void Save()
190
195
contentControl = new TextBlock
191
196
{
192
197
Text = attributes . Description ? . Replace ( "\\ r\\ n" , "\r \n " ) ?? string . Empty ,
193
- Padding = new Thickness ( 0 , 0 , 0 , 0 ) ,
198
+ Margin = SettingPanelItemTopBottomMargin ,
194
199
HorizontalAlignment = HorizontalAlignment . Left ,
195
200
TextAlignment = TextAlignment . Left ,
196
201
TextWrapping = TextWrapping . Wrap
@@ -203,7 +208,7 @@ public void Save()
203
208
var textBox = new TextBox ( )
204
209
{
205
210
Text = Settings [ attributes . Name ] as string ?? string . Empty ,
206
- Margin = settingControlMargin ,
211
+ Margin = SettingPanelItemLeftTopBottomMargin ,
207
212
HorizontalAlignment = HorizontalAlignment . Stretch ,
208
213
ToolTip = attributes . Description
209
214
} ;
@@ -222,7 +227,7 @@ public void Save()
222
227
{
223
228
var textBox = new TextBox ( )
224
229
{
225
- Margin = new Thickness ( 10 , 0 , 0 , 0 ) ,
230
+ Margin = SettingPanelItemLeftMargin ,
226
231
Text = Settings [ attributes . Name ] as string ?? string . Empty ,
227
232
HorizontalAlignment = HorizontalAlignment . Stretch ,
228
233
ToolTip = attributes . Description
@@ -235,7 +240,8 @@ public void Save()
235
240
236
241
var Btn = new Button ( )
237
242
{
238
- Margin = new Thickness ( 10 , 0 , 0 , 0 ) , Content = "Browse"
243
+ Margin = SettingPanelItemLeftMargin ,
244
+ Content = "Browse" // TODO: Localization
239
245
} ;
240
246
241
247
Btn . Click += ( _ , _ ) =>
@@ -257,15 +263,20 @@ public void Save()
257
263
System . Windows . Forms . OpenFileDialog fileDialog => fileDialog . FileName ,
258
264
_ => throw new System . NotImplementedException ( )
259
265
} ;
266
+
260
267
textBox . Text = path ;
261
268
Settings [ attributes . Name ] = path ;
262
269
} ;
263
270
264
- var dockPanel = new DockPanel ( ) { Margin = settingControlMargin } ;
271
+ var dockPanel = new DockPanel ( )
272
+ {
273
+ Margin = SettingPanelItemTopBottomMargin
274
+ } ;
265
275
266
276
DockPanel . SetDock ( Btn , Dock . Right ) ;
267
277
dockPanel . Children . Add ( Btn ) ;
268
278
dockPanel . Children . Add ( textBox ) ;
279
+
269
280
contentControl = dockPanel ;
270
281
271
282
break ;
@@ -274,8 +285,8 @@ public void Save()
274
285
{
275
286
var textBox = new TextBox ( )
276
287
{
277
- Height = 120 ,
278
- Margin = settingControlMargin ,
288
+ Height = 150 ,
289
+ Margin = SettingPanelItemLeftTopBottomMargin ,
279
290
VerticalAlignment = VerticalAlignment . Center ,
280
291
TextWrapping = TextWrapping . WrapWithOverflow ,
281
292
AcceptsReturn = true ,
@@ -297,7 +308,7 @@ public void Save()
297
308
{
298
309
var passwordBox = new PasswordBox ( )
299
310
{
300
- Margin = settingControlMargin ,
311
+ Margin = SettingPanelItemLeftTopBottomMargin ,
301
312
Password = Settings [ attributes . Name ] as string ?? string . Empty ,
302
313
PasswordChar = attributes . passwordChar == default ? '*' : attributes . passwordChar ,
303
314
HorizontalAlignment = HorizontalAlignment . Stretch ,
@@ -319,8 +330,8 @@ public void Save()
319
330
{
320
331
ItemsSource = attributes . Options ,
321
332
SelectedItem = Settings [ attributes . Name ] ,
322
- Margin = settingControlMargin ,
323
- HorizontalAlignment = HorizontalAlignment . Right ,
333
+ Margin = SettingPanelItemLeftTopBottomMargin ,
334
+ HorizontalAlignment = HorizontalAlignment . Left ,
324
335
ToolTip = attributes . Description
325
336
} ;
326
337
@@ -341,8 +352,9 @@ public void Save()
341
352
Settings [ attributes . Name ] is bool isChecked
342
353
? isChecked
343
354
: bool . Parse ( attributes . DefaultValue ) ,
344
- Margin = settingCheckboxMargin ,
345
- HorizontalAlignment = HorizontalAlignment . Right ,
355
+ Margin = SettingPanelItemTopBottomMargin ,
356
+ HorizontalAlignment = HorizontalAlignment . Left ,
357
+ Content = attributes . Label ,
346
358
ToolTip = attributes . Description
347
359
} ;
348
360
@@ -357,13 +369,27 @@ Settings[attributes.Name] is bool isChecked
357
369
}
358
370
case "hyperlink" :
359
371
{
360
- var hyperlink = new Hyperlink { ToolTip = attributes . Description , NavigateUri = attributes . url } ;
372
+ var hyperlink = new Hyperlink
373
+ {
374
+ ToolTip = attributes . Description ,
375
+ NavigateUri = attributes . url
376
+ } ;
377
+
378
+ hyperlink . Inlines . Add ( attributes . urlLabel ) ;
379
+ hyperlink . RequestNavigate += ( sender , e ) =>
380
+ {
381
+ API . OpenUrl ( e . Uri ) ;
382
+ e . Handled = true ;
383
+ } ;
384
+
385
+ var textBlock = new TextBlock ( ) ;
386
+ textBlock . Inlines . Add ( hyperlink ) ;
361
387
362
388
var linkbtn = new Button
363
389
{
364
- HorizontalAlignment = HorizontalAlignment . Right ,
365
- Margin = settingControlMargin ,
366
- Content = attributes . urlLabel
390
+ HorizontalAlignment = HorizontalAlignment . Left ,
391
+ Margin = SettingPanelItemLeftTopBottomMargin ,
392
+ Content = textBlock
367
393
} ;
368
394
369
395
contentControl = linkbtn ;
@@ -373,13 +399,16 @@ Settings[attributes.Name] is bool isChecked
373
399
case "seperator" :
374
400
{
375
401
// TODO: Move to resource
376
- contentControl = new Separator
402
+ var sep = new Separator
377
403
{
378
404
VerticalAlignment = VerticalAlignment . Top ,
379
405
Margin = new ( - 70 , 13.5 , - 18 , 13.5 ) ,
380
406
Height = 1
381
407
} ;
382
- contentControl . SetResourceReference ( Separator . BackgroundProperty , "Color03B" ) ;
408
+
409
+ sep . SetResourceReference ( Separator . BackgroundProperty , "Color03B" ) ;
410
+
411
+ contentControl = sep ;
383
412
384
413
break ;
385
414
}
@@ -407,8 +436,11 @@ Settings[attributes.Name] is bool isChecked
407
436
mainPanel . Children . Add ( contentControl ) ;
408
437
Grid . SetColumn ( contentControl , 1 ) ;
409
438
Grid . SetRow ( contentControl , rowCount ) ;
439
+ }
410
440
411
- // Add into SettingControls for later use if need
441
+ // Add into SettingControls for later use if need
442
+ if ( type != "textBlock" && type != "seperator" )
443
+ {
412
444
SettingControls [ attributes . Name ] = contentControl ;
413
445
}
414
446
0 commit comments