private void PART_EditableTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) { //try //{ txtSearch.Items.Clear(); ShowUsedItems(); txtSearch.IsDropDownOpen = true; string word = (sender as TextBox).Text; if (word == "搜索") { (sender as TextBox).Foreground = new SolidColorBrush(Color.FromRgb(0xAA, 0xAA, 0xAA)); } else { (sender as TextBox).Foreground = new SolidColorBrush(Colors.Black); } //auto hint when site support if (SiteManager.Instance.Sites[MainWindow.comboBoxIndex].IsSupportTag) { if (word.Trim().Length == 0 || word == "搜索") return; if (currentSession != null) currentSession.IsStop = true; if (path.Visibility != System.Windows.Visibility.Visible) { path.Visibility = System.Windows.Visibility.Visible; sb.Stop(); sb.Begin(); } currentSession = new SessionState(); (new System.Threading.Thread(new System.Threading.ParameterizedThreadStart((o) => { try { string[] parts = word.Split(' '); if (parts != null && parts.Length > 0) { //last word word = parts[parts.Length - 1]; } word = Uri.EscapeDataString(word); List<TagItem> tagList = SiteManager.Instance.Sites[MainWindow.comboBoxIndex].GetTags(word, MainWindow.WebProxy); if (!(o as SessionState).IsStop) { Dispatcher.Invoke(new UIdelegate((tagl) => { txtSearch.Items.Clear(); List<TagItem> tags = tagl as List<TagItem>; foreach (TagItem node in tags) { txtSearch.Items.Add(new SearchItem() { Name = node.Name, Count = node.Count }); } ShowUsedItems(); }), tagList); } } catch (Exception) { } finally { if (!(o as SessionState).IsStop) { Dispatcher.Invoke(new VoidDel(delegate() { path.Visibility = System.Windows.Visibility.Hidden; sb.Stop(); })); } } }))).Start(currentSession); } }
/// <summary> /// 获取 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click(object sender, RoutedEventArgs e) { if (!isGetting) { if (!naviMoved) { System.Windows.Media.Animation.Storyboard sbNavi = FindResource("sbNavi") as System.Windows.Media.Animation.Storyboard; sbNavi.Begin(); naviMoved = true; } txtGet.Text = "停止"; btnGet.ToolTip = "停止获取"; isGetting = true; imgGet.Source = new BitmapImage(new Uri("/Images/stop.png", UriKind.Relative)); btnNext.IsEnabled = false; btnPrev.IsEnabled = false; if (sender != null) { //记录上一次选择,用于当缩略图尚未加载就停止时恢复 lastSelectIndex = nowSelectedIndex; lastPage = realPage; //由点击获取按钮触发,所以使用界面上的设定 realNum = num; realPage = page; nowSelectedIndex = comboBoxIndex; siteText.Text = "当前站点 " + SiteManager.Instance.Sites[nowSelectedIndex].ShortName; } //btnNext.Content = "下一页 (" + (realPage + 1) + ")"; //btnPrev.Content = "上一页 (" + (realPage - 1) + ")"; pageText.Text = "当前页码 " + realPage; bgLoading.Visibility = System.Windows.Visibility.Visible; logo.Begin(); //nowSelectedIndex = comboBoxIndex; statusText.Text = "与服务器通信,请稍候..."; System.Windows.Media.Animation.Storyboard sb = FindResource("sbShowPageBtn") as System.Windows.Media.Animation.Storyboard; sb.Stop(); btnPrev.Opacity = 0; btnNext.Opacity = 0; if (searchControl.Text.Length != 0) { //一次最近搜索词 searchControl.AddUsedItem(searchControl.Text); } showExplicit = !itmxExplicit.IsChecked; string word = searchControl.Text; //string url = PrepareUrl(realPage); //nowSession = new ImgSrcProcessor(MaskInt, MaskRes, url, SrcType, LastViewed, MaskViewed); //nowSession.processComplete += new EventHandler(ProcessHTML_processComplete); //(new System.Threading.Thread(new System.Threading.ThreadStart(nowSession.ProcessSingleLink))).Start(); currentSession = new SessionState(); (new System.Threading.Thread(new System.Threading.ParameterizedThreadStart((o) => { List<Img> imgList = null; try { //prefetch string pageString = PreFetcher.Fetcher.GetPreFetchedPage(realPage, realNum, Uri.EscapeDataString(word), SiteManager.Instance.Sites[nowSelectedIndex]); if (pageString != null) { imgList = SiteManager.Instance.Sites[nowSelectedIndex].GetImages(pageString, WebProxy); } else imgList = SiteManager.Instance.Sites[nowSelectedIndex].GetImages(realPage, realNum, Uri.EscapeDataString(word), WebProxy); imgList = SiteManager.Instance.Sites[nowSelectedIndex].FilterImg(imgList, MaskInt, MaskRes, LastViewed, MaskViewed, showExplicit, true); } catch (Exception ex) { if (!(o as SessionState).IsStop) { Dispatcher.Invoke(new VoidDel(() => { MessageBox.Show(this, "获取图片遇到错误: " + ex.Message, "Moe Loader", MessageBoxButton.OK, MessageBoxImage.Warning); })); } } if (!(o as SessionState).IsStop) { Dispatcher.Invoke(new UIdelegate(LoadComplete), imgList); } }))).Start(currentSession); System.GC.Collect(); } else { if (statusText.Text == IMGLOADING) { for (int i = 0; i < imgs.Count; i++) { if (!loaded.Contains(i)) ((ImgControl)imgPanel.Children[i]).StopLoadImg(); } unloaded.Clear(); } else { currentSession.IsStop = true; statusText.Text = "加载完毕,取得 0 张图片"; //恢复站点选择 nowSelectedIndex = lastSelectIndex; siteText.Text = "当前站点 " + SiteManager.Instance.Sites[nowSelectedIndex].ShortName; realPage = lastPage; UpdatePreNextEnable(); System.Windows.Media.Animation.Storyboard sb = FindResource("sbShowPageBtn") as System.Windows.Media.Animation.Storyboard; sb.Begin(); txtGet.Text = "获取"; btnGet.ToolTip = "获取图片列表"; isGetting = false; imgGet.Source = new BitmapImage(new Uri("/Images/search.png", UriKind.Relative)); logo.Stop(); bgLoading.Visibility = System.Windows.Visibility.Hidden; } } }