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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace Wox.Plugin.WebSearch
|
||||
|
||||
_searchSources.Add(_searchSource);
|
||||
|
||||
var info = _api.GetTranslation("succeed");
|
||||
var info = _api.GetTranslation("success");
|
||||
MessageBox.Show(info);
|
||||
Close();
|
||||
}
|
||||
@@ -106,7 +106,7 @@ namespace Wox.Plugin.WebSearch
|
||||
var index = _searchSources.IndexOf(_oldSearchSource);
|
||||
_searchSources[index] = _searchSource;
|
||||
|
||||
var info = _api.GetTranslation("succeed");
|
||||
var info = _api.GetTranslation("success");
|
||||
MessageBox.Show(info);
|
||||
Close();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Windows;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Wox.Core.Plugin;
|
||||
|
||||
@@ -28,27 +28,33 @@ namespace Wox.Plugin.WebSearch
|
||||
|
||||
private void OnDeleteSearchSearchClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selected = _settings.SelectedSearchSource;
|
||||
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)
|
||||
if (_settings.SelectedSearchSource != null)
|
||||
{
|
||||
var id = _context.CurrentPluginMetadata.ID;
|
||||
PluginManager.RemoveActionKeyword(id, selected.ActionKeyword);
|
||||
_settings.SearchSources.Remove(selected);
|
||||
var selected = _settings.SelectedSearchSource;
|
||||
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;
|
||||
PluginManager.RemoveActionKeyword(id, selected.ActionKeyword);
|
||||
_settings.SearchSources.Remove(selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEditSearchSourceClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selected = _settings.SelectedSearchSource;
|
||||
var webSearch = new SearchSourceSettingWindow
|
||||
if (_settings.SelectedSearchSource != null)
|
||||
{
|
||||
var webSearch = new SearchSourceSettingWindow
|
||||
(
|
||||
_settings.SearchSources, _context, selected
|
||||
_settings.SearchSources, _context, _settings.SelectedSearchSource
|
||||
);
|
||||
webSearch.ShowDialog();
|
||||
|
||||
webSearch.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user