Skip to content

Commit d9f8e87

Browse files
Jack251970TBM13
authored andcommitted
Merge pull request Flow-Launcher#3979 from Flow-Launcher/json_plugin_setting
Improve JsonRPC Plugin Setting Panel
1 parent 4603878 commit d9f8e87

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class JsonRPCPluginSettings : ISavable
2828

2929
private JsonStorage<ConcurrentDictionary<string, object?>> _storage = null!;
3030

31+
private static readonly double MainGridColumn0MaxWidthRatio = 0.6;
3132
private static readonly Thickness SettingPanelMargin = (Thickness)Application.Current.FindResource("SettingPanelMargin");
3233
private static readonly Thickness SettingPanelItemLeftMargin = (Thickness)Application.Current.FindResource("SettingPanelItemLeftMargin");
3334
private static readonly Thickness SettingPanelItemTopBottomMargin = (Thickness)Application.Current.FindResource("SettingPanelItemTopBottomMargin");
@@ -157,7 +158,7 @@ public Control CreateSettingPanel()
157158
{
158159
if (!NeedCreateSettingPanel()) return null!;
159160

160-
// Create main grid with two columns (Column 1: Auto, Column 2: *)
161+
// Create main grid with two columns (Column 0: Auto, Column 1: *)
161162
var mainPanel = new Grid { Margin = SettingPanelMargin, VerticalAlignment = VerticalAlignment.Center };
162163
mainPanel.ColumnDefinitions.Add(new ColumnDefinition()
163164
{
@@ -201,7 +202,7 @@ public Control CreateSettingPanel()
201202
{
202203
Text = attributes.Label,
203204
VerticalAlignment = VerticalAlignment.Center,
204-
TextWrapping = TextWrapping.WrapWithOverflow
205+
TextWrapping = TextWrapping.Wrap
205206
};
206207

207208
// Create a text block for description
@@ -212,7 +213,7 @@ public Control CreateSettingPanel()
212213
{
213214
Text = attributes.Description,
214215
VerticalAlignment = VerticalAlignment.Center,
215-
TextWrapping = TextWrapping.WrapWithOverflow
216+
TextWrapping = TextWrapping.Wrap
216217
};
217218

218219
desc.SetResourceReference(TextBlock.StyleProperty, "SettingPanelTextBlockDescriptionStyle"); // for theme change
@@ -248,7 +249,8 @@ public Control CreateSettingPanel()
248249
VerticalAlignment = VerticalAlignment.Center,
249250
Margin = SettingPanelItemLeftTopBottomMargin,
250251
Text = Settings[attributes.Name] as string ?? string.Empty,
251-
ToolTip = attributes.Description
252+
ToolTip = attributes.Description,
253+
TextWrapping = TextWrapping.Wrap
252254
};
253255

254256
textBox.TextChanged += (_, _) =>
@@ -270,7 +272,8 @@ public Control CreateSettingPanel()
270272
VerticalAlignment = VerticalAlignment.Center,
271273
Margin = SettingPanelItemLeftMargin,
272274
Text = Settings[attributes.Name] as string ?? string.Empty,
273-
ToolTip = attributes.Description
275+
ToolTip = attributes.Description,
276+
TextWrapping = TextWrapping.Wrap
274277
};
275278

276279
textBox.TextChanged += (_, _) =>
@@ -336,7 +339,7 @@ public Control CreateSettingPanel()
336339
HorizontalAlignment = HorizontalAlignment.Stretch,
337340
VerticalAlignment = VerticalAlignment.Center,
338341
Margin = SettingPanelItemLeftTopBottomMargin,
339-
TextWrapping = TextWrapping.WrapWithOverflow,
342+
TextWrapping = TextWrapping.Wrap,
340343
AcceptsReturn = true,
341344
Text = Settings[attributes.Name] as string ?? string.Empty,
342345
ToolTip = attributes.Description
@@ -491,13 +494,37 @@ Settings[attributes.Name] is bool isChecked
491494
rowCount++;
492495
}
493496

497+
mainPanel.SizeChanged += MainPanel_SizeChanged;
498+
494499
// Wrap the main grid in a user control
495500
return new UserControl()
496501
{
497502
Content = mainPanel
498503
};
499504
}
500505

506+
private void MainPanel_SizeChanged(object sender, SizeChangedEventArgs e)
507+
{
508+
if (sender is not Grid grid) return;
509+
510+
var workingWidth = grid.ActualWidth;
511+
512+
if (workingWidth <= 0) return;
513+
514+
var constrainedWidth = MainGridColumn0MaxWidthRatio * workingWidth;
515+
516+
// Set MaxWidth of column 0 and its children
517+
// We must set MaxWidth of its children to make text wrapping work correctly
518+
grid.ColumnDefinitions[0].MaxWidth = constrainedWidth;
519+
foreach (var child in grid.Children)
520+
{
521+
if (child is FrameworkElement element && Grid.GetColumn(element) == 0 && Grid.GetColumnSpan(element) == 1)
522+
{
523+
element.MaxWidth = constrainedWidth;
524+
}
525+
}
526+
}
527+
501528
private static bool NeedSaveInSettings(string type)
502529
{
503530
return type != "textBlock" && type != "separator" && type != "hyperlink";

0 commit comments

Comments
 (0)