Add settings control

This commit is contained in:
Jack251970 2025-09-04 22:06:02 +08:00
parent 1dc1643071
commit 33a9654fe0
4 changed files with 134 additions and 3 deletions

View file

@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Controls;
using Flow.Launcher.Plugin.SharedCommands;
namespace Flow.Launcher.Plugin.Url
{
public class Main : IPlugin, IPluginI18n
public class Main : IPlugin, IPluginI18n, ISettingProvider
{
//based on https://gist.github.com/dperini/729294
private const string UrlPattern = "^" +
@ -123,5 +124,10 @@ namespace Flow.Launcher.Plugin.Url
{
return Context.API.GetTranslation("flowlauncher_plugin_url_plugin_description");
}
public Control CreateSettingPanel()
{
return new SettingsControl();
}
}
}

View file

@ -1,10 +1,22 @@
namespace Flow.Launcher.Plugin.Url
{
public class Settings
public class Settings : BaseModel
{
public bool UseCustomBrowser { get; set; } = false;
public string BrowserPath { get; set; } = string.Empty;
private string _browserPath = string.Empty;
public string BrowserPath
{
get => _browserPath;
set
{
if (_browserPath != value)
{
_browserPath = value;
OnPropertyChanged();
}
}
}
public bool OpenInNewBrowserWindow { get; set; } = false;

View file

@ -0,0 +1,86 @@
<UserControl
x:Class="Flow.Launcher.Plugin.Url.SettingsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Flow.Launcher.Plugin.Url"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="450"
d:DesignWidth="800"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
mc:Ignorable="d">
<Grid Margin="{StaticResource SettingPanelMargin}">
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<CheckBox
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="{DynamicResource flowlauncher_plugin_use_custom_browser}"
IsChecked="{Binding Settings.UseCustomBrowser, Mode=TwoWay}" />
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource flowlauncher_plugin_browser_path}" />
<Grid
Grid.Row="1"
Grid.Column="1"
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox
Grid.Column="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
IsReadOnly="True"
Text="{Binding Settings.BrowserPath, Mode=OneWay}" />
<Button
Grid.Column="1"
Margin="{StaticResource SettingPanelItemLeftMargin}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Click="SelectBrowserPath"
Content="{DynamicResource flowlauncher_plugin_url_plugin_choose}" />
</Grid>
<CheckBox
Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="{DynamicResource flowlauncher_plugin_url_open_in_new_window}"
IsChecked="{Binding Settings.OpenInNewBrowserWindow, Mode=TwoWay}" />
<CheckBox
Grid.Row="3"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="{DynamicResource flowlauncher_plugin_url_open_in_private}"
IsChecked="{Binding Settings.OpenInPrivateMode, Mode=TwoWay}" />
</Grid>
</UserControl>

View file

@ -0,0 +1,27 @@
using System.Windows;
using System.Windows.Controls;
namespace Flow.Launcher.Plugin.Url;
public partial class SettingsControl : UserControl
{
public Settings Settings => Main.Settings;
public SettingsControl()
{
InitializeComponent();
}
private void SelectBrowserPath(object sender, RoutedEventArgs e)
{
var dlg = new Microsoft.Win32.OpenFileDialog
{
Filter = Main.Context.API.GetTranslation("flowlauncher_plugin_url_plugin_filter")
};
if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
{
Settings.BrowserPath = dlg.FileName;
}
}
}