Merge branch 'master' into update_browserbookmarks_open_newbrowser

This commit is contained in:
Jeremy Wu
2019-08-20 07:47:01 +10:00
7 changed files with 105 additions and 80 deletions

View File

@@ -1,9 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Controls; using System.Windows.Controls;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
using Wox.Plugin.SharedCommands;
namespace Wox.Plugin.Url namespace Wox.Plugin.Url
{ {
@@ -79,15 +79,8 @@ namespace Wox.Plugin.Url
} }
try try
{ {
if (_settings.BrowserPath.Length == 0) raw.NewBrowserWindow(_settings.BrowserPath);
{
Process.Start(raw);
}
else
{
Process.Start(_settings.BrowserPath,raw);
}
return true; return true;
} }
catch(Exception ex) catch(Exception ex)

View File

@@ -8,6 +8,7 @@ using System.Threading.Tasks;
using System.Windows.Controls; using System.Windows.Controls;
using Wox.Infrastructure; using Wox.Infrastructure;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
using Wox.Plugin.SharedCommands;
namespace Wox.Plugin.WebSearch namespace Wox.Plugin.WebSearch
{ {
@@ -23,6 +24,8 @@ namespace Wox.Plugin.WebSearch
public const string Images = "Images"; public const string Images = "Images";
public static string ImagesDirectory; public static string ImagesDirectory;
private readonly string SearchSourceGlobalPluginWildCardSign = "*";
public void Save() public void Save()
{ {
_viewModel.Save(); _viewModel.Save();
@@ -30,52 +33,58 @@ namespace Wox.Plugin.WebSearch
public List<Result> Query(Query query) public List<Result> Query(Query query)
{ {
var searchSourceList = new List<SearchSource>();
var results = new List<Result>();
_updateSource?.Cancel(); _updateSource?.Cancel();
_updateSource = new CancellationTokenSource(); _updateSource = new CancellationTokenSource();
_updateToken = _updateSource.Token; _updateToken = _updateSource.Token;
_settings.SearchSources.Where(o => (o.ActionKeyword == query.ActionKeyword || o.ActionKeyword == SearchSourceGlobalPluginWildCardSign)
&& o.Enabled)
.ToList()
.ForEach(x => searchSourceList.Add(x));
SearchSource searchSource = if (searchSourceList.Any())
_settings.SearchSources.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled);
if (searchSource != null)
{ {
string keyword = query.Search; foreach (SearchSource searchSource in searchSourceList)
string title = keyword;
string subtitle = _context.API.GetTranslation("wox_plugin_websearch_search") + " " + searchSource.Title;
if (string.IsNullOrEmpty(keyword))
{ {
var result = new Result string keyword = query.Search;
string title = keyword;
string subtitle = _context.API.GetTranslation("wox_plugin_websearch_search") + " " +
searchSource.Title;
if (string.IsNullOrEmpty(keyword))
{ {
Title = subtitle, var result = new Result
SubTitle = string.Empty,
IcoPath = searchSource.IconPath
};
return new List<Result> {result};
}
else
{
var results = new List<Result>();
var result = new Result
{
Title = title,
SubTitle = subtitle,
Score = 6,
IcoPath = searchSource.IconPath,
Action = c =>
{ {
Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword))); Title = subtitle,
return true; SubTitle = string.Empty,
} IcoPath = searchSource.IconPath
}; };
results.Add(result); results.Add(result);
UpdateResultsFromSuggestion(results, keyword, subtitle, searchSource, query); }
return results; else
{
var result = new Result
{
Title = title,
SubTitle = subtitle,
Score = 6,
IcoPath = searchSource.IconPath,
Action = c =>
{
searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)).NewBrowserWindow("");
return true;
}
};
results.Add(result);
UpdateResultsFromSuggestion(results, keyword, subtitle, searchSource, query);
}
} }
} }
else
{ return results;
return new List<Result>();
}
} }
private void UpdateResultsFromSuggestion(List<Result> results, string keyword, string subtitle, private void UpdateResultsFromSuggestion(List<Result> results, string keyword, string subtitle,
@@ -115,7 +124,7 @@ namespace Wox.Plugin.WebSearch
IcoPath = searchSource.IconPath, IcoPath = searchSource.IconPath,
Action = c => Action = c =>
{ {
Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o))); searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewBrowserWindow("");
return true; return true;
} }
}); });
@@ -160,4 +169,4 @@ namespace Wox.Plugin.WebSearch
public event ResultUpdatedEventHandler ResultsUpdated; public event ResultUpdatedEventHandler ResultsUpdated;
} }
} }

View File

@@ -1,4 +1,4 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using Wox.Core.Plugin; using Wox.Core.Plugin;
@@ -28,27 +28,33 @@ namespace Wox.Plugin.WebSearch
private void OnDeleteSearchSearchClick(object sender, RoutedEventArgs e) private void OnDeleteSearchSearchClick(object sender, RoutedEventArgs e)
{ {
var selected = _settings.SelectedSearchSource; if (_settings.SelectedSearchSource != null)
var warning = _context.API.GetTranslation("wox_plugin_websearch_delete_warning");
var formated = string.Format(warning, selected.Title);
var result = MessageBox.Show(formated, string.Empty, MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{ {
var id = _context.CurrentPluginMetadata.ID; var selected = _settings.SelectedSearchSource;
PluginManager.RemoveActionKeyword(id, selected.ActionKeyword); var warning = _context.API.GetTranslation("wox_plugin_websearch_delete_warning");
_settings.SearchSources.Remove(selected); var formated = string.Format(warning, selected.Title);
var result = MessageBox.Show(formated, string.Empty, MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
var id = _context.CurrentPluginMetadata.ID;
PluginManager.RemoveActionKeyword(id, selected.ActionKeyword);
_settings.SearchSources.Remove(selected);
}
} }
} }
private void OnEditSearchSourceClick(object sender, RoutedEventArgs e) private void OnEditSearchSourceClick(object sender, RoutedEventArgs e)
{ {
var selected = _settings.SelectedSearchSource; if (_settings.SelectedSearchSource != null)
var webSearch = new SearchSourceSettingWindow {
var webSearch = new SearchSourceSettingWindow
( (
_settings.SearchSources, _context, selected _settings.SearchSources, _context, _settings.SelectedSearchSource
); );
webSearch.ShowDialog();
webSearch.ShowDialog();
}
} }
} }
} }

View File

@@ -55,8 +55,17 @@ Contribution
Build Build
----- -----
1. Install Visual Studio 2015 and tick all Windows 10 sdk options Install Visual Studio 2015/2017/2019
2. Open powershell with admin permission and `Set-ExecutionPolicy Unrestricted -Scope CurrentUser`
This project requires Windows 10 SDK:
VS 2015:
- Tick all Windows 10 sdk options
VS 2017/2019 and later:
- Last Windows 10 SDK which [supported](https://github.com/Wox-launcher/Wox/pull/1827#commitcomment-26475392) UwpDesktop is version 10.0.14393.795. It is needed to compile "Programs" Plugin (UWP.cs), you will see the "References" of Plugin.Programs as broken if you use a later SDK version.
- This SDK cannot be installed via VS 2019 installer.
- Download and install [Windows 10 SDK version 10.0.14393.795](https://go.microsoft.com/fwlink/p/?LinkId=838916).
Documentation Documentation
------------- -------------

View File

@@ -106,16 +106,12 @@ namespace Wox.Core.Plugin
foreach (var plugin in AllPlugins) foreach (var plugin in AllPlugins)
{ {
if (IsGlobalPlugin(plugin.Metadata)) if (IsGlobalPlugin(plugin.Metadata))
{
GlobalPlugins.Add(plugin); GlobalPlugins.Add(plugin);
}
else // Plugins may have multiple ActionKeywords, eg. WebSearch
{ plugin.Metadata.ActionKeywords.Where(x => x != Query.GlobalPluginWildcardSign)
foreach (string actionKeyword in plugin.Metadata.ActionKeywords) .ToList()
{ .ForEach(x => NonGlobalPlugins[x] = plugin);
NonGlobalPlugins[actionKeyword] = plugin;
}
}
} }
} }
@@ -289,14 +285,20 @@ namespace Wox.Core.Plugin
public static void RemoveActionKeyword(string id, string oldActionkeyword) public static void RemoveActionKeyword(string id, string oldActionkeyword)
{ {
var plugin = GetPluginForId(id); var plugin = GetPluginForId(id);
if (oldActionkeyword == Query.GlobalPluginWildcardSign) if (oldActionkeyword == Query.GlobalPluginWildcardSign
&& // Plugins may have multiple ActionKeywords that are global, eg. WebSearch
plugin.Metadata.ActionKeywords
.Where(x => x == Query.GlobalPluginWildcardSign)
.ToList()
.Count == 1)
{ {
GlobalPlugins.Remove(plugin); GlobalPlugins.Remove(plugin);
} }
else
{ if(oldActionkeyword != Query.GlobalPluginWildcardSign)
NonGlobalPlugins.Remove(oldActionkeyword); NonGlobalPlugins.Remove(oldActionkeyword);
}
plugin.Metadata.ActionKeywords.Remove(oldActionkeyword); plugin.Metadata.ActionKeywords.Remove(oldActionkeyword);
} }

View File

@@ -0,0 +1 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Base.xaml"></ResourceDictionary> </ResourceDictionary.MergedDictionaries> <Style x:Key="QueryBoxStyle" BasedOn="{StaticResource BaseQueryBoxStyle}" TargetType="{x:Type TextBox}"> <Setter Property="Background" Value="#000000"/> <Setter Property="Foreground" Value="#ffffff" /> </Style> <Style x:Key="WindowBorderStyle" BasedOn="{StaticResource BaseWindowBorderStyle}" TargetType="{x:Type Border}"> <Setter Property="Background" Value="#000000"></Setter> </Style> <Style x:Key="WindowStyle" TargetType="{x:Type Window}" BasedOn="{StaticResource BaseWindowStyle}" > </Style> <Style x:Key="PendingLineStyle" BasedOn="{StaticResource BasePendingLineStyle}" TargetType="{x:Type Line}" > </Style> <Style x:Key="ItemTitleStyle" BasedOn="{StaticResource BaseItemTitleStyle}" TargetType="{x:Type TextBlock}" > <Setter Property="Foreground" Value="#FFFFF8"></Setter> </Style> <Style x:Key="ItemSubTitleStyle" BasedOn="{StaticResource BaseItemSubTitleStyle}" TargetType="{x:Type TextBlock}" > <Setter Property="Foreground" Value="#D9D9D4"></Setter> </Style> <Style x:Key="ItemTitleSelectedStyle" BasedOn="{StaticResource BaseItemTitleSelectedStyle}" TargetType="{x:Type TextBlock}"> <Setter Property="Foreground" Value="#FFFFF8" /> </Style> <Style x:Key="ItemSubTitleSelectedStyle" BasedOn="{StaticResource BaseItemSubTitleSelectedStyle}" TargetType="{x:Type TextBlock}"> <Setter Property="Foreground" Value="#D9D9D4" /> </Style> <SolidColorBrush x:Key="ItemSelectedBackgroundColor">#4F6180</SolidColorBrush> <Style x:Key="ThumbStyle" BasedOn="{StaticResource BaseThumbStyle}" TargetType="{x:Type Thumb}"> </Style> <Style x:Key="ScrollBarStyle" BasedOn="{StaticResource BaseScrollBarStyle}" TargetType="{x:Type ScrollBar}"> </Style> </ResourceDictionary>

View File

@@ -374,6 +374,11 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
<Page Include="Themes\BlackAndWhite.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Page>
<Page Include="Themes\BlurBlack.xaml"> <Page Include="Themes\BlurBlack.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
@@ -462,7 +467,7 @@
<ItemGroup /> <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>powershell.exe -NoProfile -File $(SolutionDir)Scripts\post_build.ps1 $(ConfigurationName) $(SolutionDir)</PostBuildEvent> <PostBuildEvent>powershell.exe -NoProfile -ExecutionPolicy Bypass -File $(SolutionDir)Scripts\post_build.ps1 $(ConfigurationName) $(SolutionDir)</PostBuildEvent>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<PreBuildEvent>taskkill /f /fi "IMAGENAME eq Wox.exe"</PreBuildEvent> <PreBuildEvent>taskkill /f /fi "IMAGENAME eq Wox.exe"</PreBuildEvent>