diff --git a/Flow.Launcher.Core/Plugin/JsonRPCConfigurationModel.cs b/Flow.Launcher.Core/Plugin/JsonRPCConfigurationModel.cs index 1f63f85a806..6dc4be881a8 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCConfigurationModel.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCConfigurationModel.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Flow.Launcher.Core.Plugin { @@ -26,6 +27,8 @@ public class FieldAttributes public string Name { get; set; } public string Label { get; set; } public string Description { get; set; } + public string urlLabel { get; set; } + public Uri url { get; set; } public bool Validation { get; set; } public List Options { get; set; } public string DefaultValue { get; set; } @@ -40,4 +43,4 @@ public void Deconstruct(out string Name, out string Label, out string Descriptio DefaultValue = this.DefaultValue; } } -} \ No newline at end of file +} diff --git a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs index e3efcd296c4..4df5037a574 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCPlugin.cs @@ -22,6 +22,10 @@ using Orientation = System.Windows.Controls.Orientation; using TextBox = System.Windows.Controls.TextBox; using UserControl = System.Windows.Controls.UserControl; +using System.Windows.Documents; +using static System.Windows.Forms.LinkLabel; +using Droplex; +using System.Windows.Forms; namespace Flow.Launcher.Core.Plugin { @@ -33,7 +37,6 @@ internal abstract class JsonRPCPlugin : IAsyncPlugin, IContextMenu, ISettingProv { protected PluginInitContext context; public const string JsonRPC = "JsonRPC"; - /// /// The language this JsonRPCPlugin support /// @@ -340,9 +343,14 @@ public virtual async Task InitAsync(PluginInitContext context) this.context = context; await InitSettingAsync(); } - private static readonly Thickness settingControlMargin = new(10, 4, 10, 4); - private static readonly Thickness settingPanelMargin = new(15, 20, 15, 20); - private static readonly Thickness settingTextBlockMargin = new(10, 4, 10, 4); + private static readonly Thickness settingControlMargin = new(0, 9, 18, 9); + private static readonly Thickness settingCheckboxMargin = new(0, 9, 9, 9); + private static readonly Thickness settingPanelMargin = new(0, 0, 0, 0); + private static readonly Thickness settingTextBlockMargin = new(70, 9, 18, 9); + private static readonly Thickness settingLabelPanelMargin = new(70, 9, 18, 9); + private static readonly Thickness settingLabelMargin = new(0, 0, 0, 0); + private static readonly Thickness settingDescMargin = new(0, 2, 0, 0); + private static readonly Thickness settingSepMargin = new(0, 0, 0, 2); private JsonRpcConfigurationModel _settingsTemplate; public Control CreateSettingPanel() @@ -350,26 +358,60 @@ public Control CreateSettingPanel() if (Settings == null) return new(); var settingWindow = new UserControl(); - var mainPanel = new StackPanel + var mainPanel = new Grid { - Margin = settingPanelMargin, Orientation = Orientation.Vertical + Margin = settingPanelMargin, VerticalAlignment = VerticalAlignment.Center }; - settingWindow.Content = mainPanel; + ColumnDefinition gridCol1 = new ColumnDefinition(); + ColumnDefinition gridCol2 = new ColumnDefinition(); + gridCol1.Width = new GridLength(70, GridUnitType.Star); + gridCol2.Width = new GridLength(30, GridUnitType.Star); + mainPanel.ColumnDefinitions.Add(gridCol1); + mainPanel.ColumnDefinitions.Add(gridCol2); + settingWindow.Content = mainPanel; + int rowCount = 0; foreach (var (type, attribute) in _settingsTemplate.Body) { + Separator sep = new Separator(); + sep.VerticalAlignment = VerticalAlignment.Top; + sep.Margin = settingSepMargin; + sep.SetResourceReference(Separator.BackgroundProperty, "Color03B"); /* for theme change */ var panel = new StackPanel { - Orientation = Orientation.Horizontal, Margin = settingControlMargin + Orientation = Orientation.Vertical, VerticalAlignment = VerticalAlignment.Center, + Margin = settingLabelPanelMargin }; + RowDefinition gridRow = new RowDefinition(); + mainPanel.RowDefinitions.Add(gridRow); var name = new TextBlock() { Text = attribute.Label, - Width = 120, VerticalAlignment = VerticalAlignment.Center, - Margin = settingControlMargin, + Margin = settingLabelMargin, + TextWrapping = TextWrapping.WrapWithOverflow + }; + var desc = new TextBlock() + { + Text = attribute.Description, FontSize = 12, + VerticalAlignment = VerticalAlignment.Center,Margin = settingDescMargin, TextWrapping = TextWrapping.WrapWithOverflow }; + desc.SetResourceReference(TextBlock.ForegroundProperty, "Color04B"); + + if (attribute.Description == null) /* if no description, hide */ + desc.Visibility = Visibility.Collapsed; + + + if (type != "textBlock") /* if textBlock, hide desc */ + { + panel.Children.Add(name); + panel.Children.Add(desc); + } + + + Grid.SetColumn(panel, 0); + Grid.SetRow(panel, rowCount); FrameworkElement contentControl; @@ -381,18 +423,28 @@ public Control CreateSettingPanel() { Text = attribute.Description.Replace("\\r\\n", "\r\n"), Margin = settingTextBlockMargin, - MaxWidth = 500, - TextWrapping = TextWrapping.WrapWithOverflow + Padding = new Thickness(0,0,0,0), + HorizontalAlignment = System.Windows.HorizontalAlignment.Left, + TextAlignment = TextAlignment.Left, + TextWrapping = TextWrapping.Wrap }; - break; + Grid.SetColumn(contentControl, 0); + Grid.SetColumnSpan(contentControl, 2); + Grid.SetRow(contentControl, rowCount); + if (rowCount != 0) + mainPanel.Children.Add(sep); + Grid.SetRow(sep, rowCount); + Grid.SetColumn(sep, 0); + Grid.SetColumnSpan(sep, 2); + break; } case "input": { var textBox = new TextBox() { - Width = 300, Text = Settings[attribute.Name] as string ?? string.Empty, Margin = settingControlMargin, + HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, ToolTip = attribute.Description }; textBox.TextChanged += (_, _) => @@ -400,17 +452,60 @@ public Control CreateSettingPanel() Settings[attribute.Name] = textBox.Text; }; contentControl = textBox; - break; + Grid.SetColumn(contentControl, 1); + Grid.SetRow(contentControl, rowCount); + if (rowCount != 0) + mainPanel.Children.Add(sep); + Grid.SetRow(sep, rowCount); + Grid.SetColumn(sep, 0); + Grid.SetColumnSpan(sep, 2); + break; } + case "inputWithFileBtn": + { + var textBox = new TextBox() + { + Margin = new Thickness(10, 0, 0, 0), + Text = Settings[attribute.Name] as string ?? string.Empty, + HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, + ToolTip = attribute.Description + }; + textBox.TextChanged += (_, _) => + { + Settings[attribute.Name] = textBox.Text; + }; + var Btn = new System.Windows.Controls.Button() + { + Margin = new Thickness(10,0,0,0), + Content = "Browse" + }; + var dockPanel = new DockPanel() + { + Margin = settingControlMargin + }; + DockPanel.SetDock(Btn, Dock.Right); + dockPanel.Children.Add(Btn); + dockPanel.Children.Add(textBox); + contentControl = dockPanel; + Grid.SetColumn(contentControl, 1); + Grid.SetRow(contentControl, rowCount); + if (rowCount != 0) + mainPanel.Children.Add(sep); + Grid.SetRow(sep, rowCount); + Grid.SetColumn(sep, 0); + Grid.SetColumnSpan(sep, 2); + break; + } case "textarea": { var textBox = new TextBox() { - Width = 300, Height = 120, Margin = settingControlMargin, + VerticalAlignment = VerticalAlignment.Center, TextWrapping = TextWrapping.WrapWithOverflow, AcceptsReturn = true, + HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, Text = Settings[attribute.Name] as string ?? string.Empty, ToolTip = attribute.Description }; @@ -419,16 +514,23 @@ public Control CreateSettingPanel() Settings[attribute.Name] = ((TextBox)sender).Text; }; contentControl = textBox; - break; + Grid.SetColumn(contentControl, 1); + Grid.SetRow(contentControl, rowCount); + if (rowCount != 0) + mainPanel.Children.Add(sep); + Grid.SetRow(sep, rowCount); + Grid.SetColumn(sep, 0); + Grid.SetColumnSpan(sep, 2); + break; } case "passwordBox": { var passwordBox = new PasswordBox() { - Width = 300, Margin = settingControlMargin, Password = Settings[attribute.Name] as string ?? string.Empty, PasswordChar = attribute.passwordChar == default ? '*' : attribute.passwordChar, + HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch, ToolTip = attribute.Description }; passwordBox.PasswordChanged += (sender, _) => @@ -436,29 +538,45 @@ public Control CreateSettingPanel() Settings[attribute.Name] = ((PasswordBox)sender).Password; }; contentControl = passwordBox; - break; + Grid.SetColumn(contentControl, 1); + Grid.SetRow(contentControl, rowCount); + if (rowCount != 0) + mainPanel.Children.Add(sep); + Grid.SetRow(sep, rowCount); + Grid.SetColumn(sep, 0); + Grid.SetColumnSpan(sep, 2); + break; } case "dropdown": { - var comboBox = new ComboBox() + var comboBox = new System.Windows.Controls.ComboBox() { ItemsSource = attribute.Options, SelectedItem = Settings[attribute.Name], Margin = settingControlMargin, + HorizontalAlignment = System.Windows.HorizontalAlignment.Right, ToolTip = attribute.Description }; comboBox.SelectionChanged += (sender, _) => { - Settings[attribute.Name] = (string)((ComboBox)sender).SelectedItem; + Settings[attribute.Name] = (string)((System.Windows.Controls.ComboBox)sender).SelectedItem; }; contentControl = comboBox; - break; + Grid.SetColumn(contentControl, 1); + Grid.SetRow(contentControl, rowCount); + if (rowCount != 0) + mainPanel.Children.Add(sep); + Grid.SetRow(sep, rowCount); + Grid.SetColumn(sep, 0); + Grid.SetColumnSpan(sep, 2); + break; } case "checkbox": var checkBox = new CheckBox { IsChecked = Settings[attribute.Name] is bool isChecked ? isChecked : bool.Parse(attribute.DefaultValue), - Margin = settingControlMargin, + Margin = settingCheckboxMargin, + HorizontalAlignment = System.Windows.HorizontalAlignment.Right, ToolTip = attribute.Description }; checkBox.Click += (sender, _) => @@ -466,15 +584,45 @@ public Control CreateSettingPanel() Settings[attribute.Name] = ((CheckBox)sender).IsChecked; }; contentControl = checkBox; + Grid.SetColumn(contentControl, 1); + Grid.SetRow(contentControl, rowCount); + if (rowCount != 0) + mainPanel.Children.Add(sep); + Grid.SetRow(sep, rowCount); + Grid.SetColumn(sep, 0); + Grid.SetColumnSpan(sep, 2); + break; + case "hyperlink": + var hyperlink = new Hyperlink + { + ToolTip = attribute.Description, + NavigateUri = attribute.url + }; + var linkbtn = new System.Windows.Controls.Button + { + HorizontalAlignment = System.Windows.HorizontalAlignment.Right, + Margin = settingControlMargin + }; + linkbtn.Content = attribute.urlLabel; + + contentControl = linkbtn; + Grid.SetColumn(contentControl, 1); + Grid.SetRow(contentControl, rowCount); + if (rowCount != 0) + mainPanel.Children.Add(sep); + Grid.SetRow(sep, rowCount); + Grid.SetColumn(sep, 0); + Grid.SetColumnSpan(sep, 2); break; default: continue; } if (type != "textBlock") _settingControls[attribute.Name] = contentControl; - panel.Children.Add(name); - panel.Children.Add(contentControl); mainPanel.Children.Add(panel); + mainPanel.Children.Add(contentControl); + rowCount++; + } return settingWindow; } @@ -510,7 +658,7 @@ public void UpdateSettings(Dictionary settings) case PasswordBox passwordBox: passwordBox.Dispatcher.Invoke(() => passwordBox.Password = value as string); break; - case ComboBox comboBox: + case System.Windows.Controls.ComboBox comboBox: comboBox.Dispatcher.Invoke(() => comboBox.SelectedItem = value); break; case CheckBox checkBox: diff --git a/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml b/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml index 66aa34b2a19..f806900dedc 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml +++ b/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml @@ -1,33 +1,39 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs b/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs index cdcc977a9a9..b5f1531c3a2 100644 --- a/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs +++ b/Plugins/Flow.Launcher.Plugin.Sys/SysSettings.xaml.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Windows; using System.Windows.Controls; namespace Flow.Launcher.Plugin.Sys @@ -14,5 +15,17 @@ public SysSettings(List Results) lbxCommands.Items.Add(Result); } } + private void ListView_SizeChanged(object sender, SizeChangedEventArgs e) + { + ListView listView = sender as ListView; + GridView gView = listView.View as GridView; + + var workingWidth = listView.ActualWidth - SystemParameters.VerticalScrollBarWidth; // take into account vertical scrollbar + var col1 = 0.3; + var col2 = 0.7; + + gView.Columns[0].Width = workingWidth * col1; + gView.Columns[1].Width = workingWidth * col2; + } } }