Skip to content

Commit 8fb873b

Browse files
committed
Merge branch 'allow_option_websearch_openintab' into dev
2 parents e1fc112 + c17eb5f commit 8fb873b

File tree

15 files changed

+204
-17
lines changed

15 files changed

+204
-17
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')" />

Plugins/Wox.Plugin.Url/Main.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,14 @@ public List<Result> Query(Query query)
7979
}
8080
try
8181
{
82-
raw.NewBrowserWindow(_settings.BrowserPath);
82+
if (_settings.OpenInNewBrowserWindow)
83+
{
84+
raw.NewBrowserWindow(_settings.BrowserPath);
85+
}
86+
else
87+
{
88+
raw.NewTabInBrowser(_settings.BrowserPath);
89+
}
8390

8491
return true;
8592
}

Plugins/Wox.Plugin.Url/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ namespace Wox.Plugin.Url
99
public class Settings
1010
{
1111
public string BrowserPath { get; set; }
12+
13+
public bool OpenInNewBrowserWindow { get; set; } = true;
1214
}
1315
}

Plugins/Wox.Plugin.Url/SettingsControl.xaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@
1616
<ColumnDefinition Width="0*"/>
1717
<ColumnDefinition Width="0*"/>
1818
</Grid.ColumnDefinitions>
19-
<Label HorizontalAlignment="Left" Margin="99,22,0,0" VerticalAlignment="Top" Height="43" Width="318" FontSize="20" Content="{DynamicResource wox_plugin_url_plugin_set_tip}"/>
20-
<TextBox x:Name="browserPathBox" HorizontalAlignment="Left" Height="34" Margin="35,90,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="311"/>
21-
<Button x:Name="setButton" HorizontalAlignment="Left" Margin="356,247,0,0" VerticalAlignment="Top" Width="110" Height="33" FontSize="20" Click="OnApplyBTClick" Content="{DynamicResource wox_plugin_url_plugin_apply}"/>
22-
<Button x:Name="viewButton" HorizontalAlignment="Left" Margin="369,90,0,0" VerticalAlignment="Top" Width="86" Height="34" Click="OnChooseClick" FontSize="20" Content="{DynamicResource wox_plugin_url_plugin_choose}"/>
23-
19+
<StackPanel Orientation="Horizontal" Grid.Row="0">
20+
<Label Content="Open search in:" Margin="40,3,0,272"/>
21+
<RadioButton Name="NewWindowBrowser" GroupName="OpenSearchBehaviour" Content="New window" Click="OnNewBrowserWindowClick" Margin="10,10,10,272" />
22+
<RadioButton Name="NewTabInBrowser" GroupName="OpenSearchBehaviour" Content="New tab" Click="OnNewTabClick" Margin="10,10,10,272" />
23+
</StackPanel>
24+
<StackPanel VerticalAlignment="Center">
25+
<Label Content="{DynamicResource wox_plugin_url_plugin_set_tip}" Height="42" Margin="0,0,155,0" HorizontalAlignment="Right" Width="310"/>
26+
<TextBox x:Name="browserPathBox" HorizontalAlignment="Left" Height="34" Margin="35,0,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="311" RenderTransformOrigin="0.502,-1.668"/>
27+
<Button x:Name="setButton" HorizontalAlignment="Left" Margin="272,5,0,0" Width="73" Height="25" FontSize="10" Click="OnApplyBTClick" Content="{DynamicResource wox_plugin_url_plugin_apply}" />
28+
<Button x:Name="viewButton" HorizontalAlignment="Left" Margin="180,-25,0,0" Width="73" Height="25" Click="OnChooseClick" FontSize="10" Content="{DynamicResource wox_plugin_url_plugin_choose}" />
29+
</StackPanel>
2430
</Grid>
2531
</UserControl>

Plugins/Wox.Plugin.Url/SettingsControl.xaml.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public SettingsControl(IPublicAPI woxAPI,Settings settings)
3131
_settings = settings;
3232
_woxAPI = woxAPI;
3333
browserPathBox.Text = _settings.BrowserPath;
34+
NewWindowBrowser.IsChecked = _settings.OpenInNewBrowserWindow;
35+
NewTabInBrowser.IsChecked = !_settings.OpenInNewBrowserWindow;
3436
}
3537

3638
private void OnApplyBTClick(object sender, RoutedEventArgs e)
@@ -49,5 +51,15 @@ private void OnChooseClick(object sender, RoutedEventArgs e)
4951
browserPathBox.Text = fileBrowserDialog.FileName;
5052
}
5153
}
54+
55+
private void OnNewBrowserWindowClick(object sender, RoutedEventArgs e)
56+
{
57+
_settings.OpenInNewBrowserWindow = true;
58+
}
59+
60+
private void OnNewTabClick(object sender, RoutedEventArgs e)
61+
{
62+
_settings.OpenInNewBrowserWindow = false;
63+
}
5264
}
5365
}

Plugins/Wox.Plugin.WebSearch/Main.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,14 @@ public List<Result> Query(Query query)
7474
IcoPath = searchSource.IconPath,
7575
Action = c =>
7676
{
77-
searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)).NewBrowserWindow("");
77+
if (_settings.OpenInNewBrowser)
78+
{
79+
searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)).NewBrowserWindow("");
80+
}
81+
else
82+
{
83+
searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)).NewTabInBrowser("");
84+
}
7885

7986
return true;
8087
}
@@ -132,7 +139,15 @@ private async Task<IEnumerable<Result>> Suggestions(string keyword, string subti
132139
IcoPath = searchSource.IconPath,
133140
Action = c =>
134141
{
135-
searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewBrowserWindow("");
142+
if (_settings.OpenInNewBrowser)
143+
{
144+
searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewBrowserWindow("");
145+
}
146+
else
147+
{
148+
searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewTabInBrowser("");
149+
}
150+
136151
return true;
137152
}
138153
});

0 commit comments

Comments
 (0)