MainWindow.xaml.cs 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. using GeekDesk.Constant;
  2. using GeekDesk.Control.UserControls.Config;
  3. using GeekDesk.Control.UserControls.PannelCard;
  4. using GeekDesk.Control.Windows;
  5. using GeekDesk.Interface;
  6. using GeekDesk.MyThread;
  7. using GeekDesk.Plugins.EveryThing;
  8. using GeekDesk.Plugins.EveryThing.Constant;
  9. using GeekDesk.Task;
  10. using GeekDesk.Util;
  11. using GeekDesk.ViewModel;
  12. using GeekDesk.ViewModel.Temp;
  13. using Microsoft.Win32;
  14. using NPinyin;
  15. using ShowSeconds;
  16. using System;
  17. using System.Collections.ObjectModel;
  18. using System.Diagnostics;
  19. using System.Runtime.InteropServices;
  20. using System.Text;
  21. using System.Threading;
  22. using System.Windows;
  23. using System.Windows.Controls;
  24. using System.Windows.Input;
  25. using System.Windows.Interop;
  26. using System.Windows.Media.Animation;
  27. using System.Windows.Media.Imaging;
  28. using System.Windows.Shell;
  29. using System.Windows.Threading;
  30. using static GeekDesk.Util.ShowWindowFollowMouse;
  31. namespace GeekDesk
  32. {
  33. /// <summary>
  34. /// MainWindow.xaml 的交互逻辑
  35. /// </summary>
  36. ///
  37. public partial class MainWindow : Window, IWindowCommon
  38. {
  39. public static AppData appData = CommonCode.GetAppDataByFile();
  40. public static ToDoInfoWindow toDoInfoWindow;
  41. public static int hotKeyId = -1;
  42. public static int toDoHotKeyId = -1;
  43. public static int colorPickerHotKeyId = -1;
  44. public static MainWindow mainWindow;
  45. public MainWindow()
  46. {
  47. //加载数据
  48. LoadData();
  49. InitializeComponent();
  50. //用于其他类访问
  51. mainWindow = this;
  52. //执行待办提醒
  53. ToDoTask.BackLogCheck();
  54. ////实例化隐藏 Hide类,进行时间timer设置
  55. MarginHide.ReadyHide(this);
  56. if (appData.AppConfig.MarginHide)
  57. {
  58. MarginHide.StartHide();
  59. }
  60. }
  61. /// <summary>
  62. /// 搜索快捷键按下
  63. /// </summary>
  64. /// <param name="sender"></param>
  65. /// <param name="e"></param>
  66. private void SearchHotKeyDown(object sender, CanExecuteRoutedEventArgs e)
  67. {
  68. if (appData.AppConfig.SearchType == SearchType.HOT_KEY)
  69. {
  70. ShowSearchBox();
  71. }
  72. }
  73. /// <summary>
  74. /// 显示搜索框
  75. /// </summary>
  76. private void ShowSearchBox()
  77. {
  78. RunTimeStatus.SEARCH_BOX_SHOW = true;
  79. RightCard.VisibilitySearchCard(Visibility.Visible);
  80. SearchBox.Width = 400;
  81. SearchBox.Focus();
  82. //执行一遍a查询
  83. SearchBox_TextChanged(null, null);
  84. }
  85. /// <summary>
  86. /// 搜索开始
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. private void SearchBox_TextChanged(object sender, TextChangedEventArgs e)
  91. {
  92. if (!RunTimeStatus.SEARCH_BOX_SHOW
  93. && appData.AppConfig.SearchType != SearchType.KEY_DOWN
  94. )
  95. {
  96. SearchBox.TextChanged -= SearchBox_TextChanged;
  97. SearchBox.Clear();
  98. SearchBox.TextChanged += SearchBox_TextChanged;
  99. return;
  100. }
  101. if (!RunTimeStatus.SEARCH_BOX_SHOW) ShowSearchBox();
  102. //刷新搜索后 鼠标移动次数置为0
  103. RunTimeStatus.MOUSE_MOVE_COUNT = 0;
  104. //隐藏popup
  105. RightCard.MyPoptip.IsOpen = false;
  106. string inputText = SearchBox.Text.ToLower();
  107. RightCard.VerticalUFG.Visibility = Visibility.Collapsed;
  108. if (!string.IsNullOrEmpty(inputText))
  109. {
  110. RunTimeStatus.EVERYTHING_SEARCH_DELAY_TIME = 300;
  111. if (!RunTimeStatus.EVERYTHING_NEW_SEARCH)
  112. {
  113. RunTimeStatus.EVERYTHING_NEW_SEARCH = true;
  114. SearchDelay(null, null);
  115. }
  116. } else
  117. {
  118. new Thread(() =>
  119. {
  120. this.Dispatcher.Invoke(() =>
  121. {
  122. SearchIconList.RemoveAll();
  123. });
  124. }).Start();
  125. }
  126. }
  127. private void SearchDelay(object sender, EventArgs args)
  128. {
  129. new Thread(() =>
  130. {
  131. while (RunTimeStatus.EVERYTHING_SEARCH_DELAY_TIME > 0)
  132. {
  133. Thread.Sleep(10);
  134. RunTimeStatus.EVERYTHING_SEARCH_DELAY_TIME -= 10;
  135. }
  136. RunTimeStatus.EVERYTHING_NEW_SEARCH = false;
  137. this.Dispatcher.Invoke(() =>
  138. {
  139. if (SearchIconList.IconList.Count > 0)
  140. {
  141. SearchIconList.RemoveAll();
  142. }
  143. //DelayHelper dh = sender as DelayHelper;
  144. //string inpuText = dh.Source as string;
  145. string inputText = SearchBox.Text.ToLower().Trim();
  146. int count = 0;
  147. //GeekDesk数据搜索
  148. ObservableCollection<MenuInfo> menuList = appData.MenuList;
  149. foreach (MenuInfo menu in menuList)
  150. {
  151. ObservableCollection<IconInfo> iconList = menu.IconList;
  152. foreach (IconInfo icon in iconList)
  153. {
  154. if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return;
  155. string pyName = Pinyin.GetInitials(icon.Name).ToLower();
  156. if (icon.Name.Contains(inputText) || pyName.Contains(inputText))
  157. {
  158. SearchIconList.IconList.Add(icon);
  159. count++;
  160. }
  161. }
  162. }
  163. if (appData.AppConfig.EnableEveryThing == true)
  164. {
  165. new Thread(() =>
  166. {
  167. //EveryThing全盘搜索
  168. ObservableCollection<IconInfo> iconBakList = EveryThingUtil.Search(inputText);
  169. count += iconBakList.Count;
  170. this.Dispatcher.Invoke(() =>
  171. {
  172. TotalMsgBtn.Visibility = Visibility.Visible;
  173. TotalMsgBtn.Content = count + " of " + Convert.ToInt64(EveryThingUtil.Everything_GetNumResults());
  174. foreach (IconInfo icon in iconBakList)
  175. {
  176. if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return;
  177. SearchIconList.IconList.Add(icon);
  178. }
  179. });
  180. //异步加载图标
  181. if (iconBakList != null && iconBakList.Count > 0)
  182. {
  183. new Thread(() =>
  184. {
  185. foreach (IconInfo icon in iconBakList)
  186. {
  187. if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return;
  188. this.Dispatcher.Invoke(() =>
  189. {
  190. icon.BitmapImage_NoWrite = ImageUtil.GetBitmapIconByUnknownPath(icon.Path);
  191. });
  192. }
  193. }).Start();
  194. }
  195. }).Start();
  196. }
  197. if (RightCard.SearchListBox.Items.Count > 0)
  198. {
  199. RightCard.SearchListBox.SelectedIndex = 0;
  200. }
  201. RightCard.VerticalUFG.Visibility = Visibility.Visible;
  202. });
  203. }).Start();
  204. }
  205. /// <summary>
  206. /// 隐藏搜索框
  207. /// </summary>
  208. public void HidedSearchBox()
  209. {
  210. RunTimeStatus.EVERYTHING_NEW_SEARCH = true;
  211. new Thread(() =>
  212. {
  213. Thread.Sleep(1000);
  214. RunTimeStatus.EVERYTHING_NEW_SEARCH = false;
  215. }).Start();
  216. Keyboard.Focus(SearchBox);
  217. RunTimeStatus.SEARCH_BOX_SHOW = false;
  218. SearchBox.TextChanged -= SearchBox_TextChanged;
  219. SearchBox.Clear();
  220. SearchBox.TextChanged += SearchBox_TextChanged;
  221. SearchBox.Width = 0;
  222. TotalMsgBtn.Content = "0 of 0";
  223. TotalMsgBtn.Visibility = Visibility.Hidden;
  224. RightCard.VisibilitySearchCard(Visibility.Collapsed);
  225. SearchIconList.RemoveAll();
  226. //App.DoEvents();
  227. //new Thread(() =>
  228. //{
  229. // this.Dispatcher.Invoke(() =>
  230. // {
  231. // });
  232. //}).Start();
  233. }
  234. /// <summary>
  235. /// 加载缓存数据
  236. /// </summary>
  237. private void LoadData()
  238. {
  239. this.DataContext = appData;
  240. if (appData.MenuList.Count == 0)
  241. {
  242. appData.MenuList.Add(new MenuInfo() { MenuName = "NewMenu", MenuId = System.Guid.NewGuid().ToString(), MenuEdit = Visibility.Collapsed });
  243. }
  244. this.Width = appData.AppConfig.WindowWidth;
  245. this.Height = appData.AppConfig.WindowHeight;
  246. }
  247. /// <summary>
  248. /// 窗口加载完毕 执行方法
  249. /// </summary>
  250. /// <param name="sender"></param>
  251. /// <param name="e"></param>
  252. void Window_Loaded(object sender, RoutedEventArgs e)
  253. {
  254. BGSettingUtil.BGSetting();
  255. if (!appData.AppConfig.StartedShowPanel)
  256. {
  257. this.Visibility = Visibility.Collapsed;
  258. }
  259. else
  260. {
  261. ShowApp();
  262. }
  263. //给任务栏图标一个名字
  264. BarIcon.Text = Constants.MY_NAME;
  265. //注册热键
  266. if (true == appData.AppConfig.EnableAppHotKey)
  267. {
  268. RegisterHotKey(true);
  269. }
  270. if (true == appData.AppConfig.EnableTodoHotKey)
  271. {
  272. RegisterCreateToDoHotKey(true);
  273. }
  274. if (true == appData.AppConfig.EnableColorPickerHotKey)
  275. {
  276. RegisterColorPickerHotKey(true);
  277. }
  278. //注册自启动
  279. if (!appData.AppConfig.SelfStartUped && !Constants.DEV)
  280. {
  281. RegisterUtil.SetSelfStarting(appData.AppConfig.SelfStartUp, Constants.MY_NAME);
  282. }
  283. //注册鼠标监听事件
  284. if (appData.AppConfig.MouseMiddleShow)
  285. {
  286. MouseHookThread.Hook();
  287. }
  288. //显秒插件
  289. if (appData.AppConfig.SecondsWindow == true)
  290. {
  291. SecondsWindow.ShowWindow();
  292. }
  293. //监听实时文件夹菜单
  294. FileWatcher.StartLinkMenuWatcher(appData);
  295. //更新线程开启 检测更新
  296. UpdateThread.Update();
  297. //建立相对路径
  298. RelativePathThread.MakeRelativePath();
  299. //毛玻璃 暂时未解决阴影问题
  300. //BlurGlassUtil.EnableBlur(this);
  301. WindowUtil.SetOwner(this, WindowUtil.GetDesktopHandle(this, DesktopLayer.Progman));
  302. if (appData.AppConfig.EnableEveryThing == true)
  303. {
  304. //开启EveryThing插件
  305. EveryThingUtil.EnableEveryThing();
  306. }
  307. Keyboard.Focus(SearchBox);
  308. MessageUtil.ChangeWindowMessageFilter(MessageUtil.WM_COPYDATA, 1);
  309. }
  310. /// <summary>
  311. /// 注册当前窗口的热键
  312. /// </summary>
  313. public static void RegisterHotKey(bool first)
  314. {
  315. try
  316. {
  317. if (appData.AppConfig.HotkeyModifiers != GlobalHotKey.HotkeyModifiers.None)
  318. {
  319. hotKeyId = GlobalHotKey.RegisterHotKey(appData.AppConfig.HotkeyModifiers, appData.AppConfig.Hotkey, () =>
  320. {
  321. if (MotionControl.hotkeyFinished)
  322. {
  323. if (CheckSholeShowApp())
  324. {
  325. ShowApp();
  326. }
  327. else
  328. {
  329. HideApp();
  330. }
  331. }
  332. });
  333. if (!first)
  334. {
  335. HandyControl.Controls.Growl.Success("GeekDesk快捷键注册成功(" + appData.AppConfig.HotkeyStr + ")!", "HotKeyGrowl");
  336. }
  337. }
  338. else
  339. {
  340. }
  341. }
  342. catch (Exception)
  343. {
  344. if (first)
  345. {
  346. HandyControl.Controls.Growl.WarningGlobal("GeekDesk启动快捷键已被其它程序占用(" + appData.AppConfig.HotkeyStr + ")!");
  347. }
  348. else
  349. {
  350. HandyControl.Controls.Growl.Warning("GeekDesk启动快捷键已被其它程序占用(" + appData.AppConfig.HotkeyStr + ")!", "HotKeyGrowl");
  351. }
  352. }
  353. }
  354. /// <summary>
  355. /// 注册新建待办的热键
  356. /// </summary>
  357. public static void RegisterCreateToDoHotKey(bool first)
  358. {
  359. try
  360. {
  361. if (appData.AppConfig.HotkeyModifiers != GlobalHotKey.HotkeyModifiers.None)
  362. {
  363. //加载完毕注册热键
  364. toDoHotKeyId = GlobalHotKey.RegisterHotKey(appData.AppConfig.ToDoHotkeyModifiers, appData.AppConfig.ToDoHotkey, () =>
  365. {
  366. if (MotionControl.hotkeyFinished)
  367. {
  368. ToDoWindow.ShowOrHide();
  369. }
  370. });
  371. if (!first)
  372. {
  373. HandyControl.Controls.Growl.Success("新建待办任务快捷键注册成功(" + appData.AppConfig.ToDoHotkeyStr + ")!", "HotKeyGrowl");
  374. }
  375. }
  376. }
  377. catch (Exception)
  378. {
  379. if (first)
  380. {
  381. HandyControl.Controls.Growl.WarningGlobal("新建待办任务快捷键已被其它程序占用(" + appData.AppConfig.ToDoHotkeyStr + ")!");
  382. }
  383. else
  384. {
  385. HandyControl.Controls.Growl.Warning("新建待办任务快捷键已被其它程序占用(" + appData.AppConfig.ToDoHotkeyStr + ")!", "HotKeyGrowl");
  386. }
  387. }
  388. }
  389. /// <summary>
  390. /// 注册新建待办的热键
  391. /// </summary>
  392. public static void RegisterColorPickerHotKey(bool first)
  393. {
  394. try
  395. {
  396. if (appData.AppConfig.HotkeyModifiers != GlobalHotKey.HotkeyModifiers.None)
  397. {
  398. //加载完毕注册热键
  399. colorPickerHotKeyId = GlobalHotKey.RegisterHotKey(appData.AppConfig.ColorPickerHotkeyModifiers, appData.AppConfig.ColorPickerHotkey, () =>
  400. {
  401. if (MotionControl.hotkeyFinished)
  402. {
  403. GlobalColorPickerWindow.CreateNoShow();
  404. }
  405. });
  406. if (!first)
  407. {
  408. HandyControl.Controls.Growl.Success("拾色器快捷键注册成功(" + appData.AppConfig.ColorPickerHotkeyStr + ")!", "HotKeyGrowl");
  409. }
  410. }
  411. }
  412. catch (Exception)
  413. {
  414. if (first)
  415. {
  416. HandyControl.Controls.Growl.WarningGlobal("拾色器快捷键已被其它程序占用(" + appData.AppConfig.ColorPickerHotkeyStr + ")!");
  417. }
  418. else
  419. {
  420. HandyControl.Controls.Growl.Warning("拾色器快捷键已被其它程序占用(" + appData.AppConfig.ColorPickerHotkeyStr + ")!", "HotKeyGrowl");
  421. }
  422. }
  423. }
  424. /// <summary>
  425. /// 程序窗体拖动
  426. /// </summary>
  427. /// <param name="sender"></param>
  428. /// <param name="e"></param>
  429. private void DragMove(object sender, MouseEventArgs e)
  430. {
  431. if (e.LeftButton == MouseButtonState.Pressed)
  432. {
  433. var windowMode = this.ResizeMode;
  434. if (this.ResizeMode != ResizeMode.NoResize)
  435. {
  436. this.ResizeMode = ResizeMode.NoResize;
  437. }
  438. this.UpdateLayout();
  439. /* 当点击拖拽区域的时候,让窗口跟着移动
  440. (When clicking the drag area, make the window follow) */
  441. DragMove();
  442. if (this.ResizeMode != windowMode)
  443. {
  444. this.ResizeMode = windowMode;
  445. }
  446. this.UpdateLayout();
  447. }
  448. }
  449. /// <summary>
  450. /// 关闭按钮单击事件
  451. /// </summary>
  452. /// <param name="sender"></param>
  453. /// <param name="e"></param>
  454. private void CloseButtonClick(object sender, RoutedEventArgs e)
  455. {
  456. HideApp();
  457. }
  458. ///// <summary>
  459. ///// 左侧栏宽度改变 持久化
  460. ///// </summary>
  461. ///// <param name="sender"></param>
  462. ///// <param name="e"></param>
  463. //private void LeftCardResize(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
  464. //{
  465. // appData.AppConfig.MenuCardWidth = LeftColumn.Width.Value;
  466. //}
  467. /// <summary>
  468. /// 右键任务栏图标 显示主面板
  469. /// </summary>
  470. /// <param name="sender"></param>
  471. /// <param name="e"></param>
  472. public void ShowApp(object sender, RoutedEventArgs e)
  473. {
  474. ShowApp();
  475. }
  476. public static void ShowApp()
  477. {
  478. //有全屏化应用则不显示
  479. //if (CommonCode.IsPrimaryFullScreen())
  480. //{
  481. // return;
  482. //}
  483. if (MarginHide.ON_HIDE)
  484. {
  485. //修改贴边隐藏状态为未隐藏
  486. MarginHide.IS_HIDE = false;
  487. if (!CommonCode.MouseInWindow(mainWindow))
  488. {
  489. RunTimeStatus.MARGIN_HIDE_AND_OTHER_SHOW = true;
  490. MarginHide.WaitHide(3000);
  491. }
  492. }
  493. if (appData.AppConfig.FollowMouse)
  494. {
  495. ShowWindowFollowMouse.Show(mainWindow, MousePosition.CENTER, 0, 0);
  496. }
  497. MainWindow.mainWindow.Activate();
  498. mainWindow.Show();
  499. //mainWindow.Visibility = Visibility.Visible;
  500. if (appData.AppConfig.AppAnimation)
  501. {
  502. appData.AppConfig.IsShow = true;
  503. }
  504. else
  505. {
  506. appData.AppConfig.IsShow = null;
  507. //防止永远不显示界面
  508. if (mainWindow.Opacity < 1)
  509. {
  510. mainWindow.Opacity = 1;
  511. }
  512. }
  513. //FadeStoryBoard(1, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Visible);
  514. Keyboard.Focus(mainWindow);
  515. if (RunTimeStatus.SHOW_MENU_PASSWORDBOX)
  516. {
  517. mainWindow.RightCard.PDDialog.SetFocus();
  518. }
  519. else
  520. {
  521. Keyboard.Focus(mainWindow.SearchBox);
  522. }
  523. }
  524. public static void HideApp()
  525. {
  526. if (appData.AppConfig.AppAnimation)
  527. {
  528. appData.AppConfig.IsShow = false;
  529. }
  530. else
  531. {
  532. appData.AppConfig.IsShow = null;
  533. HideAppVis();
  534. }
  535. }
  536. private static void HideAppVis()
  537. {
  538. //关闭锁定
  539. RunTimeStatus.LOCK_APP_PANEL = false;
  540. if (RunTimeStatus.SEARCH_BOX_SHOW)
  541. {
  542. mainWindow.HidedSearchBox();
  543. }
  544. mainWindow.Visibility = Visibility.Collapsed;
  545. //if (!MarginHide.IS_HIDE)
  546. //{
  547. //}
  548. //else
  549. //{
  550. // ShowApp();
  551. //}
  552. }
  553. /// <summary>
  554. /// 淡入淡出效果
  555. /// </summary>
  556. /// <param name="opacity"></param>
  557. /// <param name="milliseconds"></param>
  558. /// <param name="visibility"></param>
  559. public static void FadeStoryBoard(int opacity, int milliseconds, Visibility visibility)
  560. {
  561. if (appData.AppConfig.AppAnimation)
  562. {
  563. DoubleAnimation opacityAnimation = new DoubleAnimation
  564. {
  565. From = mainWindow.Opacity,
  566. To = opacity,
  567. Duration = new Duration(TimeSpan.FromMilliseconds(milliseconds))
  568. };
  569. opacityAnimation.Completed += (s, e) =>
  570. {
  571. mainWindow.BeginAnimation(OpacityProperty, null);
  572. if (visibility == Visibility.Visible)
  573. {
  574. mainWindow.Opacity = 1;
  575. }
  576. else
  577. {
  578. mainWindow.Opacity = 0;
  579. CommonCode.SortIconList();
  580. }
  581. };
  582. Timeline.SetDesiredFrameRate(opacityAnimation, 60);
  583. mainWindow.BeginAnimation(OpacityProperty, opacityAnimation);
  584. }
  585. else
  586. {
  587. //防止关闭动画后 窗体仍是0透明度
  588. mainWindow.Opacity = 1;
  589. mainWindow.Visibility = visibility;
  590. if (visibility == Visibility.Collapsed)
  591. {
  592. CommonCode.SortIconList();
  593. }
  594. }
  595. }
  596. /// <summary>
  597. /// 图片图标单击事件
  598. /// </summary>
  599. /// <param name="sender"></param>
  600. /// <param name="e"></param>
  601. private void NotifyIcon_Click(object sender, RoutedEventArgs e)
  602. {
  603. if (CheckSholeShowApp())
  604. {
  605. ShowApp();
  606. }
  607. else
  608. {
  609. HideApp();
  610. }
  611. }
  612. private static bool CheckSholeShowApp()
  613. {
  614. return mainWindow.Visibility == Visibility.Collapsed
  615. || mainWindow.Opacity == 0
  616. || MarginHide.IS_HIDE
  617. || !WindowUtil.WindowIsTop(mainWindow);
  618. }
  619. /// <summary>
  620. /// 右键任务栏图标 设置
  621. /// </summary>
  622. /// <param name="sender"></param>
  623. /// <param name="e"></param>
  624. private void ConfigApp(object sender, RoutedEventArgs e)
  625. {
  626. ConfigWindow.Show(appData.AppConfig, this);
  627. }
  628. /// <summary>
  629. /// 右键任务栏图标打开程序目录
  630. /// </summary>
  631. /// <param name="sender"></param>
  632. /// <param name="e"></param>
  633. private void OpenThisDir(object sender, RoutedEventArgs e)
  634. {
  635. Process p = new Process();
  636. p.StartInfo.FileName = "Explorer.exe";
  637. p.StartInfo.Arguments = "/e,/select," + Constants.APP_DIR + Constants.MY_NAME + ".exe";
  638. p.Start();
  639. }
  640. /// <summary>
  641. /// 设置图标
  642. /// </summary>
  643. /// <param name="sender"></param>
  644. /// <param name="e"></param>
  645. private void ConfigButtonClick(object sender, RoutedEventArgs e)
  646. {
  647. SettingMenus.IsOpen = true;
  648. }
  649. /// <summary>
  650. /// 设置菜单点击
  651. /// </summary>
  652. /// <param name="sender"></param>
  653. /// <param name="e"></param>
  654. private void ConfigMenuClick(object sender, RoutedEventArgs e)
  655. {
  656. ConfigWindow.Show(appData.AppConfig, this);
  657. }
  658. /// <summary>
  659. /// 待办任务
  660. /// </summary>
  661. /// <param name="sender"></param>
  662. /// <param name="e"></param>
  663. private void BacklogMenuClick(object sender, RoutedEventArgs e)
  664. {
  665. ToDoWindow.Show();
  666. }
  667. /// <summary>
  668. /// 禁用设置按钮右键菜单
  669. /// </summary>
  670. /// <param name="sender"></param>
  671. /// <param name="e"></param>
  672. private void SettingButton_Initialized(object sender, EventArgs e)
  673. {
  674. SettingButton.ContextMenu = null;
  675. }
  676. private void AppWindowLostFocus()
  677. {
  678. if (appData.AppConfig.AppHideType == AppHideType.LOST_FOCUS
  679. && this.Opacity == 1 && !RunTimeStatus.LOCK_APP_PANEL)
  680. {
  681. //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
  682. if (!appData.AppConfig.MarginHide || (appData.AppConfig.MarginHide && !MarginHide.IS_HIDE))
  683. {
  684. HideApp();
  685. }
  686. }
  687. }
  688. private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
  689. {
  690. if (this.DataContext != null)
  691. {
  692. AppData appData = this.DataContext as AppData;
  693. appData.AppConfig.WindowWidth = this.Width;
  694. appData.AppConfig.WindowHeight = this.Height;
  695. }
  696. }
  697. /// <summary>
  698. /// 右键任务栏图标退出
  699. /// </summary>
  700. /// <param name="sender"></param>
  701. /// <param name="e"></param>
  702. private void ExitApp(object sender, RoutedEventArgs e)
  703. {
  704. if (appData.AppConfig.MouseMiddleShow || appData.AppConfig.SecondsWindow == true)
  705. {
  706. MouseHookThread.Dispose();
  707. }
  708. if (appData.AppConfig.EnableEveryThing == true)
  709. {
  710. EveryThingUtil.DisableEveryThing();
  711. }
  712. Application.Current.Shutdown();
  713. }
  714. /// <summary>
  715. /// 重启
  716. /// </summary>
  717. /// <param name="sender"></param>
  718. /// <param name="e"></param>
  719. private void ReStartApp(object sender, RoutedEventArgs e)
  720. {
  721. if (appData.AppConfig.MouseMiddleShow || appData.AppConfig.SecondsWindow == true)
  722. {
  723. MouseHookThread.Dispose();
  724. }
  725. Process p = new Process();
  726. p.StartInfo.FileName = Constants.APP_DIR + "GeekDesk.exe";
  727. p.StartInfo.WorkingDirectory = Constants.APP_DIR;
  728. p.Start();
  729. Application.Current.Shutdown();
  730. }
  731. /// <summary>
  732. /// 关闭托盘图标
  733. /// </summary>
  734. /// <param name="sender"></param>
  735. /// <param name="e"></param>
  736. private void CloseBarIcon(object sender, RoutedEventArgs e)
  737. {
  738. appData.AppConfig.ShowBarIcon = false;
  739. }
  740. public void OnKeyDown(object sender, KeyEventArgs e)
  741. {
  742. //char c = (char)e.Key;
  743. if (e.Key == Key.Escape)
  744. {
  745. HideApp();
  746. }
  747. if (RunTimeStatus.SEARCH_BOX_SHOW && (e.Key == Key.Up
  748. || e.Key == Key.Down
  749. || e.Key == Key.Tab
  750. || e.Key == Key.Enter
  751. ))
  752. {
  753. if (e.Key == Key.Down || e.Key == Key.Tab)
  754. {
  755. RightCard.SearchListBoxIndexAdd();
  756. }
  757. else if (e.Key == Key.Up)
  758. {
  759. RightCard.SearchListBoxIndexSub();
  760. }
  761. else if (e.Key == Key.Enter)
  762. {
  763. RightCard.StartupSelectionItem();
  764. }
  765. }
  766. }
  767. /// <summary>
  768. /// 为了让修改菜单的textBox失去焦点
  769. /// </summary>
  770. /// <param name="sender"></param>
  771. /// <param name="e"></param>
  772. private void MainWindow_MouseDown(object sender, MouseButtonEventArgs e)
  773. {
  774. SearchBox.Focus();
  775. }
  776. /// <summary>
  777. /// 鼠标进入后
  778. /// </summary>
  779. /// <param name="sender"></param>
  780. /// <param name="e"></param>
  781. private void MainWindow_MouseEnter(object sender, MouseEventArgs e)
  782. {
  783. //防止延迟贴边隐藏
  784. RunTimeStatus.MARGIN_HIDE_AND_OTHER_SHOW = false;
  785. }
  786. /// <summary>
  787. /// 打开屏幕拾色器
  788. /// </summary>
  789. /// <param name="sender"></param>
  790. /// <param name="e"></param>
  791. private void ColorPicker(object sender, RoutedEventArgs e)
  792. {
  793. TaskbarContextMenu.IsOpen = false;
  794. GlobalColorPickerWindow.CreateNoShow();
  795. }
  796. private void Window_GotFocus(object sender, RoutedEventArgs e)
  797. {
  798. // 如果没有在修改菜单 并且不是右键点击了面板
  799. if (!RunTimeStatus.IS_MENU_EDIT
  800. && !RunTimeStatus.SHOW_RIGHT_BTN_MENU
  801. && !RunTimeStatus.APP_BTN_IS_DOWN)
  802. {
  803. if (RunTimeStatus.SHOW_MENU_PASSWORDBOX)
  804. {
  805. //必须在其它文本框没有工作的时候才给密码框焦点
  806. RightCard.PDDialog.SetFocus();
  807. }
  808. else
  809. {
  810. //必须在其它文本框没有工作的时候才给搜索框焦点
  811. Keyboard.Focus(SearchBox);
  812. }
  813. }
  814. }
  815. private void AppWindow_Deactivated(object sender, EventArgs e)
  816. {
  817. AppWindowLostFocus();
  818. }
  819. /// <summary>
  820. /// 备份数据文件
  821. /// </summary>
  822. /// <param name="sender"></param>
  823. /// <param name="e"></param>
  824. [Obsolete]
  825. private void BakDataFile(object sender, RoutedEventArgs e)
  826. {
  827. Thread t = new Thread(() =>
  828. {
  829. CommonCode.BakAppData();
  830. });
  831. t.ApartmentState = ApartmentState.STA;
  832. t.Start();
  833. }
  834. private void AppButton_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  835. {
  836. //点击了面板
  837. RunTimeStatus.APP_BTN_IS_DOWN = true;
  838. new Thread(() =>
  839. {
  840. Thread.Sleep(50);
  841. RunTimeStatus.APP_BTN_IS_DOWN = false;
  842. }).Start();
  843. }
  844. private ICommand _hideCommand;
  845. public ICommand HideCommand
  846. {
  847. get
  848. {
  849. if (_hideCommand == null)
  850. {
  851. _hideCommand = new RelayCommand(
  852. p =>
  853. {
  854. return true;
  855. },
  856. p =>
  857. {
  858. HideAppVis();
  859. });
  860. }
  861. return _hideCommand;
  862. }
  863. }
  864. protected override void OnSourceInitialized(EventArgs e)
  865. {
  866. base.OnSourceInitialized(e);
  867. HwndSource hwndSource = PresentationSource.FromVisual(this) as HwndSource;
  868. if (hwndSource != null)
  869. {
  870. IntPtr handle = hwndSource.Handle;
  871. hwndSource.AddHook(new HwndSourceHook(WndProc));
  872. }
  873. }
  874. IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
  875. {
  876. if (msg == MessageUtil.WM_COPYDATA)
  877. {
  878. MessageUtil.CopyDataStruct cds = (MessageUtil.CopyDataStruct)System.Runtime.InteropServices.Marshal.PtrToStructure(lParam, typeof(MessageUtil.CopyDataStruct));
  879. if ("ShowApp".Equals(cds.msg))
  880. {
  881. ShowApp();
  882. }
  883. }
  884. return hwnd;
  885. }
  886. }
  887. }