RightCardControl.xaml.cs 38 KB

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