Skip to content

Commit 0a3b566

Browse files
committed
Implment textBlock and add tooltip
1 parent c35ddbc commit 0a3b566

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal abstract class JsonRPCPlugin : IAsyncPlugin, IContextMenu, ISettingProv
4040
protected PluginInitContext context;
4141
public const string JsonRPC = "JsonRPC";
4242

43-
/// <summary>
43+
/// <summary=
4444
/// The language this JsonRPCPlugin support
4545
/// </summary>
4646
public abstract string SupportedLanguage { get; set; }
@@ -82,7 +82,7 @@ public List<Result> LoadContextMenus(Result selectedResult)
8282
};
8383
private Dictionary<string, object> Settings { get; set; }
8484

85-
private Dictionary<string, Control> _settingControls = new();
85+
private Dictionary<string, FrameworkElement> _settingControls = new();
8686

8787
private async Task<List<Result>> DeserializedResultAsync(Stream output)
8888
{
@@ -337,6 +337,8 @@ public async Task InitSettingAsync()
337337

338338
foreach (var (type, attribute) in _settingsTemplate.Body)
339339
{
340+
if (type == "textBlock")
341+
continue;
340342
if (!Settings.ContainsKey(attribute.Name))
341343
{
342344
Settings[attribute.Name] = attribute.DefaultValue;
@@ -376,17 +378,29 @@ public Control CreateSettingPanel()
376378
Margin = settingControlMargin
377379
};
378380

379-
Control contentControl;
381+
FrameworkElement contentControl;
380382

381383
switch (type)
382384
{
385+
case "textBlock":
386+
{
387+
contentControl = new TextBlock
388+
{
389+
Text = attribute.Description.Replace("\\r\\n", "\r\n"),
390+
Margin = settingControlMargin,
391+
MaxWidth = 400,
392+
TextWrapping = TextWrapping.WrapWithOverflow
393+
};
394+
break;
395+
}
383396
case "input":
384397
{
385398
var textBox = new TextBox()
386399
{
387400
Width = 300,
388401
Text = Settings[attribute.Name] as string ?? string.Empty,
389-
Margin = settingControlMargin
402+
Margin = settingControlMargin,
403+
ToolTip = attribute.Description
390404
};
391405
textBox.TextChanged += (_, _) =>
392406
{
@@ -404,7 +418,8 @@ public Control CreateSettingPanel()
404418
Margin = settingControlMargin,
405419
TextWrapping = TextWrapping.WrapWithOverflow,
406420
AcceptsReturn = true,
407-
Text = Settings[attribute.Name] as string ?? string.Empty
421+
Text = Settings[attribute.Name] as string ?? string.Empty,
422+
ToolTip = attribute.Description
408423
};
409424
textBox.TextChanged += (sender, _) =>
410425
{
@@ -420,7 +435,8 @@ public Control CreateSettingPanel()
420435
Width = 300,
421436
Margin = settingControlMargin,
422437
Password = Settings[attribute.Name] as string ?? string.Empty,
423-
PasswordChar = attribute.passwordChar == default ? '*' : attribute.passwordChar
438+
PasswordChar = attribute.passwordChar == default ? '*' : attribute.passwordChar,
439+
ToolTip = attribute.Description
424440
};
425441
passwordBox.PasswordChanged += (sender, _) =>
426442
{
@@ -435,7 +451,8 @@ public Control CreateSettingPanel()
435451
{
436452
ItemsSource = attribute.Options,
437453
SelectedItem = Settings[attribute.Name],
438-
Margin = settingControlMargin
454+
Margin = settingControlMargin,
455+
ToolTip = attribute.Description
439456
};
440457
comboBox.SelectionChanged += (sender, _) =>
441458
{
@@ -448,7 +465,8 @@ public Control CreateSettingPanel()
448465
var checkBox = new CheckBox
449466
{
450467
IsChecked = Settings[attribute.Name] is bool isChecked ? isChecked : bool.Parse(attribute.DefaultValue),
451-
Margin = settingControlMargin
468+
Margin = settingControlMargin,
469+
ToolTip = attribute.Description
452470
};
453471
checkBox.Click += (sender, _) =>
454472
{
@@ -459,7 +477,8 @@ public Control CreateSettingPanel()
459477
default:
460478
continue;
461479
}
462-
_settingControls[attribute.Name] = contentControl;
480+
if (type != "textBlock")
481+
_settingControls[attribute.Name] = contentControl;
463482
panel.Children.Add(name);
464483
panel.Children.Add(contentControl);
465484
mainPanel.Children.Add(panel);

0 commit comments

Comments
 (0)