RightCardControl.xaml.cs 37 KB

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