Skip to content

Commit 50b5a0e

Browse files
authored
Merge pull request #1613 from onesounds/FixCustomSettingPanelPadding
Adjust Setting Panel Layout (System & JsonRPC)
2 parents 25cb290 + d6a31f0 commit 50b5a0e

File tree

4 files changed

+230
-60
lines changed

4 files changed

+230
-60
lines changed

Flow.Launcher.Core/Plugin/JsonRPCConfigurationModel.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23

34
namespace Flow.Launcher.Core.Plugin
45
{
@@ -26,6 +27,8 @@ public class FieldAttributes
2627
public string Name { get; set; }
2728
public string Label { get; set; }
2829
public string Description { get; set; }
30+
public string urlLabel { get; set; }
31+
public Uri url { get; set; }
2932
public bool Validation { get; set; }
3033
public List<string> Options { get; set; }
3134
public string DefaultValue { get; set; }
@@ -40,4 +43,4 @@ public void Deconstruct(out string Name, out string Label, out string Descriptio
4043
DefaultValue = this.DefaultValue;
4144
}
4245
}
43-
}
46+
}

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 174 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
using Orientation = System.Windows.Controls.Orientation;
2323
using TextBox = System.Windows.Controls.TextBox;
2424
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;
2529

2630
namespace Flow.Launcher.Core.Plugin
2731
{
@@ -33,7 +37,6 @@ internal abstract class JsonRPCPlugin : IAsyncPlugin, IContextMenu, ISettingProv
3337
{
3438
protected PluginInitContext context;
3539
public const string JsonRPC = "JsonRPC";
36-
3740
/// <summary>
3841
/// The language this JsonRPCPlugin support
3942
/// </summary>
@@ -340,36 +343,75 @@ public virtual async Task InitAsync(PluginInitContext context)
340343
this.context = context;
341344
await InitSettingAsync();
342345
}
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);
346354
private JsonRpcConfigurationModel _settingsTemplate;
347355

348356
public Control CreateSettingPanel()
349357
{
350358
if (Settings == null)
351359
return new();
352360
var settingWindow = new UserControl();
353-
var mainPanel = new StackPanel
361+
var mainPanel = new Grid
354362
{
355-
Margin = settingPanelMargin, Orientation = Orientation.Vertical
363+
Margin = settingPanelMargin, VerticalAlignment = VerticalAlignment.Center
356364
};
357-
settingWindow.Content = mainPanel;
365+
ColumnDefinition gridCol1 = new ColumnDefinition();
366+
ColumnDefinition gridCol2 = new ColumnDefinition();
358367

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;
359374
foreach (var (type, attribute) in _settingsTemplate.Body)
360375
{
376+
Separator sep = new Separator();
377+
sep.VerticalAlignment = VerticalAlignment.Top;
378+
sep.Margin = settingSepMargin;
379+
sep.SetResourceReference(Separator.BackgroundProperty, "Color03B"); /* for theme change */
361380
var panel = new StackPanel
362381
{
363-
Orientation = Orientation.Horizontal, Margin = settingControlMargin
382+
Orientation = Orientation.Vertical, VerticalAlignment = VerticalAlignment.Center,
383+
Margin = settingLabelPanelMargin
364384
};
385+
RowDefinition gridRow = new RowDefinition();
386+
mainPanel.RowDefinitions.Add(gridRow);
365387
var name = new TextBlock()
366388
{
367389
Text = attribute.Label,
368-
Width = 120,
369390
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,
371398
TextWrapping = TextWrapping.WrapWithOverflow
372399
};
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);
373415

374416
FrameworkElement contentControl;
375417

@@ -381,36 +423,89 @@ public Control CreateSettingPanel()
381423
{
382424
Text = attribute.Description.Replace("\\r\\n", "\r\n"),
383425
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
386430
};
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;
388440
}
389441
case "input":
390442
{
391443
var textBox = new TextBox()
392444
{
393-
Width = 300,
394445
Text = Settings[attribute.Name] as string ?? string.Empty,
395446
Margin = settingControlMargin,
447+
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
396448
ToolTip = attribute.Description
397449
};
398450
textBox.TextChanged += (_, _) =>
399451
{
400452
Settings[attribute.Name] = textBox.Text;
401453
};
402454
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;
404463
}
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+
}
405499
case "textarea":
406500
{
407501
var textBox = new TextBox()
408502
{
409-
Width = 300,
410503
Height = 120,
411504
Margin = settingControlMargin,
505+
VerticalAlignment = VerticalAlignment.Center,
412506
TextWrapping = TextWrapping.WrapWithOverflow,
413507
AcceptsReturn = true,
508+
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
414509
Text = Settings[attribute.Name] as string ?? string.Empty,
415510
ToolTip = attribute.Description
416511
};
@@ -419,62 +514,115 @@ public Control CreateSettingPanel()
419514
Settings[attribute.Name] = ((TextBox)sender).Text;
420515
};
421516
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;
423525
}
424526
case "passwordBox":
425527
{
426528
var passwordBox = new PasswordBox()
427529
{
428-
Width = 300,
429530
Margin = settingControlMargin,
430531
Password = Settings[attribute.Name] as string ?? string.Empty,
431532
PasswordChar = attribute.passwordChar == default ? '*' : attribute.passwordChar,
533+
HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch,
432534
ToolTip = attribute.Description
433535
};
434536
passwordBox.PasswordChanged += (sender, _) =>
435537
{
436538
Settings[attribute.Name] = ((PasswordBox)sender).Password;
437539
};
438540
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;
440549
}
441550
case "dropdown":
442551
{
443-
var comboBox = new ComboBox()
552+
var comboBox = new System.Windows.Controls.ComboBox()
444553
{
445554
ItemsSource = attribute.Options,
446555
SelectedItem = Settings[attribute.Name],
447556
Margin = settingControlMargin,
557+
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
448558
ToolTip = attribute.Description
449559
};
450560
comboBox.SelectionChanged += (sender, _) =>
451561
{
452-
Settings[attribute.Name] = (string)((ComboBox)sender).SelectedItem;
562+
Settings[attribute.Name] = (string)((System.Windows.Controls.ComboBox)sender).SelectedItem;
453563
};
454564
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;
456573
}
457574
case "checkbox":
458575
var checkBox = new CheckBox
459576
{
460577
IsChecked = Settings[attribute.Name] is bool isChecked ? isChecked : bool.Parse(attribute.DefaultValue),
461-
Margin = settingControlMargin,
578+
Margin = settingCheckboxMargin,
579+
HorizontalAlignment = System.Windows.HorizontalAlignment.Right,
462580
ToolTip = attribute.Description
463581
};
464582
checkBox.Click += (sender, _) =>
465583
{
466584
Settings[attribute.Name] = ((CheckBox)sender).IsChecked;
467585
};
468586
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);
469616
break;
470617
default:
471618
continue;
472619
}
473620
if (type != "textBlock")
474621
_settingControls[attribute.Name] = contentControl;
475-
panel.Children.Add(name);
476-
panel.Children.Add(contentControl);
477622
mainPanel.Children.Add(panel);
623+
mainPanel.Children.Add(contentControl);
624+
rowCount++;
625+
478626
}
479627
return settingWindow;
480628
}
@@ -510,7 +658,7 @@ public void UpdateSettings(Dictionary<string, object> settings)
510658
case PasswordBox passwordBox:
511659
passwordBox.Dispatcher.Invoke(() => passwordBox.Password = value as string);
512660
break;
513-
case ComboBox comboBox:
661+
case System.Windows.Controls.ComboBox comboBox:
514662
comboBox.Dispatcher.Invoke(() => comboBox.SelectedItem = value);
515663
break;
516664
case CheckBox checkBox:

0 commit comments

Comments
 (0)