Merge branch 'allow_option_websearch_openintab' into dev

This commit is contained in:
Jeremy Wu 2019-11-11 08:01:05 +11:00
commit 8fb873b085
15 changed files with 204 additions and 17 deletions

View File

@ -1,21 +1,34 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using Wox.Infrastructure.Storage;
using Wox.Plugin.BrowserBookmark.Commands;
using Wox.Plugin.BrowserBookmark.Models;
using Wox.Plugin.BrowserBookmark.Views;
using Wox.Plugin.SharedCommands;
namespace Wox.Plugin.BrowserBookmark
{
public class Main : IPlugin, IReloadable, IPluginI18n
public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, ISavable
{
private PluginInitContext context;
private List<Bookmark> cachedBookmarks = new List<Bookmark>();
private List<Bookmark> cachedBookmarks = new List<Bookmark>();
private readonly Settings _settings;
private readonly PluginJsonStorage<Settings> _storage;
public Main()
{
_storage = new PluginJsonStorage<Settings>();
_settings = _storage.Load();
cachedBookmarks = Bookmarks.LoadAllBookmarks();
}
public void Init(PluginInitContext context)
{
this.context = context;
cachedBookmarks = Bookmarks.LoadAllBookmarks();
}
public List<Result> Query(Query query)
@ -42,8 +55,15 @@ namespace Wox.Plugin.BrowserBookmark
Score = 5,
Action = (e) =>
{
context.API.HideApp();
c.Url.NewBrowserWindow("");
if (_settings.OpenInNewBrowserWindow)
{
c.Url.NewBrowserWindow("");
}
else
{
c.Url.NewTabInBrowser("");
}
return true;
}
}).ToList();
@ -66,5 +86,14 @@ namespace Wox.Plugin.BrowserBookmark
return context.API.GetTranslation("wox_plugin_browserbookmark_plugin_description");
}
public Control CreateSettingPanel()
{
return new SettingsControl(_settings);
}
public void Save()
{
_storage.Save();
}
}
}

View File

@ -0,0 +1,7 @@
namespace Wox.Plugin.BrowserBookmark.Models
{
public class Settings : BaseModel
{
public bool OpenInNewBrowserWindow { get; set; } = true;
}
}

View File

@ -0,0 +1,21 @@
<UserControl x:Class="Wox.Plugin.BrowserBookmark.Views.SettingsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
Background="White"
d:DesignHeight="300" d:DesignWidth="500">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0">
<Label Content="Open bookmark in:" Margin="40 3 0 8"/>
<RadioButton Name="NewWindowBrowser" GroupName="OpenSearchBehaviour" Content="New window" Click="OnNewBrowserWindowClick" Margin="10" />
<RadioButton Name="NewTabInBrowser" GroupName="OpenSearchBehaviour" Content="New tab" Click="OnNewTabClick" Margin="10" />
</StackPanel>
</Grid>
</UserControl>

View File

@ -0,0 +1,32 @@
using System.Windows;
using System.Windows.Controls;
using Wox.Plugin.BrowserBookmark.Models;
namespace Wox.Plugin.BrowserBookmark.Views
{
/// <summary>
/// Interaction logic for BrowserBookmark.xaml
/// </summary>
public partial class SettingsControl : UserControl
{
private readonly Settings _settings;
public SettingsControl(Settings settings)
{
InitializeComponent();
_settings = settings;
NewWindowBrowser.IsChecked = _settings.OpenInNewBrowserWindow;
NewTabInBrowser.IsChecked = !_settings.OpenInNewBrowserWindow;
}
private void OnNewBrowserWindowClick(object sender, RoutedEventArgs e)
{
_settings.OpenInNewBrowserWindow = true;
}
private void OnNewTabClick(object sender, RoutedEventArgs e)
{
_settings.OpenInNewBrowserWindow = false;
}
}
}

View File

@ -44,6 +44,7 @@
<HintPath>..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
@ -57,6 +58,7 @@
<Reference Include="System.Data.SQLite.Linq, Version=1.0.111.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Data.SQLite.Linq.1.0.111.0\lib\net451\System.Data.SQLite.Linq.dll</HintPath>
</Reference>
<Reference Include="System.Xaml" />
<Reference Include="UnidecodeSharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\UnidecodeSharp.1.0.0.0\lib\net35\UnidecodeSharp.dll</HintPath>
<Private>True</Private>
@ -69,7 +71,11 @@
<Compile Include="Commands\Bookmarks.cs" />
<Compile Include="FirefoxBookmarks.cs" />
<Compile Include="Main.cs" />
<Compile Include="Models\Settings.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Views\SettingsControl.xaml.cs">
<DependentUpon>SettingsControl.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
@ -111,6 +117,13 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Page Include="Views\SettingsControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<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')" />

View File

@ -79,7 +79,14 @@ namespace Wox.Plugin.Url
}
try
{
raw.NewBrowserWindow(_settings.BrowserPath);
if (_settings.OpenInNewBrowserWindow)
{
raw.NewBrowserWindow(_settings.BrowserPath);
}
else
{
raw.NewTabInBrowser(_settings.BrowserPath);
}
return true;
}

View File

@ -9,5 +9,7 @@ namespace Wox.Plugin.Url
public class Settings
{
public string BrowserPath { get; set; }
public bool OpenInNewBrowserWindow { get; set; } = true;
}
}

View File

@ -16,10 +16,16 @@
<ColumnDefinition Width="0*"/>
<ColumnDefinition Width="0*"/>
</Grid.ColumnDefinitions>
<Label HorizontalAlignment="Left" Margin="99,22,0,0" VerticalAlignment="Top" Height="43" Width="318" FontSize="20" Content="{DynamicResource wox_plugin_url_plugin_set_tip}"/>
<TextBox x:Name="browserPathBox" HorizontalAlignment="Left" Height="34" Margin="35,90,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="311"/>
<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}"/>
<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}"/>
<StackPanel Orientation="Horizontal" Grid.Row="0">
<Label Content="Open search in:" Margin="40,3,0,272"/>
<RadioButton Name="NewWindowBrowser" GroupName="OpenSearchBehaviour" Content="New window" Click="OnNewBrowserWindowClick" Margin="10,10,10,272" />
<RadioButton Name="NewTabInBrowser" GroupName="OpenSearchBehaviour" Content="New tab" Click="OnNewTabClick" Margin="10,10,10,272" />
</StackPanel>
<StackPanel VerticalAlignment="Center">
<Label Content="{DynamicResource wox_plugin_url_plugin_set_tip}" Height="42" Margin="0,0,155,0" HorizontalAlignment="Right" Width="310"/>
<TextBox x:Name="browserPathBox" HorizontalAlignment="Left" Height="34" Margin="35,0,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="311" RenderTransformOrigin="0.502,-1.668"/>
<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}" />
<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}" />
</StackPanel>
</Grid>
</UserControl>

View File

@ -31,6 +31,8 @@ namespace Wox.Plugin.Url
_settings = settings;
_woxAPI = woxAPI;
browserPathBox.Text = _settings.BrowserPath;
NewWindowBrowser.IsChecked = _settings.OpenInNewBrowserWindow;
NewTabInBrowser.IsChecked = !_settings.OpenInNewBrowserWindow;
}
private void OnApplyBTClick(object sender, RoutedEventArgs e)
@ -49,5 +51,15 @@ namespace Wox.Plugin.Url
browserPathBox.Text = fileBrowserDialog.FileName;
}
}
private void OnNewBrowserWindowClick(object sender, RoutedEventArgs e)
{
_settings.OpenInNewBrowserWindow = true;
}
private void OnNewTabClick(object sender, RoutedEventArgs e)
{
_settings.OpenInNewBrowserWindow = false;
}
}
}

View File

@ -74,7 +74,14 @@ namespace Wox.Plugin.WebSearch
IcoPath = searchSource.IconPath,
Action = c =>
{
searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)).NewBrowserWindow("");
if (_settings.OpenInNewBrowser)
{
searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)).NewBrowserWindow("");
}
else
{
searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)).NewTabInBrowser("");
}
return true;
}
@ -132,7 +139,15 @@ namespace Wox.Plugin.WebSearch
IcoPath = searchSource.IconPath,
Action = c =>
{
searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewBrowserWindow("");
if (_settings.OpenInNewBrowser)
{
searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewBrowserWindow("");
}
else
{
searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewTabInBrowser("");
}
return true;
}
});

View File

@ -219,5 +219,7 @@ namespace Wox.Plugin.WebSearch
}
}
}
public bool OpenInNewBrowser { get; set; } = true;
}
}

View File

@ -21,8 +21,11 @@
Content="{DynamicResource wox_plugin_websearch_enable_suggestion}" />
<ComboBox ItemsSource="{Binding Settings.Suggestions}"
SelectedItem="{Binding Settings.SelectedSuggestion}"
IsEnabled="{Binding ElementName=EnableSuggestion, Path=IsChecked}" Margin="10" />
IsEnabled="{Binding ElementName=EnableSuggestion, Path=IsChecked}" Margin="10,3,10,10" />
<!-- Not sure why binding IsEnabled directly to Settings.EnableWebSaerchSuggestion is not working -->
<Label Content="Open search in:" Margin="40 3 0 8"/>
<RadioButton Name="NewWindowBrowser" GroupName="OpenSearchBehaviour" Content="New window" Click="OnNewBrowserWindowClick" Margin="10" />
<RadioButton Name="NewTabInBrowser" GroupName="OpenSearchBehaviour" Content="New tab" Click="OnNewTabClick" Margin="10" />
</StackPanel>
<ListView ItemsSource="{Binding Settings.SearchSources}"
SelectedItem="{Binding Settings.SelectedSearchSource}"

View File

@ -18,6 +18,8 @@ namespace Wox.Plugin.WebSearch
_context = context;
_settings = viewModel.Settings;
DataContext = viewModel;
NewWindowBrowser.IsChecked = _settings.OpenInNewBrowser;
NewTabInBrowser.IsChecked = !_settings.OpenInNewBrowser;
}
private void OnAddSearchSearchClick(object sender, RoutedEventArgs e)
@ -56,5 +58,15 @@ namespace Wox.Plugin.WebSearch
webSearch.ShowDialog();
}
}
private void OnNewBrowserWindowClick(object sender, RoutedEventArgs e)
{
_settings.OpenInNewBrowser = true;
}
private void OnNewTabClick(object sender, RoutedEventArgs e)
{
_settings.OpenInNewBrowser = false;
}
}
}

View File

@ -28,6 +28,8 @@ Features
Installation
------------
View new features released from this fork since Wox v1.3.524: [new releases](https://github.com/jjw24/Wox/releases)
To install this fork's version of Wox, you can **download** it [here](https://github.com/jjw24/Wox/releases/latest).
To install the upstream version:

View File

@ -7,10 +7,11 @@ namespace Wox.Plugin.SharedCommands
{
public static class SearchWeb
{
/// <summary> Opens search in a new browser. If no browser path is passed in then Chrome is used.
/// <summary>
/// Opens search in a new browser. If no browser path is passed in then Chrome is used.
/// Leave browser path blank to use Chrome.
/// </summary>
public static void NewBrowserWindow(this string url, string browserPath)
public static void NewBrowserWindow(this string url, string browserPath)
{
var browserExecutableName = browserPath?
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
@ -30,5 +31,28 @@ namespace Wox.Plugin.SharedCommands
Process.Start(url);
}
}
/// <summary>
/// Opens search as a tab in the default browser chosen in Windows settings.
/// </summary>
public static void NewTabInBrowser(this string url, string browserPath)
{
try
{
if (!string.IsNullOrEmpty(browserPath))
{
Process.Start(browserPath, url);
}
else
{
Process.Start(url);
}
}
// This error may be thrown for Process.Start(browserPath, url)
catch (System.ComponentModel.Win32Exception)
{
Process.Start(url);
}
}
}
}