mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
Merge branch 'master' into update_websearch_when_suggestions_on
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin.SharedCommands;
|
||||
|
||||
namespace Wox.Plugin.WebSearch
|
||||
{
|
||||
@@ -23,6 +24,8 @@ namespace Wox.Plugin.WebSearch
|
||||
public const string Images = "Images";
|
||||
public static string ImagesDirectory;
|
||||
|
||||
private readonly string SearchSourceGlobalPluginWildCardSign = "*";
|
||||
|
||||
public void Save()
|
||||
{
|
||||
_viewModel.Save();
|
||||
@@ -30,59 +33,65 @@ namespace Wox.Plugin.WebSearch
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
var searchSourceList = new List<SearchSource>();
|
||||
var results = new List<Result>();
|
||||
|
||||
_updateSource?.Cancel();
|
||||
_updateSource = new CancellationTokenSource();
|
||||
_updateToken = _updateSource.Token;
|
||||
|
||||
_settings.SearchSources.Where(o => (o.ActionKeyword == query.ActionKeyword || o.ActionKeyword == SearchSourceGlobalPluginWildCardSign)
|
||||
&& o.Enabled)
|
||||
.ToList()
|
||||
.ForEach(x => searchSourceList.Add(x));
|
||||
|
||||
SearchSource searchSource =
|
||||
_settings.SearchSources.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled);
|
||||
|
||||
if (searchSource != null)
|
||||
if (searchSourceList.Any())
|
||||
{
|
||||
string keyword = query.Search;
|
||||
string title = keyword;
|
||||
string subtitle = _context.API.GetTranslation("wox_plugin_websearch_search") + " " + searchSource.Title;
|
||||
if (string.IsNullOrEmpty(keyword))
|
||||
foreach (SearchSource searchSource in searchSourceList)
|
||||
{
|
||||
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,
|
||||
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 =>
|
||||
var result = new Result
|
||||
{
|
||||
Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
results.Add(result);
|
||||
ResultsUpdated?.Invoke(this, new ResultUpdatedEventArgs
|
||||
Title = subtitle,
|
||||
SubTitle = string.Empty,
|
||||
IcoPath = searchSource.IconPath
|
||||
};
|
||||
results.Add(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Results = results,
|
||||
Query = query
|
||||
});
|
||||
UpdateResultsFromSuggestion(results, keyword, subtitle, searchSource, query);
|
||||
var result = new Result
|
||||
{
|
||||
Title = title,
|
||||
SubTitle = subtitle,
|
||||
Score = 6,
|
||||
IcoPath = searchSource.IconPath,
|
||||
Action = c =>
|
||||
{
|
||||
searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)).NewBrowserWindow("");
|
||||
|
||||
return results;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
results.Add(result);
|
||||
ResultsUpdated?.Invoke(this, new ResultUpdatedEventArgs
|
||||
{
|
||||
Results = results,
|
||||
Query = query
|
||||
});
|
||||
|
||||
UpdateResultsFromSuggestion(results, keyword, subtitle, searchSource, query);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<Result>();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private void UpdateResultsFromSuggestion(List<Result> results, string keyword, string subtitle,
|
||||
@@ -122,7 +131,7 @@ namespace Wox.Plugin.WebSearch
|
||||
IcoPath = searchSource.IconPath,
|
||||
Action = c =>
|
||||
{
|
||||
Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)));
|
||||
searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewBrowserWindow("");
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -167,4 +176,4 @@ namespace Wox.Plugin.WebSearch
|
||||
|
||||
public event ResultUpdatedEventHandler ResultsUpdated;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user