Skip to content

Commit c17eb5f

Browse files
committed
Add user selection option for browserbookmark plugin
1 parent 91e9bdf commit c17eb5f

File tree

5 files changed

+108
-6
lines changed

5 files changed

+108
-6
lines changed

Plugins/Wox.Plugin.BrowserBookmark/Main.cs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11
using System.Collections.Generic;
22
using System.Linq;
3+
using System.Windows.Controls;
4+
using Wox.Infrastructure.Storage;
35
using Wox.Plugin.BrowserBookmark.Commands;
6+
using Wox.Plugin.BrowserBookmark.Models;
7+
using Wox.Plugin.BrowserBookmark.Views;
48
using Wox.Plugin.SharedCommands;
59

610
namespace Wox.Plugin.BrowserBookmark
711
{
8-
public class Main : IPlugin, IReloadable, IPluginI18n
12+
public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, ISavable
913
{
1014
private PluginInitContext context;
1115

12-
private List<Bookmark> cachedBookmarks = new List<Bookmark>();
16+
private List<Bookmark> cachedBookmarks = new List<Bookmark>();
1317

14-
public void Init(PluginInitContext context)
18+
private readonly Settings _settings;
19+
private readonly PluginJsonStorage<Settings> _storage;
20+
21+
public Main()
1522
{
16-
this.context = context;
23+
_storage = new PluginJsonStorage<Settings>();
24+
_settings = _storage.Load();
1725

1826
cachedBookmarks = Bookmarks.LoadAllBookmarks();
1927
}
2028

29+
public void Init(PluginInitContext context)
30+
{
31+
this.context = context;
32+
}
33+
2134
public List<Result> Query(Query query)
2235
{
2336
string param = query.GetAllRemainingParameter().TrimStart();
@@ -42,8 +55,15 @@ public List<Result> Query(Query query)
4255
Score = 5,
4356
Action = (e) =>
4457
{
45-
context.API.HideApp();
46-
c.Url.NewBrowserWindow("");
58+
if (_settings.OpenInNewBrowserWindow)
59+
{
60+
c.Url.NewBrowserWindow("");
61+
}
62+
else
63+
{
64+
c.Url.NewTabInBrowser("");
65+
}
66+
4767
return true;
4868
}
4969
}).ToList();
@@ -66,5 +86,14 @@ public string GetTranslatedPluginDescription()
6686
return context.API.GetTranslation("wox_plugin_browserbookmark_plugin_description");
6787
}
6888

89+
public Control CreateSettingPanel()
90+
{
91+
return new SettingsControl(_settings);
92+
}
93+
94+
public void Save()
95+
{
96+
_storage.Save();
97+
}
6998
}
7099
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Wox.Plugin.BrowserBookmark.Models
2+
{
3+
public class Settings : BaseModel
4+
{
5+
public bool OpenInNewBrowserWindow { get; set; } = true;
6+
}
7+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<UserControl x:Class="Wox.Plugin.BrowserBookmark.Views.SettingsControl"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
mc:Ignorable="d"
7+
Background="White"
8+
d:DesignHeight="300" d:DesignWidth="500">
9+
<Grid Margin="10">
10+
<Grid.RowDefinitions>
11+
<RowDefinition Height="40" />
12+
<RowDefinition />
13+
<RowDefinition Height="40" />
14+
</Grid.RowDefinitions>
15+
<StackPanel Orientation="Horizontal" Grid.Row="0">
16+
<Label Content="Open bookmark in:" Margin="40 3 0 8"/>
17+
<RadioButton Name="NewWindowBrowser" GroupName="OpenSearchBehaviour" Content="New window" Click="OnNewBrowserWindowClick" Margin="10" />
18+
<RadioButton Name="NewTabInBrowser" GroupName="OpenSearchBehaviour" Content="New tab" Click="OnNewTabClick" Margin="10" />
19+
</StackPanel>
20+
</Grid>
21+
</UserControl>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
3+
using Wox.Plugin.BrowserBookmark.Models;
4+
5+
namespace Wox.Plugin.BrowserBookmark.Views
6+
{
7+
/// <summary>
8+
/// Interaction logic for BrowserBookmark.xaml
9+
/// </summary>
10+
public partial class SettingsControl : UserControl
11+
{
12+
private readonly Settings _settings;
13+
14+
public SettingsControl(Settings settings)
15+
{
16+
InitializeComponent();
17+
_settings = settings;
18+
NewWindowBrowser.IsChecked = _settings.OpenInNewBrowserWindow;
19+
NewTabInBrowser.IsChecked = !_settings.OpenInNewBrowserWindow;
20+
}
21+
22+
private void OnNewBrowserWindowClick(object sender, RoutedEventArgs e)
23+
{
24+
_settings.OpenInNewBrowserWindow = true;
25+
}
26+
27+
private void OnNewTabClick(object sender, RoutedEventArgs e)
28+
{
29+
_settings.OpenInNewBrowserWindow = false;
30+
}
31+
}
32+
}

Plugins/Wox.Plugin.BrowserBookmark/Wox.Plugin.BrowserBookmark.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<HintPath>..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
4545
</Reference>
4646
<Reference Include="PresentationCore" />
47+
<Reference Include="PresentationFramework" />
4748
<Reference Include="System" />
4849
<Reference Include="System.ComponentModel.DataAnnotations" />
4950
<Reference Include="System.Core" />
@@ -57,6 +58,7 @@
5758
<Reference Include="System.Data.SQLite.Linq, Version=1.0.111.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
5859
<HintPath>..\..\packages\System.Data.SQLite.Linq.1.0.111.0\lib\net451\System.Data.SQLite.Linq.dll</HintPath>
5960
</Reference>
61+
<Reference Include="System.Xaml" />
6062
<Reference Include="UnidecodeSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
6163
<HintPath>..\..\packages\UnidecodeSharp.1.0.0.0\lib\net35\UnidecodeSharp.dll</HintPath>
6264
<Private>True</Private>
@@ -69,7 +71,11 @@
6971
<Compile Include="Commands\Bookmarks.cs" />
7072
<Compile Include="FirefoxBookmarks.cs" />
7173
<Compile Include="Main.cs" />
74+
<Compile Include="Models\Settings.cs" />
7275
<Compile Include="Properties\AssemblyInfo.cs" />
76+
<Compile Include="Views\SettingsControl.xaml.cs">
77+
<DependentUpon>SettingsControl.xaml</DependentUpon>
78+
</Compile>
7379
</ItemGroup>
7480
<ItemGroup>
7581
<None Include="app.config" />
@@ -111,6 +117,13 @@
111117
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
112118
</Content>
113119
</ItemGroup>
120+
<ItemGroup>
121+
<Page Include="Views\SettingsControl.xaml">
122+
<Generator>MSBuild:Compile</Generator>
123+
<SubType>Designer</SubType>
124+
</Page>
125+
</ItemGroup>
126+
<ItemGroup />
114127
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
115128
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
116129
<Import Project="..\..\packages\System.Data.SQLite.Core.1.0.111.0\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\..\packages\System.Data.SQLite.Core.1.0.111.0\build\net451\System.Data.SQLite.Core.targets')" />

0 commit comments

Comments
 (0)