Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

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

private static readonly double MainGridColumn0MaxWidthRatio = 0.6;
private static readonly Thickness SettingPanelMargin = (Thickness)Application.Current.FindResource("SettingPanelMargin");
private static readonly Thickness SettingPanelItemLeftMargin = (Thickness)Application.Current.FindResource("SettingPanelItemLeftMargin");
private static readonly Thickness SettingPanelItemTopBottomMargin = (Thickness)Application.Current.FindResource("SettingPanelItemTopBottomMargin");
Expand Down Expand Up @@ -156,11 +157,12 @@
{
if (!NeedCreateSettingPanel()) return null!;

// Create main grid with two columns (Column 1: Auto, Column 2: *)
// Create main grid with two columns (Column 0: Auto, Column 1: *)
var mainPanel = new Grid { Margin = SettingPanelMargin, VerticalAlignment = VerticalAlignment.Center };
mainPanel.ColumnDefinitions.Add(new ColumnDefinition()
{
Width = new GridLength(0, GridUnitType.Auto)
Width = new GridLength(0, GridUnitType.Auto),
MaxWidth = MainGridColumn0MaxWidthRatio * 560 // 560 is the default available width
});
mainPanel.ColumnDefinitions.Add(new ColumnDefinition()
{
Expand Down Expand Up @@ -200,7 +202,7 @@
{
Text = attributes.Label,
VerticalAlignment = VerticalAlignment.Center,
TextWrapping = TextWrapping.WrapWithOverflow
TextWrapping = TextWrapping.Wrap
};

// Create a text block for description
Expand All @@ -211,7 +213,7 @@
{
Text = attributes.Description,
VerticalAlignment = VerticalAlignment.Center,
TextWrapping = TextWrapping.WrapWithOverflow
TextWrapping = TextWrapping.Wrap
};

desc.SetResourceReference(TextBlock.StyleProperty, "SettingPanelTextBlockDescriptionStyle"); // for theme change
Expand Down Expand Up @@ -247,7 +249,8 @@
VerticalAlignment = VerticalAlignment.Center,
Margin = SettingPanelItemLeftTopBottomMargin,
Text = Settings[attributes.Name] as string ?? string.Empty,
ToolTip = attributes.Description
ToolTip = attributes.Description,
TextWrapping = TextWrapping.Wrap
};

textBox.TextChanged += (_, _) =>
Expand All @@ -269,7 +272,8 @@
VerticalAlignment = VerticalAlignment.Center,
Margin = SettingPanelItemLeftMargin,
Text = Settings[attributes.Name] as string ?? string.Empty,
ToolTip = attributes.Description
ToolTip = attributes.Description,
TextWrapping = TextWrapping.Wrap
};

textBox.TextChanged += (_, _) =>
Expand Down Expand Up @@ -333,7 +337,7 @@
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Center,
Margin = SettingPanelItemLeftTopBottomMargin,
TextWrapping = TextWrapping.WrapWithOverflow,
TextWrapping = TextWrapping.Wrap,
AcceptsReturn = true,
Text = Settings[attributes.Name] as string ?? string.Empty,
ToolTip = attributes.Description
Expand Down Expand Up @@ -417,16 +421,16 @@

break;
}
case "hyperlink":

Check warning on line 424 in Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`hyperlink` is not a recognized word. (unrecognized-spelling)
{
var hyperlink = new Hyperlink

Check warning on line 426 in Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`hyperlink` is not a recognized word. (unrecognized-spelling)
{
ToolTip = attributes.Description,
NavigateUri = attributes.url
};

hyperlink.Inlines.Add(attributes.urlLabel);

Check warning on line 432 in Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`hyperlink` is not a recognized word. (unrecognized-spelling)
hyperlink.RequestNavigate += (sender, e) =>

Check warning on line 433 in Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`hyperlink` is not a recognized word. (unrecognized-spelling)
{
API.OpenUrl(e.Uri);
e.Handled = true;
Expand All @@ -440,7 +444,7 @@
TextAlignment = TextAlignment.Left,
TextWrapping = TextWrapping.Wrap
};
textBlock.Inlines.Add(hyperlink);

Check warning on line 447 in Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`hyperlink` is not a recognized word. (unrecognized-spelling)

contentControl = textBlock;

Expand Down Expand Up @@ -488,13 +492,41 @@
rowCount++;
}

mainPanel.SizeChanged += MainPanel_SizeChanged;

// Wrap the main grid in a user control
return new UserControl()
{
Content = mainPanel
};
}

private void MainPanel_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (sender is not Grid grid) return;

var workingWidth =
(int)(grid.ActualWidth - SystemParameters.VerticalScrollBarWidth); // take into account vertical scrollbar

if (workingWidth <= 0) return;

var constrainedWidth = MainGridColumn0MaxWidthRatio * workingWidth;

// Set MaxWidth of column 0 and its childrens

Check warning on line 515 in Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`childrens` is not a recognized word. (unrecognized-spelling)
// We must set MaxWidth of its childrens to make text wrapping work correctly

Check warning on line 516 in Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`childrens` is not a recognized word. (unrecognized-spelling)
grid.ColumnDefinitions[0].MaxWidth = constrainedWidth;
foreach (var child in grid.Children)
{
if (child is FrameworkElement element && Grid.GetColumn(element) == 0 && Grid.GetColumnSpan(element) == 1)
{
if (element.MaxWidth < constrainedWidth)
continue;

element.MaxWidth = constrainedWidth;
}
}
}

private static bool NeedSaveInSettings(string type)
{
return type != "textBlock" && type != "separator" && type != "hyperlink";
Expand Down
Loading