/// <summary> /// Handles the Click event of the searchButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void SearchButtonClick(object sender = null, RoutedEventArgs e = null) { if (string.IsNullOrWhiteSpace(textBox.Text)) { return; } if (_searching) { ActiveSearch.CancelAsync(); DownloadSearchDone(); return; } _results = new ConcurrentBag <LinkItem>(); DownloadLinksListViewItemCollection.Clear(); textBox.IsEnabled = false; searchButton.Content = "Cancel"; ActiveSearch = new DownloadSearch(AutoDownloader.ActiveSearchEngines, filterResults.IsChecked); ActiveSearch.DownloadSearchDone += DownloadSearchDone; ActiveSearch.DownloadSearchEngineNewLink += DownloadSearchEngineNewLink; ActiveSearch.DownloadSearchEngineDone += DownloadSearchEngineDone; ActiveSearch.DownloadSearchEngineError += DownloadSearchEngineError; SetStatus("Searching for download links on " + (string.Join(", ", ActiveSearch.SearchEngines.Select(engine => engine.Name).ToArray())) + "...", true); _searching = true; ActiveSearch.SearchAsync(textBox.Text); Utils.Win7Taskbar(0, TaskbarProgressBarState.Normal); }
/// <summary> /// Initiates a search on this usercontrol. /// </summary> /// <param name="query">The query.</param> public void Search(string query) { Dispatcher.Invoke((Action)(() => { // cancel if one is running if (_searching) { ActiveSearch.CancelAsync(); DownloadSearchDone(); } textBox.Text = query; SearchButtonClick(); })); }