LeftCardControl.xaml.cs 25 KB

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