SearchResControl.xaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. using GeekDesk.Constant;
  2. using GeekDesk.Control.Windows;
  3. using GeekDesk.Plugins.EveryThing;
  4. using GeekDesk.Util;
  5. using GeekDesk.ViewModel;
  6. using GeekDesk.ViewModel.Temp;
  7. using HandyControl.Controls;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Diagnostics;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Data;
  20. using System.Windows.Documents;
  21. using System.Windows.Input;
  22. using System.Windows.Media;
  23. using System.Windows.Media.Imaging;
  24. using System.Windows.Navigation;
  25. namespace GeekDesk.Control.Other
  26. {
  27. /// <summary>
  28. /// SearchResControl.xaml 的交互逻辑
  29. /// </summary>
  30. public partial class SearchResControl : UserControl
  31. {
  32. public SearchResControl(ObservableCollection<IconInfo> iconList)
  33. {
  34. this.DataContext = iconList;
  35. InitializeComponent();
  36. }
  37. public void SearchListBoxIndexAdd()
  38. {
  39. //控制移动后 鼠标即使在图标上也不显示popup
  40. RunTimeStatus.MOUSE_MOVE_COUNT = 0;
  41. MainWindow.mainWindow.RightCard.MyPoptip.IsOpen = false;
  42. if (SearchListBox.Items.Count > 0)
  43. {
  44. if (SearchListBox.SelectedIndex < SearchListBox.Items.Count - 1)
  45. {
  46. SearchListBox.SelectedIndex += 1;
  47. }
  48. }
  49. }
  50. public void SearchListBoxIndexSub()
  51. {
  52. //控制移动后 鼠标即使在图标上也不显示popup
  53. RunTimeStatus.MOUSE_MOVE_COUNT = 0;
  54. MainWindow.mainWindow.RightCard.MyPoptip.IsOpen = false;
  55. if (SearchListBox.Items.Count > 0)
  56. {
  57. if (SearchListBox.SelectedIndex > 0)
  58. {
  59. SearchListBox.SelectedIndex -= 1;
  60. }
  61. }
  62. }
  63. public void StartupSelectionItem()
  64. {
  65. if (SearchListBox.SelectedItem != null)
  66. {
  67. IconInfo icon = SearchListBox.SelectedItem as IconInfo;
  68. if (icon.AdminStartUp)
  69. {
  70. ProcessUtil.StartIconApp(icon, IconStartType.ADMIN_STARTUP);
  71. }
  72. else
  73. {
  74. ProcessUtil.StartIconApp(icon, IconStartType.DEFAULT_STARTUP);
  75. }
  76. }
  77. }
  78. private void SearchListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  79. {
  80. SearchListBox.ScrollIntoView(SearchListBox.SelectedItem);
  81. }
  82. /// <summary>
  83. /// 查询结果ICON鼠标移动事件
  84. /// </summary>
  85. /// <param name="sender"></param>
  86. /// <param name="e"></param>
  87. private void SearchIcon_MouseMove(object sender, MouseEventArgs e)
  88. {
  89. //控制首次刷新搜索结果后, 鼠标首次移动后显示popup
  90. RunTimeStatus.MOUSE_MOVE_COUNT++;
  91. //防止移动后不刷新popup content
  92. IconInfo info = (sender as Panel).Tag as IconInfo;
  93. MainWindow.mainWindow.RightCard.MyPoptipContent.Text = info.Content;
  94. MainWindow.mainWindow.RightCard.MyPoptip.VerticalOffset = 30;
  95. if (RunTimeStatus.MOUSE_MOVE_COUNT > 1 && !RunTimeStatus.ICONLIST_MOUSE_WHEEL)
  96. {
  97. MainWindow.mainWindow.RightCard.MyPoptip.IsOpen = true;
  98. }
  99. }
  100. /// <summary>
  101. /// 查询结果 ICON 鼠标进入事件
  102. /// </summary>
  103. /// <param name="sender"></param>
  104. /// <param name="e"></param>
  105. private void SearchIcon_MouseEnter(object sender, MouseEventArgs e)
  106. {
  107. //显示popup
  108. RunTimeStatus.MOUSE_ENTER_ICON = true;
  109. if (!RunTimeStatus.ICONLIST_MOUSE_WHEEL)
  110. {
  111. new Thread(() =>
  112. {
  113. this.Dispatcher.BeginInvoke(new Action(() =>
  114. {
  115. IconInfo info = (sender as Panel).Tag as IconInfo;
  116. MainWindow.mainWindow.RightCard.MyPoptipContent.Text = info.Content;
  117. MainWindow.mainWindow.RightCard.MyPoptip.VerticalOffset = 30;
  118. Thread.Sleep(100);
  119. if (!RunTimeStatus.ICONLIST_MOUSE_WHEEL && RunTimeStatus.MOUSE_MOVE_COUNT > 1)
  120. {
  121. MainWindow.mainWindow.RightCard.MyPoptip.IsOpen = true;
  122. }
  123. }));
  124. }).Start();
  125. }
  126. }
  127. /// <summary>
  128. /// 查询结果ICON鼠标离开事件
  129. /// </summary>
  130. /// <param name="sender"></param>
  131. /// <param name="e"></param>
  132. private void SearchIcon_MouseLeave(object sender, MouseEventArgs e)
  133. {
  134. RunTimeStatus.MOUSE_ENTER_ICON = false;
  135. MainWindow.mainWindow.RightCard.MyPoptip.IsOpen = false;
  136. }
  137. /// <summary>
  138. /// 搜索结果icon 列表鼠标滚轮预处理时间
  139. /// 主要使用自定义popup解决卡顿问题解决卡顿问题
  140. /// </summary>
  141. /// <param name="sender"></param>
  142. /// <param name="e"></param>
  143. private void VerticalIconList_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
  144. {
  145. //控制在滚动时不显示popup 否则会在低GPU性能机器上造成卡顿
  146. MainWindow.mainWindow.RightCard.MyPoptip.IsOpen = false;
  147. if (RunTimeStatus.ICONLIST_MOUSE_WHEEL)
  148. {
  149. RunTimeStatus.MOUSE_WHEEL_WAIT_MS = 500;
  150. }
  151. else
  152. {
  153. RunTimeStatus.ICONLIST_MOUSE_WHEEL = true;
  154. new Thread(() =>
  155. {
  156. while (RunTimeStatus.MOUSE_WHEEL_WAIT_MS > 0)
  157. {
  158. Thread.Sleep(1);
  159. RunTimeStatus.MOUSE_WHEEL_WAIT_MS -= 1;
  160. }
  161. if (RunTimeStatus.MOUSE_ENTER_ICON)
  162. {
  163. this.Dispatcher.BeginInvoke(new Action(() =>
  164. {
  165. MainWindow.mainWindow.RightCard.MyPoptip.IsOpen = true;
  166. }));
  167. }
  168. RunTimeStatus.MOUSE_WHEEL_WAIT_MS = 100;
  169. RunTimeStatus.ICONLIST_MOUSE_WHEEL = false;
  170. }).Start();
  171. }
  172. }
  173. private void Icon_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  174. {
  175. if (MainWindow.appData.AppConfig.DoubleOpen)
  176. {
  177. IconClick(sender, e);
  178. }
  179. }
  180. private void Icon_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  181. {
  182. if (!MainWindow.appData.AppConfig.DoubleOpen)
  183. {
  184. IconClick(sender, e);
  185. }
  186. }
  187. /// <summary>
  188. /// 图标点击事件
  189. /// </summary>
  190. /// <param name="sender"></param>
  191. /// <param name="e"></param>
  192. private void IconClick(object sender, MouseButtonEventArgs e)
  193. {
  194. if (MainWindow.appData.AppConfig.DoubleOpen && e.ClickCount >= 2)
  195. {
  196. IconInfo icon = (IconInfo)((Panel)sender).Tag;
  197. if (icon.AdminStartUp)
  198. {
  199. ProcessUtil.StartIconApp(icon, IconStartType.ADMIN_STARTUP);
  200. }
  201. else
  202. {
  203. ProcessUtil.StartIconApp(icon, IconStartType.DEFAULT_STARTUP);
  204. }
  205. }
  206. else if (!MainWindow.appData.AppConfig.DoubleOpen && e.ClickCount == 1)
  207. {
  208. IconInfo icon = (IconInfo)((Panel)sender).Tag;
  209. if (icon.AdminStartUp)
  210. {
  211. ProcessUtil.StartIconApp(icon, IconStartType.ADMIN_STARTUP);
  212. }
  213. else
  214. {
  215. ProcessUtil.StartIconApp(icon, IconStartType.DEFAULT_STARTUP);
  216. }
  217. }
  218. }
  219. private static volatile bool EveryThingRuning = false;
  220. private void VerticalCard_ScrollChanged(object sender, ScrollChangedEventArgs e)
  221. {
  222. if (MainWindow.appData.AppConfig.EnableEveryThing == true && EveryThingUtil.HasNext())
  223. {
  224. HandyControl.Controls.ScrollViewer sv = sender as HandyControl.Controls.ScrollViewer;
  225. if (sv.ExtentHeight - (sv.ActualHeight + sv.VerticalOffset) < 100
  226. && EveryThingUtil.HasNext()
  227. && !EveryThingRuning)
  228. {
  229. EveryThingRuning = true;
  230. MainWindow.mainWindow.RightCard.Loading_RightCard.Visibility = Visibility.Visible;
  231. int everyThingCount = Convert.ToInt32(MainWindow.mainWindow.EverythingSearchCount.Text);
  232. ObservableCollection<IconInfo> resList = this.DataContext as ObservableCollection<IconInfo>;
  233. ThreadPool.QueueUserWorkItem(state =>
  234. {
  235. ObservableCollection<IconInfo> searchRes = EveryThingUtil.NextPage();
  236. this.Dispatcher.Invoke(() =>
  237. {
  238. everyThingCount += searchRes.Count;
  239. MainWindow.mainWindow.EverythingSearchCount.Text = Convert.ToString(everyThingCount);
  240. foreach (IconInfo info in searchRes)
  241. {
  242. resList.Add(info);
  243. }
  244. MainWindow.mainWindow.RightCard.Loading_RightCard.Visibility = Visibility.Collapsed;
  245. EveryThingRuning = false;
  246. });
  247. });
  248. }
  249. }
  250. }
  251. /// <summary>
  252. /// 管理员方式启动
  253. /// </summary>
  254. /// <param name="sender"></param>
  255. /// <param name="e"></param>
  256. private void IconAdminStart(object sender, RoutedEventArgs e)
  257. {
  258. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  259. ProcessUtil.StartIconApp(icon, IconStartType.ADMIN_STARTUP);
  260. }
  261. /// <summary>
  262. /// 打开文件所在位置
  263. /// </summary>
  264. /// <param name="sender"></param>
  265. /// <param name="e"></param>
  266. private void ShowInExplore(object sender, RoutedEventArgs e)
  267. {
  268. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  269. ProcessUtil.StartIconApp(icon, IconStartType.SHOW_IN_EXPLORE);
  270. }
  271. private void SystemContextMenu(object sender, RoutedEventArgs e)
  272. {
  273. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  274. DirectoryInfo[] folders = new DirectoryInfo[1];
  275. folders[0] = new DirectoryInfo(icon.Path);
  276. ShellContextMenu scm = new ShellContextMenu();
  277. System.Drawing.Point p = System.Windows.Forms.Cursor.Position;
  278. p.X -= 80;
  279. p.Y -= 80;
  280. scm.ShowContextMenu(folders, p);
  281. }
  282. }
  283. }