22
22
using Orientation = System . Windows . Controls . Orientation ;
23
23
using TextBox = System . Windows . Controls . TextBox ;
24
24
using UserControl = System . Windows . Controls . UserControl ;
25
+ using System . Windows . Documents ;
26
+ using static System . Windows . Forms . LinkLabel ;
27
+ using Droplex ;
28
+ using System . Windows . Forms ;
25
29
26
30
namespace Flow . Launcher . Core . Plugin
27
31
{
@@ -33,7 +37,6 @@ internal abstract class JsonRPCPlugin : IAsyncPlugin, IContextMenu, ISettingProv
33
37
{
34
38
protected PluginInitContext context ;
35
39
public const string JsonRPC = "JsonRPC" ;
36
-
37
40
/// <summary>
38
41
/// The language this JsonRPCPlugin support
39
42
/// </summary>
@@ -340,36 +343,75 @@ public virtual async Task InitAsync(PluginInitContext context)
340
343
this . context = context ;
341
344
await InitSettingAsync ( ) ;
342
345
}
343
- private static readonly Thickness settingControlMargin = new ( 10 , 4 , 10 , 4 ) ;
344
- private static readonly Thickness settingPanelMargin = new ( 15 , 20 , 15 , 20 ) ;
345
- private static readonly Thickness settingTextBlockMargin = new ( 10 , 4 , 10 , 4 ) ;
346
+ private static readonly Thickness settingControlMargin = new ( 0 , 9 , 18 , 9 ) ;
347
+ private static readonly Thickness settingCheckboxMargin = new ( 0 , 9 , 9 , 9 ) ;
348
+ private static readonly Thickness settingPanelMargin = new ( 0 , 0 , 0 , 0 ) ;
349
+ private static readonly Thickness settingTextBlockMargin = new ( 70 , 9 , 18 , 9 ) ;
350
+ private static readonly Thickness settingLabelPanelMargin = new ( 70 , 9 , 18 , 9 ) ;
351
+ private static readonly Thickness settingLabelMargin = new ( 0 , 0 , 0 , 0 ) ;
352
+ private static readonly Thickness settingDescMargin = new ( 0 , 2 , 0 , 0 ) ;
353
+ private static readonly Thickness settingSepMargin = new ( 0 , 0 , 0 , 2 ) ;
346
354
private JsonRpcConfigurationModel _settingsTemplate ;
347
355
348
356
public Control CreateSettingPanel ( )
349
357
{
350
358
if ( Settings == null )
351
359
return new ( ) ;
352
360
var settingWindow = new UserControl ( ) ;
353
- var mainPanel = new StackPanel
361
+ var mainPanel = new Grid
354
362
{
355
- Margin = settingPanelMargin , Orientation = Orientation . Vertical
363
+ Margin = settingPanelMargin , VerticalAlignment = VerticalAlignment . Center
356
364
} ;
357
- settingWindow . Content = mainPanel ;
365
+ ColumnDefinition gridCol1 = new ColumnDefinition ( ) ;
366
+ ColumnDefinition gridCol2 = new ColumnDefinition ( ) ;
358
367
368
+ gridCol1 . Width = new GridLength ( 70 , GridUnitType . Star ) ;
369
+ gridCol2 . Width = new GridLength ( 30 , GridUnitType . Star ) ;
370
+ mainPanel . ColumnDefinitions . Add ( gridCol1 ) ;
371
+ mainPanel . ColumnDefinitions . Add ( gridCol2 ) ;
372
+ settingWindow . Content = mainPanel ;
373
+ int rowCount = 0 ;
359
374
foreach ( var ( type , attribute ) in _settingsTemplate . Body )
360
375
{
376
+ Separator sep = new Separator ( ) ;
377
+ sep . VerticalAlignment = VerticalAlignment . Top ;
378
+ sep . Margin = settingSepMargin ;
379
+ sep . SetResourceReference ( Separator . BackgroundProperty , "Color03B" ) ; /* for theme change */
361
380
var panel = new StackPanel
362
381
{
363
- Orientation = Orientation . Horizontal , Margin = settingControlMargin
382
+ Orientation = Orientation . Vertical , VerticalAlignment = VerticalAlignment . Center ,
383
+ Margin = settingLabelPanelMargin
364
384
} ;
385
+ RowDefinition gridRow = new RowDefinition ( ) ;
386
+ mainPanel . RowDefinitions . Add ( gridRow ) ;
365
387
var name = new TextBlock ( )
366
388
{
367
389
Text = attribute . Label ,
368
- Width = 120 ,
369
390
VerticalAlignment = VerticalAlignment . Center ,
370
- Margin = settingControlMargin ,
391
+ Margin = settingLabelMargin ,
392
+ TextWrapping = TextWrapping . WrapWithOverflow
393
+ } ;
394
+ var desc = new TextBlock ( )
395
+ {
396
+ Text = attribute . Description , FontSize = 12 ,
397
+ VerticalAlignment = VerticalAlignment . Center , Margin = settingDescMargin ,
371
398
TextWrapping = TextWrapping . WrapWithOverflow
372
399
} ;
400
+ desc . SetResourceReference ( TextBlock . ForegroundProperty , "Color04B" ) ;
401
+
402
+ if ( attribute . Description == null ) /* if no description, hide */
403
+ desc . Visibility = Visibility . Collapsed ;
404
+
405
+
406
+ if ( type != "textBlock" ) /* if textBlock, hide desc */
407
+ {
408
+ panel . Children . Add ( name ) ;
409
+ panel . Children . Add ( desc ) ;
410
+ }
411
+
412
+
413
+ Grid . SetColumn ( panel , 0 ) ;
414
+ Grid . SetRow ( panel , rowCount ) ;
373
415
374
416
FrameworkElement contentControl ;
375
417
@@ -381,36 +423,89 @@ public Control CreateSettingPanel()
381
423
{
382
424
Text = attribute . Description . Replace ( "\\ r\\ n" , "\r \n " ) ,
383
425
Margin = settingTextBlockMargin ,
384
- MaxWidth = 500 ,
385
- TextWrapping = TextWrapping . WrapWithOverflow
426
+ Padding = new Thickness ( 0 , 0 , 0 , 0 ) ,
427
+ HorizontalAlignment = System . Windows . HorizontalAlignment . Left ,
428
+ TextAlignment = TextAlignment . Left ,
429
+ TextWrapping = TextWrapping . Wrap
386
430
} ;
387
- break ;
431
+ Grid . SetColumn ( contentControl , 0 ) ;
432
+ Grid . SetColumnSpan ( contentControl , 2 ) ;
433
+ Grid . SetRow ( contentControl , rowCount ) ;
434
+ if ( rowCount != 0 )
435
+ mainPanel . Children . Add ( sep ) ;
436
+ Grid . SetRow ( sep , rowCount ) ;
437
+ Grid . SetColumn ( sep , 0 ) ;
438
+ Grid . SetColumnSpan ( sep , 2 ) ;
439
+ break ;
388
440
}
389
441
case "input" :
390
442
{
391
443
var textBox = new TextBox ( )
392
444
{
393
- Width = 300 ,
394
445
Text = Settings [ attribute . Name ] as string ?? string . Empty ,
395
446
Margin = settingControlMargin ,
447
+ HorizontalAlignment = System . Windows . HorizontalAlignment . Stretch ,
396
448
ToolTip = attribute . Description
397
449
} ;
398
450
textBox . TextChanged += ( _ , _ ) =>
399
451
{
400
452
Settings [ attribute . Name ] = textBox . Text ;
401
453
} ;
402
454
contentControl = textBox ;
403
- break ;
455
+ Grid . SetColumn ( contentControl , 1 ) ;
456
+ Grid . SetRow ( contentControl , rowCount ) ;
457
+ if ( rowCount != 0 )
458
+ mainPanel . Children . Add ( sep ) ;
459
+ Grid . SetRow ( sep , rowCount ) ;
460
+ Grid . SetColumn ( sep , 0 ) ;
461
+ Grid . SetColumnSpan ( sep , 2 ) ;
462
+ break ;
404
463
}
464
+ case "inputWithFileBtn" :
465
+ {
466
+ var textBox = new TextBox ( )
467
+ {
468
+ Margin = new Thickness ( 10 , 0 , 0 , 0 ) ,
469
+ Text = Settings [ attribute . Name ] as string ?? string . Empty ,
470
+ HorizontalAlignment = System . Windows . HorizontalAlignment . Stretch ,
471
+ ToolTip = attribute . Description
472
+ } ;
473
+ textBox . TextChanged += ( _ , _ ) =>
474
+ {
475
+ Settings [ attribute . Name ] = textBox . Text ;
476
+ } ;
477
+ var Btn = new System . Windows . Controls . Button ( )
478
+ {
479
+ Margin = new Thickness ( 10 , 0 , 0 , 0 ) ,
480
+ Content = "Browse"
481
+ } ;
482
+ var dockPanel = new DockPanel ( )
483
+ {
484
+ Margin = settingControlMargin
485
+ } ;
486
+ DockPanel . SetDock ( Btn , Dock . Right ) ;
487
+ dockPanel . Children . Add ( Btn ) ;
488
+ dockPanel . Children . Add ( textBox ) ;
489
+ contentControl = dockPanel ;
490
+ Grid . SetColumn ( contentControl , 1 ) ;
491
+ Grid . SetRow ( contentControl , rowCount ) ;
492
+ if ( rowCount != 0 )
493
+ mainPanel . Children . Add ( sep ) ;
494
+ Grid . SetRow ( sep , rowCount ) ;
495
+ Grid . SetColumn ( sep , 0 ) ;
496
+ Grid . SetColumnSpan ( sep , 2 ) ;
497
+ break ;
498
+ }
405
499
case "textarea" :
406
500
{
407
501
var textBox = new TextBox ( )
408
502
{
409
- Width = 300 ,
410
503
Height = 120 ,
411
504
Margin = settingControlMargin ,
505
+ VerticalAlignment = VerticalAlignment . Center ,
412
506
TextWrapping = TextWrapping . WrapWithOverflow ,
413
507
AcceptsReturn = true ,
508
+ HorizontalAlignment = System . Windows . HorizontalAlignment . Stretch ,
414
509
Text = Settings [ attribute . Name ] as string ?? string . Empty ,
415
510
ToolTip = attribute . Description
416
511
} ;
@@ -419,62 +514,115 @@ public Control CreateSettingPanel()
419
514
Settings [ attribute . Name ] = ( ( TextBox ) sender ) . Text ;
420
515
} ;
421
516
contentControl = textBox ;
422
- break ;
517
+ Grid . SetColumn ( contentControl , 1 ) ;
518
+ Grid . SetRow ( contentControl , rowCount ) ;
519
+ if ( rowCount != 0 )
520
+ mainPanel . Children . Add ( sep ) ;
521
+ Grid . SetRow ( sep , rowCount ) ;
522
+ Grid . SetColumn ( sep , 0 ) ;
523
+ Grid . SetColumnSpan ( sep , 2 ) ;
524
+ break ;
423
525
}
424
526
case "passwordBox" :
425
527
{
426
528
var passwordBox = new PasswordBox ( )
427
529
{
428
- Width = 300 ,
429
530
Margin = settingControlMargin ,
430
531
Password = Settings [ attribute . Name ] as string ?? string . Empty ,
431
532
PasswordChar = attribute . passwordChar == default ? '*' : attribute . passwordChar ,
533
+ HorizontalAlignment = System . Windows . HorizontalAlignment . Stretch ,
432
534
ToolTip = attribute . Description
433
535
} ;
434
536
passwordBox . PasswordChanged += ( sender , _ ) =>
435
537
{
436
538
Settings [ attribute . Name ] = ( ( PasswordBox ) sender ) . Password ;
437
539
} ;
438
540
contentControl = passwordBox ;
439
- break ;
541
+ Grid . SetColumn ( contentControl , 1 ) ;
542
+ Grid . SetRow ( contentControl , rowCount ) ;
543
+ if ( rowCount != 0 )
544
+ mainPanel . Children . Add ( sep ) ;
545
+ Grid . SetRow ( sep , rowCount ) ;
546
+ Grid . SetColumn ( sep , 0 ) ;
547
+ Grid . SetColumnSpan ( sep , 2 ) ;
548
+ break ;
440
549
}
441
550
case "dropdown" :
442
551
{
443
- var comboBox = new ComboBox ( )
552
+ var comboBox = new System . Windows . Controls . ComboBox ( )
444
553
{
445
554
ItemsSource = attribute . Options ,
446
555
SelectedItem = Settings [ attribute . Name ] ,
447
556
Margin = settingControlMargin ,
557
+ HorizontalAlignment = System . Windows . HorizontalAlignment . Right ,
448
558
ToolTip = attribute . Description
449
559
} ;
450
560
comboBox . SelectionChanged += ( sender , _ ) =>
451
561
{
452
- Settings [ attribute . Name ] = ( string ) ( ( ComboBox ) sender ) . SelectedItem ;
562
+ Settings [ attribute . Name ] = ( string ) ( ( System . Windows . Controls . ComboBox ) sender ) . SelectedItem ;
453
563
} ;
454
564
contentControl = comboBox ;
455
- break ;
565
+ Grid . SetColumn ( contentControl , 1 ) ;
566
+ Grid . SetRow ( contentControl , rowCount ) ;
567
+ if ( rowCount != 0 )
568
+ mainPanel . Children . Add ( sep ) ;
569
+ Grid . SetRow ( sep , rowCount ) ;
570
+ Grid . SetColumn ( sep , 0 ) ;
571
+ Grid . SetColumnSpan ( sep , 2 ) ;
572
+ break ;
456
573
}
457
574
case "checkbox" :
458
575
var checkBox = new CheckBox
459
576
{
460
577
IsChecked = Settings [ attribute . Name ] is bool isChecked ? isChecked : bool . Parse ( attribute . DefaultValue ) ,
461
- Margin = settingControlMargin ,
578
+ Margin = settingCheckboxMargin ,
579
+ HorizontalAlignment = System . Windows . HorizontalAlignment . Right ,
462
580
ToolTip = attribute . Description
463
581
} ;
464
582
checkBox . Click += ( sender , _ ) =>
465
583
{
466
584
Settings [ attribute . Name ] = ( ( CheckBox ) sender ) . IsChecked ;
467
585
} ;
468
586
contentControl = checkBox ;
587
+ Grid . SetColumn ( contentControl , 1 ) ;
588
+ Grid . SetRow ( contentControl , rowCount ) ;
589
+ if ( rowCount != 0 )
590
+ mainPanel . Children . Add ( sep ) ;
591
+ Grid . SetRow ( sep , rowCount ) ;
592
+ Grid . SetColumn ( sep , 0 ) ;
593
+ Grid . SetColumnSpan ( sep , 2 ) ;
594
+ break ;
595
+ case "hyperlink" :
596
+ var hyperlink = new Hyperlink
597
+ {
598
+ ToolTip = attribute . Description ,
599
+ NavigateUri = attribute . url
600
+ } ;
601
+ var linkbtn = new System . Windows . Controls . Button
602
+ {
603
+ HorizontalAlignment = System . Windows . HorizontalAlignment . Right ,
604
+ Margin = settingControlMargin
605
+ } ;
606
+ linkbtn . Content = attribute . urlLabel ;
607
+
608
+ contentControl = linkbtn ;
609
+ Grid . SetColumn ( contentControl , 1 ) ;
610
+ Grid . SetRow ( contentControl , rowCount ) ;
611
+ if ( rowCount != 0 )
612
+ mainPanel . Children . Add ( sep ) ;
613
+ Grid . SetRow ( sep , rowCount ) ;
614
+ Grid . SetColumn ( sep , 0 ) ;
615
+ Grid . SetColumnSpan ( sep , 2 ) ;
469
616
break ;
470
617
default :
471
618
continue ;
472
619
}
473
620
if ( type != "textBlock" )
474
621
_settingControls [ attribute . Name ] = contentControl ;
475
- panel . Children . Add ( name ) ;
476
- panel . Children . Add ( contentControl ) ;
477
622
mainPanel . Children . Add ( panel ) ;
623
+ mainPanel . Children . Add ( contentControl ) ;
624
+ rowCount ++ ;
625
+
478
626
}
479
627
return settingWindow ;
480
628
}
@@ -510,7 +658,7 @@ public void UpdateSettings(Dictionary<string, object> settings)
510
658
case PasswordBox passwordBox :
511
659
passwordBox . Dispatcher . Invoke ( ( ) => passwordBox . Password = value as string ) ;
512
660
break ;
513
- case ComboBox comboBox :
661
+ case System . Windows . Controls . ComboBox comboBox :
514
662
comboBox . Dispatcher . Invoke ( ( ) => comboBox . SelectedItem = value ) ;
515
663
break ;
516
664
case CheckBox checkBox :
0 commit comments