private void QuerySuggestions(string keyword, Query query, string subtitle, WebSearch webSearch) { ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(WebSearchStorage.Instance.WebSearchSuggestionSource, context); if (sugg != null) { var result = sugg.GetSuggestions(keyword); if (result != null) { context.API.PushResults(query, context.CurrentPluginMetadata, result.Select(o => new Result() { Title = o, SubTitle = subtitle, Score = 5, IcoPath = webSearch.IconPath, Action = (c) => { Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(o))); return(true); } }).ToList()); } } }
private void btnAddWebSearch_OnClick(object sender, RoutedEventArgs e) { var setting = new WebSearchSetting(this, _settings); var webSearch = new WebSearch(); setting.AddItem(webSearch); setting.ShowDialog(); }
public void AddItem(WebSearch websearch) { _webSearch = websearch; if (string.IsNullOrEmpty(_webSearch.IconPath)) { _webSearch.IconPath = DefaultIcon; WebSearchIcon.Source = LoadIcon(_webSearch.IconPath); } }
public List <Result> Query(Query query) { _updateSource?.Cancel(); _updateSource = new CancellationTokenSource(); _updateToken = _updateSource.Token; WebSearch webSearch = _settings.WebSearches.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled); if (webSearch != null) { string keyword = query.Search; string title = keyword; string subtitle = Context.API.GetTranslation("wox_plugin_websearch_search") + " " + webSearch.Title; if (string.IsNullOrEmpty(keyword)) { var result = new Result { Title = subtitle, SubTitle = string.Empty, IcoPath = webSearch.IconPath }; return(new List <Result> { result }); } else { var results = new List <Result>(); var result = new Result { Title = title, SubTitle = subtitle, Score = 6, IcoPath = webSearch.IconPath, Action = c => { Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(keyword))); return(true); } }; results.Add(result); UpdateResultsFromSuggestion(results, keyword, subtitle, webSearch, query); return(results); } } else { return(new List <Result>()); } }
public List <Result> Query(Query query) { List <Result> results = new List <Result>(); if (!query.Search.Contains(' ')) { return(results); } WebSearch webSearch = WebSearchStorage.Instance.WebSearches.FirstOrDefault(o => o.ActionWord == query.FirstSearch.Trim() && o.Enabled); if (webSearch != null) { string keyword = query.SecondToEndSearch; string title = keyword; string subtitle = context.API.GetTranslation("wox_plugin_websearch_search") + " " + webSearch.Title; if (string.IsNullOrEmpty(keyword)) { title = subtitle; subtitle = null; } context.API.PushResults(query, context.CurrentPluginMetadata, new List <Result>() { new Result() { Title = title, SubTitle = subtitle, Score = 6, IcoPath = webSearch.IconPath, Action = (c) => { Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(keyword))); return(true); } } }); if (WebSearchStorage.Instance.EnableWebSearchSuggestion && !string.IsNullOrEmpty(keyword)) { if (suggestionTimer != null) { suggestionTimer.Dispose(); } suggestionTimer = EasyTimer.SetTimeout(() => { QuerySuggestions(keyword, query, subtitle, webSearch); }, 350); } } return(results); }
private void btnEditWebSearch_OnClick(object sender, RoutedEventArgs e) { WebSearch selectedWebSearch = webSearchView.SelectedItem as WebSearch; if (selectedWebSearch != null) { WebSearchSetting webSearch = new WebSearchSetting(this, context); webSearch.UpdateItem(selectedWebSearch); webSearch.ShowDialog(); } else { string warning = context.API.GetTranslation("wox_plugin_websearch_pls_select_web_search"); MessageBox.Show(warning); } }
public void UpdateItem(WebSearch webSearch) { _webSearch = _settings.WebSearches.FirstOrDefault(o => o == webSearch); if (_webSearch == null || string.IsNullOrEmpty(_webSearch.Url)) { string warning = _context.API.GetTranslation("wox_plugin_websearch_invalid_web_search"); MessageBox.Show(warning); Close(); return; } _isUpdate = true; ConfirmButton.Content = "Update"; WebSearchIcon.Source = ImageLoader.Load(webSearch.IconPath); EnableCheckBox.IsChecked = webSearch.Enabled; WebSearchName.Text = webSearch.Title; Url.Text = webSearch.Url; Actionword.Text = webSearch.ActionKeyword; }
private void btnDeleteWebSearch_OnClick(object sender, RoutedEventArgs e) { WebSearch selectedWebSearch = webSearchView.SelectedItem as WebSearch; if (selectedWebSearch != null) { string msg = string.Format(context.API.GetTranslation("wox_plugin_websearch_delete_warning"), selectedWebSearch.Title); if (MessageBox.Show(msg, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes) { WebSearchStorage.Instance.WebSearches.Remove(selectedWebSearch); webSearchView.Items.Refresh(); } } else { string warning = context.API.GetTranslation("wox_plugin_websearch_pls_select_web_search"); MessageBox.Show(warning); } }
public void UpdateItem(WebSearch webSearch) { _updateWebSearch = WebSearchStorage.Instance.WebSearches.FirstOrDefault(o => o == webSearch); if (_updateWebSearch == null || string.IsNullOrEmpty(_updateWebSearch.Url)) { string warning = _context.API.GetTranslation("wox_plugin_websearch_invalid_web_search"); MessageBox.Show(warning); Close(); return; } _isUpdate = true; lblAdd.Text = "Update"; tbIconPath.Text = webSearch.IconPath; ShowIcon(webSearch.IconPath); cbEnable.IsChecked = webSearch.Enabled; tbTitle.Text = webSearch.Title; tbUrl.Text = webSearch.Url; tbActionword.Text = webSearch.ActionKeyword; }
public void UpdateItem(WebSearch webSearch) { updateWebSearch = WebSearchStorage.Instance.WebSearches.FirstOrDefault(o => o == webSearch); if (updateWebSearch == null || string.IsNullOrEmpty(updateWebSearch.Url)) { string warning = context.API.GetTranslation("wox_plugin_websearch_invalid_web_search"); MessageBox.Show(warning); Close(); return; } update = true; lblAdd.Text = "Update"; tbIconPath.Text = webSearch.IconPath; ShowIcon(webSearch.IconPath); cbEnable.IsChecked = webSearch.Enabled; tbTitle.Text = webSearch.Title; tbUrl.Text = webSearch.Url; tbActionword.Text = webSearch.ActionKeyword; }
public List <WebSearch> LoadDefaultWebSearches() { List <WebSearch> webSearches = new List <WebSearch>(); WebSearch googleWebSearch = new WebSearch() { Title = "Google", ActionKeyword = "g", IconPath = @"Images\google.png", Url = "https://www.google.com/search?q={q}", Enabled = true }; webSearches.Add(googleWebSearch); WebSearch wikiWebSearch = new WebSearch() { Title = "Wikipedia", ActionKeyword = "wiki", IconPath = @"Images\wiki.png", Url = "http://en.wikipedia.org/wiki/{q}", Enabled = true }; webSearches.Add(wikiWebSearch); WebSearch findIcon = new WebSearch() { Title = "FindIcon", ActionKeyword = "findicon", IconPath = @"Images\pictures.png", Url = "http://findicons.com/search/{q}", Enabled = true }; webSearches.Add(findIcon); return(webSearches); }
private IEnumerable<Result> ResultsFromSuggestions(string keyword, string subtitle, WebSearch webSearch) { ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(WebSearchStorage.Instance.WebSearchSuggestionSource, Context); var suggestions = sugg?.GetSuggestions(keyword); if (suggestions != null) { var resultsFromSuggestion = suggestions.Select(o => new Result { Title = o, SubTitle = subtitle, Score = 5, IcoPath = webSearch.IconPath, Action = c => { Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(o))); return true; } }); return resultsFromSuggestion; } return new List<Result>(); }
public List <Result> Query(Query query) { List <Result> results = new List <Result>(); WebSearch webSearch = _settings.WebSearches.FirstOrDefault(o => o.ActionKeyword == query.ActionKeyword && o.Enabled); if (webSearch != null) { string keyword = query.Search; string title = keyword; string subtitle = Context.API.GetTranslation("wox_plugin_websearch_search") + " " + webSearch.Title; if (string.IsNullOrEmpty(keyword)) { title = subtitle; subtitle = string.Empty; } var result = new Result { Title = title, SubTitle = subtitle, Score = 6, IcoPath = webSearch.IconPath, Action = c => { Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(keyword ?? string.Empty))); return(true); } }; results.Add(result); if (_settings.EnableWebSearchSuggestion && !string.IsNullOrEmpty(keyword)) { // todo use Task.Wait when .net upgraded results.AddRange(ResultsFromSuggestions(keyword, subtitle, webSearch)); } } return(results); }
private void QuerySuggestions(string keyword, Query query, string subtitle, WebSearch webSearch) { ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(WebSearchStorage.Instance.WebSearchSuggestionSource, context); if (sugg != null) { var result = sugg.GetSuggestions(keyword); if (result != null) { context.API.PushResults(query, context.CurrentPluginMetadata, result.Select(o => new Result() { Title = o, SubTitle = subtitle, Score = 5, IcoPath = webSearch.IconPath, Action = (c) => { Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(o))); return true; } }).ToList()); } } }
public void AddItem(WebSearch webSearch) { _webSearch = webSearch; WebSearchIcon.Source = ImageLoader.Load(webSearch.IconPath); }
private void UpdateResultsFromSuggestion(List <Result> results, string keyword, string subtitle, WebSearch webSearch, Query query) { if (_settings.EnableWebSearchSuggestion) { const int waittime = 300; var task = Task.Run(async() => { var suggestions = await Suggestions(keyword, subtitle, webSearch); results.AddRange(suggestions); }, _updateToken); if (!task.Wait(waittime)) { task.ContinueWith(_ => ResultsUpdated?.Invoke(this, new ResultUpdatedEventArgs { Results = results, Query = query }), _updateToken); } } }
private IEnumerable <Result> ResultsFromSuggestions(string keyword, string subtitle, WebSearch webSearch) { ISuggestionSource sugg = SuggestionSourceFactory.GetSuggestionSource(_settings.WebSearchSuggestionSource, Context); var suggestions = sugg?.GetSuggestions(keyword); if (suggestions != null) { var resultsFromSuggestion = suggestions.Select(o => new Result { Title = o, SubTitle = subtitle, Score = 5, IcoPath = webSearch.IconPath, Action = c => { Process.Start(webSearch.Url.Replace("{q}", Uri.EscapeDataString(o))); return(true); } }); return(resultsFromSuggestion); } return(new List <Result>()); }