1
0

RightCardControl.xaml.cs 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  1. using DraggAnimatedPanelExample;
  2. using GeekDesk.Constant;
  3. using GeekDesk.Control.Other;
  4. using GeekDesk.Control.Windows;
  5. using GeekDesk.Plugins.EveryThing;
  6. using GeekDesk.Util;
  7. using GeekDesk.ViewModel;
  8. using GeekDesk.ViewModel.Temp;
  9. using HandyControl.Controls;
  10. using System;
  11. using System.Collections.ObjectModel;
  12. using System.Diagnostics;
  13. using System.IO;
  14. using System.Reflection;
  15. using System.Threading;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. using System.Windows.Input;
  19. using System.Windows.Media;
  20. using System.Windows.Media.Animation;
  21. using System.Windows.Threading;
  22. namespace GeekDesk.Control.UserControls.PannelCard
  23. {
  24. /// <summary>
  25. /// RightCardControl.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class RightCardControl : UserControl
  28. {
  29. private AppData appData = MainWindow.appData;
  30. ListBoxDragDropManager<IconInfo> dragMgr;
  31. //private Thread dropCheckThread = null;
  32. public RightCardControl()
  33. {
  34. InitializeComponent();
  35. this.Loaded += RightCardControl_Loaded;
  36. }
  37. private void RightCardControl_Loaded(object sender, RoutedEventArgs e)
  38. {
  39. this.dragMgr = new ListBoxDragDropManager<IconInfo>(this.IconListBox);
  40. }
  41. //#region 图标拖动
  42. //DelegateCommand<int[]> _swap;
  43. //public DelegateCommand<int[]> SwapCommand
  44. //{
  45. // get
  46. // {
  47. // if (_swap == null)
  48. // _swap = new DelegateCommand<int[]>(
  49. // (indexes) =>
  50. // {
  51. // DROP_ICON = true;
  52. // if (appData.AppConfig.IconSortType != SortType.CUSTOM
  53. // && (dropCheckThread == null || !dropCheckThread.IsAlive))
  54. // {
  55. // dropCheckThread = new Thread(() =>
  56. // {
  57. // do
  58. // {
  59. // DROP_ICON = false;
  60. // Thread.Sleep(1000);
  61. // } while (DROP_ICON);
  62. // MainWindow.appData.AppConfig.IconSortType = SortType.CUSTOM;
  63. // App.Current.Dispatcher.Invoke(() =>
  64. // {
  65. // if (MainWindow.mainWindow.Visibility == Visibility.Collapsed
  66. // || MainWindow.mainWindow.Opacity != 1)
  67. // {
  68. // Growl.WarningGlobal("已将图标排序规则重置为自定义!");
  69. // }
  70. // else
  71. // {
  72. // Growl.Warning("已将图标排序规则重置为自定义!", "MainWindowGrowl");
  73. // }
  74. // });
  75. // });
  76. // dropCheckThread.Start();
  77. // }
  78. // int fromS = indexes[0];
  79. // int to = indexes[1];
  80. // ObservableCollection<IconInfo> iconList = appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList;
  81. // var elementSource = iconList[to];
  82. // var dragged = iconList[fromS];
  83. // iconList.Remove(dragged);
  84. // iconList.Insert(to, dragged);
  85. // }
  86. // );
  87. // return _swap;
  88. // }
  89. //}
  90. //#endregion 图标拖动
  91. private void Icon_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  92. {
  93. if (appData.AppConfig.DoubleOpen)
  94. {
  95. IconClick(sender, e);
  96. }
  97. }
  98. private void Icon_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  99. {
  100. if (!appData.AppConfig.DoubleOpen)
  101. {
  102. IconClick(sender, e);
  103. }
  104. }
  105. /// <summary>
  106. /// 图标点击事件
  107. /// </summary>
  108. /// <param name="sender"></param>
  109. /// <param name="e"></param>
  110. private void IconClick(object sender, MouseButtonEventArgs e)
  111. {
  112. if (appData.AppConfig.DoubleOpen && e.ClickCount >= 2)
  113. {
  114. IconInfo icon = (IconInfo)((Panel)sender).Tag;
  115. if (icon.AdminStartUp)
  116. {
  117. StartIconApp(icon, IconStartType.ADMIN_STARTUP);
  118. }
  119. else
  120. {
  121. StartIconApp(icon, IconStartType.DEFAULT_STARTUP);
  122. }
  123. }
  124. else if (!appData.AppConfig.DoubleOpen && e.ClickCount == 1)
  125. {
  126. IconInfo icon = (IconInfo)((Panel)sender).Tag;
  127. if (icon.AdminStartUp)
  128. {
  129. StartIconApp(icon, IconStartType.ADMIN_STARTUP);
  130. }
  131. else
  132. {
  133. StartIconApp(icon, IconStartType.DEFAULT_STARTUP);
  134. }
  135. }
  136. }
  137. /// <summary>
  138. /// 管理员方式启动
  139. /// </summary>
  140. /// <param name="sender"></param>
  141. /// <param name="e"></param>
  142. private void IconAdminStart(object sender, RoutedEventArgs e)
  143. {
  144. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  145. StartIconApp(icon, IconStartType.ADMIN_STARTUP);
  146. }
  147. /// <summary>
  148. /// 打开文件所在位置
  149. /// </summary>
  150. /// <param name="sender"></param>
  151. /// <param name="e"></param>
  152. private void ShowInExplore(object sender, RoutedEventArgs e)
  153. {
  154. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  155. StartIconApp(icon, IconStartType.SHOW_IN_EXPLORE);
  156. }
  157. private void StartIconApp(IconInfo icon, IconStartType type, bool useRelativePath = false)
  158. {
  159. try
  160. {
  161. using (Process p = new Process())
  162. {
  163. string startArg = icon.StartArg;
  164. if (startArg != null && Constants.SYSTEM_ICONS.ContainsKey(startArg))
  165. {
  166. StartSystemApp(startArg, type);
  167. }
  168. else
  169. {
  170. string path;
  171. if (useRelativePath)
  172. {
  173. string fullPath = Path.Combine(Constants.APP_DIR, icon.RelativePath);
  174. path = Path.GetFullPath(fullPath);
  175. }
  176. else
  177. {
  178. path = icon.Path;
  179. }
  180. p.StartInfo.FileName = path;
  181. if (!StringUtil.IsEmpty(startArg))
  182. {
  183. p.StartInfo.Arguments = startArg;
  184. }
  185. if (icon.IconType == IconType.OTHER)
  186. {
  187. if (!File.Exists(path) && !Directory.Exists(path))
  188. {
  189. //如果没有使用相对路径 那么使用相对路径启动一次
  190. if (!useRelativePath)
  191. {
  192. StartIconApp(icon, type, true);
  193. return;
  194. }
  195. else
  196. {
  197. HandyControl.Controls.Growl.WarningGlobal("程序启动失败(文件路径不存在或已删除)!");
  198. return;
  199. }
  200. }
  201. p.StartInfo.WorkingDirectory = path.Substring(0, path.LastIndexOf("\\"));
  202. switch (type)
  203. {
  204. case IconStartType.ADMIN_STARTUP:
  205. //p.StartInfo.Arguments = "1";//启动参数
  206. p.StartInfo.Verb = "runas";
  207. //p.StartInfo.CreateNoWindow = false; //设置显示窗口
  208. p.StartInfo.UseShellExecute = true;//不使用操作系统外壳程序启动进程
  209. //p.StartInfo.ErrorDialog = false;
  210. if (appData.AppConfig.AppHideType == AppHideType.START_EXE && !RunTimeStatus.LOCK_APP_PANEL)
  211. {
  212. //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
  213. if (appData.AppConfig.MarginHide)
  214. {
  215. if (!MarginHide.IsMargin())
  216. {
  217. MainWindow.HideApp();
  218. }
  219. }
  220. else
  221. {
  222. MainWindow.HideApp();
  223. }
  224. }
  225. break;// c#好像不能case穿透
  226. case IconStartType.DEFAULT_STARTUP:
  227. if (appData.AppConfig.AppHideType == AppHideType.START_EXE && !RunTimeStatus.LOCK_APP_PANEL)
  228. {
  229. //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
  230. if (appData.AppConfig.MarginHide)
  231. {
  232. if (!MarginHide.IsMargin())
  233. {
  234. MainWindow.HideApp();
  235. }
  236. }
  237. else
  238. {
  239. MainWindow.HideApp();
  240. }
  241. }
  242. break;
  243. case IconStartType.SHOW_IN_EXPLORE:
  244. p.StartInfo.FileName = "Explorer.exe";
  245. p.StartInfo.Arguments = "/e,/select," + icon.Path;
  246. break;
  247. }
  248. }
  249. else
  250. {
  251. if (appData.AppConfig.AppHideType == AppHideType.START_EXE && !RunTimeStatus.LOCK_APP_PANEL)
  252. {
  253. //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
  254. if (appData.AppConfig.MarginHide)
  255. {
  256. if (!MarginHide.IS_HIDE)
  257. {
  258. MainWindow.HideApp();
  259. }
  260. }
  261. else
  262. {
  263. MainWindow.HideApp();
  264. }
  265. }
  266. }
  267. p.Start();
  268. if (useRelativePath)
  269. {
  270. //如果使用相对路径启动成功 那么重新设置程序绝对路径
  271. icon.Path = path;
  272. }
  273. }
  274. }
  275. icon.Count++;
  276. //隐藏搜索框
  277. if (RunTimeStatus.SEARCH_BOX_SHOW)
  278. {
  279. MainWindow.mainWindow.HidedSearchBox();
  280. }
  281. }
  282. catch (Exception e)
  283. {
  284. if (!useRelativePath)
  285. {
  286. StartIconApp(icon, type, true);
  287. }
  288. else
  289. {
  290. HandyControl.Controls.Growl.WarningGlobal("程序启动失败(可能为不支持的启动方式)!");
  291. LogUtil.WriteErrorLog(e, "程序启动失败:path=" + icon.Path + ",type=" + type);
  292. }
  293. }
  294. }
  295. private void StartSystemApp(string startArg, IconStartType type)
  296. {
  297. if (type == IconStartType.SHOW_IN_EXPLORE)
  298. {
  299. Growl.WarningGlobal("系统项目不支持打开文件位置操作!");
  300. return;
  301. }
  302. switch (startArg)
  303. {
  304. case "Calculator":
  305. Process.Start("calc.exe");
  306. break;
  307. case "Computer":
  308. Process.Start("explorer.exe");
  309. break;
  310. case "GroupPolicy":
  311. Process.Start("gpedit.msc");
  312. break;
  313. case "Notepad":
  314. Process.Start("notepad");
  315. break;
  316. case "Network":
  317. Process.Start("ncpa.cpl");
  318. break;
  319. case "RecycleBin":
  320. Process.Start("shell:RecycleBinFolder");
  321. break;
  322. case "Registry":
  323. Process.Start("regedit.exe");
  324. break;
  325. case "Mstsc":
  326. if (type == IconStartType.ADMIN_STARTUP)
  327. {
  328. Process.Start("mstsc", "-admin");
  329. }
  330. else
  331. {
  332. Process.Start("mstsc");
  333. }
  334. break;
  335. case "Control":
  336. Process.Start("Control");
  337. break;
  338. case "CMD":
  339. if (type == IconStartType.ADMIN_STARTUP)
  340. {
  341. using (Process process = new Process())
  342. {
  343. process.StartInfo.FileName = "cmd.exe";
  344. process.StartInfo.Verb = "runas";
  345. process.Start();
  346. }
  347. }
  348. else
  349. {
  350. Process.Start("cmd");
  351. }
  352. break;
  353. case "Services":
  354. Process.Start("services.msc");
  355. break;
  356. }
  357. //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
  358. if (appData.AppConfig.MarginHide)
  359. {
  360. if (!MarginHide.IS_HIDE)
  361. {
  362. MainWindow.HideApp();
  363. }
  364. }
  365. else
  366. {
  367. MainWindow.HideApp();
  368. }
  369. }
  370. /// <summary>
  371. /// 拖动添加项目
  372. /// </summary>
  373. /// <param name="sender"></param>
  374. /// <param name="e"></param>
  375. private void Wrap_Drop(object sender, DragEventArgs e)
  376. {
  377. Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop);
  378. if (dropObject == null) return;
  379. foreach (object obj in dropObject)
  380. {
  381. string path = (string)obj;
  382. IconInfo iconInfo = CommonCode.GetIconInfoByPath(path);
  383. MainWindow.appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Add(iconInfo);
  384. }
  385. CommonCode.SortIconList();
  386. CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
  387. }
  388. /// <summary>
  389. /// 从列表删除图标
  390. /// </summary>
  391. /// <param name="sender"></param>
  392. /// <param name="e"></param>
  393. private void RemoveIcon(object sender, RoutedEventArgs e)
  394. {
  395. appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Remove((IconInfo)((MenuItem)sender).Tag);
  396. }
  397. private void SystemContextMenu(object sender, RoutedEventArgs e)
  398. {
  399. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  400. DirectoryInfo[] folders = new DirectoryInfo[1];
  401. folders[0] = new DirectoryInfo(icon.Path);
  402. ShellContextMenu scm = new ShellContextMenu();
  403. System.Drawing.Point p = System.Windows.Forms.Cursor.Position;
  404. p.X -= 80;
  405. p.Y -= 80;
  406. scm.ShowContextMenu(folders, p);
  407. }
  408. /// <summary>
  409. /// 弹出Icon属性修改面板
  410. /// </summary>
  411. /// <param name="sender"></param>
  412. /// <param name="e"></param>
  413. private void PropertyConfig(object sender, RoutedEventArgs e)
  414. {
  415. IconInfo info = (IconInfo)((MenuItem)sender).Tag;
  416. switch (info.IconType)
  417. {
  418. case IconType.URL:
  419. IconInfoUrlDialog urlDialog = new IconInfoUrlDialog(info);
  420. urlDialog.dialog = HandyControl.Controls.Dialog.Show(urlDialog, "MainWindowDialog");
  421. break;
  422. default:
  423. IconInfoDialog dialog = new IconInfoDialog(info);
  424. dialog.dialog = HandyControl.Controls.Dialog.Show(dialog, "MainWindowDialog");
  425. break;
  426. }
  427. }
  428. private void MenuIcon_MouseEnter(object sender, MouseEventArgs e)
  429. {
  430. RunTimeStatus.MOUSE_ENTER_ICON = true;
  431. if (!RunTimeStatus.ICONLIST_MOUSE_WHEEL)
  432. {
  433. ThreadPool.QueueUserWorkItem(state =>
  434. {
  435. this.Dispatcher.BeginInvoke(new Action(() =>
  436. {
  437. IconInfo info = (sender as Panel).Tag as IconInfo;
  438. MyPoptipContent.Text = info.Content;
  439. MyPoptip.VerticalOffset = 30;
  440. Thread.Sleep(50);
  441. if (!RunTimeStatus.ICONLIST_MOUSE_WHEEL)
  442. {
  443. MyPoptip.IsOpen = true;
  444. }
  445. }));
  446. });
  447. }
  448. double width = appData.AppConfig.ImageWidth;
  449. double height = appData.AppConfig.ImageHeight;
  450. width += width * 0.15;
  451. height += height * 0.15;
  452. ThreadPool.QueueUserWorkItem(state =>
  453. {
  454. this.Dispatcher.BeginInvoke(new Action(() =>
  455. {
  456. ImgStoryBoard(sender, (int)width, (int)height, 1, true);
  457. }));
  458. });
  459. }
  460. private void MenuIcon_MouseLeave(object sender, MouseEventArgs e)
  461. {
  462. RunTimeStatus.MOUSE_ENTER_ICON = false;
  463. MyPoptip.IsOpen = false;
  464. ThreadPool.QueueUserWorkItem(state =>
  465. {
  466. this.Dispatcher.BeginInvoke(new Action(() =>
  467. {
  468. ImgStoryBoard(sender, appData.AppConfig.ImageWidth, appData.AppConfig.ImageHeight, 260);
  469. }));
  470. });
  471. }
  472. private void ImgStoryBoard(object sender, int height, int width, int milliseconds, bool checkRmStoryboard = false)
  473. {
  474. if (appData.AppConfig.PMModel) return;
  475. //int count = 0;
  476. //Panel sp = sender as Panel;
  477. //Image img = sp.Children[0] as Image;
  478. //int nowH = (int)img.Height;
  479. //bool isSmall = nowH > height;
  480. //if (!isSmall)
  481. //{
  482. // img.Height = height;
  483. // img.Width = width;
  484. // return;
  485. //}
  486. //double subLen = (double)Math.Abs(nowH - height) / (double)milliseconds;
  487. //new Thread(() =>
  488. //{
  489. // this.Dispatcher.Invoke(() =>
  490. // {
  491. // while (count < milliseconds)
  492. // {
  493. // if (!isSmall)
  494. // {
  495. // img.Height += subLen;
  496. // img.Width += subLen;
  497. // } else
  498. // {
  499. // //if (img.Height > 1)
  500. // //{
  501. // // img.Height -= 1;
  502. // // img.Width -= 1;
  503. // //}
  504. // Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,
  505. // new Action(delegate {
  506. // img.Height -= subLen;
  507. // img.Width -= subLen;
  508. // }));
  509. // //img.Height -= subLen;
  510. // //img.Width -= subLen;
  511. // }
  512. // count++;
  513. // Thread.Sleep(1);
  514. // }
  515. // img.Height = height;
  516. // img.Width = width;
  517. // });
  518. //}).Start();
  519. Panel sp = sender as Panel;
  520. DependencyObject dos = sp.Parent;
  521. Image img = sp.Children[0] as Image;
  522. double afterHeight = img.Height;
  523. double afterWidth = img.Width;
  524. //动画定义
  525. Storyboard myStoryboard = new Storyboard();
  526. DoubleAnimation heightAnimation = new DoubleAnimation
  527. {
  528. From = afterHeight,
  529. To = height,
  530. Duration = new Duration(TimeSpan.FromMilliseconds(milliseconds))
  531. };
  532. DoubleAnimation widthAnimation = new DoubleAnimation
  533. {
  534. From = afterWidth,
  535. To = width,
  536. Duration = new Duration(TimeSpan.FromMilliseconds(milliseconds))
  537. };
  538. Timeline.SetDesiredFrameRate(heightAnimation, 60);
  539. Timeline.SetDesiredFrameRate(widthAnimation, 60);
  540. Storyboard.SetTarget(widthAnimation, img);
  541. Storyboard.SetTargetProperty(widthAnimation, new PropertyPath("Width"));
  542. Storyboard.SetTarget(heightAnimation, img);
  543. Storyboard.SetTargetProperty(heightAnimation, new PropertyPath("Height"));
  544. myStoryboard.Children.Add(heightAnimation);
  545. myStoryboard.Children.Add(widthAnimation);
  546. CheckRemoveStoryboard crs = new CheckRemoveStoryboard
  547. {
  548. sb = myStoryboard,
  549. sp = sp,
  550. heightAnimation = heightAnimation,
  551. widthAnimation = widthAnimation,
  552. img = img,
  553. isMouseOver = !checkRmStoryboard
  554. };
  555. heightAnimation.Completed += (s, e) =>
  556. {
  557. if (checkRmStoryboard)
  558. {
  559. ThreadStart ts = new ThreadStart(crs.Remove);
  560. System.Threading.Thread t = new System.Threading.Thread(ts);
  561. t.IsBackground = true;
  562. t.Start();
  563. }
  564. else
  565. {
  566. img.BeginAnimation(WidthProperty, null);
  567. img.BeginAnimation(HeightProperty, null);
  568. }
  569. };
  570. img.BeginAnimation(WidthProperty, widthAnimation);
  571. img.BeginAnimation(HeightProperty, heightAnimation);
  572. //###################################################################
  573. //myStoryboard.Completed += (s, e) =>
  574. //{
  575. // if (checkRmStoryboard)
  576. // {
  577. // ThreadStart ts = new ThreadStart(crs.Remove);
  578. // System.Threading.Thread t = new System.Threading.Thread(ts);
  579. // t.Start();
  580. // }
  581. // else
  582. // {
  583. // myStoryboard.Remove();
  584. // }
  585. //};
  586. //myStoryboard.Begin();
  587. }
  588. private class CheckRemoveStoryboard
  589. {
  590. public Storyboard sb;
  591. public Panel sp;
  592. public Image img;
  593. public DoubleAnimation heightAnimation;
  594. public DoubleAnimation widthAnimation;
  595. public bool isMouseOver;
  596. public void Remove()
  597. {
  598. while (true)
  599. {
  600. if (sp.IsMouseOver == isMouseOver)
  601. {
  602. App.Current.Dispatcher.Invoke((Action)(() =>
  603. {
  604. img.BeginAnimation(WidthProperty, null);
  605. img.BeginAnimation(HeightProperty, null);
  606. //heightAnimation.FillBehavior = FillBehavior.Stop;
  607. //widthAnimation.FillBehavior = FillBehavior.Stop;
  608. }));
  609. return;
  610. }
  611. else
  612. {
  613. System.Threading.Thread.Sleep(500);
  614. }
  615. }
  616. }
  617. }
  618. public void RemoveSB(Object sb)
  619. {
  620. Storyboard sb2 = sb as Storyboard;
  621. System.Threading.Thread.Sleep(500);
  622. sb2.Remove();
  623. }
  624. /// <summary>
  625. /// 添加URL项目
  626. /// </summary>
  627. /// <param name="sender"></param>
  628. /// <param name="e"></param>
  629. private void AddUrlIcon(object sender, RoutedEventArgs e)
  630. {
  631. IconInfoUrlDialog urlDialog = new IconInfoUrlDialog();
  632. urlDialog.dialog = HandyControl.Controls.Dialog.Show(urlDialog, "MainWindowDialog");
  633. }
  634. /// <summary>
  635. /// 添加系统项目
  636. /// </summary>
  637. /// <param name="sender"></param>
  638. /// <param name="e"></param>
  639. private void AddSystemIcon(object sender, RoutedEventArgs e)
  640. {
  641. SystemItemWindow.Show();
  642. }
  643. public void VisibilitySearchCard(Visibility vb)
  644. {
  645. VerticalCard.Visibility = vb;
  646. if (vb == Visibility.Visible)
  647. {
  648. WrapCard.Visibility = Visibility.Collapsed;
  649. }
  650. else
  651. {
  652. WrapCard.Visibility = Visibility.Visible;
  653. }
  654. }
  655. /// <summary>
  656. /// 搜索Card点击事件
  657. /// </summary>
  658. /// <param name="sender"></param>
  659. /// <param name="e"></param>
  660. private void VerticalCard_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  661. {
  662. //隐藏搜索框
  663. if (RunTimeStatus.SEARCH_BOX_SHOW)
  664. {
  665. MainWindow.mainWindow.HidedSearchBox();
  666. }
  667. }
  668. /// <summary>
  669. /// 设置光标
  670. /// </summary>
  671. /// <param name="sender"></param>
  672. /// <param name="e"></param>
  673. private void CursorPanel_MouseEnter(object sender, MouseEventArgs e)
  674. {
  675. this.Cursor = Cursors.Hand;
  676. }
  677. /// <summary>
  678. /// 设置光标
  679. /// </summary>
  680. /// <param name="sender"></param>
  681. /// <param name="e"></param>
  682. private void CursorPanel_MouseLeave(object sender, MouseEventArgs e)
  683. {
  684. this.Cursor = Cursors.Arrow;
  685. }
  686. /// <summary>
  687. /// 锁定/解锁主面板
  688. /// </summary>
  689. /// <param name="sender"></param>
  690. /// <param name="e"></param>
  691. private void LockAppPanel(object sender, RoutedEventArgs e)
  692. {
  693. RunTimeStatus.LOCK_APP_PANEL = !RunTimeStatus.LOCK_APP_PANEL;
  694. }
  695. private void WrapCard_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
  696. {
  697. if (RunTimeStatus.LOCK_APP_PANEL)
  698. {
  699. CardLockCM.Header = "解锁主面板";
  700. }
  701. else
  702. {
  703. CardLockCM.Header = "锁定主面板";
  704. }
  705. }
  706. public void SearchListBoxIndexAdd()
  707. {
  708. //控制移动后 鼠标即使在图标上也不显示popup
  709. RunTimeStatus.MOUSE_MOVE_COUNT = 0;
  710. MyPoptip.IsOpen = false;
  711. if (SearchListBox.Items.Count > 0)
  712. {
  713. if (SearchListBox.SelectedIndex < SearchListBox.Items.Count - 1)
  714. {
  715. SearchListBox.SelectedIndex += 1;
  716. }
  717. }
  718. }
  719. public void SearchListBoxIndexSub()
  720. {
  721. //控制移动后 鼠标即使在图标上也不显示popup
  722. RunTimeStatus.MOUSE_MOVE_COUNT = 0;
  723. MyPoptip.IsOpen = false;
  724. if (SearchListBox.Items.Count > 0)
  725. {
  726. if (SearchListBox.SelectedIndex > 0)
  727. {
  728. SearchListBox.SelectedIndex -= 1;
  729. }
  730. }
  731. }
  732. public void StartupSelectionItem()
  733. {
  734. if (SearchListBox.SelectedItem != null)
  735. {
  736. IconInfo icon = SearchListBox.SelectedItem as IconInfo;
  737. if (icon.AdminStartUp)
  738. {
  739. StartIconApp(icon, IconStartType.ADMIN_STARTUP);
  740. }
  741. else
  742. {
  743. StartIconApp(icon, IconStartType.DEFAULT_STARTUP);
  744. }
  745. }
  746. }
  747. private void SearchListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  748. {
  749. SearchListBox.ScrollIntoView(SearchListBox.SelectedItem);
  750. }
  751. private void PDDialog_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  752. {
  753. if (PDDialog.Visibility == Visibility.Visible)
  754. {
  755. RunTimeStatus.SHOW_MENU_PASSWORDBOX = true;
  756. PDDialog.ClearVal();
  757. PDDialog.ErrorMsg.Visibility = Visibility.Collapsed;
  758. PDDialog.PasswordGrid.Visibility = Visibility.Visible;
  759. PDDialog.HintGrid.Visibility = Visibility.Collapsed;
  760. PDDialog.count = 0;
  761. PDDialog.SetFocus();
  762. }
  763. else
  764. {
  765. RunTimeStatus.SHOW_MENU_PASSWORDBOX = false;
  766. PDDialog.ClearVal();
  767. MainWindow.mainWindow.Focus();
  768. }
  769. }
  770. /// <summary>
  771. /// 菜单结果icon 列表鼠标滚轮预处理时间
  772. /// 主要使用自定义popup解决卡顿问题解决卡顿问题
  773. /// 以及滚动条首尾切换菜单
  774. /// </summary>
  775. /// <param name="sender"></param>
  776. /// <param name="e"></param>
  777. private void IconListBox_MouseWheel(object sender, MouseWheelEventArgs e)
  778. {
  779. //控制在滚动时不显示popup 否则会在低GPU性能机器上造成卡顿
  780. MyPoptip.IsOpen = false;
  781. if (RunTimeStatus.ICONLIST_MOUSE_WHEEL)
  782. {
  783. RunTimeStatus.MOUSE_WHEEL_WAIT_MS = 500;
  784. }
  785. else
  786. {
  787. RunTimeStatus.ICONLIST_MOUSE_WHEEL = true;
  788. new Thread(() =>
  789. {
  790. while (RunTimeStatus.MOUSE_WHEEL_WAIT_MS > 0)
  791. {
  792. Thread.Sleep(1);
  793. RunTimeStatus.MOUSE_WHEEL_WAIT_MS -= 1;
  794. }
  795. if (RunTimeStatus.MOUSE_ENTER_ICON)
  796. {
  797. this.Dispatcher.BeginInvoke(new Action(() =>
  798. {
  799. MyPoptip.IsOpen = true;
  800. }));
  801. }
  802. RunTimeStatus.MOUSE_WHEEL_WAIT_MS = 100;
  803. RunTimeStatus.ICONLIST_MOUSE_WHEEL = false;
  804. }).Start();
  805. }
  806. //修改菜单时不切换菜单
  807. if (RunTimeStatus.IS_MENU_EDIT) return;
  808. //切换菜单
  809. System.Windows.Controls.ScrollViewer scrollViewer = sender as System.Windows.Controls.ScrollViewer;
  810. if (scrollViewer == null)
  811. {
  812. //在card 上获取的事件
  813. scrollViewer = ScrollUtil.FindSimpleVisualChild<System.Windows.Controls.ScrollViewer>(IconListBox);
  814. }
  815. if (e.Delta < 0)
  816. {
  817. int index = MainWindow.mainWindow.LeftCard.MenuListBox.SelectedIndex;
  818. if (ScrollUtil.IsBootomScrollView(scrollViewer))
  819. {
  820. if (index < MainWindow.mainWindow.LeftCard.MenuListBox.Items.Count - 1)
  821. {
  822. index++;
  823. }
  824. else
  825. {
  826. index = 0;
  827. }
  828. MainWindow.mainWindow.LeftCard.MenuListBox.SelectedIndex = index;
  829. scrollViewer.ScrollToVerticalOffset(0);
  830. }
  831. }
  832. else if (e.Delta > 0)
  833. {
  834. if (ScrollUtil.IsTopScrollView(scrollViewer))
  835. {
  836. int index = MainWindow.mainWindow.LeftCard.MenuListBox.SelectedIndex;
  837. if (index > 0)
  838. {
  839. index--;
  840. }
  841. else
  842. {
  843. index = MainWindow.mainWindow.LeftCard.MenuListBox.Items.Count - 1;
  844. }
  845. MainWindow.mainWindow.LeftCard.MenuListBox.SelectedIndex = index;
  846. scrollViewer.ScrollToVerticalOffset(0);
  847. }
  848. }
  849. }
  850. /// <summary>
  851. /// 搜索结果icon 列表鼠标滚轮预处理时间
  852. /// 主要使用自定义popup解决卡顿问题解决卡顿问题
  853. /// </summary>
  854. /// <param name="sender"></param>
  855. /// <param name="e"></param>
  856. private void VerticalIconList_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
  857. {
  858. //控制在滚动时不显示popup 否则会在低GPU性能机器上造成卡顿
  859. MyPoptip.IsOpen = false;
  860. if (RunTimeStatus.ICONLIST_MOUSE_WHEEL)
  861. {
  862. RunTimeStatus.MOUSE_WHEEL_WAIT_MS = 500;
  863. }
  864. else
  865. {
  866. RunTimeStatus.ICONLIST_MOUSE_WHEEL = true;
  867. new Thread(() =>
  868. {
  869. while (RunTimeStatus.MOUSE_WHEEL_WAIT_MS > 0)
  870. {
  871. Thread.Sleep(1);
  872. RunTimeStatus.MOUSE_WHEEL_WAIT_MS -= 1;
  873. }
  874. if (RunTimeStatus.MOUSE_ENTER_ICON)
  875. {
  876. this.Dispatcher.BeginInvoke(new Action(() =>
  877. {
  878. MyPoptip.IsOpen = true;
  879. }));
  880. }
  881. RunTimeStatus.MOUSE_WHEEL_WAIT_MS = 100;
  882. RunTimeStatus.ICONLIST_MOUSE_WHEEL = false;
  883. }).Start();
  884. }
  885. }
  886. /// <summary>
  887. /// 查询结果 ICON 鼠标进入事件
  888. /// </summary>
  889. /// <param name="sender"></param>
  890. /// <param name="e"></param>
  891. private void SearchIcon_MouseEnter(object sender, MouseEventArgs e)
  892. {
  893. //显示popup
  894. RunTimeStatus.MOUSE_ENTER_ICON = true;
  895. if (!RunTimeStatus.ICONLIST_MOUSE_WHEEL)
  896. {
  897. new Thread(() =>
  898. {
  899. this.Dispatcher.BeginInvoke(new Action(() =>
  900. {
  901. IconInfo info = (sender as Panel).Tag as IconInfo;
  902. MyPoptipContent.Text = info.Content;
  903. MyPoptip.VerticalOffset = 30;
  904. Thread.Sleep(100);
  905. if (!RunTimeStatus.ICONLIST_MOUSE_WHEEL && RunTimeStatus.MOUSE_MOVE_COUNT > 1)
  906. {
  907. MyPoptip.IsOpen = true;
  908. }
  909. }));
  910. }).Start();
  911. }
  912. }
  913. /// <summary>
  914. /// 查询结果ICON鼠标离开事件
  915. /// </summary>
  916. /// <param name="sender"></param>
  917. /// <param name="e"></param>
  918. private void SearchIcon_MouseLeave(object sender, MouseEventArgs e)
  919. {
  920. RunTimeStatus.MOUSE_ENTER_ICON = false;
  921. MyPoptip.IsOpen = false;
  922. }
  923. /// <summary>
  924. /// 查询结果ICON鼠标移动事件
  925. /// </summary>
  926. /// <param name="sender"></param>
  927. /// <param name="e"></param>
  928. private void SearchIcon_MouseMove(object sender, MouseEventArgs e)
  929. {
  930. //控制首次刷新搜索结果后, 鼠标首次移动后显示popup
  931. RunTimeStatus.MOUSE_MOVE_COUNT++;
  932. //防止移动后不刷新popup content
  933. IconInfo info = (sender as Panel).Tag as IconInfo;
  934. MyPoptipContent.Text = info.Content;
  935. MyPoptip.VerticalOffset = 30;
  936. if (RunTimeStatus.MOUSE_MOVE_COUNT > 1 && !RunTimeStatus.ICONLIST_MOUSE_WHEEL)
  937. {
  938. MyPoptip.IsOpen = true;
  939. }
  940. }
  941. /// <summary>
  942. /// menu结果ICON鼠标移动事件
  943. /// </summary>
  944. /// <param name="sender"></param>
  945. /// <param name="e"></param>
  946. private void MenuIcon_MouseMove(object sender, MouseEventArgs e)
  947. {
  948. //防止移动后不刷新popup content
  949. IconInfo info = (sender as Panel).Tag as IconInfo;
  950. MyPoptipContent.Text = info.Content;
  951. MyPoptip.VerticalOffset = 30;
  952. }
  953. private void VerticalCard_ScrollChanged(object sender, ScrollChangedEventArgs e)
  954. {
  955. if (appData.AppConfig.EnableEveryThing == true && EveryThingUtil.hasNext())
  956. {
  957. HandyControl.Controls.ScrollViewer sv = sender as HandyControl.Controls.ScrollViewer;
  958. if (sv.ExtentHeight - (sv.ActualHeight + sv.VerticalOffset) < 200 && EveryThingUtil.hasNext())
  959. {
  960. string[] split = MainWindow.mainWindow.TotalMsgBtn.Content.ToString().Split(' ');
  961. long count = Convert.ToInt64(split[0]);
  962. ObservableCollection<IconInfo> iconBakList = EveryThingUtil.NextPage();
  963. count += iconBakList.Count;
  964. this.Dispatcher.Invoke(() =>
  965. {
  966. MainWindow.mainWindow.TotalMsgBtn.Content = count + " of " + split[split.Length - 1];
  967. foreach (IconInfo icon in iconBakList)
  968. {
  969. if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return;
  970. SearchIconList.IconList.Add(icon);
  971. }
  972. });
  973. //异步加载图标
  974. if (iconBakList != null && iconBakList.Count > 0)
  975. {
  976. ThreadPool.QueueUserWorkItem(state =>
  977. {
  978. foreach (IconInfo icon in iconBakList)
  979. {
  980. if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return;
  981. this.Dispatcher.Invoke(() =>
  982. {
  983. icon.BitmapImage_NoWrite = ImageUtil.GetBitmapIconByUnknownPath(icon.Path);
  984. });
  985. }
  986. });
  987. }
  988. }
  989. }
  990. }
  991. }
  992. }