@@ -24,10 +24,14 @@ public class JsonRPCPluginSettings
2424
2525 private JsonStorage < ConcurrentDictionary < string , object > > _storage = null ! ;
2626
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" ) ;
3135
3236 public async Task InitializeAsync ( )
3337 {
@@ -109,15 +113,15 @@ public void Save()
109113 return null ;
110114 }
111115
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 } ;
114118 mainPanel . ColumnDefinitions . Add ( new ColumnDefinition ( )
115119 {
116120 Width = new GridLength ( 0 , GridUnitType . Auto )
117121 } ) ;
118122 mainPanel . ColumnDefinitions . Add ( new ColumnDefinition ( )
119123 {
120- Width = new GridLength ( 0 , GridUnitType . Auto )
124+ Width = new GridLength ( 1 , GridUnitType . Star )
121125 } ) ;
122126
123127 // Iterate over each setting and create one row for it
@@ -140,12 +144,13 @@ public void Save()
140144 StackPanel ? panel = null ;
141145 FrameworkElement contentControl ;
142146
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" )
145149 {
146150 // Create a panel to hold the label and description
147151 panel = new StackPanel
148152 {
153+ Margin = SettingPanelItemTopBottomMargin ,
149154 Orientation = Orientation . Vertical ,
150155 VerticalAlignment = VerticalAlignment . Center
151156 } ;
@@ -190,7 +195,7 @@ public void Save()
190195 contentControl = new TextBlock
191196 {
192197 Text = attributes . Description ? . Replace ( "\\ r\\ n" , "\r \n " ) ?? string . Empty ,
193- Padding = new Thickness ( 0 , 0 , 0 , 0 ) ,
198+ Margin = SettingPanelItemTopBottomMargin ,
194199 HorizontalAlignment = HorizontalAlignment . Left ,
195200 TextAlignment = TextAlignment . Left ,
196201 TextWrapping = TextWrapping . Wrap
@@ -203,7 +208,7 @@ public void Save()
203208 var textBox = new TextBox ( )
204209 {
205210 Text = Settings [ attributes . Name ] as string ?? string . Empty ,
206- Margin = settingControlMargin ,
211+ Margin = SettingPanelItemLeftTopBottomMargin ,
207212 HorizontalAlignment = HorizontalAlignment . Stretch ,
208213 ToolTip = attributes . Description
209214 } ;
@@ -222,7 +227,7 @@ public void Save()
222227 {
223228 var textBox = new TextBox ( )
224229 {
225- Margin = new Thickness ( 10 , 0 , 0 , 0 ) ,
230+ Margin = SettingPanelItemLeftMargin ,
226231 Text = Settings [ attributes . Name ] as string ?? string . Empty ,
227232 HorizontalAlignment = HorizontalAlignment . Stretch ,
228233 ToolTip = attributes . Description
@@ -235,7 +240,8 @@ public void Save()
235240
236241 var Btn = new Button ( )
237242 {
238- Margin = new Thickness ( 10 , 0 , 0 , 0 ) , Content = "Browse"
243+ Margin = SettingPanelItemLeftMargin ,
244+ Content = "Browse" // TODO: Localization
239245 } ;
240246
241247 Btn . Click += ( _ , _ ) =>
@@ -257,15 +263,20 @@ public void Save()
257263 System . Windows . Forms . OpenFileDialog fileDialog => fileDialog . FileName ,
258264 _ => throw new System . NotImplementedException ( )
259265 } ;
266+
260267 textBox . Text = path ;
261268 Settings [ attributes . Name ] = path ;
262269 } ;
263270
264- var dockPanel = new DockPanel ( ) { Margin = settingControlMargin } ;
271+ var dockPanel = new DockPanel ( )
272+ {
273+ Margin = SettingPanelItemTopBottomMargin
274+ } ;
265275
266276 DockPanel . SetDock ( Btn , Dock . Right ) ;
267277 dockPanel . Children . Add ( Btn ) ;
268278 dockPanel . Children . Add ( textBox ) ;
279+
269280 contentControl = dockPanel ;
270281
271282 break ;
@@ -274,8 +285,8 @@ public void Save()
274285 {
275286 var textBox = new TextBox ( )
276287 {
277- Height = 120 ,
278- Margin = settingControlMargin ,
288+ Height = 150 ,
289+ Margin = SettingPanelItemLeftTopBottomMargin ,
279290 VerticalAlignment = VerticalAlignment . Center ,
280291 TextWrapping = TextWrapping . WrapWithOverflow ,
281292 AcceptsReturn = true ,
@@ -297,7 +308,7 @@ public void Save()
297308 {
298309 var passwordBox = new PasswordBox ( )
299310 {
300- Margin = settingControlMargin ,
311+ Margin = SettingPanelItemLeftTopBottomMargin ,
301312 Password = Settings [ attributes . Name ] as string ?? string . Empty ,
302313 PasswordChar = attributes . passwordChar == default ? '*' : attributes . passwordChar ,
303314 HorizontalAlignment = HorizontalAlignment . Stretch ,
@@ -319,8 +330,8 @@ public void Save()
319330 {
320331 ItemsSource = attributes . Options ,
321332 SelectedItem = Settings [ attributes . Name ] ,
322- Margin = settingControlMargin ,
323- HorizontalAlignment = HorizontalAlignment . Right ,
333+ Margin = SettingPanelItemLeftTopBottomMargin ,
334+ HorizontalAlignment = HorizontalAlignment . Left ,
324335 ToolTip = attributes . Description
325336 } ;
326337
@@ -341,8 +352,9 @@ public void Save()
341352 Settings [ attributes . Name ] is bool isChecked
342353 ? isChecked
343354 : bool . Parse ( attributes . DefaultValue ) ,
344- Margin = settingCheckboxMargin ,
345- HorizontalAlignment = HorizontalAlignment . Right ,
355+ Margin = SettingPanelItemTopBottomMargin ,
356+ HorizontalAlignment = HorizontalAlignment . Left ,
357+ Content = attributes . Label ,
346358 ToolTip = attributes . Description
347359 } ;
348360
@@ -357,13 +369,27 @@ Settings[attributes.Name] is bool isChecked
357369 }
358370 case "hyperlink" :
359371 {
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 ) ;
361387
362388 var linkbtn = new Button
363389 {
364- HorizontalAlignment = HorizontalAlignment . Right ,
365- Margin = settingControlMargin ,
366- Content = attributes . urlLabel
390+ HorizontalAlignment = HorizontalAlignment . Left ,
391+ Margin = SettingPanelItemLeftTopBottomMargin ,
392+ Content = textBlock
367393 } ;
368394
369395 contentControl = linkbtn ;
@@ -373,13 +399,16 @@ Settings[attributes.Name] is bool isChecked
373399 case "seperator" :
374400 {
375401 // TODO: Move to resource
376- contentControl = new Separator
402+ var sep = new Separator
377403 {
378404 VerticalAlignment = VerticalAlignment . Top ,
379405 Margin = new ( - 70 , 13.5 , - 18 , 13.5 ) ,
380406 Height = 1
381407 } ;
382- contentControl . SetResourceReference ( Separator . BackgroundProperty , "Color03B" ) ;
408+
409+ sep . SetResourceReference ( Separator . BackgroundProperty , "Color03B" ) ;
410+
411+ contentControl = sep ;
383412
384413 break ;
385414 }
@@ -407,8 +436,11 @@ Settings[attributes.Name] is bool isChecked
407436 mainPanel . Children . Add ( contentControl ) ;
408437 Grid . SetColumn ( contentControl , 1 ) ;
409438 Grid . SetRow ( contentControl , rowCount ) ;
439+ }
410440
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+ {
412444 SettingControls [ attributes . Name ] = contentControl ;
413445 }
414446
0 commit comments