Skip to content

Commit 33a9654

Browse files
committed
Add settings control
1 parent 1dc1643 commit 33a9654

File tree

4 files changed

+134
-3
lines changed

4 files changed

+134
-3
lines changed

Plugins/Flow.Launcher.Plugin.Url/Main.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Text.RegularExpressions;
4+
using System.Windows.Controls;
45
using Flow.Launcher.Plugin.SharedCommands;
56

67
namespace Flow.Launcher.Plugin.Url
78
{
8-
public class Main : IPlugin, IPluginI18n
9+
public class Main : IPlugin, IPluginI18n, ISettingProvider
910
{
1011
//based on https://gist.github.com/dperini/729294
1112
private const string UrlPattern = "^" +
@@ -123,5 +124,10 @@ public string GetTranslatedPluginDescription()
123124
{
124125
return Context.API.GetTranslation("flowlauncher_plugin_url_plugin_description");
125126
}
127+
128+
public Control CreateSettingPanel()
129+
{
130+
return new SettingsControl();
131+
}
126132
}
127133
}

Plugins/Flow.Launcher.Plugin.Url/Settings.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
namespace Flow.Launcher.Plugin.Url
22
{
3-
public class Settings
3+
public class Settings : BaseModel
44
{
55
public bool UseCustomBrowser { get; set; } = false;
66

7-
public string BrowserPath { get; set; } = string.Empty;
7+
private string _browserPath = string.Empty;
8+
public string BrowserPath
9+
{
10+
get => _browserPath;
11+
set
12+
{
13+
if (_browserPath != value)
14+
{
15+
_browserPath = value;
16+
OnPropertyChanged();
17+
}
18+
}
19+
}
820

921
public bool OpenInNewBrowserWindow { get; set; } = false;
1022

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<UserControl
2+
x:Class="Flow.Launcher.Plugin.Url.SettingsControl"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:Flow.Launcher.Plugin.Url"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
d:DesignHeight="450"
9+
d:DesignWidth="800"
10+
DataContext="{Binding RelativeSource={RelativeSource Self}}"
11+
mc:Ignorable="d">
12+
13+
<Grid Margin="{StaticResource SettingPanelMargin}">
14+
<Grid.RowDefinitions>
15+
<RowDefinition Height="auto" />
16+
<RowDefinition Height="auto" />
17+
<RowDefinition Height="auto" />
18+
<RowDefinition Height="auto" />
19+
</Grid.RowDefinitions>
20+
<Grid.ColumnDefinitions>
21+
<ColumnDefinition Width="Auto" />
22+
<ColumnDefinition Width="*" />
23+
</Grid.ColumnDefinitions>
24+
25+
<CheckBox
26+
Grid.Row="0"
27+
Grid.Column="0"
28+
Grid.ColumnSpan="2"
29+
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
30+
HorizontalAlignment="Left"
31+
VerticalAlignment="Center"
32+
Content="{DynamicResource flowlauncher_plugin_use_custom_browser}"
33+
IsChecked="{Binding Settings.UseCustomBrowser, Mode=TwoWay}" />
34+
35+
<TextBlock
36+
Grid.Row="1"
37+
Grid.Column="0"
38+
Margin="{StaticResource SettingPanelItemRightTopBottomMargin}"
39+
VerticalAlignment="Center"
40+
FontSize="14"
41+
Text="{DynamicResource flowlauncher_plugin_browser_path}" />
42+
<Grid
43+
Grid.Row="1"
44+
Grid.Column="1"
45+
Margin="{StaticResource SettingPanelItemLeftTopBottomMargin}">
46+
<Grid.ColumnDefinitions>
47+
<ColumnDefinition Width="*" />
48+
<ColumnDefinition Width="Auto" />
49+
</Grid.ColumnDefinitions>
50+
51+
<TextBox
52+
Grid.Column="0"
53+
HorizontalAlignment="Stretch"
54+
VerticalAlignment="Center"
55+
IsReadOnly="True"
56+
Text="{Binding Settings.BrowserPath, Mode=OneWay}" />
57+
<Button
58+
Grid.Column="1"
59+
Margin="{StaticResource SettingPanelItemLeftMargin}"
60+
HorizontalAlignment="Left"
61+
VerticalAlignment="Center"
62+
Click="SelectBrowserPath"
63+
Content="{DynamicResource flowlauncher_plugin_url_plugin_choose}" />
64+
</Grid>
65+
66+
<CheckBox
67+
Grid.Row="2"
68+
Grid.Column="0"
69+
Grid.ColumnSpan="2"
70+
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
71+
HorizontalAlignment="Left"
72+
VerticalAlignment="Center"
73+
Content="{DynamicResource flowlauncher_plugin_url_open_in_new_window}"
74+
IsChecked="{Binding Settings.OpenInNewBrowserWindow, Mode=TwoWay}" />
75+
76+
<CheckBox
77+
Grid.Row="3"
78+
Grid.Column="0"
79+
Grid.ColumnSpan="2"
80+
Margin="{StaticResource SettingPanelItemTopBottomMargin}"
81+
HorizontalAlignment="Left"
82+
VerticalAlignment="Center"
83+
Content="{DynamicResource flowlauncher_plugin_url_open_in_private}"
84+
IsChecked="{Binding Settings.OpenInPrivateMode, Mode=TwoWay}" />
85+
</Grid>
86+
</UserControl>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
4+
namespace Flow.Launcher.Plugin.Url;
5+
6+
public partial class SettingsControl : UserControl
7+
{
8+
public Settings Settings => Main.Settings;
9+
10+
public SettingsControl()
11+
{
12+
InitializeComponent();
13+
}
14+
15+
private void SelectBrowserPath(object sender, RoutedEventArgs e)
16+
{
17+
var dlg = new Microsoft.Win32.OpenFileDialog
18+
{
19+
Filter = Main.Context.API.GetTranslation("flowlauncher_plugin_url_plugin_filter")
20+
};
21+
22+
if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
23+
{
24+
Settings.BrowserPath = dlg.FileName;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)