LeftCardControl.xaml.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  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 Microsoft.Win32;
  8. using System;
  9. using System.Collections.ObjectModel;
  10. using System.IO;
  11. using System.Runtime.Serialization.Formatters.Binary;
  12. using System.Threading;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Threading;
  18. using WindowsAPICodePack.Dialogs;
  19. namespace GeekDesk.Control.UserControls.PannelCard
  20. {
  21. /// <summary>
  22. /// LeftCardControl.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class LeftCardControl : UserControl
  25. {
  26. private int menuSelectIndexTemp = -1;
  27. private AppData appData = MainWindow.appData;
  28. private SolidColorBrush bac = new SolidColorBrush(Color.FromRgb(255, 255, 255));
  29. public LeftCardControl()
  30. {
  31. InitializeComponent();
  32. bac.Opacity = 0.6;
  33. this.Loaded += (s, e) =>
  34. {
  35. SelectLastMenu();
  36. SetMenuListBoxItemEvent();
  37. };
  38. }
  39. private void SetMenuListBoxItemEvent()
  40. {
  41. int size = MenuListBox.Items.Count;
  42. for (int i = 0; i < size; i++)
  43. {
  44. ListBoxItem lbi = (ListBoxItem)(MenuListBox.ItemContainerGenerator.ContainerFromIndex(i));
  45. if (lbi != null)
  46. {
  47. SetListBoxItemEvent(lbi);
  48. }
  49. }
  50. //首次触发不了Selected事件
  51. object obj = MenuListBox.ItemContainerGenerator.ContainerFromIndex(MenuListBox.SelectedIndex);
  52. Lbi_Selected(obj, null);
  53. }
  54. private void SetListBoxItemEvent(ListBoxItem lbi)
  55. {
  56. lbi.MouseEnter += (s, me) =>
  57. {
  58. lbi.Background = bac;
  59. };
  60. lbi.Unselected += Lbi_Unselected;
  61. lbi.MouseLeave += Lbi_MouseLeave;
  62. lbi.Selected += Lbi_Selected;
  63. }
  64. private void SelectLastMenu()
  65. {
  66. if (appData.AppConfig.SelectedMenuIndex >= appData.MenuList.Count || appData.AppConfig.SelectedMenuIndex == -1)
  67. {
  68. MenuListBox.SelectedIndex = 0;
  69. appData.AppConfig.SelectedMenuIndex = MenuListBox.SelectedIndex;
  70. appData.AppConfig.SelectedMenuIcons = appData.MenuList[0].IconList;
  71. }
  72. else
  73. {
  74. MenuListBox.SelectedIndex = appData.AppConfig.SelectedMenuIndex;
  75. appData.AppConfig.SelectedMenuIcons = appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList;
  76. }
  77. }
  78. DelegateCommand<int[]> _swap;
  79. public DelegateCommand<int[]> SwapCommand
  80. {
  81. get
  82. {
  83. if (_swap == null)
  84. _swap = new DelegateCommand<int[]>(
  85. (indexes) =>
  86. {
  87. int fromS = indexes[0];
  88. int to = indexes[1];
  89. ObservableCollection<MenuInfo> menuList = MainWindow.appData.MenuList;
  90. var elementSource = menuList[to];
  91. var dragged = menuList[fromS];
  92. menuList.Remove(dragged);
  93. menuList.Insert(to, dragged);
  94. MenuListBox.SelectedIndex = to;
  95. MainWindow.appData.MenuList = menuList;
  96. }
  97. );
  98. return _swap;
  99. }
  100. }
  101. /// <summary>
  102. /// 当修改菜单元素可见时 设置原菜单为不可见 并且不可选中
  103. /// 修改菜单元素不可见时 原菜单可见 并 选中
  104. /// </summary>
  105. /// <param name="sender"></param>
  106. /// <param name="e"></param>
  107. private void MenuWhenVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)
  108. {
  109. StackPanel sp = sender as StackPanel;
  110. ListBoxItem lbi = (sp.TemplatedParent as ContentPresenter).TemplatedParent as ListBoxItem;
  111. if (sp.Visibility == Visibility.Collapsed)
  112. {
  113. lbi.MouseEnter += Lbi_MouseEnter;
  114. if (MenuListBox.SelectedIndex != -1)
  115. {
  116. menuSelectIndexTemp = MenuListBox.SelectedIndex;
  117. MenuListBox.SelectedIndex = -1;
  118. }
  119. else
  120. {
  121. MenuListBox.SelectedIndex = menuSelectIndexTemp;
  122. }
  123. }
  124. else
  125. {
  126. lbi.MouseEnter += (s, me) =>
  127. {
  128. lbi.Background = bac;
  129. };
  130. lbi.MouseLeave += Lbi_MouseLeave;
  131. lbi.Selected += Lbi_Selected;
  132. }
  133. }
  134. #region 设置菜单触发事件
  135. private void Lbi_MouseEnter(object sender, MouseEventArgs e)
  136. {
  137. ListBoxItem lbi = sender as ListBoxItem;
  138. lbi.Background = Brushes.Transparent;
  139. }
  140. private void Lbi_Unselected(object sender, RoutedEventArgs e)
  141. {
  142. //添加Leave效果
  143. ListBoxItem lbi = sender as ListBoxItem;
  144. lbi.Background = Brushes.Transparent;
  145. lbi.MouseLeave += Lbi_MouseLeave;
  146. }
  147. private void Lbi_Selected(object sender, RoutedEventArgs e)
  148. {
  149. try
  150. {
  151. ListBoxItem lbi = sender as ListBoxItem;
  152. SolidColorBrush fontColor = new SolidColorBrush(Colors.Black);
  153. lbi.MouseLeave -= Lbi_MouseLeave;
  154. lbi.Background = bac;
  155. lbi.Foreground = fontColor;
  156. }
  157. catch { }
  158. }
  159. private void Lbi_MouseLeave(object sender, MouseEventArgs e)
  160. {
  161. ListBoxItem lbi = sender as ListBoxItem;
  162. lbi.Background = Brushes.Transparent;
  163. }
  164. #endregion
  165. /// <summary>
  166. /// 新建菜单
  167. /// </summary>
  168. /// <param name="sender"></param>
  169. /// <param name="e"></param>
  170. private void CreateMenu(object sender, RoutedEventArgs e)
  171. {
  172. MenuInfo info = new MenuInfo() { MenuEdit = Visibility.Collapsed, MenuId = System.Guid.NewGuid().ToString(), MenuName = "NewMenu" };
  173. appData.MenuList.Add(info);
  174. MenuListBox.SelectedIndex = appData.MenuList.Count - 1;
  175. appData.AppConfig.SelectedMenuIndex = MenuListBox.SelectedIndex;
  176. appData.AppConfig.SelectedMenuIcons = info.IconList;
  177. //首次触发不了Selected事件
  178. object obj = MenuListBox.ItemContainerGenerator.ContainerFromIndex(MenuListBox.SelectedIndex);
  179. SetListBoxItemEvent((ListBoxItem)obj);
  180. Lbi_Selected(obj, null);
  181. }
  182. /// <summary>
  183. /// 创建实时文件菜单
  184. /// </summary>
  185. /// <param name="sender"></param>
  186. /// <param name="e"></param>
  187. private void CreateLinkMenu(object sender, RoutedEventArgs e)
  188. {
  189. try
  190. {
  191. CommonOpenFileDialog dialog = new CommonOpenFileDialog
  192. {
  193. IsFolderPicker = true,
  194. Title = "选择关联文件夹"
  195. };
  196. if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
  197. {
  198. string menuId = System.Guid.NewGuid().ToString();
  199. string path = dialog.FileName;
  200. MenuInfo menuInfo = new MenuInfo
  201. {
  202. MenuName = Path.GetFileNameWithoutExtension(path),
  203. MenuId = menuId,
  204. MenuType = MenuType.LINK,
  205. LinkPath = path,
  206. IsEncrypt = false,
  207. };
  208. appData.MenuList.Add(menuInfo);
  209. MenuListBox.SelectedIndex = appData.MenuList.Count - 1;
  210. appData.AppConfig.SelectedMenuIndex = MenuListBox.SelectedIndex;
  211. appData.AppConfig.SelectedMenuIcons = menuInfo.IconList;
  212. //首次触发不了Selected事件
  213. object obj = MenuListBox.ItemContainerGenerator.ContainerFromIndex(MenuListBox.SelectedIndex);
  214. SetListBoxItemEvent((ListBoxItem)obj);
  215. Lbi_Selected(obj, null);
  216. HandyControl.Controls.Growl.Success("菜单关联成功, 加载列表中, 稍后重新进入此菜单可查看列表!", "MainWindowGrowl");
  217. FileWatcher.LinkMenuWatcher(menuInfo);
  218. new Thread(() =>
  219. {
  220. DirectoryInfo dirInfo = new DirectoryInfo(menuInfo.LinkPath);
  221. FileSystemInfo[] fileInfos = dirInfo.GetFileSystemInfos();
  222. ObservableCollection<IconInfo> iconList = new ObservableCollection<IconInfo>();
  223. foreach (FileSystemInfo fileInfo in fileInfos)
  224. {
  225. IconInfo iconInfo = CommonCode.GetIconInfoByPath_NoWrite(fileInfo.FullName);
  226. iconList.Add(iconInfo);
  227. }
  228. this.Dispatcher.Invoke(() =>
  229. {
  230. menuInfo.IconList = iconList;
  231. //foreach (IconInfo iconInfo in iconList)
  232. //{
  233. // menuInfo.IconList = iconList;
  234. //}
  235. });
  236. }).Start();
  237. }
  238. }
  239. catch (Exception ex)
  240. {
  241. LogUtil.WriteErrorLog(ex, "新建关联菜单失败!");
  242. HandyControl.Controls.Growl.WarningGlobal("新建关联菜单失败!");
  243. }
  244. }
  245. /// <summary>
  246. /// 重命名菜单 将textbox 设置为可见
  247. /// </summary>
  248. /// <param name="sender"></param>
  249. /// <param name="e"></param>
  250. private void RenameMenu(object sender, RoutedEventArgs e)
  251. {
  252. RunTimeStatus.IS_MENU_EDIT = true;
  253. MenuInfo menuInfo = ((MenuItem)sender).Tag as MenuInfo;
  254. menuInfo.MenuEdit = (int)Visibility.Visible;
  255. }
  256. /// <summary>
  257. /// 删除菜单
  258. /// </summary>
  259. /// <param name="sender"></param>
  260. /// <param name="e"></param>
  261. private void DeleteMenu(object sender, RoutedEventArgs e)
  262. {
  263. MenuInfo menuInfo = ((MenuItem)sender).Tag as MenuInfo;
  264. if (menuInfo.IconList != null && menuInfo.IconList.Count > 0)
  265. {
  266. HandyControl.Controls.Growl.Ask("确认删除此菜单吗?", isConfirmed =>
  267. {
  268. if (isConfirmed)
  269. {
  270. DeleteMenu(menuInfo);
  271. }
  272. return true;
  273. }, "MainWindowAskGrowl");
  274. } else
  275. {
  276. DeleteMenu(menuInfo);
  277. }
  278. }
  279. private void DeleteMenu(MenuInfo menuInfo)
  280. {
  281. if (appData.MenuList.Count == 1)
  282. {
  283. //如果删除以后没有菜单的话 先创建一个
  284. CreateMenu(null, null);
  285. }
  286. int index = appData.MenuList.IndexOf(menuInfo);
  287. if (index == 0)
  288. {
  289. index = 0;
  290. }
  291. else
  292. {
  293. index--;
  294. }
  295. appData.MenuList.Remove(menuInfo);
  296. // 选中下一个菜单
  297. MenuListBox.SelectedIndex = index;
  298. appData.AppConfig.SelectedMenuIndex = MenuListBox.SelectedIndex;
  299. appData.AppConfig.SelectedMenuIcons = appData.MenuList[index].IconList;
  300. }
  301. /// <summary>
  302. /// 编辑菜单失焦或者敲下Enter键时保存修改后的菜单
  303. /// </summary>
  304. /// <param name="sender"></param>
  305. /// <param name="e"></param>
  306. private void LostFocusOrEnterDown(object sender, EventArgs e)
  307. {
  308. bool done = true;
  309. TextBox menuBox = null;
  310. if (e.GetType() == typeof(KeyEventArgs))
  311. {
  312. KeyEventArgs eKey = e as KeyEventArgs;
  313. if (eKey.Key == Key.Enter)
  314. {
  315. menuBox = ((TextBox)sender);
  316. }
  317. else
  318. {
  319. done = false;
  320. }
  321. }
  322. else if (e.GetType() == typeof(RoutedEventArgs))
  323. {
  324. menuBox = ((TextBox)sender);
  325. }
  326. if (done)
  327. {
  328. if (menuBox != null)
  329. {
  330. MenuInfo menuInfo = menuBox.Tag as MenuInfo;
  331. string text = menuBox.Text;
  332. menuInfo.MenuName = text;
  333. menuInfo.MenuEdit = Visibility.Collapsed;
  334. }
  335. RunTimeStatus.IS_MENU_EDIT = false;
  336. //为了解决无法修改菜单的问题
  337. MainWindow.mainWindow.SearchBox.Focus();
  338. MenuListBox.SelectedIndex = menuSelectIndexTemp;
  339. }
  340. }
  341. /// <summary>
  342. /// 当修改菜单元素可见时 设置全选并获得焦点
  343. /// </summary>
  344. /// <param name="sender"></param>
  345. /// <param name="e"></param>
  346. private void MenuEditWhenVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)
  347. {
  348. TextBox box = sender as TextBox;
  349. MenuInfo mi = box.Tag as MenuInfo;
  350. if (box.Visibility == Visibility.Visible)
  351. {
  352. Keyboard.Focus(box);
  353. box.SelectAll();
  354. }
  355. }
  356. /// <summary>
  357. /// 修改菜单图标
  358. /// </summary>
  359. /// <param name="sender"></param>
  360. /// <param name="e"></param>
  361. private void EditMenuGeometry(object sender, RoutedEventArgs e)
  362. {
  363. MenuInfo menuInfo = ((MenuItem)sender).Tag as MenuInfo;
  364. IconfontWindow.Show(SvgToGeometry.GetIconfonts(), menuInfo);
  365. }
  366. private void Menu_SelectionChanged(object sender, SelectionChangedEventArgs e)
  367. {
  368. if (RunTimeStatus.IS_MENU_EDIT) return;
  369. if (appData.AppConfig.ItemSpradeAnimation)
  370. {
  371. //是否启用列表展开动画
  372. MainWindow.mainWindow.RightCard.WrapUFG.Visibility = Visibility.Collapsed;
  373. }
  374. //设置对应菜单的图标列表
  375. if (MenuListBox.SelectedIndex == -1)
  376. {
  377. //appData.AppConfig.SelectedMenuIcons = appData.MenuList[appData.MenuList.Count - 1].IconList;
  378. }
  379. else
  380. {
  381. if (appData.MenuList[MenuListBox.SelectedIndex].IsEncrypt)
  382. {
  383. appData.AppConfig.SelectedMenuIcons = null;
  384. RunTimeStatus.SHOW_MENU_PASSWORDBOX = true;
  385. MainWindow.mainWindow.RightCard.PDDialog.Title.Text = "输入密码";
  386. MainWindow.mainWindow.RightCard.PDDialog.type = PasswordType.INPUT;
  387. MainWindow.mainWindow.RightCard.PDDialog.Visibility = Visibility.Visible;
  388. }
  389. else
  390. {
  391. MainWindow.mainWindow.RightCard.PDDialog.Visibility = Visibility.Collapsed;
  392. appData.AppConfig.SelectedMenuIcons = appData.MenuList[MenuListBox.SelectedIndex].IconList;
  393. }
  394. }
  395. MainWindow.mainWindow.RightCard.WrapUFG.Visibility = Visibility.Visible;
  396. //App.DoEvents();
  397. }
  398. /// <summary>
  399. /// 鼠标悬停切换菜单
  400. /// </summary>
  401. /// <param name="sender"></param>
  402. /// <param name="e"></param>
  403. private void Menu_MouseEnter(object sender, MouseEventArgs e)
  404. {
  405. if (appData.AppConfig.HoverMenu && !RunTimeStatus.IS_MENU_EDIT)
  406. {
  407. Thread t = new Thread(() =>
  408. {
  409. Thread.Sleep(200);
  410. this.Dispatcher.Invoke(() =>
  411. {
  412. ListBoxItem lbi = sender as ListBoxItem;
  413. if (lbi.IsMouseOver)
  414. {
  415. int index = MenuListBox.ItemContainerGenerator.IndexFromContainer(lbi);
  416. MenuListBox.SelectedIndex = index;
  417. if (appData.AppConfig.IconBatch_NoWrite)
  418. {
  419. appData.AppConfig.IconBatch_NoWrite = false;
  420. }
  421. }
  422. });
  423. });
  424. t.IsBackground = true;
  425. t.Start();
  426. }
  427. }
  428. /// <summary>
  429. /// 点击菜单后 隐藏搜索框
  430. /// </summary>
  431. /// <param name="sender"></param>
  432. /// <param name="e"></param>
  433. private void ListBoxItem_MouseDown(object sender, MouseButtonEventArgs e)
  434. {
  435. if (RunTimeStatus.SEARCH_BOX_SHOW)
  436. {
  437. MainWindow.mainWindow.HidedSearchBox();
  438. }
  439. ListBoxItem lbi = sender as ListBoxItem;
  440. MenuInfo mi = lbi.DataContext as MenuInfo;
  441. int index = MenuListBox.Items.IndexOf(mi);
  442. MenuListBox.SelectedIndex = index;
  443. if (appData.AppConfig.IconBatch_NoWrite)
  444. {
  445. appData.AppConfig.IconBatch_NoWrite = false;
  446. MainWindow.mainWindow.RightCard.IconListBox.SelectionMode = SelectionMode.Extended;
  447. }
  448. }
  449. ///// <summary>
  450. ///// 点击菜单后 隐藏搜索框
  451. ///// </summary>
  452. ///// <param name="sender"></param>
  453. ///// <param name="e"></param>
  454. //private void ListBoxItemPanel_MouseDown(object sender, MouseButtonEventArgs e)
  455. //{
  456. // if (RunTimeStatus.SEARCH_BOX_SHOW)
  457. // {
  458. // MainWindow.mainWindow.HidedSearchBox();
  459. // }
  460. // MenuInfo mi = (sender as StackPanel).Tag as MenuInfo;
  461. // int index = MenuListBox.Items.IndexOf(mi);
  462. // MenuListBox.SelectedIndex = index;
  463. //}
  464. /// <summary>
  465. /// 隐藏搜索框
  466. /// </summary>
  467. /// <param name="sender"></param>
  468. /// <param name="e"></param>
  469. private void MyCard_MouseDown(object sender, MouseButtonEventArgs e)
  470. {
  471. if (RunTimeStatus.SEARCH_BOX_SHOW)
  472. {
  473. MainWindow.mainWindow.HidedSearchBox();
  474. }
  475. }
  476. private void Menu_MouseWheel(object sender, MouseWheelEventArgs e)
  477. {
  478. if (RunTimeStatus.IS_MENU_EDIT) return;
  479. ScrollViewer scrollViewer = ScrollUtil.FindSimpleVisualChild<ScrollViewer>(MenuListBox);
  480. if (e.Delta < 0)
  481. {
  482. //判断是否到了最底部
  483. if (ScrollUtil.IsBootomScrollView(scrollViewer))
  484. {
  485. int index = MenuListBox.SelectedIndex;
  486. if (index < MenuListBox.Items.Count - 1)
  487. {
  488. index++;
  489. }
  490. else
  491. {
  492. index = 0;
  493. }
  494. MenuListBox.SelectedIndex = index;
  495. }
  496. }
  497. else if (e.Delta > 0)
  498. {
  499. if (ScrollUtil.IsTopScrollView(scrollViewer))
  500. {
  501. int index = MenuListBox.SelectedIndex;
  502. if (index > 0)
  503. {
  504. index--;
  505. }
  506. else
  507. {
  508. index = MenuListBox.Items.Count - 1;
  509. }
  510. MenuListBox.SelectedIndex = index;
  511. }
  512. }
  513. //滚动到选中项
  514. MenuListBox.ScrollIntoView(MenuListBox.SelectedItem);
  515. }
  516. private void Menu_PreviewDragLeave(object sender, DragEventArgs e)
  517. {
  518. MyPoptip.IsOpen = false;
  519. }
  520. private void Menu_PreviewDragEnter(object sender, DragEventArgs e)
  521. {
  522. MenuInfo mi = (sender as ListBoxItem).DataContext as MenuInfo;
  523. MyPoptipContent.Text = "移动至:" + mi.MenuName;
  524. MyPoptip.VerticalOffset = 30;
  525. MyPoptip.IsOpen = true;
  526. }
  527. private void Menu_MouseLeave(object sender, MouseEventArgs e)
  528. {
  529. MyPoptip.IsOpen = false;
  530. }
  531. /// <summary>
  532. /// 拖动移动图标到指定菜单
  533. /// </summary>
  534. /// <param name="sender"></param>
  535. /// <param name="e"></param>
  536. private void Menu_Drop(object sender, DragEventArgs e)
  537. {
  538. MyPoptip.IsOpen = false;
  539. MenuInfo mi = (sender as ListBoxItem).DataContext as MenuInfo;
  540. IconInfo iconInfo = (IconInfo)e.Data.GetData(typeof(IconInfo));
  541. if (iconInfo != null)
  542. {
  543. // 将已有图标移动到该菜单
  544. appData.MenuList[MenuListBox.SelectedIndex].IconList.Remove(iconInfo);
  545. appData.MenuList[MenuListBox.Items.IndexOf(mi)].IconList.Add(iconInfo);
  546. }
  547. else
  548. {
  549. // 直接将新图标移动到该菜单
  550. Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop);
  551. if (dropObject == null) return;
  552. foreach (object obj in dropObject)
  553. {
  554. string path = (string)obj;
  555. iconInfo = CommonCode.GetIconInfoByPath(path);
  556. if (iconInfo == null)
  557. {
  558. LogUtil.WriteErrorLog("添加项目失败,未能获取到项目图标:" + path);
  559. break;
  560. }
  561. appData.MenuList[MenuListBox.Items.IndexOf(mi)].IconList.Add(iconInfo);
  562. }
  563. CommonCode.SortIconList();
  564. CommonCode.SaveAppData(MainWindow.appData, Constants.DATA_FILE_PATH);
  565. }
  566. }
  567. private void EncryptMenu(object sender, RoutedEventArgs e)
  568. {
  569. MenuInfo menuInfo = ((MenuItem)sender).Tag as MenuInfo;
  570. if (menuInfo.IsEncrypt)
  571. {
  572. MainWindow.mainWindow.RightCard.PDDialog.menuInfo = menuInfo;
  573. MainWindow.mainWindow.RightCard.PDDialog.Title.Text = "输入密码";
  574. MainWindow.mainWindow.RightCard.PDDialog.type = PasswordType.CANCEL;
  575. RunTimeStatus.SHOW_MENU_PASSWORDBOX = true;
  576. MainWindow.mainWindow.RightCard.PDDialog.Visibility = Visibility.Visible;
  577. //单独设置焦点
  578. MainWindow.mainWindow.RightCard.PDDialog.SetFocus();
  579. }
  580. else
  581. {
  582. if (string.IsNullOrEmpty(appData.AppConfig.MenuPassword))
  583. {
  584. MainWindow.mainWindow.RightCard.PDDialog.menuInfo = menuInfo;
  585. MainWindow.mainWindow.RightCard.PDDialog.Title.Text = "设置新密码";
  586. MainWindow.mainWindow.RightCard.PDDialog.type = PasswordType.CREATE;
  587. RunTimeStatus.SHOW_MENU_PASSWORDBOX = true;
  588. MainWindow.mainWindow.RightCard.PDDialog.Visibility = Visibility.Visible;
  589. }
  590. else
  591. {
  592. menuInfo.IsEncrypt = true;
  593. HandyControl.Controls.Growl.Success(menuInfo.MenuName + " 已加密!", "MainWindowGrowl");
  594. }
  595. }
  596. }
  597. private void AlterPassword(object sender, RoutedEventArgs e)
  598. {
  599. MainWindow.mainWindow.RightCard.PDDialog.Title.Text = "输入旧密码";
  600. MainWindow.mainWindow.RightCard.PDDialog.type = PasswordType.ALTER;
  601. MainWindow.mainWindow.RightCard.PDDialog.Visibility = Visibility.Visible;
  602. //单独设置焦点
  603. MainWindow.mainWindow.RightCard.PDDialog.SetFocus();
  604. }
  605. /// <summary>
  606. /// 右键点击进行处理
  607. /// </summary>
  608. /// <param name="sender"></param>
  609. /// <param name="e"></param>
  610. private void MyCard_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
  611. {
  612. RunTimeStatus.SHOW_RIGHT_BTN_MENU = true;
  613. new Thread(() =>
  614. {
  615. Thread.Sleep(50);
  616. RunTimeStatus.SHOW_RIGHT_BTN_MENU = false;
  617. }).Start();
  618. //在没有设置密码的情况下不弹出修改密码菜单
  619. if (string.IsNullOrEmpty(appData.AppConfig.MenuPassword))
  620. {
  621. AlterPW1.Visibility = Visibility.Collapsed;
  622. }
  623. else
  624. {
  625. AlterPW1.Visibility = Visibility.Visible;
  626. }
  627. }
  628. private void ListBoxItem_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
  629. {
  630. ListBoxItem lbi = sender as ListBoxItem;
  631. MenuInfo info = lbi.DataContext as MenuInfo;
  632. ItemCollection ics = lbi.ContextMenu.Items;
  633. foreach (object obj in ics)
  634. {
  635. MenuItem mi = (MenuItem)obj;
  636. if (mi.Header.Equals("修改密码"))
  637. {
  638. if (string.IsNullOrEmpty(appData.AppConfig.MenuPassword))
  639. {
  640. mi.Visibility = Visibility.Collapsed;
  641. }
  642. else
  643. {
  644. mi.Visibility = Visibility.Visible;
  645. }
  646. break;
  647. }
  648. if (mi.Header.Equals("加密此列表") || mi.Header.Equals("取消加密此列表"))
  649. {
  650. if (info.IsEncrypt)
  651. {
  652. mi.Header = "取消加密此列表";
  653. }
  654. else
  655. {
  656. mi.Header = "加密此列表";
  657. }
  658. }
  659. }
  660. }
  661. }
  662. }